コード例 #1
0
        private void InitiateSync_DoWork(object sender, DoWorkEventArgs workArgs)
        {
            string cmd = "sync -n ";

            cmd += (SyncOptions.ForceSync) ? "-f " : "";
            cmd += "./...";
            cmd += (SyncOptions.CLNumber != 0) ? ("@" + SyncOptions.CLNumber) : "";

            MyExecute exec = new MyExecute("sd.exe", cmd, false, true);

            lock (processMutex)
            {
                processes.Add(exec.ProcessHandle);
            }

            bool retval = exec.Run();

            lock (processMutex)
            {
                processes.Remove(exec.ProcessHandle);
            }

            if (retval == true)
            {
                workArgs.Result = exec.Output;
            }
        }
コード例 #2
0
        private void FolderSync_DoWork(object sender, DoWorkEventArgs workArgs)
        {
            List <Folder> folders = workArgs.Argument as List <Folder>;

            workArgs.Result = folders;

            string cmd = "sync ";

            cmd += (parent.Options.ForceSync) ? "-f " : "";
            cmd += (parent.Options.ClobberWriteable) ? "-w " : "";

            foreach (Folder folder in folders)
            {
                cmd += "\"" + folder.Name + "\"";
                cmd += string.IsNullOrEmpty(parent.Options.Revision) ? "" : ("@" + parent.Options.Revision);
                cmd += " ";
            }

            MyExecute exec   = null;
            string    error  = string.Empty;
            bool      retval = false;

            int retryCount = 2;

            while (retryCount != 0)
            {
                //We will never redirect output as it lowers the performance.
                exec = new MyExecute("sd.exe", cmd, parent.Options.ShowWindows, false, true);

                lock (processMutex)
                {
                    processes.Add(exec.ProcessHandle);
                }

                retval = exec.Run();
                retryCount--;

                lock (processMutex)
                {
                    processes.Remove(exec.ProcessHandle);
                }

                error = exec.Error.Trim();

                if ((retval == true) && (string.IsNullOrEmpty(error) || error.Contains("up-to-date")))
                {
                    break;
                }
            }

            if (retval == false)
            {
                throw (new Exception("Execution failed"));
            }

            if (!string.IsNullOrEmpty(error.Trim()) && !error.Contains("up-to-date"))
            {
                throw (new Exception(error));
            }
        }
コード例 #3
0
        private void FolderSync_DoWork(object sender, DoWorkEventArgs workArgs)
        {
            string path = workArgs.Argument as string;

            workArgs.Result = path;

            string cmd = "sync ";

            cmd += (SyncOptions.ForceSync) ? "-f " : "";
            cmd += "\"" + path + "\"";
            cmd += (SyncOptions.CLNumber != 0) ? ("@" + SyncOptions.CLNumber) : "";

            //We will never redirect output as it lowers the performance.
            MyExecute exec = new MyExecute("sd.exe", cmd, SyncOptions.ShowWindows, false);

            /* Don't add the data to the UI as it slows down the process
             * if (redirectOutput)
             * {
             *  exec.OnOutputAvailable += new ExecuteOutputAvailable(exec_OnOutputAvailable);
             *  exec.OnErrorAvailable += new ExecuteOutputAvailable(exec_OnErrorAvailable);
             * }
             */

            lock (processMutex)
            {
                processes.Add(exec.ProcessHandle);
            }

            bool retval = exec.Run();

            lock (processMutex)
            {
                processes.Remove(exec.ProcessHandle);
            }

            if (retval == false)
            {
                throw (new Exception("Execution failed"));
            }
        }
コード例 #4
0
        private void ClientInfo_DoWork(object sender, DoWorkEventArgs workArgs)
        {
            string    cmd  = "info";
            MyExecute exec = new MyExecute("sd.exe", cmd, false, true, true);

            if (exec.Run() && !string.IsNullOrEmpty(exec.Output))
            {
                string[] delim = new string[1];
                delim[0] = "\r\n";
                string[] parts = exec.Output.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                foreach (string entry in parts)
                {
                    if (entry.StartsWith("Client name:"))
                    {
                        ClientName = entry.Replace("Client name: ", "").ToLower();
                    }
                    else if (entry.StartsWith("Client root:"))
                    {
                        ClientRoot = entry.Replace("Client root: ", "").ToLower();
                    }
                }
            }
        }
コード例 #5
0
        private List <string> GetSubFolders(string folder)
        {
            List <string> subFolders = new List <string>();

            if (folder.EndsWith("*"))
            {
                return(subFolders);
            }

            string originalFolder = folder.Replace("\\...", "");

            folder = originalFolder + "\\*";
            subFolders.Add(folder);

            string cmd = "dirs ";

            cmd += folder;

            MyExecute exec = new MyExecute("sd.exe", cmd, false, true, true);

            lock (processMutex)
            {
                processes.Add(exec.ProcessHandle);
            }

            bool retval = exec.Run();

            lock (processMutex)
            {
                processes.Remove(exec.ProcessHandle);
            }

            if (retval == true)
            {
                string output = exec.Output.Trim();
                string error  = exec.Error.Trim();

                if (string.IsNullOrEmpty(output))
                {
                    if (string.IsNullOrEmpty(error))
                    {
                        //no additional subfolders
                    }
                    else
                    {
                        //error in getting the subfolders
                        subFolders.Clear();
                    }
                }
                else
                {
                    string[] delim = new string[1];
                    delim[0] = "\r\n";
                    string[] folders = output.Split(delim, StringSplitOptions.RemoveEmptyEntries);

                    foreach (string fld in folders)
                    {
                        int    index   = fld.LastIndexOf('/');
                        string fldname = fld.Substring(index + 1);
                        subFolders.Add(originalFolder + "\\" + fldname + "\\...");
                    }
                }
            }
            else
            {
                subFolders.Clear();
            }

            return(subFolders);
        }
コード例 #6
0
        private void InitiateSync_DoWork(object sender, DoWorkEventArgs workArgs)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            List <string> foldersToProcess = new List <string>();

            foldersToProcess.Add(parent.Options.SyncFolder);

            InitiateSyncResult result = new InitiateSyncResult();

            result.Output = string.Empty;
            result.Error  = string.Empty;

            while (foldersToProcess.Count != 0)
            {
                string folder = foldersToProcess[0];
                foldersToProcess.RemoveAt(0);

                worker.ReportProgress(10, folder);

                string cmd = "sync -n ";
                cmd += (parent.Options.ForceSync) ? "-f " : "";
                cmd += folder;
                cmd += string.IsNullOrEmpty(parent.Options.Revision) ? "" : ("@" + parent.Options.Revision);

                MyExecute exec = new MyExecute("sd.exe", cmd, false, true, true);

                lock (processMutex)
                {
                    processes.Add(exec.ProcessHandle);
                }

                bool retval = exec.Run();

                lock (processMutex)
                {
                    processes.Remove(exec.ProcessHandle);
                }

                if (retval == true)
                {
                    string output = exec.Output.Trim();
                    string error  = exec.Error.Trim();

                    if (string.IsNullOrEmpty(output))
                    {
                        if (string.IsNullOrEmpty(error))
                        {
                            //nothing to sync
                        }
                        else
                        {
                            if (error.Contains("up-to-date") ||
                                error.Contains("no such file"))
                            {
                                //nothing to sync
                            }
                            else if (error.Contains("Request too large"))
                            {
                                //need to breakup the request
                                List <string> subfolders = GetSubFolders(folder);
                                foldersToProcess.AddRange(subfolders);

                                result.ForceSplit = true;
                            }
                            else
                            {
                                //got an unhandled error
                                result.Error += folder + ": " + error + "\n";
                            }
                        }
                    }
                    else
                    {
                        result.Output += "\r\n" + output;
                    }
                }
                else
                {
                    result.Output = string.Empty;
                    result.Error  = "Failed to execute sd.exe.";
                    break;
                }
            }

            result.Output = result.Output.Trim();
            result.Error  = result.Error.Trim();

            workArgs.Result = result;
        }