Example #1
0
        public DialogResult AnalyzeFolderPair(SyncTask curTask)
        {
            DialogResult result = DialogResult.None;
            try
            {
                this.NotifyUIs("Analyzing " + curTask.Name + "...");
                Detector detector = new Detector(_metaDataDir, curTask);
                detector.CompareFolders();
                if (!detector.IsSynchronized())
                {
                    if (!CheckSufficientDiskSpace(curTask.Source.Substring(0, 1), detector.TgtDirtySize, false) ||
                            !CheckSufficientDiskSpace(curTask.Target.Substring(0, 1), detector.SrcDirtySize, false))
                    {
                        throw new Exception("Insufficient disk space");
                    }
                    _previewReconciler = new Reconciler(detector.SourceList, detector.TargetList, curTask, _metaDataDir);
                    _previewReconciler.Preview();
                    FolderDiffForm form = new FolderDiffForm(_previewReconciler.PreviewFilesList,
                                                            _previewReconciler.PreviewFoldersList, curTask);
                    this.NotifyUIs("Analysis completed");
                    result = form.ShowDialog();
                }
                else
                {
                    this.NotifyUIs("Analysis completed");
                    MessageBox.Show("Task: " + curTask.Name + "\n\n" +
                    "There are no differences between the source and target folders contents.",
                    "SyncSharp", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.UpdateSyncTaskResult(curTask, "Successful");
                }
            }
            catch (Exception e)
            {
                Logger.LogFileLocation = _metaDataDir + @"\";
                Logger.LogFileName = Logger.LogFileLocation + curTask.Name + ".log";
                Logger.WriteErrorLog(e.Message);
                this.UpdateSyncTaskResult(curTask, "Unsuccessful");
            }

            this.UpdateSyncTaskTime(curTask, DateTime.Now.ToString());
            return result;
        }
Example #2
0
        public void SyncFolderPair(SyncTask curTask, bool disablePrompt)
        {
            try
            {
                Logger.WriteSyncLog(_metaDataDir, curTask.Name, true);
                this.NotifyUIs("Analyzing " + curTask.Name + "...");

                Detector detector = new Detector(_metaDataDir, curTask);
                detector.CompareFolders();

                if (!detector.IsSynchronized())
                {
                    if (!CheckSufficientDiskSpace(curTask.Source.Substring(0, 1), detector.TgtDirtySize, disablePrompt) ||
                            !CheckSufficientDiskSpace(curTask.Target.Substring(0, 1), detector.SrcDirtySize, disablePrompt))
                    {
                        throw new Exception("Insufficient disk space");
                    }

                    Reconciler reconciler = new Reconciler(detector.SourceList, detector.TargetList, curTask, _metaDataDir);
                    this.NotifyUIs("Synchronizing " + curTask.Name + "...");

                    if (curTask.TypeOfSync)
                    {
                        reconciler.Sync();
                        SyncMetaData.WriteMetaData(_metaDataDir + @"\" + curTask.Name + ".meta", reconciler.UpdatedList);
                    }
                    else
                    {
                        reconciler.BackupSource(detector.BackupFiles);
                        SyncMetaData.WriteMetaData(_metaDataDir + @"\" + curTask.Name + ".bkp", detector.BackupFiles);
                    }
                }

                this.UpdateSyncTaskResult(curTask, "Successful");
            }
            catch (Exception e)
            {
                Logger.WriteErrorLog(e.Message);
                this.UpdateSyncTaskResult(curTask, "Unsuccessful");
            }
            finally
            {
                Logger.WriteSyncLog(_metaDataDir, curTask.Name, false);
            }

            this.UpdateSyncTaskTime(curTask, DateTime.Now.ToString());
        }
Example #3
0
        private void TestSync(TestCase t, SyncTask curTask)
        {
            RemoveExistingDirectories(curTask);
            Thread.Sleep(25);
            CreateTestDirectories(curTask);
            Thread.Sleep(25);

            CustomDictionary<String, String, FileUnit> srcMeta = new CustomDictionary<string, string, FileUnit>();
            CustomDictionary<String, String, FileUnit> tgtMeta = new CustomDictionary<string, string, FileUnit>();
            int srcLength = curTask.Source.Length;
            int tgtLength = curTask.Target.Length;
            char[] delimiters = new char[] { ',' };

            String createScenario = t.Param2;
            String[] createFiles = createScenario.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            CreateOldState(curTask, t, createFiles, srcMeta, srcLength, tgtMeta, tgtLength);
            Thread.Sleep(25);

            String scenario = t.Param3;
            String[] performChanges = scenario.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            SimulateChanges(curTask, performChanges);

            Detector tester;
            TestCompareFolders(curTask, t, srcMeta, tgtMeta, out tester);

            Reconciler reconciler = new Reconciler(tester.SourceList, tester.TargetList, curTask, "");
            Console.WriteLine("Performing Sync...");
            reconciler.Sync();

            tester = null;
            tester = new Detector("", curTask);
            SyncMetaData.WriteMetaData(@".\srcmetatest", reconciler.UpdatedList);
            SyncMetaData.WriteMetaData(@".\tgtmetatest", reconciler.UpdatedList);
            tester.SMetaData = SyncMetaData.ReadMetaData(@".\srcmetatest");
            tester.TMetaData = SyncMetaData.ReadMetaData(@".\tgtmetatest");
            Console.WriteLine("Comparing Output...");
            tester.CompareFolders();
            tester.IsSynchronized();

            t.Actual = tester.IsSynchronized() ? true.ToString() : false.ToString();
            t.Passed = (t.Actual.Equals(t.Param4.Trim())) ? true : false;
            if (t.Passed) _totalPassed++;
            else _totalFailed++;
            Console.WriteLine("");
        }