Exemplo n.º 1
0
        public async Task <bool> MakeFolder(string filespaceId, string path)
        {
            Log.LogDebug("MakeFolder: filespaceId={0}, path={1}", filespaceId, path);
            try
            {
                var mkDirParams = new MkDir
                {
                    filespaceid = filespaceId,
                    path        = path,//WebUtility.UrlEncode(path),
                    force       = true
                };

                var mkDirResult = await ExecuteRequest <MkDirResult>(Ticket, "MkDir", mkDirParams);

                if (mkDirResult != null)
                {
                    if (mkDirResult.success)
                    {
                        return(true);
                    }
                    CheckForInvalidTicket(mkDirResult, "MakeFolder");
                    return(mkDirResult.success);
                }
            }
            catch (Exception ex)
            {
                Log.LogError(ex, "Failed to make directory");
            }
            return(false);
        }
Exemplo n.º 2
0
        public Response DispatchCommand()
        {
            var cmdName = Parameters["cmd"];

            if (string.IsNullOrEmpty(cmdName))
            {
                return new ErrorResponse("Command not set");
            }

            ICommand cmd = null;

            switch (cmdName)
            {
                case "open":
                    if (!string.IsNullOrEmpty(Parameters["init"]) && Parameters["init"] == "true")
                        cmd = new Init();
                    else
                    {
                        cmd = new Open(Parameters["target"]);
                    }
                    break;
                case "mkdir":
                    cmd = new MkDir(Parameters["current"], Parameters["name"]);
                    break;
                case "rm":
                    cmd = new Rm(Parameters["current"], Parameters["targets[]"]);
                    break;
                case "rename":
                    cmd = new Rename(Parameters["current"], Parameters["target"], Parameters["name"]);
                    break;
                case "upload":
                    cmd = new Upload(Parameters["current"], Files);
                    break;
                case "ping":
                    cmd = new Ping();
                    break;
                case "duplicate":
                    cmd = new Duplicate(Parameters["current"], Parameters["target"]);
                    break;
                case "paste":
                    cmd = new Paste(Parameters["src"], Parameters["dst"], Parameters["targets[]"], Parameters["cut"]);
                    break;
            }

            if (cmd == null)
            {
                return new ErrorResponse("Unknown command");
            }

            return cmd.Execute();

            return new ErrorResponse("Unknown error");
        }
Exemplo n.º 3
0
        public bool CopyFile(Organization org, string srcFullName, string dstFullName)
        {
            Log.DebugFormat("CopyFile: org={0} {1}, srcFullName={2}, dstFullName={3}", org.shortName, org.filespaceId,
                            srcFullName, dstFullName);
            try
            {
                if (!FolderExists(org.filespaceId, dstFullName.Substring(0, dstFullName.LastIndexOf("/")) + "/"))
                {
                    MkDir mkdirParams = new MkDir()
                    {
                        filespaceid = org.filespaceId,
                        force       = true,
                        path        = dstFullName.Substring(0, dstFullName.LastIndexOf("/")) + "/"
                    };
                    var resultCreate = ExecuteRequest(Ticket, Method.GET, "/tcc/MkDir", mkdirParams, typeof(ApiResult));
                    if (resultCreate == null)
                    {
                        Log.ErrorFormat("Can not create folder for org {0} folder {1}", org.shortName, dstFullName.Substring(0, dstFullName.LastIndexOf("/")) + "/");
                        return(false);
                    }
                }

                CopyParams copyParams = new CopyParams()
                {
                    filespaceid    = org.filespaceId,
                    path           = srcFullName,
                    newfilespaceid = org.filespaceId,
                    newPath        = dstFullName,
                    merge          = false,
                    replace        = true
                };
                var result = ExecuteRequest(Ticket, Method.GET, "/tcc/Copy", copyParams, typeof(ApiResult));
                if (result != null)
                {
                    if (result.success)
                    {
                        return(true);
                    }
                    CheckForInvalidTicket(result, "CopyFile");
                }
                else
                {
                    Log.ErrorFormat("Null result from CopyFile for org {0} file {1}", org.shortName, srcFullName);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Failed to copy TCC file for org {0} file {1}: {2}", org.shortName, srcFullName, ex.Message);
            }
            return(false);
        }
Exemplo n.º 4
0
        public bool MoveFile(Organization org, string srcFullName, string dstFullName)
        {
            const string FILE_CHECKED_OUT_ERROR_ID = "INVALID_OPERATION_FILE_IS_LOCKED";

            Log.LogDebug("MoveFile: org={0} {1}, srcFullName={2}, dstFullName={3}", org.shortName, org.filespaceId,
                         srcFullName, dstFullName);
            try
            {
                if (!FolderExists(org.filespaceId, dstFullName.Substring(0, dstFullName.LastIndexOf("/")) + "/"))
                {
                    var mkdirParams = new MkDir
                    {
                        filespaceid = org.filespaceId,
                        force       = true,
                        path        = dstFullName.Substring(0, dstFullName.LastIndexOf("/")) + "/"
                    };
                    var resultCreate = ExecuteRequest(Ticket, Method.GET, "/tcc/MkDir", mkdirParams, typeof(RenResult));
                    if (resultCreate == null)
                    {
                        Log.LogError("Can not create folder for org {0} folder {1}", org.shortName,
                                     dstFullName.Substring(0, dstFullName.LastIndexOf("/")) + "/");
                        return(false);
                    }
                }

                var renParams = new RenParams
                {
                    filespaceid    = org.filespaceId,
                    path           = srcFullName,
                    newfilespaceid = org.filespaceId,
                    newPath        = dstFullName,
                    merge          = false,
                    replace        = true
                };
                var result    = ExecuteRequest(Ticket, Method.GET, "/tcc/Ren", renParams, typeof(RenResult));
                var renResult = result as RenResult;
                if (renResult != null && !renResult.success && renResult.errorid.Contains(FILE_CHECKED_OUT_ERROR_ID))
                {
                    Log.LogInformation($"File {srcFullName} for org {org.shortName} is locked, attempting to cancel checkout");
                    var cancelled = CancelCheckout(org, srcFullName);
                    if (cancelled)
                    {
                        Log.LogInformation($"Retrying MoveFile for {srcFullName} for org {org.shortName}");
                        result    = ExecuteRequest(Ticket, Method.GET, "/tcc/Ren", renParams, typeof(RenResult));
                        renResult = result as RenResult;
                    }
                }

                if (renResult != null)
                {
                    if (renResult.success || renResult.errorid.Contains("INVALID_OPERATION_FILE_IS_LOCKED"))
                    {
                        return(true);
                    }
                    CheckForInvalidTicket(renResult, "MoveFile");
                }
                else
                {
                    Log.LogError("Null result from MoveFile for org {0} file {1}", org.shortName, srcFullName);
                }
            }
            catch (Exception ex)
            {
                Log.LogError("Failed to move TCC file for org {0} file {1}: {2}", org.shortName, srcFullName, ex.Message);
            }

            return(false);
        }