Class BaseHandler
Base API handler.
Inheritance
Namespace: Appearition.Common
Assembly: Appearition.SDK.dll
Syntax
public abstract class BaseHandler
Fields
JSON_FOLDER_NAME
Name of the folder where JSON data will be stored when appropriate.
Declaration
public const string JSON_FOLDER_NAME = "JSON"
Field Value
| Type | Description |
|---|---|
| System.String |
Methods
CopyFileToDestinationProcess(String, String, Action<Boolean>)
Copies the file from a source location to a given destination full path.
Declaration
protected static IEnumerator CopyFileToDestinationProcess(string pathToSourceFile, string pathToDestinationFile, Action<bool> onComplete = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | pathToSourceFile | Full path to the source file. |
| System.String | pathToDestinationFile | Full path to the destination file. |
| System.Action<System.Boolean> | onComplete | Called once the process has completed. Contains whether or not the operation was successful. |
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |
DecryptData(String)
Decrypts the given data using MD5 encryption, using the encryptionKey as a key.
Declaration
protected static string DecryptData(string data)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | data | Data. |
Returns
| Type | Description |
|---|---|
| System.String | The data. |
DeleteFileProcess(String, Action<Boolean>)
Deletes the file at a given path.
Declaration
protected static IEnumerator DeleteFileProcess(string pathToFile, Action<bool> onComplete = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | pathToFile | Full path to the file. |
| System.Action<System.Boolean> | onComplete | Called once the process has completed. Contains whether or not the operation was successful. |
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |
DownloadGenericFile(String, String, String, Boolean, Action<Byte[]>)
Downloads a file from the EMS to a given full path (including file name and extension). If the file already exists with a matching checksum, will load the local file instead.
Declaration
protected static IEnumerator DownloadGenericFile(string url, string fileFullPath, string checksum, bool saveFile, Action<byte[]> onComplete)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | url | Full URL where the file is located. |
| System.String | fileFullPath | The full path to the file that is about to get downloaded. |
| System.String | checksum | The checksum of the file's current version as it came down from the EMS. |
| System.Boolean | saveFile | Whether or not the downloaded file should be saved locally. |
| System.Action<System.Byte[]> | onComplete | Called once the process has completed. Contains the data that was downloaded and saved. |
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |
EncryptData(String)
Encrypts the given data using MD5 encryption, using the encryptionKey as a key.
Declaration
protected static string EncryptData(string data)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | data | Data. |
Returns
| Type | Description |
|---|---|
| System.String | The data. |
GetApiJsonFileFullPath<T, K>(UserProfile)
Generates a full path for a single API call. By default, any Handler process with offline capability will save the JSON content at the location generated.
Declaration
protected static string GetApiJsonFileFullPath<T, K>(UserProfile user)
where T : BaseApi, new()
where K : BaseHandler
Parameters
| Type | Name | Description |
|---|---|---|
| UserProfile | user |
Returns
| Type | Description |
|---|---|
| System.String |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
| K | Handler class |
GetApiJsonFileName<T>()
Generates a filename for a json file based on an API type and user profile.
Declaration
protected static string GetApiJsonFileName<T>()
where T : BaseApi, new()
Returns
| Type | Description |
|---|---|
| System.String |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
GetApiJsonFileName<T>(UserProfile)
Generates a filename for a json file based on an API type and user profile.
Declaration
protected static string GetApiJsonFileName<T>(UserProfile user)
where T : BaseApi, new()
Parameters
| Type | Name | Description |
|---|---|---|
| UserProfile | user | Related user |
Returns
| Type | Description |
|---|---|
| System.String | The json file name. |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
GetContentFromFileProcess(String, Action<Byte[]>)
Fetches the content of a local file at a given path.
Declaration
protected static IEnumerator GetContentFromFileProcess(string pathToFile, Action<byte[]> onComplete = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | pathToFile | The full path to the file. |
| System.Action<System.Byte[]> | onComplete | Called once the process has completed. Contains the content of the data of the Media. |
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |
GetHandlerJsonFolderPath<T>()
Fetches the folder name where the JSON files generated by the given type should be located.
Declaration
protected static string GetHandlerJsonFolderPath<T>()
where T : BaseHandler
Returns
| Type | Description |
|---|---|
| System.String | The json folder path. |
Type Parameters
| Name | Description |
|---|---|
| T | Handler class |
GetHandlerStoragePath<T>()
The name of the directory inside the root where all the content from this handler is to be saved.
Declaration
public static string GetHandlerStoragePath<T>()
where T : BaseHandler
Returns
| Type | Description |
|---|---|
| System.String |
Type Parameters
| Name | Description |
|---|---|
| T |
GetReusableApiRequest<T>()
Fetches (or creates) an API request sample of the given type. Stores them locally for reusable purpose.
Declaration
public static T GetReusableApiRequest<T>()
where T : BaseApi, new()
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T | The 1st type parameter. |
HandleSimpleOfflineApiContentLoadingWithCallback<T, K>(Action<T>, Action<EmsError>, Action<Boolean>)
Handles a simple offline loading of an API. The onSuccessContent should contain the call of the traditional onSuccess. Handles onFailure and onComplete automatically.
Declaration
protected static bool HandleSimpleOfflineApiContentLoadingWithCallback<T, K>(Action<T> onSuccessContent, Action<EmsError> onFailure, Action<bool> onComplete)
where T : BaseApi, new()
where K : BaseHandler
Parameters
| Type | Name | Description |
|---|---|---|
| System.Action<T> | onSuccessContent | |
| System.Action<EmsError> | onFailure | |
| System.Action<System.Boolean> | onComplete |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
| K | Handler class |
HandleSimpleOnlineOnlyApiInternetCheck(Action<Boolean>, Action<EmsError>, Action<Boolean>)
Handles a simple error handling of an online-only API. U se the value of internetCheckSuccess to determine whether to end the handler process upon the completion of this coroutine, and forward the onFailure and onComplete from the original process.
Declaration
protected static IEnumerator HandleSimpleOnlineOnlyApiInternetCheck(Action<bool> internetCheckSuccess, Action<EmsError> onFailure, Action<bool> onComplete)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Action<System.Boolean> | internetCheckSuccess | |
| System.Action<EmsError> | onFailure | |
| System.Action<System.Boolean> | onComplete |
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |
IsThereExistingMediaWithMatchingChecksum(String, String)
Whether or not the existing file's checksum matches a given checksum.
Declaration
public static bool IsThereExistingMediaWithMatchingChecksum(string fullPath, string checksum)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | fullPath | The full path to the file. |
| System.String | checksum | The checksum of the file's current version as it came down from the EMS. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Whether or not the existing file's checksum matches a given checksum. |
LoadJsonTextInFile<K>(String)
Reads a json file inside the handler's json data folder.
Declaration
protected static string LoadJsonTextInFile<K>(string jsonFileName)
where K : BaseHandler
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | jsonFileName |
Returns
| Type | Description |
|---|---|
| System.String |
Type Parameters
| Name | Description |
|---|---|
| K | Handler class |
SaveContentToFileProcess(Byte[], String, Action<Boolean>)
Saves the Media File data to the given path.
Declaration
protected static IEnumerator SaveContentToFileProcess(byte[] data, string pathToFile, Action<bool> onComplete = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | data | The content of this File. |
| System.String | pathToFile | The full path to the file. |
| System.Action<System.Boolean> | onComplete | Called once the process has completed. Contains whether or not the operation was successful. |
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |
SaveJsonData<K>(String, String)
Simply saves JSON data in the handler's specific folder and a given filename.
Declaration
protected static void SaveJsonData<K>(string data, string jsonFileName)
where K : BaseHandler
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | data | |
| System.String | jsonFileName |
Type Parameters
| Name | Description |
|---|---|
| K | Handler class |
SaveJsonData<T, K>(AppearitionRequest<T>)
Should only be called with a completed request. Saves the request outcome as a JSON file at a generated location.
Declaration
protected static void SaveJsonData<T, K>(AppearitionRequest<T> completedRequest)
where T : BaseApi, new()
where K : BaseHandler
Parameters
| Type | Name | Description |
|---|---|---|
| AppearitionRequest<T> | completedRequest |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
| K | Handler class |
SaveJsonData<T, K>(AppearitionRequest<T>, UserProfile)
Should only be called with a completed request. Saves the request outcome as a JSON file at a generated location.
Declaration
protected static void SaveJsonData<T, K>(AppearitionRequest<T> completedRequest, UserProfile user)
where T : BaseApi, new()
where K : BaseHandler
Parameters
| Type | Name | Description |
|---|---|---|
| AppearitionRequest<T> | completedRequest | |
| UserProfile | user |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
| K | Handler class |
SaveJsonData<T, K>(AppearitionRequest<T>, String)
Should only be called with a completed request. Saves the request outcome as a JSON file at a generated location with a custom file name.
Declaration
protected static void SaveJsonData<T, K>(AppearitionRequest<T> completedRequest, string customFileName)
where T : BaseApi, new()
where K : BaseHandler
Parameters
| Type | Name | Description |
|---|---|---|
| AppearitionRequest<T> | completedRequest | |
| System.String | customFileName |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
| K | Handler class |
TryToFetchOfflineRequestContent<T, K>()
Attempts to fetch the offline content, and returns a request holding the content if successful. Remember to handle the output request, and run the callbacks when necessary.
Declaration
protected static T TryToFetchOfflineRequestContent<T, K>()
where T : BaseApi, new()
where K : BaseHandler
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
| K | Handler class |
TryToFetchOfflineRequestContent<T, K>(UserProfile)
Attempts to fetch the offline content, and returns a request holding the content if successful.
Declaration
protected static T TryToFetchOfflineRequestContent<T, K>(UserProfile user)
where T : BaseApi, new()
where K : BaseHandler
Parameters
| Type | Name | Description |
|---|---|---|
| UserProfile | user |
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
| K | Handler class |
TryToFetchOfflineRequestContent<T, K>(String)
Attempts to fetch the offline content, and returns a request holding the content if successful.
Declaration
protected static T TryToFetchOfflineRequestContent<T, K>(string jsonFileName)
where T : BaseApi, new()
where K : BaseHandler
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | jsonFileName |
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T | API class |
| K | Handler class |