public void TestGetRegexFromDateUnitUndefined()
        {
            string dateFormat = "";

            Assert.AreEqual(FileSync.GetRegexFromDateUnit("f", ref dateFormat), "f");
            Assert.AreEqual(dateFormat, "'f'&");

            dateFormat = "";
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("ff", ref dateFormat), "ff");
            Assert.AreEqual(dateFormat, "'ff'&");

            dateFormat = "";
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("asdf", ref dateFormat), "asdf");
            Assert.AreEqual(dateFormat, "'asdf'&");

            dateFormat = "";
            Assert.AreEqual(FileSync.GetRegexFromDateUnit(" ", ref dateFormat), @"\ ");
            Assert.AreEqual(dateFormat, "' '&");

            dateFormat = "";
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("*", ref dateFormat), @"\*");
            Assert.AreEqual(dateFormat, "'*'&");

            dateFormat = "";
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("#", ref dateFormat), @"\#");
            Assert.AreEqual(dateFormat, "'#'&");
        }
Example #2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     FileSync.CreateDir();
     FileSync.CheckVersionFile();
     ListBoxAddItem(public_list, FileSync.VERSION_INFO.publicVersions);
     ListBoxAddItem(ea_list, FileSync.VERSION_INFO.eaVersions);
 }
        public void TestGetTokenRegexStr()
        {
            string dateFormat = "";

            Assert.AreEqual(FileSync.GetTokenRegexStr("yy-MM-dd", ref dateFormat), @"(\d{2})(-)(\d{2})(-)(\d{2})");
            Assert.AreEqual(FileSync.GetTokenRegexStr("d", ref dateFormat), @"(\d{1,2})");
        }
Example #4
0
 private void OnRenamed(object sender, RenamedEventArgs e)
 {
     if (BOD.NodeDetails.Ip == BOD.NodeDetails.LeaderNode)
     {
         FileSync fileSync = new FileSync();
         fileSync.OnFileRenamed(e);
     }
 }
Example #5
0
 public Importer()
 {
     StagingDirectory = GetStagingDirectory();
     Git      = new Gitter();
     Finder   = new FileFinder();
     FileSync = new FileSync();
     Backup   = new FileBackup();
 }
Example #6
0
 private void OnChanged(object sender, FileSystemEventArgs e)
 {
     if (BOD.NodeDetails.Ip == BOD.NodeDetails.LeaderNode)
     {
         FileSync fileSync = new FileSync();
         fileSync.OnFileChange(e);
     }
 }
Example #7
0
        public async Task TestMethodException9()
        {
            var service = new FileSync();

            service.ShouldNotBeNull();

            await Task.Delay(TimeSpan.FromSeconds(1));
        }
        public void GivenValidData_WhenAFileSyncIsUpdatedAndItIsTheFirstFileSync_ThenTheFileSyncIsCreated()
        {
            FileSync _fileSync1 = null;

            _fileSyneRepository.Setup(f => f.GetLatest()).Returns(_fileSync1);
            _filesyncService.UpdateFileSync(It.IsAny <int>());

            _fileSyneRepository.Verify(s => s.Create(It.IsAny <FileSync>()), Times.Once());
        }
Example #9
0
        public void Setup()
        {
            _transactionScope   = new TransactionScope();
            _fileSyncRepository = new FileSyncRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString);

            _fileSync1 = new FileSync {
                GridRunId = 1
            };
        }
Example #10
0
 /// <summary>
 /// Call back method which is called when sync event occurs
 /// </summary>
 /// <param name="args">Simias event details</param>
 private void OnSyncEvent(SimiasEventArgs args)
 {
     try
     {
         if (enabled)
         {
             CollectionSyncEventArgs cArgs = args as CollectionSyncEventArgs;
             if (cArgs != null)
             {
                 if (CollectionSync != null)
                 {
                     Delegate[] cbList = CollectionSync.GetInvocationList();
                     foreach (CollectionSyncEventHandler cb in cbList)
                     {
                         try
                         {
                             cb(cArgs);
                         }
                         catch (Exception ex)
                         {
                             logger.Debug(ex, "Delegate {0}.{1} failed", cb.Target, cb.Method);
                             CollectionSync -= cb;
                         }
                     }
                 }
             }
             else
             {
                 FileSyncEventArgs fArgs = args as FileSyncEventArgs;
                 if (fArgs != null)
                 {
                     if (FileSync != null)
                     {
                         Delegate[] cbList = FileSync.GetInvocationList();
                         foreach (FileSyncEventHandler cb in cbList)
                         {
                             try
                             {
                                 cb(fArgs);
                             }
                             catch (Exception ex)
                             {
                                 logger.Debug(ex, "Delegate {0}.{1} failed", cb.Target, cb.Method);
                                 FileSync -= cb;
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         new SimiasException(args.ToString(), ex);
     }
 }
        public void WhenAttemptingToGeTheLatestFileSync_AndThereAreNoFileSyncsCurrently_ANewFileSyncIsCreatedWithADummySyncDate()
        {
            FileSync fileSync1 = null;

            _fileSyneRepository.Setup(s => s.GetLatest()).Returns(fileSync1);
            var fileSync = _filesyncService.GetLatest();

            fileSync.Id.Should().Be(0);
            fileSync.SyncDate.Should().Be(new DateTime(2013, 1, 1));
        }
        public void WhenTheLatestFileSyncIsRetrieved_ThenTheFileSyncIsRetrievedFromTheRepository()
        {
            FileSync fileSync1 = null;

            _fileSyneRepository.Setup(s => s.GetLatest()).Returns(fileSync1);

            var fileSync = _filesyncService.GetLatest();

            _fileSyneRepository.Verify(s => s.GetLatest(), Times.Once());
        }
Example #13
0
        public Form1()
        {
            InitializeComponent();
            // GamePath
            string gamePath = FileSync.GetGamePath();

            if (!string.IsNullOrEmpty(gamePath))
            {
                GameDirPath.Text = gamePath;
            }
        }
        public void TestExtractDateStringSuccess()
        {
            Regex  regex = new Regex(@"^C:\\Music\\(\d{4}-\d{2}-\d{2})\ recording.mp3$");
            string path  = @"C:\Music\2020-01-31 recording.mp3";

            Assert.AreEqual(FileSync.ExtractDateString(regex, path), "2020-01-31&");

            regex = new Regex(@"^C:\\Music\\(\d{4}-\d{2}-\d{2})\ recording.mp3$");
            path  = @"C:\Music\2020-01-30 recording.mp3";
            Assert.AreEqual(FileSync.ExtractDateString(regex, path), "2020-01-30&");
        }
Example #15
0
        public void Sync(string projectName, string projectPath)
        {
            Console.WriteLine("");
            Console.WriteLine("Synchronising files between imported project...");
            Console.WriteLine("Project:");
            Console.WriteLine(projectName);
            Console.WriteLine("Path:");
            Console.WriteLine(projectPath);
            Console.WriteLine("");

            var importedProjectPath = StagingDirectory
                                      + Path.DirectorySeparatorChar
                                      + projectName;

            var patternsFile = importedProjectPath
                               + Path.DirectorySeparatorChar
                               + "patterns.txt";

            if (!File.Exists(patternsFile))
            {
                throw new Exception("No import/export patterns have been set for '" + projectName + "' import. Add them by using the ImportFile and ExportFile functions.");  // TODO: Create a custom exception class
            }
            else
            {
                var patterns = File.ReadAllLines(patternsFile);

                foreach (var pattern in patterns)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Pattern:");
                    Console.WriteLine(pattern);
                    Console.WriteLine("");

                    // TODO: Instead of using time based sync, export all files and commit to git, then import all files

                    FileSync.Sync(WorkingDirectory, importedProjectPath, pattern);
                    Git.AddTo(importedProjectPath, pattern);
                }

                var sourcePath = File.ReadAllText(importedProjectPath + Path.DirectorySeparatorChar + "source.txt");

                // Commit import project
                Git.CommitTo(importedProjectPath, "Sync.");

                // Get the remote name
                var remoteName = Path.GetFileName(importedProjectPath);

                // Add the importable project directory as a remote to the original
                Git.AddRemoteTo(sourcePath, remoteName, importedProjectPath);

                // Pull changes to back to the original project
                Git.PullTo(sourcePath, remoteName);
            }
        }
Example #16
0
        static void Main()
        {
            // 创建、检查相关文件夹
            FileSync.CreateDir();
            // check,备份,download version.json文件
            // FileSync.CheckVersionFile();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Example #17
0
 public void CreateFileSync(int gridRunId)
 {
     try
     {
         FileSync fileSync = new FileSync(gridRunId);
         _fileSyncRepository.Create(fileSync);
     }
     catch (Exception e)
     {
         throw new UnityException("Unable to create file sync", e);
     }
 }
Example #18
0
        public void GivenAnExistingFileSync_WhenIUpdateTheSyncDate_TheSyncDateIsUpdated()
        {
            DateTime updateDate = new DateTime(2013, 1, 1, 0, 0, 0);

            _fileSyncRepository.Create(_fileSync1);

            FileSync fileSync = _fileSyncRepository.GetLatest();

            fileSync.SyncDate = updateDate;

            _fileSyncRepository.Update(_fileSync1);
            fileSync.SyncDate.Should().Be(updateDate);
        }
        public void TestExtractDateStringExceptions()
        {
            Regex  regex = new Regex(@"^C:\\Music\\(\d{4}-\d{2}-\d{2})\ recording.mp3$");
            string path  = @"C:\Music\2020-01-30.mp3";

            try { FileSync.ExtractDateString(regex, path); Assert.Fail(); }
            catch { Assert.IsTrue(true); }

            regex = new Regex(@"^C:\\Music\\(\d{4}-\d{2}-\d{2})\ recording.mp3$");
            path  = @"C:\Music\2020-01-3 recording.mp3";
            try { FileSync.ExtractDateString(regex, path); Assert.Fail(); }
            catch { Assert.IsTrue(true); }
        }
        public void ShouldAttachAndDetach()
        {
            ISync sut1 = new ThreadDiscoverRomania();
            ISync sut2 = new ThreadHotels();
            ISync sut3 = new ThreadTravelAgents();

            FileSync sync = new FileSync();

            sync.attach(sut1);
            sync.attach(sut2);
            sync.detach(sut3);

            Assert.AreEqual(2, sync.syncList.Count);
        }
        public void WhenAttemptingToGeTheLatestFileSync_AndThereAreNoFileSyncsCurrently_AnExistingFileSyncIsReturned()
        {
            DateTime syncDate       = new DateTime(2013, 1, 1);
            FileSync fileSyncReturn = new FileSync()
            {
                Id = 1, GridRunId = 1, SyncDate = syncDate
            };

            _fileSyneRepository.Setup(s => s.GetLatest()).Returns(fileSyncReturn);

            var fileSync = _filesyncService.GetLatest();

            fileSync.Id.Should().NotBe(0);
            fileSync.SyncDate.Should().Be(syncDate);
        }
        public void TestGetRegexFromDateUnitDictionary()
        {
            string dateFormat = "";

            Assert.AreEqual(FileSync.GetRegexFromDateUnit("yyyy", ref dateFormat), @"\d{4}");
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("h", ref dateFormat), @"\d{1,2}");
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("HH", ref dateFormat), @"\d{2}");
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("H", ref dateFormat), @"\d{1,2}");
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("mm", ref dateFormat), @"\d{2}");
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("m", ref dateFormat), @"\d{1,2}");
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("ss", ref dateFormat), @"\d{2}");
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("s", ref dateFormat), @"\d{1,2}");
            Assert.AreEqual(FileSync.GetRegexFromDateUnit("tt", ref dateFormat), @"[AP]M");
            Assert.AreEqual(dateFormat, @"yyyy&h&HH&H&mm&m&ss&s&tt&");
        }
Example #23
0
        private void button1_Click(object sender, EventArgs e)
        {
            VersionInfo info = FileSync.DownloadVersionFile();

            // 点击更新版本文件的时候,更新版本
            if (info == null)
            {
                MessageBox.Show("文件格式错误,请到论坛相应的帖子或者Github上反馈");
            }
            else
            {
                updateSource(public_list, info.publicVersions);
                updateSource(ea_list, info.eaVersions);
                MessageBox.Show("已经获取最新的版本信息");
            }
        }
Example #24
0
        private void P2PVPNForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //FileIO.StopQueue = true;
            tabs.SelectedTab = tabVPNTraffic;
            Disconnect();
            try
            {
                Utilities.MediaServer.TakeShareOffline(true);
                FileSync.Dispose(true);
            }
            catch
            {
            }

            //FileIO.ResetTransfers();
        }
Example #25
0
        /**
         * 清楚本地汉化文件
         */
        private void button4_Click(object sender, EventArgs e)
        {
            string tips = String.Empty;

            foreach (var dir in FileSync.NEED_EMPTY_DIR)
            {
                tips = tips + dir + "\n";
            }

            DialogResult dialogResult = MessageBox.Show("这将会删除游戏的汉化文件,包括\n" + tips + "中的汉化文件", "警告", MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Warning);

            if (dialogResult == DialogResult.Yes)
            {
                FileSync.DeleteChinesization();
            }
        }
Example #26
0
        public void WatchFileSystem()
        {
            try
            {
                Settings settings = Settings.Get();
                FileIO.FinshedFileTransfer += (sender, info) =>
                {
                    lblMediaCopyProgress.SetControlText("Finished Copying " + info.SourceFile);
                    //ControlHelpers.s
                    Logging.Log("Finished Copying " + info.SourceFile);
                };

                FileIO.FileTransferProgress += (sender, info) =>
                {
                    string transfer = string.Format("Copying: {0}   {1}%", info.SourceFile, info.PercentComplete);
                    lblMediaCopyProgress.SetControlText(transfer);

                    //var fileTransfer = settings.MediaFileTransferQue.FirstOrDefault(x => x.SourceDirectory == sender.SourceDirectory);

                    //if (fileTransfer != null && !fileTransfer.IsTransfering)
                    //{
                    //    fileTransfer.IsTransfering = true;
                    //    Settings.Save(settings);
                    //}
                    //Logging.Log("File Transfer Percent: " + percentComplete.ToString());
                };



                if (string.IsNullOrWhiteSpace(settings.MediaFileTransfer.SourceDirectory) ||
                    string.IsNullOrWhiteSpace(settings.MediaFileTransfer.TargetDirectory))
                {
                    return;
                }
                FileSync.WatchFileSystem(settings.MediaFileTransfer.SourceDirectory, settings.MediaFileTransfer.TargetDirectory);
                //FileIO.WatchFileSystem();
                //FileIO.ProcessFileTransferQueue();
            }
            catch (Exception ex)
            {
                ControlHelpers.ShowMessageBox(ex.Message, ControlHelpers.MessageBoxType.Error);
                return;
            }
        }
Example #27
0
        public void Init()
        {
            LogClient.LogMessage("Loading PatchMod");
            if (!System.IO.Directory.Exists(PathHelpers.PatchModDepDirectory))
            {
                LogClient.LogMessage($"ERROR: Missing lib directory at {PathHelpers.PatchModDepDirectory}");
            }

            LibManager.LoadDeps();
            PathHelpers.CheckDirectories();
            LibManager.LoadPlugins();
            LogClient.LogMessage("PatchMod Loaded");
            Patcher.Patch();

            if (Patcher.PatchMessageSent)
            {
                LogClient.LogMessage($"Patches Complete");
            }

            if ((bool)PatchMod.Config["SyncEnabled", typeof(bool)])
            {
                SyncSource S = SyncProviderManager.GetSource((string)PatchMod.Config["SyncMode"]);
                if (S == null)
                {
                    LogClient.LogMessage($"Invalid Sync Source '{(string)PatchMod.Config["SyncMode"]}'");
                }
                else
                {
                    S.Source = (string)PatchMod.Config["SyncPath"];
                    S.Init();
                    LogClient.LogMessage($"Starting Sync...");
                    FileSync.SyncFrom(S);
                    if (S.FilesChanged)
                    {
                        LogClient.LogMessage($"Files synced from server. Acquired {S.NewFiles} new file/s from server.");
                    }
                    else
                    {
                        LogClient.LogMessage($"Files are up to date.");
                    }
                    S.Shutdown();
                }
            }
        }
Example #28
0
        private void Use(string prefix, ListBox listBox)
        {
            Version row = listBox.SelectedItem as Version;

            if (row != null)
            {
                string downloadPath = row.path;
                string name         = row.version + ".zip";
                bool   useStatus    = FileSync.Use(prefix, name, downloadPath);
                if (useStatus)
                {
                    MessageBox.Show("已经成功使用版本号为 " + row.version + " 的汉化文件,赶紧去玩吧");
                }
            }
            else
            {
                MessageBox.Show("确认已经选择了汉化文件的版本??");
            }
        }
Example #29
0
        //  当文本框中的目录改变时触发
        private void GameDirPath_TextChanged(object sender, EventArgs e)
        {
            string gamePath = GameDirPath.Text;

            if (!string.IsNullOrEmpty(gamePath) &&
                !gamePath.EndsWith("Mount & Blade II Bannerlord") &&
                !gamePath.Equals(FileSync.GetGamePath()))
            {
                DialogResult boxResult = MessageBox.Show("检测到您选中的路径并不是以Mount & Blade II Bannerlord结尾,您确定选择的路径正确?",
                                                         "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (boxResult == DialogResult.Yes)
                {
                    FileSync.StorageGamePath(GameDirPath.Text);
                }
            }
            else
            {
                FileSync.StorageGamePath(GameDirPath.Text);
            }
        }
Example #30
0
        public void UpdateFileSync(int gridRunId)
        {
            try
            {
                FileSync fileSync = _fileSyncRepository.GetLatest();

                if (fileSync == null)
                {
                    fileSync = new FileSync(gridRunId);
                    _fileSyncRepository.Create(fileSync);
                }
                else
                {
                    fileSync.GridRunId = gridRunId;
                    fileSync.SyncDate  = DateTime.Now;
                    _fileSyncRepository.Update(fileSync);
                }
            }
            catch (Exception e)
            {
                throw new UnityException("Unable to update file sync", e);
            }
        }
Example #31
0
 private void btnOK_Click(object sender, System.EventArgs e)
 {
     FileSync Fs = new FileSync();
     Fs.Backup("c:\\temp\\temp5\\");
 }
Example #32
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     FileSync Fs = new FileSync();
     foreach (string s in DirList)
     {
         Fs.Backup(s);
     }
 }