Category Archives: Uncategorized

Delegates for c#

Doubly Linked List

Situations for using a Doubly Linked list would be

  • deck of cards
  • browser cache
  • Metro

A new node’s previous points left, and next points right. When we add a new node, we pass in the linked list’s tail into the new Node’s constructor.

The new Node will re-wire it so that its previous points to the last node of the linked list (via the tail).

Then have the next of the last node point to the new Node.

Then, the linked list will proceed to re-assign the tail to the new node. Thus, completing the push.

Also, each node is connected with each by 2 traits:

  • The first node’s next points to the second node. The first node’s previous points to the node on its left side. (or bottom, if you are looking at it vertically)
  • The second node’s previous points to the first node. And its next points to the node on its right side. (or top, if you are looking at it vertically)

Getter/Setters

Getter setter is done by first declaring a name that matches your property but with a capital first letter. Then, you use keywords get and write a function for when you retrieve the property.

Use keyword set to write a function where you assign another value to your property. The incoming value is designated as keyword “value”. The value keyword is a contextual keyword, that is, it has a different meaning based on its context.

Inside a set block, it simply means the value that the programmer has set it to.

Outside of a set block, you can use value as a variable identifier, as such:
int value = 5;

You’d use it like this:

myList.Count = 222;

Doubly Linked List source

queue

For queues, we append new node at the tail end, and the tail take on its next.

The head pointer stays in place at the first node. When we execute something, we pop from the queue, and the head moves to next.

Stack

Stack appends (or pushes) at the end. And pops at the end also. hence, all we need is one pointer to do that.

Abstraction

Abstraction

Abstraction is the tactic of stripping an idea or object of its unnecessary accompaniments until you are left with its essential, minimal form. A good abstraction clears away unimportant details and allows you to focus and concentrate on the important details.

  • Declare the abstract class, then use keyword abstract to define your abstraction methods
  • Create a class, and conform to that abstraction
  • Once conformed, use keyword override to implement for that abstraction

Classes and Structs

http://stackoverflow.com/questions/521298/when-to-use-struct

Struct

Struct is a blueprint for a value – no identity, no accessible state, no added behavior (methods).

Variables of struct type are strictly called values.

Value types are the types found at the lowest level of a program. They are the elements used to build larger software entities. Value types can be freely copied and exist on the stack as local variables or as attributes inside the objects they describe.

Consider defining a structure instead of a class if instances of the type are small and commonly short-lived or are commonly embedded in other objects.

Do not define a structure unless the type has all of the following characteristics:

It logically represents a single value, similar to primitive types (integer, double, and so on).
It has an instance size smaller than 16 bytes.
It is immutable.
It will not have to be boxed frequently.

notes –

In addition, realize that when a struct implements an interface – as Enumerator does – and is cast to that implemented type, the struct becomes a reference type and is moved to the heap.

Whenever you don’t need polymorphism, want value semantics, and want to avoid heap allocation and the associated garbage collection overhead. The caveat, however, is that structs (arbitrarily large) are more expensive to pass around than class references (usually one machine word), so classes could end up being faster in practice.

Class

A class is a blueprint for an object.

It has identity. Identity is an instantiated object with its own state.
It has accessible state (private variables), added behavior (methods).

Types represented by classes are called reference types.
Reference types are the types found at the higher levels of a program. They are built from smaller software entities. Reference types generally cannot be copied, and they exist on the heap.

If you copy a struct, C# creates a new copy of the object and assigns the copy of the object to a separate struct instance. Thus, we’re dealing with the object itself.

However, if you copy a class, C# creates a new copy of the reference to the object and assigns the copy of the reference to the separate class instance. We’re dealing with the address here.

Access Token, Refresh Token

https://medium.com/@bantic/more-oauth-2-0-surprises-the-refresh-token-1831d71f4af6#.i6aemn6ol

https://auth0.com/learn/refresh-tokens/

Since access tokens are so powerful yet also so potentially insecure, their risk is mitigated by giving them short-lived expiration windows.

Hence an access token returned by Azure iOS client framework will last for 1 hour. Within that hour, you can access data from your Easy Table. After an hour, you will get an authentication error.

However, this introduces another difficulty for web programmers — how to continue to access data on behalf of your users when their access tokens expire? Enter refresh tokens.

Refresh Token

What is a Refresh Token?

A Refresh Token is a special kind of token that can be used to obtain a renewed access token. An access token allows accessing a protected resource (i.e https://abc-123.azurewebsites.net/TodoItems) at any time.

You can keep requesting new access tokens until the refresh token expires.

Refresh tokens must be stored securely by an application because they essentially allow a user to remain authenticated forever.

How Refresh Tokens work

An Access Token is required to access a protected resource. Thus, a client will use a Refresh Token to get that Access Token, which is issued by the Authentication Server.

Although Access Tokens can be renewed at any time using Refresh Tokens, they should be renewed when old ones have expired, or when getting access to a new resource for the first time. Refresh Tokens can also expire but are rather long-lived. They are usually subject to strict storage requirements to ensure they are not leaked. Nevertheless, they can be blacklisted by the authorization server.

A Refresh Token is used to obtain new Access Tokens (and access protected resources) until it is expires (which may take a long time).

Access Tokens must also be kept secret, but due to its shorter life, security considerations are less critical.

In the case of Azure Active Directory refresh tokens

When refresh tokens were first explained to me, I was told something along the lines that a refresh token is used to refresh an access token. The word “refresh” certainly implies that that is the case. When I thought about it this way I imagine the access token as a battery-operated toy with dead batteries. It is “stale”, and cannot be used. In order to “refresh” it you replace the batteries and now the freshened toy works again.

But that is not what a refresh token does. Access tokens do not become stale only to be refreshed later on and reused. Access tokens expire, never to be valid again. A refresh token is not tied to an access token. It is simply used to get a new, valid access token when you need it.

How do you know when your access token is not valid? By attempting to use it and having the OAuth provider reject it.

Azure AAD token notes

http://cgillum.tech/2016/03/07/app-service-token-store/

Please, correct me if I’m wrong:
– the first time end-user uses my xamarin app (google authentication), he gets a token that will expire in 1 hour, after that, he finishes use my app and closes it.
– Three hours later, he opens the app and tries to access data from an azure table (for example): in this case, now, his “old” token is expired so, using your code above, he gets a “new” refresh token and he is able to obtain his data from azure. Perfect.

And now, what happens? will this new refreshed token expire in one hour like the first one?
So, does he have to get a new one in 72-hours? And so on with the cycle?
If not, “a fresh re-auth by the end-user will be required to get a new, non-expired authentication token”?

cgillum says:
May 25, 2016 at 9:31 am
Your understanding is correct. Refreshed tokens will have the same lifetime as the original tokens (1 hour in the case of Google). The tokens can be refreshed at anytime before or within the 72-hour window without requiring a re-auth. This will be a regular cycle within your app.

When the Access Token expires, you can use the Refresh Token to get a new Access Token. This Access token, along with the 1st access token, all expire in 1 hour. You can continue to use refresh token to request access tokens. The standard request token expiration date is 14 days. After 14 days, you need to sign in again.

Install Azure iOS SDK (framework)

azuresdk-ios-v3-2-0

http://azure.github.io/azure-mobile-apps-ios-client/
http://stackoverflow.com/questions/27615041/uiwebview-and-wkwebview

First, unzip the framework. Drag the framework into your project.

Then, you may get a
undefined symbols for architecture arm64 MSLoginView

Solution:
Go to your Project, click on General, scroll down to Linked Frameworks and Libraries, and add WebKit.framework as Optional.

Async Fetch Request – part 2

xCode 7.3 AsyncFetchRequestEx2

Fetch Request

Result Block

The Async Fetch Request

Perform the async fetch request with a context

Deleting in Azure

Given that a refresh pull involves pulling data that is filtered according to an attribute, Soft Delete involves setting that attribute to YES/NO. This affects clients in that they will then not be able to pull that data. Additionally, that data is kept safe in Easy Table for future references and undeletes.

For example, let’s say you create an attribute “complete”.
When pulling data, you may specify that you want to pull all data that has NO for attribute “complete”.

Once you assign YES for attribute complete on say row 88, client refresh pulls will not include row 88 anymore. It will include all rows with NO for attribute “complete”.

When fetching from your fetch controller/core data, simply filter data according to complete == NO.

HARD DELETE – Delete on Local and Server

If you want to remove local AND server data, all you have to do is call the delete method from your MSSyncTable.

It sends a request to your local data source to remove the given item, then queues a request to send the delete to the mobile service.

It first removes the data locally.
Then, when the queued request goes through into the mobile service, then it will update remotely, and you can log into your Azure account, look at the Easy Tables, and see that the item has been removed.

Notes

Do not remove data by hand on the backend directly. Currently, MS have no way to re-syncing, and your client app will have many error messages on its request queue.