Exemplo n.º 1
0
 protected void CopyFile(String PathFileName)
 {
     using (var SourceStream = SourceFileSystem.OpenFile(FileSystem.CombinePath(DestinationPath, PathFileName), FileMode.Open))
         using (var DestinationStream = DestinationFileSystem.OpenFile(FileSystem.CombinePath(DestinationPath, PathFileName), FileMode.Create))
         {
             SourceStream.CopyToFast(DestinationStream);
         }
 }
Exemplo n.º 2
0
 protected void CreateFolder(String PathFileName)
 {
     try
     {
         DestinationFileSystem.CreateDirectory(FileSystem.CombinePath(DestinationPath, PathFileName));
     }
     catch (Exception Exception)
     {
         Console.WriteLine("Error creating folder '{0}' : {1}", FileSystem.CombinePath(DestinationPath, PathFileName), Exception.Message);
     }
 }
Exemplo n.º 3
0
 protected void RemoveFile(String PathFileName)
 {
     try
     {
         DestinationFileSystem.DeleteFile(FileSystem.CombinePath(DestinationPath, PathFileName));
     }
     catch (Exception Exception)
     {
         Console.WriteLine("Error deleting file '{0}' : {1}", FileSystem.CombinePath(DestinationPath, PathFileName), Exception.Message);
     }
 }
Exemplo n.º 4
0
        public override void Execute()
        {
            if (AutoConvert)
            {
                // TODO convert-copy
                throw new NotImplementedException("ImportJob convert-copy mode not implemented");
            }
            else
            {
                var sw = new Stopwatch();
                sw.Start();

                // import files into loaded archive
                for (int i = 0; i < Files.Length; i++)
                {
                    string file          = Files[i];
                    string localFilePath = Path.Combine(LocalBasePath, file);

                    // TODO status bar
                    Status = string.Format(Resources.IO_ImportProgressUpdate, i + 1, Files.Length, localFilePath);
                    Log.Note(Status, Resources.Tag_IO);
                    Progress = (double)(i + 1) / Files.Length;

                    using (var srcStream = SourceFileSystem.OpenFile(file))
                        using (var dstStream = DestinationFileSystem.CreateFile(localFilePath)) {
                            srcStream.CopyTo(dstStream);
                        }
                }

                sw.Stop();

                // update tree view
                Application.Current.Dispatcher.Invoke(() => {
                    foreach (string file in Files)
                    {
                        ViewModel.AddFile(Path.Combine(LocalBasePath, file));
                    }
                });

                // TODO status bar
                Status = string.Format(Resources.IO_ImportFinished, Files.Length, sw.Elapsed.TotalSeconds);
                Log.Note(Status, Resources.Tag_IO);
                Progress = 1;
            }

            if (CloseSourceFileSystem)
            {
                SourceFileSystem.Dispose();
            }
        }
Exemplo n.º 5
0
        public void ShowProgressForm(Action Start = null, Action Complete = null)
        {
            var ProgressForm = new ProgressForm();

            ProgressForm.WaitObject = this.IsFinishedLockObject;

            this.OnStep += delegate(double Value, String Details)
            {
                ProgressForm.SetStep(Value, Details);
            };

            ProgressForm.SetOriginDestination(
                SourceFileSystem.Title,
                DestinationFileSystem.Title
                );

            this.OnError += delegate(Exception Exception)
            {
                if (!Canceling)
                {
                    MessageBox.Show(Exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }
            };

            ProgressForm.OnCancelClick = delegate()
            {
                return(MessageBox.Show("¿Está seguro de querer cancelar la sincronización?", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes);
            };

            if (Complete != null)
            {
                ProgressForm.Complete += Complete;
            }

            ProgressForm.Process = delegate()
            {
RetrySource:

                try
                {
                    CallStep(0, String.Format(ConnectingToFormat, SourceFileSystem.Title));
                    SourceFileSystem.TryInitialize();
                }
                catch (Exception Exception)
                {
                    Console.WriteLine(Exception);
                    if (!Canceling)
                    {
                        if (MessageBox.Show(Exception.Message + "\n\n" + Exception.StackTrace, "Can't connect to local FileSystem", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) == DialogResult.Retry)
                        {
                            goto RetrySource;
                        }
                    }
                }

RetryDestination:

                try
                {
                    CallStep(0, String.Format(ConnectingToFormat, DestinationFileSystem.Title));
                    DestinationFileSystem.TryInitialize();
                }
                catch (Exception Exception)
                {
                    Console.WriteLine(Exception);
                    if (!Canceling)
                    {
                        if (MessageBox.Show(Exception.Message + "\n\n" + Exception.StackTrace, "Can't connect to remote FileSystem", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) == DialogResult.Retry)
                        {
                            goto RetryDestination;
                        }
                    }
                }

                Console.WriteLine("Started SynchronizeFolder ({0} -> {1})...", SourceFileSystem, DestinationFileSystem);
                this.SynchronizeFolder();
            };

            ProgressForm.Cancel = this.Cancel;

            if (Start != null)
            {
                Start();
            }

            //ProgressForm.ShowDialog();
            ProgressForm.ExecuteProcess();
        }