Exemplo n.º 1
0
        private void Timer_Tick(object sender, System.Timers.ElapsedEventArgs args)
        {
            JobContainer jContainer  = this.wcontainer.Container;
            string       destination = SharedBO.CalculateDestination(
                jContainer.SourceDirectory, fullpath, jContainer.DestinationDirectory);                // Path.Combine(jContainer.DestinationDirectory, Path.GetFileName(this.fullpath));

            try {
                if (DoneTrying())
                {
                    IReporter reporter = ReporterManager.GetReporter();
                    reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, "Attempted to copy file " + this.RetryCount + " times.", this.fullpath, destination));
                    this.QTimer.Stop();
                    this.OnFinished(EventArgs.Empty);
                }
                else
                {
                    if (!File.Exists(this.fullpath))
                    {
                        if (wcontainer.ChangeType == WatcherChangeTypes.Renamed)
                        {
                            string relativeOldDir = SharedBO.CalculateDestination(
                                wcontainer.OldFullPath,
                                jContainer.SourceDirectory,
                                jContainer.DestinationDirectory);
                            Directory.Move(relativeOldDir, destination);
                        }
                        else
                        {
                            if (!Directory.Exists(destination))
                            {
                                Directory.CreateDirectory(destination);
                            }
                        }

                        this.QTimer.Stop();
                        this.OnFinished(EventArgs.Empty);
                    }
                    else
                    {
                        this.Copier.Copy(this.fullpath, destination, true);
                        this.QTimer.Stop();
                        this.OnFinished(EventArgs.Empty);
                    }
                }
            }
            catch (System.IO.FileNotFoundException) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, "File Not Found", this.fullpath, destination));
                this.QTimer.Stop();
                this.OnFinished(EventArgs.Empty);
            }
            catch (System.Exception ex) {
                IReporter reporter = ReporterManager.GetReporter();
                reporter.AddReport(new ActionReportContainer(ActionType.Copy, ActionReportResult.Failed, ex.ToString(), this.fullpath, destination));
                this.RetryCount++;
            }
        }
Exemplo n.º 2
0
 public void Save()
 {
     try {
         string configFile = SharedBO.GetConfigurationFile();
         //MoreXmlSerializer.Serialize<ConfigurationContainer>(cContainer, configFile);
         WriteConfiguration(cContainer, configFile);
     }
     catch { }
 }
Exemplo n.º 3
0
 public void LoadConfiguration()
 {
     try{
         string configFile = SharedBO.GetConfigurationFile();
         //cContainer = MoreXmlSerializer.Deserialize<ConfigurationContainer>(configFile);
         cContainer = ReadConfiguration(configFile);
     }catch {
         CreateDefaultConfiguration();
     }
 }
Exemplo n.º 4
0
 public void Save()
 {
     try {
         string jobsfile = SharedBO.GetJobsFile();
         //MoreXmlSerializer.Serialize<JobsContainer>(jContainer, jobsfile);
         WriteJobs(jContainer, jobsfile);
         ListenerBO bo = (ListenerBO)SingletonManager.GetSingleton(typeof(ListenerBO));
         bo.RestartListeners();
     }
     catch {            /*(Exception e){
                         * System.Windows.Forms.MessageBox.Show(e.ToString());*/
     }
 }
Exemplo n.º 5
0
 private void LoadJobs()
 {
     try {
         string jobsfile = SharedBO.GetJobsFile();
         //jContainer = MoreXmlSerializer.Deserialize<JobsContainer>(jobsfile);
         jContainer = ReadJobs(jobsfile);
         if (jContainer == null)
         {
             jContainer = new JobsContainer();
         }
     }
     catch {
         jContainer = new JobsContainer();
     }
 }
Exemplo n.º 6
0
 public static void LaunchHelp()
 {
     try {
         //throw new Exception();
         System.Diagnostics.Process.Start(SharedBO.GetHelpFile());
     }
     catch (Exception) {
         LlamaCarbonCopy.Controls.Forms.CopyURLForm frm = new LlamaCarbonCopy.Controls.Forms.CopyURLForm();
         frm.Website = SharedBO.GetHelpFile();
         frm.Msg     =
             "Llama Carbon Copy tried to open the Help for you.  " +
             "An error was encountered possibly caused by your security configurations, therefore " +
             "Llama Carbon Copy cannot automatically open the Help information for you.  \n\n" +
             "Please click the button below to copy the help webpage, so that you can paste it into " +
             "your web browser.  The Help file is local to your machine, so you do not need to be connected \n" +
             "to the internet.";
         frm.ShowDialog();
     }
 }
Exemplo n.º 7
0
        public void SynchronizeDirectory(string oBaseDir, string oDirectory, string cDirectory, bool includeSubfolders, bool delete)
        {
            if (Directory.Exists(oDirectory))
            {
                if (Directory.Exists(cDirectory))
                {
                    string[] oFiles = Directory.GetFiles(oDirectory);
                    foreach (string oFile in oFiles)
                    {
                        string file = Path.GetFileName(oFile);
                        //string dir = Path.GetDirectoryName(oFile);
                        string cFile = Path.Combine(cDirectory, file);
                        if (!FilesExist(oFile, cFile) || !CompareFiles(oFile, cFile))
                        {
                            Copy(oFile, cFile);
                            OnSynchronized(new SynchEventHandlerArgs(SynchTotalFileCount, SynchProgressCount++, "Copied: " + oFile));
                        }
                    }
                    if (delete)
                    {
                        try {
                            List <string> sOFiles = new List <string>();
                            foreach (string f in oFiles)
                            {
                                sOFiles.Add(Path.Combine(cDirectory, Path.GetFileName(f)));
                            }
                            string[] cFiles = Directory.GetFiles(cDirectory);
                            foreach (string cFile in cFiles)
                            {
                                if (!sOFiles.Contains(cFile))
                                {
                                    File.Delete(cFile);
                                }
                            }

                            List <string> cSubDirectories = new List <string>(Directory.GetDirectories(cDirectory));
                            List <string> oSubDirectories = new List <string>();
                            foreach (string s in Directory.GetDirectories(oDirectory))
                            {
                                oSubDirectories.Add(Path.GetFileName(s));
                            }
                            foreach (string dir in cSubDirectories)
                            {
                                if (!oSubDirectories.Contains(Path.GetFileName(dir)))
                                {
                                    Directory.Delete(dir, true);
                                }
                            }
                        }
                        catch (UnauthorizedAccessException) { }
                        catch (Exception) { }
                    }
                    if (includeSubfolders)
                    {
                        foreach (string dir in Directory.GetDirectories(oDirectory))
                        {
                            SynchronizeDirectory(
                                oBaseDir,
                                dir,
                                SharedBO.CalculateDestination(oDirectory, dir, cDirectory),
                                includeSubfolders,
                                delete);
                        }
                    }
                }
                else
                {
                    Directory.CreateDirectory(cDirectory);
                    string[] oFiles = Directory.GetFiles(oDirectory);
                    foreach (string oFile in oFiles)
                    {
                        Copy(oFile, Path.Combine(cDirectory, Path.GetFileName(oFile)));
                        OnSynchronized(new SynchEventHandlerArgs(SynchTotalFileCount, SynchProgressCount++, "Copied: " + oFile));
                    }
                    if (includeSubfolders)
                    {
                        foreach (string dir in Directory.GetDirectories(oDirectory))
                        {
                            SynchronizeDirectory(
                                oBaseDir,
                                dir,
                                SharedBO.CalculateDestination(oDirectory, dir, cDirectory),
                                includeSubfolders,
                                false);
                        }
                    }
                }
            }
            else
            {
                DirectoryExistsFailure(oDirectory);
            }
        }