/// <summary>
        /// Upload contents recursively
        /// </summary>
        private void UploadRecursive(ShareFileClient client, int uploadId, FileSystemInfo source, Models.Item target, ActionType actionType)
        {
            if (source is DirectoryInfo)
            {
                var newFolder = new Models.Folder()
                {
                    Name = source.Name
                };
                bool isExist = false;

                if (Synchronize)
                {
                    try
                    {
                        string path = String.Format("/{0}", source.Name);
                        Item   item = null;
                        try
                        {
                            item = client.Items.ByPath(target.url, path).Execute();
                        }
                        catch (ODataException e)
                        {
                            if (e.Code != System.Net.HttpStatusCode.NotFound)
                            {
                                throw e;
                            }
                        }

                        if (item != null && item is Folder)
                        {
                            isExist   = true;
                            newFolder = (Folder)item;
                        }
                    }
                    catch { }
                }

                if (!isExist)
                {
                    newFolder = client.Items.CreateFolder(target.url, newFolder, OverWrite, false).Execute();
                }

                ActionManager actionManager = new ActionManager(this, source.Name);

                foreach (var fsInfo in ((DirectoryInfo)source).EnumerateFileSystemInfos())
                {
                    if (fsInfo is DirectoryInfo && Recursive)
                    {
                        UploadRecursive(client, uploadId, fsInfo, newFolder, actionType);
                    }
                    else if (fsInfo is FileInfo)
                    {
                        IAction uploadAction = new UploadAction(FileSupport, client, fsInfo, newFolder, Details, actionType);
                        actionManager.AddAction(uploadAction);
                    }
                }

                actionManager.Execute();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Start Upload to Sharefile location
        /// </summary>
        private void StartUpload(ShareFileClient client, int uploadId, Models.Item target, ICollection <string> resolvedPaths, ActionType actionType)
        {
            int transactionId = new Random((int)DateTime.Now.Ticks).Next();

            Logger.Instance.Info("Uploading files to ShareFile server.");

            ActionManager actionManager  = new ActionManager();
            bool          firstIteration = true;

            foreach (string path in resolvedPaths)
            {
                FileAttributes attr   = System.IO.File.GetAttributes(path);
                FileSystemInfo source = ((attr & FileAttributes.Directory) == FileAttributes.Directory) ? new DirectoryInfo(path) : source = new FileInfo(path);

                // create an extra parent folder if CreateRoot flag is specified on target location
                if (firstIteration && CreateRoot)
                {
                    DirectoryInfo parentFolder = Directory.GetParent(path);
                    var           newFolder    = new Models.Folder()
                    {
                        Name = parentFolder.Name
                    };
                    target         = client.Items.CreateFolder(target.url, newFolder, OverWrite, false).Execute();
                    firstIteration = false;
                }

                if (source is DirectoryInfo)
                {
                    UploadRecursive(client, uploadId, source, target, actionType);
                }
                else
                {
                    IAction uploadAction = new UploadAction(FileSupport, client, source, target, Details, actionType);
                    actionManager.AddAction(uploadAction);
                }
            }

            actionManager.Execute();

            if (Move)
            {
                foreach (string path in resolvedPaths)
                {
                    FileAttributes attr   = System.IO.File.GetAttributes(path);
                    FileSystemInfo source = ((attr & FileAttributes.Directory) == FileAttributes.Directory) ? new DirectoryInfo(path) : source = new FileInfo(path);

                    if (Strict && source is DirectoryInfo)
                    {
                        DeleteSharefileStrictRecursive(client, source as DirectoryInfo, target);
                    }

                    DeleteLocalItemRecursive(source, Recursive);
                }
            }
        }
Esempio n. 3
0
        private List <ExecutableAction> CreateActionsForFile(FileInfo fileInfo)
        {
            var actions = new List <ExecutableAction>();

            foreach (string profile in AppSettings.Default.TranscodingProfiles)
            {
                var    profileParts   = profile.Split('|');
                string profileName    = profileParts[0].Trim();
                string profileCommand = profileParts[1].Trim();

                string outputFileNameShort =
                    Path.GetFileNameWithoutExtension(fileInfo.Name) +
                    "-" + profileName + ".mp4";
                string outputFileNameFull = this.workDir + "\\" + outputFileNameShort;

                TranscodeAction transcodeAction = new TranscodeAction()
                {
                    Description        = $"Transcoding {fileInfo.Name} to {profileName}",
                    InputFile          = fileInfo.FullName,
                    TranscodingCommand = profileCommand
                                         .Replace("{input}", '"' + fileInfo.FullName + '"')
                                         .Replace("{output}", '"' + outputFileNameFull + '"'),
                    OutputFile = outputFileNameFull
                };
                transcodeAction.ExecutionStateChanged += TranscodeAction_ExecutionStateChanged;
                transcodeAction.ErrorOccurred         += TranscodeAction_ErrorOccurred;
                actions.Add(transcodeAction);

                string ftpPath = this.textBoxFTPPath.Text;
                if (!ftpPath.EndsWith("/"))
                {
                    ftpPath = ftpPath + "/";
                }
                UploadAction uploadAction = new UploadAction()
                {
                    Description = $"Uploading {outputFileNameShort} to FTP folder {ftpPath}",
                    InputFile   = outputFileNameFull,
                    FtpClient   = new FtpClient(
                        this.ftpClient.Host,
                        this.ftpClient.Credentials
                        ),
                    PathAtFTP       = ftpPath + outputFileNameShort,
                    DependsOnAction = transcodeAction
                };
                uploadAction.FtpClient.DataConnectionType = this.ftpClient.DataConnectionType;
                uploadAction.FtpClient.SocketKeepAlive    = this.ftpClient.SocketKeepAlive;
                uploadAction.ExecutionStateChanged       += UploadAction_ExecutionStateChanged;
                uploadAction.ErrorOccurred += UploadAction_ErrorOccurred;
                actions.Add(uploadAction);
            }

            return(actions);
        }
Esempio n. 4
0
        private void RecursiveUpload(ShareFileClient client, int uploadId, FileSystemInfo source, Models.Item target)
        {
            if (source is DirectoryInfo)
            {
                var newFolder = new Models.Folder()
                {
                    Name = source.Name
                };
                newFolder = client.Items.CreateFolder(target.url, newFolder, Force || ResumeSupport.IsPending, false).Execute();

                ActionManager actionManager = new ActionManager(this, source.Name);
                ActionType    actionType    = Force ? ActionType.Force : ActionType.None;

                foreach (var fsInfo in ((DirectoryInfo)source).EnumerateFileSystemInfos())
                {
                    if (fsInfo is DirectoryInfo)
                    {
                        RecursiveUpload(client, uploadId, fsInfo, newFolder);
                    }
                    else if (fsInfo is FileInfo)
                    {
                        if (!ResumeSupport.IsPending || !ResumeSupport.CheckFileStatus(fsInfo.Name))
                        {
                            IAction uploadAction = new UploadAction(FileSupport, client, fsInfo, newFolder, Details, actionType);
                            actionManager.AddAction(uploadAction);
                        }
                    }
                }

                actionManager.Execute();
            }
            else if (source is FileInfo)
            {
                ActionManager actionManager = new ActionManager(this, source.Name);
                if (!ResumeSupport.IsPending || !ResumeSupport.CheckFileStatus(source.Name))
                {
                    ActionType actionType   = Force || ResumeSupport.IsPending ? ActionType.Force : ActionType.None;
                    IAction    uploadAction = new UploadAction(FileSupport, client, source, target, Details, actionType);
                    actionManager.AddAction(uploadAction);
                }
                actionManager.Execute();
            }
        }
Esempio n. 5
0
        private void UploadAction_ExecutionStateChanged(object sender, EventArgs e)
        {
            UploadAction action = sender as UploadAction;

            if (action.ExecutionState == ExecutionState.Running)
            {
                this.Log($"FTP upload <b>started</b>: <code>{action.Description}</code>", indentTabs: 1);
            }
            else if (action.ExecutionState == ExecutionState.CompletedSuccessfully)
            {
                this.Log($"FTP upload <b>successful</b>: <code>{action.Description}</code>", indentTabs: 1);
            }
            else if (action.ExecutionState == ExecutionState.Failed)
            {
                this.Log($"FTP upload <b>failed</b>: <code>{action.Description}</code>", indentTabs: 1);
            }
            else if (action.ExecutionState == ExecutionState.Canceled)
            {
                this.Log($"FTP upload <b>canceled</b>: <code>{action.Description}</code>", indentTabs: 1);
            }
        }
        /// <summary>
        /// Upload contents recursively
        /// </summary>
        private void UploadRecursive(ShareFileClient client, int uploadId, FileSystemInfo source, Models.Item target, ActionType actionType)
        {
            if (source is DirectoryInfo)
            {
                var newFolder = new Models.Folder() { Name = source.Name };
                bool isExist = false;

                if (Synchronize)
                {
                    try
                    {
                        string path = String.Format("/{0}", source.Name);
                        Item item = null;
                        try
                        {
                            item = client.Items.ByPath(target.url, path).Execute();
                        }
                        catch (ODataException e)
                        {
                            if (e.Code != System.Net.HttpStatusCode.NotFound)
                            {
                                throw e;
                            }
                        }

                        if (item != null && item is Folder)
                        {
                            isExist = true;
                            newFolder = (Folder)item;
                        }
                    }
                    catch { }
                }

                if (!isExist)
                {
                    newFolder = client.Items.CreateFolder(target.url, newFolder, OverWrite, false).Execute();
                }

                ActionManager actionManager = new ActionManager(this, source.Name);

                foreach (var fsInfo in ((DirectoryInfo)source).EnumerateFileSystemInfos())
                {
                    if (fsInfo is DirectoryInfo && Recursive)
                    {
                        UploadRecursive(client, uploadId, fsInfo, newFolder, actionType);
                    }
                    else if (fsInfo is FileInfo)
                    {
                        IAction uploadAction = new UploadAction(FileSupport, client, fsInfo, newFolder, Details, actionType);
                        actionManager.AddAction(uploadAction);
                    }
                }

                actionManager.Execute();
            }
        }
        /// <summary>
        /// Start Upload to Sharefile location
        /// </summary>
        private void StartUpload(ShareFileClient client, int uploadId, Models.Item target, ICollection<string> resolvedPaths, ActionType actionType)
        {
            int transactionId = new Random((int)DateTime.Now.Ticks).Next();

            ActionManager actionManager = new ActionManager(this, string.Empty);
            bool firstIteration = true;

            foreach (string path in resolvedPaths)
            {
                FileAttributes attr = System.IO.File.GetAttributes(path);
                FileSystemInfo source = ((attr & FileAttributes.Directory) == FileAttributes.Directory) ? new DirectoryInfo(path) : source = new FileInfo(path);

                // create an extra parent folder if CreateRoot flag is specified on target location
                if (firstIteration && CreateRoot)
                {
                    DirectoryInfo parentFolder = Directory.GetParent(path);
                    var newFolder = new Models.Folder() { Name = parentFolder.Name };
                    target = client.Items.CreateFolder(target.url, newFolder, OverWrite, false).Execute();
                    firstIteration = false;
                }

                if (source is DirectoryInfo)
                {
                    UploadRecursive(client, uploadId, source, target, actionType);
                }
                else
                {
                    IAction uploadAction = new UploadAction(FileSupport, client, source, target, Details, actionType);
                    actionManager.AddAction(uploadAction);
                }
            }

            actionManager.Execute();

            if (Strict)
            {
                foreach (string path in resolvedPaths)
                {
                    FileAttributes attr = System.IO.File.GetAttributes(path);
                    if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        DirectoryInfo source = new DirectoryInfo(path);

                        var children = client.Items.GetChildren(target.url).Execute();
                        
                        foreach (var child in children.Feed)
                        {
                            if (child is Models.Folder && child.Name.Equals(source.Name))
                            {
                                DeleteSharefileStrictRecursive(client, source as DirectoryInfo, child);
                                break;
                            }
                        }
                    }
                }
            }

            if (Move)
            {
                foreach (string path in resolvedPaths)
                {
                    FileAttributes attr = System.IO.File.GetAttributes(path);
                    FileSystemInfo source = ((attr & FileAttributes.Directory) == FileAttributes.Directory) ? new DirectoryInfo(path) : source = new FileInfo(path);

                    DeleteLocalItemRecursive(source, Recursive);
                }
            }
        }
        private async Task <Document> UploadDocumentOrVersion(Guid projectId, UploadFileType uploadFileType,
                                                              Stream stream, string contentType, Guid?folderId = null, string nameDocument = null, Guid?documentId = null,
                                                              UploadTarget target = UploadTarget.Document, UploadAction action             = UploadAction.Add)
        {
            Dictionary <string, string> queryParams = BuildQueryParamsUploadDoc(projectId, uploadFileType, string.Empty,
                                                                                folderId, nameDocument, documentId, target, action);



            string docJson = (await Requester.Request(Requester.ApiRootUrl + "uploaddocument", ApiMethod.Post, queryParams, stream, contentType)).Data;

            return(JsonConvert.DeserializeObject <Document>(docJson));
        }
        private Dictionary <string, string> BuildQueryParamsUploadDoc(Guid projectId, UploadFileType uploadFileType,
                                                                      string filePath, Guid?folderId = null, string nameDocument                  = null, Guid?documentId = null,
                                                                      UploadTarget target            = UploadTarget.Document, UploadAction action = UploadAction.Add)
        {
            Dictionary <string, string> queryParams = new Dictionary <string, string>
            {
                { "file", uploadFileType.ToString().ToLowerInvariant() },
                { "action", action.ToString().ToLowerInvariant() },
                { "target", target.ToString().ToLowerInvariant() },
                { "projectid", projectId.ToString().ToLowerInvariant() }
            };

            if (target == UploadTarget.Document && action == UploadAction.Add)
            {
                if (String.IsNullOrEmpty(nameDocument) && !string.IsNullOrEmpty(filePath))
                {
                    nameDocument = Path.GetFileNameWithoutExtension(filePath);
                }
            }

            if (!String.IsNullOrEmpty(nameDocument))
            {
                queryParams.Add("name", nameDocument);
            }

            if (folderId.HasValue)
            {
                queryParams.Add("folderid", folderId.Value.ToString());
            }
            if (documentId.HasValue)
            {
                queryParams.Add("parentdocid", documentId.Value.ToString());
            }
            return(queryParams);
        }
Esempio n. 10
0
 internal FileUploadEventArgs(string fileName, UploadAction action, string message = "")
 {
     _fileName = fileName;
     _action   = action;
     _message  = message;
 }
Esempio n. 11
0
        private void RecursiveUpload(ShareFileClient client, int uploadId, FileSystemInfo source, Models.Item target)
        {
            if (source is DirectoryInfo)
            {
                var newFolder = new Models.Folder() { Name = source.Name };
                newFolder = client.Items.CreateFolder(target.url, newFolder, Force || ResumeSupport.IsPending, false).Execute();

                ActionManager actionManager = new ActionManager(this, source.Name);
                ActionType actionType = Force ? ActionType.Force : ActionType.None;

                foreach (var fsInfo in ((DirectoryInfo)source).EnumerateFileSystemInfos())
                {
                    if (fsInfo is DirectoryInfo)
                    {
                        RecursiveUpload(client, uploadId, fsInfo, newFolder);
                    }
                    else if (fsInfo is FileInfo)
                    {
                        if (!ResumeSupport.IsPending || !ResumeSupport.CheckFileStatus(fsInfo.Name))
                        {
                            IAction uploadAction = new UploadAction(FileSupport, client, fsInfo, newFolder, Details, actionType);
                            actionManager.AddAction(uploadAction);
                        }
                    }
                }

                actionManager.Execute();
            }
            else if (source is FileInfo)
            {
                ActionManager actionManager = new ActionManager(this, source.Name);
                if (!ResumeSupport.IsPending || !ResumeSupport.CheckFileStatus(source.Name))
                {
                    ActionType actionType = Force || ResumeSupport.IsPending ? ActionType.Force : ActionType.None;
                    IAction uploadAction = new UploadAction(FileSupport, client, source, target, Details, actionType);
                    actionManager.AddAction(uploadAction);
                }
                actionManager.Execute();
            }
        }