/**
         * Invokes the given method specified in the API request object.
         *
         * @param request APIRequest object containing method name and parameters.
         * @return APIResponse with status code, message and JSON response or a JSON null string for void functions. Status code 200 is OK, all others are HTTP standard error conditions.
         */
        public new APIResponse Invoke(APIRequest request)
        {
            APIResponse response        = new APIResponse();
            int         responseCode    = 200;
            String      responseMessage = "OK";
            String      responseJSON    = "null";

            switch (request.GetMethodName())
            {
            case "canRead":
                FileDescriptor descriptor0 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                bool           response0   = this.CanRead(descriptor0);
                responseJSON = GetJSONProcessor().SerializeObject(response0);
                break;

            case "canWrite":
                FileDescriptor descriptor1 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                bool           response1   = this.CanWrite(descriptor1);
                responseJSON = GetJSONProcessor().SerializeObject(response1);
                break;

            case "create":
                FileDescriptor      descriptor2 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                IFileResultCallback callback2   = new FileResultCallbackImpl(request.GetAsyncId());
                this.Create(descriptor2, callback2);
                break;

            case "delete":
                FileDescriptor descriptor3 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                bool           cascade3    = GetJSONProcessor().DeserializeObject <bool>(request.GetParameters()[1]);
                bool           response3   = this.Delete(descriptor3, cascade3);
                responseJSON = GetJSONProcessor().SerializeObject(response3);
                break;

            case "exists":
                FileDescriptor descriptor4 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                bool           response4   = this.Exists(descriptor4);
                responseJSON = GetJSONProcessor().SerializeObject(response4);
                break;

            case "getContent":
                FileDescriptor descriptor5            = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                IFileDataLoadResultCallback callback5 = new FileDataLoadResultCallbackImpl(request.GetAsyncId());
                this.GetContent(descriptor5, callback5);
                break;

            case "getFileStorageType":
                FileDescriptor         descriptor6 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                IFileSystemStorageType response6   = this.GetFileStorageType(descriptor6);
                responseJSON = GetJSONProcessor().SerializeObject(response6);
                break;

            case "getFileType":
                FileDescriptor  descriptor7 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                IFileSystemType response7   = this.GetFileType(descriptor7);
                responseJSON = GetJSONProcessor().SerializeObject(response7);
                break;

            case "getSecurityType":
                FileDescriptor      descriptor8 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                IFileSystemSecurity response8   = this.GetSecurityType(descriptor8);
                responseJSON = GetJSONProcessor().SerializeObject(response8);
                break;

            case "isDirectory":
                FileDescriptor descriptor9 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                bool           response9   = this.IsDirectory(descriptor9);
                responseJSON = GetJSONProcessor().SerializeObject(response9);
                break;

            case "listFiles":
                FileDescriptor          descriptor10 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                IFileListResultCallback callback10   = new FileListResultCallbackImpl(request.GetAsyncId());
                this.ListFiles(descriptor10, callback10);
                break;

            case "listFilesForRegex":
                FileDescriptor          descriptor11 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                string                  regex11      = GetJSONProcessor().DeserializeObject <string>(request.GetParameters()[1]);
                IFileListResultCallback callback11   = new FileListResultCallbackImpl(request.GetAsyncId());
                this.ListFilesForRegex(descriptor11, regex11, callback11);
                break;

            case "mkDir":
                FileDescriptor descriptor12 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                bool           recursive12  = GetJSONProcessor().DeserializeObject <bool>(request.GetParameters()[1]);
                bool           response12   = this.MkDir(descriptor12, recursive12);
                responseJSON = GetJSONProcessor().SerializeObject(response12);
                break;

            case "move":
                FileDescriptor      source13      = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                FileDescriptor      destination13 = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[1]);
                bool                createPath13  = GetJSONProcessor().DeserializeObject <bool>(request.GetParameters()[2]);
                bool                overwrite13   = GetJSONProcessor().DeserializeObject <bool>(request.GetParameters()[3]);
                IFileResultCallback callback13    = new FileResultCallbackImpl(request.GetAsyncId());
                this.Move(source13, destination13, createPath13, overwrite13, callback13);
                break;

            case "setContent":
                FileDescriptor descriptor14             = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                byte[]         content14                = GetJSONProcessor().DeserializeObject <byte[]>(request.GetParameters()[1]);
                IFileDataStoreResultCallback callback14 = new FileDataStoreResultCallbackImpl(request.GetAsyncId());
                this.SetContent(descriptor14, content14, callback14);
                break;

            default:
                // 404 - response null.
                responseCode    = 404;
                responseMessage = "FileBridge does not provide the function '" + request.GetMethodName() + "' Please check your client-side API version; should be API version >= v2.2.15.";
                break;
            }
            response.SetResponse(responseJSON);
            response.SetStatusCode(responseCode);
            response.SetStatusMessage(responseMessage);
            return(response);
        }
 /**
  * Result with warning of data retrieval/storage operation.
  *
  * @param file    File being loaded/stored.
  * @param warning Warning condition encountered.
  * @since v2.0
  */
 public void OnWarning(FileDescriptor file, IFileDataStoreResultCallbackWarning warning)
 {
     AppRegistryBridge.GetInstance().GetPlatformContextWeb().ExecuteJavaScript("Adaptive.handleFileDataStoreResultCallbackWarning( '" + GetId() + "', JSON.parse(" + GetJSONProcessor().SerializeObject(file) + "), JSON.parse(" + GetJSONProcessor().SerializeObject(warning) + ") )");
 }
        /**
         * Invokes the given method specified in the API request object.
         *
         * @param request APIRequest object containing method name and parameters.
         * @return APIResponse with status code, message and JSON response or a JSON null string for void functions. Status code 200 is OK, all others are HTTP standard error conditions.
         */
        public new APIResponse Invoke(APIRequest request)
        {
            APIResponse response        = new APIResponse();
            int         responseCode    = 200;
            String      responseMessage = "OK";
            String      responseJSON    = "null";

            switch (request.GetMethodName())
            {
            case "createFileDescriptor":
                FileDescriptor parent0   = GetJSONProcessor().DeserializeObject <FileDescriptor>(request.GetParameters()[0]);
                string         name0     = GetJSONProcessor().DeserializeObject <string>(request.GetParameters()[1]);
                FileDescriptor response0 = this.CreateFileDescriptor(parent0, name0);
                if (response0 != null)
                {
                    responseJSON = GetJSONProcessor().SerializeObject(response0);
                }
                break;

            case "getApplicationCacheFolder":
                FileDescriptor response1 = this.GetApplicationCacheFolder();
                if (response1 != null)
                {
                    responseJSON = GetJSONProcessor().SerializeObject(response1);
                }
                break;

            case "getApplicationCloudFolder":
                FileDescriptor response2 = this.GetApplicationCloudFolder();
                if (response2 != null)
                {
                    responseJSON = GetJSONProcessor().SerializeObject(response2);
                }
                break;

            case "getApplicationDocumentsFolder":
                FileDescriptor response3 = this.GetApplicationDocumentsFolder();
                if (response3 != null)
                {
                    responseJSON = GetJSONProcessor().SerializeObject(response3);
                }
                break;

            case "getApplicationFolder":
                FileDescriptor response4 = this.GetApplicationFolder();
                if (response4 != null)
                {
                    responseJSON = GetJSONProcessor().SerializeObject(response4);
                }
                break;

            case "getApplicationProtectedFolder":
                FileDescriptor response5 = this.GetApplicationProtectedFolder();
                if (response5 != null)
                {
                    responseJSON = GetJSONProcessor().SerializeObject(response5);
                }
                break;

            case "getSeparator":
                char response6 = this.GetSeparator();
                responseJSON = GetJSONProcessor().SerializeObject(response6);
                break;

            case "getSystemExternalFolder":
                FileDescriptor response7 = this.GetSystemExternalFolder();
                if (response7 != null)
                {
                    responseJSON = GetJSONProcessor().SerializeObject(response7);
                }
                break;

            default:
                // 404 - response null.
                responseCode    = 404;
                responseMessage = "FileSystemBridge does not provide the function '" + request.GetMethodName() + "' Please check your client-side API version; should be API version >= v2.2.15.";
                break;
            }
            response.SetResponse(responseJSON);
            response.SetStatusCode(responseCode);
            response.SetStatusMessage(responseMessage);
            return(response);
        }
Esempio n. 4
0
 /**
  * On correct result of a file operation.
  *
  * @param storageFile Reference to the resulting file.
  * @since v2.0
  */
 public void OnResult(FileDescriptor storageFile)
 {
     AppRegistryBridge.GetInstance().GetPlatformContextWeb().ExecuteJavaScript("Adaptive.handleFileResultCallbackResult( '" + GetId() + "', JSON.parse(" + GetJSONProcessor().SerializeObject(storageFile) + ") )");
 }