private async void Page_Loaded(object sender, RoutedEventArgs e) { await CheckForCamera(); if (SettingsManager.Get <bool>(Setting.UseCloudSynchronization) && AccountStorage.Instance.HasSynchronizer) { Synchronize.Visibility = Visibility.Visible; AccountStorage.Instance.SynchronizationCompleted += SynchronizationCompleted; if (AccountStorage.Instance.IsSynchronizing) { Synchronize.StartAnimationAndDisable(); SetButtonState(false); } } else { if (Scan.Visibility == Visibility.Collapsed) { CommandBar.Visibility = Visibility.Collapsed; } } }
public void WithComplexPropertyThrows() { var expected = "Synchronize.PropertyValues(x, y) failed.\r\n" + "The property WithComplexProperty.ComplexType of type ComplexType is not supported.\r\n" + "Solve the problem by any of:\r\n" + "* Make ComplexType immutable or use an immutable type.\r\n" + " - For immutable types the following must hold:\r\n" + " - Must be a sealed class or a struct.\r\n" + " - All fields and properties must be readonly.\r\n" + " - All field and property types must be immutable.\r\n" + " - All indexers must be readonly.\r\n" + " - Event fields are ignored.\r\n" + "* Use PropertiesSettings and specify how copying is performed:\r\n" + " - ReferenceHandling.Structural means that a the entire graph is traversed and immutable property values are copied.\r\n" + " - For structural Activator.CreateInstance is used to create instances so a parameterless constructor may be needed, can be private.\r\n" + " - ReferenceHandling.References means that references are copied.\r\n" + " - Exclude a combination of the following:\r\n" + " - The property WithComplexProperty.ComplexType.\r\n" + " - The type ComplexType.\r\n"; var source = new WithComplexProperty(); var target = new WithComplexProperty(); var exception = Assert.Throws <NotSupportedException>(() => Synchronize.PropertyValues(source, target, ReferenceHandling.Throw)); Assert.AreEqual(expected, exception.Message); Assert.DoesNotThrow(() => Synchronize.PropertyValues(source, target, ReferenceHandling.Structural)); Assert.DoesNotThrow(() => Synchronize.PropertyValues(source, target, ReferenceHandling.References)); }
private void CheckTableState(BackgroundWorker worker) { List <SyncHelper.ThreadState> listOfThread = new List <SyncHelper.ThreadState>(); foreach (SyncTables table in _entities) { SyncHelper.ThreadState _threadState = new SyncHelper.ThreadState(); _threadState.table = table; _threadState.worker = worker; try { Synchronize sync = new Synchronize(table.TableName, _filter, _threadState._event, new SqlConnection(_localConnectionString), new SqlConnection(_mainConnectionString)); ThreadPool.QueueUserWorkItem(new WaitCallback(sync.PerformSync), _threadState); _threadState._event.WaitOne(); } catch (Exception ex) { Logs.ErrorLogs("CheckTableState", "ChecktableState", ex.Message); } } //while (DoneCount != _entities.Count - 5) //{ //} }
public void HappyPath(ReferenceHandling referenceHandling) { var source = new WithSimpleProperties { IntValue = 1, NullableIntValue = 2, StringValue = "3", EnumValue = StringSplitOptions.RemoveEmptyEntries }; var target = new WithSimpleProperties { IntValue = 3, NullableIntValue = 4 }; using (Synchronize.PropertyValues(source, target, referenceHandling)) { Assert.AreEqual(1, source.IntValue); Assert.AreEqual(1, target.IntValue); Assert.AreEqual(2, source.NullableIntValue); Assert.AreEqual(2, target.NullableIntValue); Assert.AreEqual("3", source.StringValue); Assert.AreEqual("3", target.StringValue); Assert.AreEqual(StringSplitOptions.RemoveEmptyEntries, source.EnumValue); Assert.AreEqual(StringSplitOptions.RemoveEmptyEntries, target.EnumValue); source.IntValue = 5; Assert.AreEqual(5, source.IntValue); Assert.AreEqual(5, target.IntValue); } source.IntValue = 6; Assert.AreEqual(6, source.IntValue); Assert.AreEqual(5, target.IntValue); }
public void CreateAndDisposeStructural1() { var source = new ObservableCollection <ComplexType> { new ComplexType("a", 1), new ComplexType("b", 2) }; var target = new ObservableCollection <ComplexType>(); using (Synchronize.PropertyValues(source, target, ReferenceHandling.Structural)) { var expected = new[] { new ComplexType("a", 1), new ComplexType("b", 2) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); Assert.AreNotSame(source[0], target[0]); Assert.AreNotSame(source[1], target[1]); source[0].Value++; expected = new[] { new ComplexType("a", 2), new ComplexType("b", 2) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); Assert.AreNotSame(source[0], target[0]); Assert.AreNotSame(source[1], target[1]); source.Add(source[0]); expected = new[] { new ComplexType("a", 2), new ComplexType("b", 2), new ComplexType("a", 2) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); Assert.AreNotSame(source[0], target[0]); Assert.AreNotSame(source[1], target[1]); source[0].Value++; expected = new[] { new ComplexType("a", 3), new ComplexType("b", 2), new ComplexType("a", 3) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); Assert.AreNotSame(source[0], target[0]); Assert.AreNotSame(source[1], target[1]); } source.Add(new ComplexType("c", 3)); CollectionAssert.AreEqual(new[] { new ComplexType("a", 3), new ComplexType("b", 2), new ComplexType("a", 3), new ComplexType("c", 3) }, source, ComplexType.Comparer); var expectedTargets = new[] { new ComplexType("a", 3), new ComplexType("b", 2), new ComplexType("a", 3) }; CollectionAssert.AreEqual(expectedTargets, target, ComplexType.Comparer); source[0].Value++; CollectionAssert.AreEqual(new[] { new ComplexType("a", 4), new ComplexType("b", 2), new ComplexType("a", 4), new ComplexType("c", 3) }, source, ComplexType.Comparer); CollectionAssert.AreEqual(expectedTargets, target, ComplexType.Comparer); source[1].Value++; CollectionAssert.AreEqual(new[] { new ComplexType("a", 4), new ComplexType("b", 3), new ComplexType("a", 4), new ComplexType("c", 3) }, source, ComplexType.Comparer); CollectionAssert.AreEqual(expectedTargets, target, ComplexType.Comparer); source[2].Value++; CollectionAssert.AreEqual(new[] { new ComplexType("a", 5), new ComplexType("b", 3), new ComplexType("a", 5), new ComplexType("c", 3) }, source, ComplexType.Comparer); CollectionAssert.AreEqual(expectedTargets, target, ComplexType.Comparer); target[0].Value++; target.Add(new ComplexType("c", 4)); expectedTargets = new[] { new ComplexType("a", 4), new ComplexType("b", 2), new ComplexType("a", 3), new ComplexType("c", 4) }; CollectionAssert.AreEqual(expectedTargets, target, ComplexType.Comparer); }
public void HandlesPropertyChangedEmptyAndNull(string prop) { var source = new WithComplexProperty("a", 1) { ComplexType = new ComplexType("b", 2) }; var target = new WithComplexProperty("c", 3) { ComplexType = new ComplexType("d", 4) }; using (Synchronize.PropertyValues(source, target, ReferenceHandling.Structural)) { source.SetFields("e", 5, new ComplexType("f", 6)); source.OnPropertyChanged(prop); Assert.AreEqual("e", source.Name); Assert.AreEqual("e", target.Name); Assert.AreEqual(5, source.Value); Assert.AreEqual(5, target.Value); Assert.AreNotSame(source.ComplexType, target.ComplexType); Assert.AreEqual("f", source.ComplexType.Name); Assert.AreEqual("f", target.ComplexType.Name); Assert.AreEqual(6, source.ComplexType.Value); Assert.AreEqual(6, target.ComplexType.Value); } }
private void btnSendAll_Click(object sender, EventArgs e) { ////////////////////////////////////////////////////////////////////// ////////////////////// DUNG DE GOI TrUC TIEP K THONG QUA WEBSERVICE/// ////////////////////////////////////////////////////////////////////// //List<Figure> figures = SynDBCore<Figure>.GetAllToSend("Id"); //List<Figure> figures2 = SynDBCore<Figure>.SendToSV("12", figures); //SynDBCore<Figure>.SaveLog(new List<Figure>(figures2)); ////return ////////////////////////////////////////////////////////////////////// //////// DUNG DE KHAI BAO FIGURE CO ID=6 VUA MOI THAY DOI(SUA, XOA)/// ////////////////////////////////////////////////////////////////////// //if (SynDBCore<Figure>.SaveChange(6)) MessageBox.Show("Change data completed"); //return; //////////////////////////////////////////////////////////////////// //////////////////// DUNG DE GOI WEBSERVICE //////////////////////// //////////////////////////////////////////////////////////////////// Synchronize synservice = new Synchronize(); synservice.SendingCompleted += synservice_SendingCompleted; synservice.SendAll("12"); MessageBox.Show("Change data completed"); }
public void Excludes(ReferenceHandling referenceHandling) { var source = new WithSimpleProperties { IntValue = 1, StringValue = "2" }; var target = new WithSimpleProperties { IntValue = 3, StringValue = "4" }; var settings = PropertiesSettings.Build() .IgnoreProperty <WithSimpleProperties>(x => x.StringValue) .CreateSettings(referenceHandling); using (Synchronize.PropertyValues(source, target, settings)) { Assert.AreEqual(1, source.IntValue); Assert.AreEqual(1, target.IntValue); Assert.AreEqual("2", source.StringValue); Assert.AreEqual("4", target.StringValue); source.IntValue = 5; Assert.AreEqual(5, source.IntValue); Assert.AreEqual(5, target.IntValue); source.StringValue = "7"; Assert.AreEqual("7", source.StringValue); Assert.AreEqual("4", target.StringValue); } source.IntValue = 6; Assert.AreEqual(6, source.IntValue); Assert.AreEqual(5, target.IntValue); Assert.AreEqual("7", source.StringValue); Assert.AreEqual("4", target.StringValue); }
public void HandlesMissingProperty(ReferenceHandling referenceHandling) { var source = new WithSimpleProperties { IntValue = 1, StringValue = "2" }; var target = new WithSimpleProperties { IntValue = 3, StringValue = "4" }; using (Synchronize.PropertyValues(source, target, referenceHandling)) { Assert.AreEqual(1, source.IntValue); Assert.AreEqual(1, target.IntValue); Assert.AreEqual("2", source.StringValue); Assert.AreEqual("2", target.StringValue); source.OnPropertyChanged("Missing"); source.IntValue = 5; Assert.AreEqual(5, source.IntValue); Assert.AreEqual(5, target.IntValue); Assert.AreEqual("2", source.StringValue); Assert.AreEqual("2", target.StringValue); } source.IntValue = 6; Assert.AreEqual(6, source.IntValue); Assert.AreEqual(5, target.IntValue); Assert.AreEqual("2", source.StringValue); Assert.AreEqual("2", target.StringValue); }
public async Task Sync_Folder() { var sync = new Synchronize(new AppSettings { DatabaseType = AppSettings.DatabaseTypeList.InMemoryDatabase }, new FakeIQuery(), new FakeSelectorStorage(new FakeIStorage(new List <string> { "/" }, new List <string> { "/test.jpg" }, new List <byte[]> { CreateAnImage.Bytes })), new FakeIWebLogger(), new FakeMemoryCache()); var result = await sync.Sync("/"); Assert.AreEqual(2, result.Count); Assert.AreEqual(FileIndexItem.ExifStatus.Ok, result[0].Status); Assert.AreEqual(FileIndexItem.ExifStatus.Ok, result[1].Status); Assert.AreEqual("/test.jpg", result[0].FilePath); Assert.AreEqual("/", result[1].FilePath); }
public void HandlesPropertyChangedEmptyAndNull(string prop) { var source = new WithSimpleProperties { IntValue = 1, StringValue = "2" }; var target = new WithSimpleProperties { IntValue = 3, StringValue = "4" }; foreach (var referenceHandling in Enum.GetValues(typeof(ReferenceHandling)).Cast <ReferenceHandling>()) { source.IntValue = 1; source.StringValue = "2"; target.IntValue = 3; target.StringValue = "4"; using (Synchronize.PropertyValues(source, target, referenceHandling)) { Assert.AreEqual(1, source.IntValue); Assert.AreEqual(1, target.IntValue); Assert.AreEqual("2", source.StringValue); Assert.AreEqual("2", target.StringValue); source.SetFields(5, "6"); source.OnPropertyChanged(prop); Assert.AreEqual(5, source.IntValue); Assert.AreEqual(5, target.IntValue); Assert.AreEqual("6", source.StringValue); Assert.AreEqual("6", target.StringValue); } } }
private void SynchronizationCompleted(object sender, Synchronization.SynchronizationResult e) { Synchronize.StopAnimationAndEnable(); Synchronize.IsEnabled = false; SetButtonState(true); }
public async Task Sync_NotFound() { var sync = new Synchronize(_appSettings, new FakeIQuery(), new FakeSelectorStorage(), new FakeIWebLogger(), new FakeMemoryCache()); var result = await sync.Sync("/not_found.jpg"); Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundNotInIndex, result[0].Status); }
public void HandlesMissingProperty(ReferenceHandling referenceHandling) { var source = new WithSimpleProperties { IntValue = 1, StringValue = "2" }; var target = new WithSimpleProperties { IntValue = 3, StringValue = "4" }; using (Synchronize.PropertyValues(source, target, referenceHandling)) { Assert.AreEqual(1, source.IntValue); Assert.AreEqual(1, target.IntValue); Assert.AreEqual("2", source.StringValue); Assert.AreEqual("2", target.StringValue); #pragma warning disable INPC009 // Don't raise PropertyChanged for missing property. source.OnPropertyChanged("Missing"); #pragma warning restore INPC009 // Don't raise PropertyChanged for missing property. source.IntValue = 5; Assert.AreEqual(5, source.IntValue); Assert.AreEqual(5, target.IntValue); Assert.AreEqual("2", source.StringValue); Assert.AreEqual("2", target.StringValue); } source.IntValue = 6; Assert.AreEqual(6, source.IntValue); Assert.AreEqual(5, target.IntValue); Assert.AreEqual("2", source.StringValue); Assert.AreEqual("2", target.StringValue); }
public void Updates() { var source = new With <BaseClass>(); var target = new With <BaseClass>(); using (Synchronize.PropertyValues(source, target, ReferenceHandling.Structural)) { source.Value = new Derived1 { BaseValue = 1, Derived1Value = 2 }; Assert.AreEqual(null, source.Name); Assert.AreEqual(null, target.Name); Assert.IsInstanceOf <Derived1>(source.Value); Assert.IsInstanceOf <Derived1>(target.Value); Assert.AreEqual(1, source.Value.BaseValue); Assert.AreEqual(1, target.Value.BaseValue); Assert.AreEqual(2, ((Derived1)source.Value).Derived1Value); Assert.AreEqual(2, ((Derived1)target.Value).Derived1Value); source.Value = new Derived2 { BaseValue = 1, Derived2Value = 2 }; Assert.AreEqual(null, source.Name); Assert.AreEqual(null, target.Name); Assert.IsInstanceOf <Derived2>(source.Value); Assert.IsInstanceOf <Derived2>(target.Value); Assert.AreEqual(1, source.Value.BaseValue); Assert.AreEqual(1, target.Value.BaseValue); Assert.AreEqual(2, ((Derived2)source.Value).Derived2Value); Assert.AreEqual(2, ((Derived2)target.Value).Derived2Value); } }
public void MoveThenUpdate(ReferenceHandling referenceHandling) { var source = new ObservableCollection <ComplexType> { new ComplexType("a", 1), new ComplexType("b", 2), new ComplexType("c", 3) }; var target = new ObservableCollection <ComplexType> { new ComplexType("a", 1), new ComplexType("b", 2), new ComplexType("c", 3) }; using (Synchronize.PropertyValues(source, target, referenceHandling)) { source.Move(2, 0); var expected = new[] { new ComplexType("c", 3), new ComplexType("a", 1), new ComplexType("b", 2) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); source[0].Value++; expected = new[] { new ComplexType("c", 4), new ComplexType("a", 1), new ComplexType("b", 2) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); source[1].Value++; expected = new[] { new ComplexType("c", 4), new ComplexType("a", 2), new ComplexType("b", 2) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); source[2].Value++; expected = new[] { new ComplexType("c", 4), new ComplexType("a", 2), new ComplexType("b", 3) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); } }
private void SynchronizationStarted(object sender, EventArgs e) { Synchronize.StartAnimationAndDisable(); Edit.IsEnabled = false; ToggleCodesEnabled(false); ButtonUndo.IsEnabled = false; }
public void Synchronizes() { var source = new ObservableCollection <ComplexType> { new ComplexType("a", 1), new ComplexType("b", 2) }; var target = new ObservableCollection <ComplexType>(); using (Synchronize.PropertyValues(source, target, ReferenceHandling.Structural)) { var expected = new List <ComplexType> { new ComplexType("a", 1), new ComplexType("b", 2) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); Assert.AreNotSame(source[0], target[0]); Assert.AreNotSame(source[1], target[1]); source.Add(new ComplexType("c", 3)); expected.Add(new ComplexType("c", 3)); CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); Assert.AreNotSame(source[0], target[0]); Assert.AreNotSame(source[1], target[1]); Assert.AreNotSame(source[2], target[2]); source[2].Name = "changed"; expected[2].Name = "changed"; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); Assert.AreNotSame(source[0], target[0]); Assert.AreNotSame(source[1], target[1]); Assert.AreNotSame(source[2], target[2]); source.RemoveAt(1); expected.RemoveAt(1); CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); Assert.AreNotSame(source[0], target[0]); Assert.AreNotSame(source[1], target[1]); source.Clear(); Assert.AreEqual(0, source.Count); Assert.AreEqual(0, target.Count); //target.RemoveAt(0); //Assert.AreEqual(2, source.Count); //Assert.AreEqual(1, target.Count); //Assert.AreEqual("a", source[0].Name); //Assert.AreEqual("changed", target[0].Name); //Assert.AreEqual(1, source[0].Value); //Assert.AreEqual(3, target[0].Value); //Assert.AreEqual("changed", source[1].Name); //Assert.AreEqual(3, source[1].Value); //Assert.Inconclusive("Not sure how to handle the situation where target changes. Maybe throw but not very elegant"); } }
private async void RevertAndReload() { await LoadAccounts(); Codes.CanReorderItems = false; Edit.IsChecked = false; Synchronize.StopAnimationAndEnable(); }
public void GetDatabaseRunHistoryDifferenceTest1() { CommandLineArgs cmdLine = null; DatabaseRunHistory expected = null; DatabaseRunHistory actual; actual = Synchronize.GetDatabaseRunHistoryDifference(cmdLine); Assert.AreEqual(expected, actual); }
public Synchronize StartSynchronizationJob(Models.Register register, string itemType) { var synchronizationJob = new Synchronize(); synchronizationJob.Active = true; synchronizationJob.ItemType = itemType; register.Synchronizes.Add(synchronizationJob); _dbContext.SaveChanges(); return(synchronizationJob); }
public void UpdateSynchronize(Synchronize obj) { Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "USP_Synchronize_U"; DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand); db.AddInParameter(dbCommand, "p_detect_interval", DbType.Int32, obj.DetectInterval); db.AddInParameter(dbCommand, "p_retry_count", DbType.Int32, obj.RetryCount); db.ExecuteNonQuery(dbCommand); }
private async void OnSynchronizationTapped(object sender, EventArgs args) { try { configuration = AiDataStore.GetConfiguration(); (Application.Current.MainPage as MasterDetailPage).IsPresented = false; Synchronize = new Synchronize(this); await PopupNavigation.Instance.PushAsync(Synchronize); } catch (Exception ex) { } }
public void Add(ReferenceHandling referenceHandling) { var source = new ObservableCollection <ComplexType>(); var target = new ObservableCollection <ComplexType>(); using (Synchronize.PropertyValues(source, target, referenceHandling)) { source.Add(new ComplexType("a", 1)); var expected = new[] { new ComplexType("a", 1) }; CollectionAssert.AreEqual(expected, source, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target, ComplexType.Comparer); } }
public void ThrowsIfTargetChanges(ReferenceHandling referenceHandling) { var source = new WithSimpleProperties(); var target = new WithSimpleProperties(); using (Synchronize.PropertyValues(source, target, referenceHandling)) { var exception = Assert.Throws <InvalidOperationException>(() => target.IntValue++); var expected = "Target cannot be modified when a synchronizer is applied to it\r\n" + "The change would just trigger a dirty notification and the value would be updated with the value from source."; Assert.AreEqual(expected, exception.Message); } }
public void Add(ReferenceHandling referenceHandling) { var source = new ObservableCollection <WithGetReadOnlyPropertySealed <int> >(); var target = new ObservableCollection <WithGetReadOnlyPropertySealed <int> >(); using (Synchronize.PropertyValues(source, target, referenceHandling)) { source.Add(new WithGetReadOnlyPropertySealed <int>(1)); var expected = new[] { new WithGetReadOnlyPropertySealed <int>(1) }; CollectionAssert.AreEqual(expected, source); CollectionAssert.AreEqual(expected, target); Assert.AreSame(source[0], target[0]); } }
protected override void OnStart(string[] args) { try { var obj = new Synchronize(); obj.Run(); RunSchedule(); Logger.Info("Service sync data from Sql to Oracle successfully"); } catch (Exception ex) { Logger.Error("ERROR Sync data from Sql to Oracle ||Exception: " + ex); //throw; } }
public async Task Sync_File() { var sync = new Synchronize(new AppSettings(), new FakeIQuery(), new FakeSelectorStorage(new FakeIStorage(new List <string> { "/" }, new List <string> { "/test.jpg" })), new FakeIWebLogger(), new FakeMemoryCache()); var result = await sync.Sync("/test.jpg"); // is missing actual bytes Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, result[0].Status); }
protected void Run(object sender) { try { var obj = new Synchronize(); obj.Run(); } catch (Exception ex) { Logger.Error("ERROR Sync data from Sql to Oracle ||Exception: " + ex); } finally { _timer.Start(); } }
//[TestCase(ReferenceHandling.Reference)] public void Remove(ReferenceHandling referenceHandling) { var source = new WithObservableCollectionProperties(new ComplexType("a", 1), new ComplexType("b", 2)); var target = new WithObservableCollectionProperties(new ComplexType("a", 1), new ComplexType("b", 2)); using (Synchronize.PropertyValues(source, target, referenceHandling)) { source.Complexes.RemoveAt(1); var expected = new[] { new ComplexType("a", 1) }; CollectionAssert.AreEqual(expected, source.Complexes, ComplexType.Comparer); CollectionAssert.AreEqual(expected, target.Complexes, ComplexType.Comparer); source.Complexes.RemoveAt(0); CollectionAssert.IsEmpty(source.Complexes); CollectionAssert.IsEmpty(target.Complexes); } }
/// <summary> /// Run in single processing mode for the unique identifier. /// </summary> /// <param name="Options">The collection of options.</param> /// <param name="UniqueIdentifier">The unique identifier.</param> public static void Single(Options Options, string UniqueIdentifier) { // Select the provider. IProvider Provider = _Providers.FirstOrDefault(x => x.Open(UniqueIdentifier) != null); // Check if the provider is valid. if (Provider != null) { // Initialize the series. using (ISeries Series = Provider.Open(UniqueIdentifier)) { // Populate the series. using (Series.Populate()) { // Initialize the series title. string Title = Series.Title.InvalidatePath(); // Initialize the persistence. List<string> Persistence = new List<string>(); // Initialize the persistence file path. string PersistencePath = Path.Combine(Title, ".mangarack-persist"); // Check if persistent synchronization tracking is enabled and a tracking file is available. if (File.Exists(PersistencePath)) { // Iterate through each line in the persistence file. foreach (string Line in File.ReadAllLines(PersistencePath)) { // Add the line to the persistence file names. Persistence.Add(Line); } } // Iterate through each chapter using the chapter and volume filters. foreach (IChapter Chapter in Series.Children.Filter(Options)) { // Initialize whether sychronization has failed. bool HasFailed = false; // Initialize the file name. string FileName = string.Format(Chapter.Volume == -1 ? "{0} #{2}.{3}" : "{0} V{1} #{2}.{3}", Title, Chapter.Volume.ToString("00"), Chapter.Number.ToString("000.####"), Options.FileExtension.InvalidatePath()); // Initialize the file path. string FilePath = Path.Combine(Title, FileName); // Check if persistent synchronization tracking is enabled and the file name is persisted. if (Persistence.Contains(FileName)) { // Continue to the next chapter. continue; } else { // Add the file name to the persistence file names. Persistence.Add(FileName); } // Do the following code. do { // Check if the file should be synchronized. if (Options.DisableDuplicationPrevention || !File.Exists(FilePath)) { // Populate the chapter. using (Chapter.Populate()) { // Initialize a new instance of the Publisher class. using (Publisher Publisher = new Publisher(FilePath, Options, Provider)) { // Initialize a new instance of the Synchronizer class. using (Synchronize Synchronizer = new Synchronize(Publisher, Series, Chapter)) { // Populate synchronously. Synchronizer.Populate(); // Set whether synchronization has failed. HasFailed = false; } } } } else { // Check if a meta-information overwrite should be performed. if (Options.EnableOverwriteMetaInformation) { // Initialize the comic information. ComicInfo ComicInfo = new ComicInfo(), PreviousComicInfo = null; // Initialize a new instance of the ZipFile class. using (ZipFile ZipFile = new ZipFile(FilePath)) { // Find the comic information. ZipEntry ZipEntry = ZipFile.GetEntry("ComicInfo.xml"); // Check if comic information is available. if (ZipEntry != null) { // Load the comic information. PreviousComicInfo = ComicInfo.Load(ZipFile.GetInputStream(ZipEntry)); // Transcribe the series, chapter and pages information. ComicInfo.Transcribe(Series, Chapter, PreviousComicInfo.Pages); // Check if a current genre differs ... if (ComicInfo.Genre.Any(x => !PreviousComicInfo.Genre.Contains(x)) || // ... or if a previous genre differs ... PreviousComicInfo.Genre.Any(x => !ComicInfo.Genre.Contains(x)) || // ... or the manga specification differs ... ComicInfo.Manga != PreviousComicInfo.Manga || // ... or the number differs ... ComicInfo.Number != PreviousComicInfo.Number || // ... or if the page count differs ... ComicInfo.PageCount != PreviousComicInfo.PageCount || // ... or if a current penciller difffers ... ComicInfo.Penciller.Any(x => !PreviousComicInfo.Penciller.Contains(x)) || // ... or if a previous penciller difffers ... PreviousComicInfo.Penciller.Any(x => !ComicInfo.Penciller.Contains(x)) || // ... or if the series differs ... ComicInfo.Series != PreviousComicInfo.Series || // ... or if the summary differs ... ComicInfo.Summary != PreviousComicInfo.Summary || // ... or if the title differs ... ComicInfo.Title != PreviousComicInfo.Title || // ... or if the volume differs ... ComicInfo.Volume != PreviousComicInfo.Volume || // ... or if a current writer differs. ComicInfo.Writer.Any(x => !PreviousComicInfo.Writer.Contains(x)) || // ... or if a previous writer differs. PreviousComicInfo.Writer.Any(x => !ComicInfo.Writer.Contains(x))) { // Initialize a new instance of the MemoryStream class. using (MemoryStream MemoryStream = new MemoryStream()) { // Save the comic information. ComicInfo.Save(MemoryStream); // Rewind the stream. MemoryStream.Position = 0; // Begin updating the compressed file. ZipFile.BeginUpdate(); // Add the file. ZipFile.Add(new DataSource(MemoryStream), "ComicInfo.xml"); // End updating the compressed file. ZipFile.CommitUpdate(); // Write a message. Console.WriteLine("Modified {0}", FileName); } } } } } // Check if a repair should be performed. if (!Options.DisableRepairAndErrorTracking && File.Exists(string.Format("{0}.txt", FilePath))) { // Populate the chapter. using (Chapter.Populate()) { // Initialize the comic information. ComicInfo ComicInfo = null; // Initialize whether there are broken pages. bool HasBrokenPages = false; // Initialize a new instance of the ZipFile class. using (ZipFile ZipFile = new ZipFile(FilePath)) { // Find the comic information. ZipEntry ZipEntry = ZipFile.GetEntry("ComicInfo.xml"); // Check if comic information is available. if (ZipEntry == null) { // Stop the function. return; } else { // Load the comic information. ComicInfo = ComicInfo.Load(ZipFile.GetInputStream(ZipEntry)); } } // Initialize a new instance of the Publisher class. using (Publisher Publisher = new Publisher(FilePath, Options, Provider, true)) { // Initialize a new instance of the Repair class. using (Repair Repair = new Repair(Publisher, Series, Chapter, ComicInfo, File.ReadAllLines(string.Format("{0}.txt", FilePath)))) { // Populate synchronously. Repair.Populate(); // Set whether there are broken pages. HasBrokenPages = Publisher.HasBrokenPages; // Set whether synchronization has failed. HasFailed = Publisher.HasFailed = Repair.HasFailed; } } // Check if there are no broken pages. if (!HasBrokenPages && File.Exists(string.Format("{0}.txt", FilePath))) { // Delete the error file. File.Delete(string.Format("{0}.txt", FilePath)); } } } } } while (HasFailed); // Check if persistent synchronization tracking is enabled. if (Options.EnablePersistentSynchronization) { // Write each line to the persistence file path. File.WriteAllLines(PersistencePath, Persistence.ToArray()); } } } } } }
/// <summary> /// Run in single processing mode for the unique identifier. /// </summary> /// <param name="Options">The collection of options.</param> /// <param name="UniqueIdentifier">The unique identifier.</param> public static void Single(Options Options, string UniqueIdentifier) { // Select the provider. IProvider Provider = _Providers.FirstOrDefault(x => x.Open(UniqueIdentifier) != null); // Check if the provider is valid. if (Provider != null) { // Initialize the series. using (ISeries Series = Provider.Open(UniqueIdentifier)) { // Populate the series. using (Series.Populate()) { // Initialize the series title. string Title = Series.Title.InvalidatePath(); // Iterate through each chapter using the chapter and volume filters. foreach (IChapter Chapter in Series.Children.Filter(Options)) { // Initialize the file path. string FilePath = Path.Combine(Title, string.Format(Chapter.Volume == -1 ? "{0} #{2}.{3}" : "{0} V{1} #{2}.{3}", Title, Chapter.Volume.ToString("00"), Chapter.Number.ToString("000.####"), Options.FileExtension.InvalidatePath())); // Check if the file should be synchronized. if (Options.DisableDuplicationPrevention || !File.Exists(FilePath)) { // Populate the chapter. using (Chapter.Populate()) { // Initialize a new instance of the Publisher class. using (Publisher Publisher = new Publisher(FilePath, Options, Provider)) { // Initialize a new instance of the Synchronizer class. using (Synchronize Synchronizer = new Synchronize(Publisher, Series, Chapter)) { // Populate synchronously. Synchronizer.Populate(); } } } } else if (!Options.DisableRepairAndErrorTracking && File.Exists(string.Format("{0}.txt", FilePath))) { // Populate the chapter. using (Chapter.Populate()) { // Initialize the comic information. ComicInfo ComicInfo = null; // Initialize whether there are broken pages. bool HasBrokenPages = false; // Initialize whether repairing has failed. bool HasFailed = false; // Initialize a new instance of the ZipFile class. using (ZipFile ZipFile = new ZipFile(FilePath)) { // Find the comic information. ZipEntry ZipEntry = ZipFile.GetEntry("ComicInfo.xml"); // Check if comic information is available. if (ZipEntry == null) { // Stop the function. return; } else { // Load the comic information. ComicInfo = ComicInfo.Load(ZipFile.GetInputStream(ZipEntry)); } } // Initialize a new instance of the Publisher class. using (Publisher Publisher = new Publisher(FilePath, Options, Provider, true)) { // Initialize a new instance of the Repair class. using (Repair Repair = new Repair(Publisher, Series, Chapter, ComicInfo, File.ReadAllLines(string.Format("{0}.txt", FilePath)))) { // Populate synchronously. Repair.Populate(); // Set whether there are broken pages. HasBrokenPages = Publisher.HasBrokenPages; // Set whether repairing has failed. HasFailed = Publisher.HasFailed = Repair.HasFailed; } } // Check if there are no broken pages. if (!HasBrokenPages) { // Delete the error file. File.Delete(string.Format("{0}.txt", FilePath)); } // Check if repairing has failed. if (HasFailed) { // Run in single processing mode for the unique identifier. Single(Options, UniqueIdentifier); } } } } } } } }
/// <summary> /// Run in single processing mode for the location. /// </summary> /// <param name="location">The location.</param> /// <param name="options">The collection of options.</param> public static void Single(string location, Options options) { var provider = Providers.FirstOrDefault(x => x.Open(location) != null); if (provider == null) return; using (var series = provider.Open(location)) { using (series.Populate()) { var seriesTitle = series.Title.InvalidatePath(); var persistencePath = Path.Combine(seriesTitle, ".mangarack-persist"); var persistence = new List<List<string>>(); if (File.Exists(persistencePath)) { const int persistenceVersion = 2; foreach (var pieces in File.ReadAllLines(persistencePath).Select(line => new List<string>(line.Split('\0')))) { while (pieces.Count < persistenceVersion) pieces.Add(string.Empty); persistence.Add(pieces); } } foreach (var chapter in series.Children) { var line = persistence.FirstOrDefault(x => string.Equals(x[1], chapter.UniqueIdentifier)); if (line == null) continue; var currentFilePath = Path.Combine(seriesTitle, line[0]); var nextFileName = chapter.ToFileName(seriesTitle, options); if (!string.Equals(line[0], nextFileName) && File.Exists(currentFilePath)) { File.Move(currentFilePath, Path.Combine(seriesTitle, nextFileName)); line[0] = nextFileName; Persist(persistencePath, persistence); Console.WriteLine("Switched {0}", nextFileName); } } foreach (var chapter in series.Children.Filter(options)) { var hasFailed = false; var fileName = chapter.ToFileName(seriesTitle, options); var filePath = Path.Combine(seriesTitle, fileName); var persistenceFile = persistence.FirstOrDefault(x => string.Equals(x[0], fileName)); if (options.EnablePersistentSynchronization && persistenceFile != null) { continue; } if (persistenceFile != null) { persistenceFile[1] = chapter.UniqueIdentifier ?? string.Empty; } else { persistence.Add(new List<string> {fileName, chapter.UniqueIdentifier ?? string.Empty}); } do { if (options.DisableDuplicationPrevention || !File.Exists(filePath)) { using (chapter.Populate()) { using (var publisher = new Publisher(filePath, options, provider)) { using (var synchronizer = new Synchronize(publisher, series, chapter)) { synchronizer.Populate(); hasFailed = false; } } } } else { if (options.EnableOverwriteMetaInformation) { var comicInfo = new ComicInfo(); using (var zipFile = new ZipFile(filePath)) { var zipEntry = zipFile.GetEntry("ComicInfo.xml"); if (zipEntry != null) { var previousComicInfo = ComicInfo.Load(zipFile.GetInputStream(zipEntry)); comicInfo.Transcribe(series, chapter, previousComicInfo.Pages); if (comicInfo.Genre.Any(x => !previousComicInfo.Genre.Contains(x)) || previousComicInfo.Genre.Any(x => !comicInfo.Genre.Contains(x)) || comicInfo.Manga != previousComicInfo.Manga || comicInfo.Number != previousComicInfo.Number || comicInfo.PageCount != previousComicInfo.PageCount || comicInfo.Penciller.Any(x => !previousComicInfo.Penciller.Contains(x)) || previousComicInfo.Penciller.Any(x => !comicInfo.Penciller.Contains(x)) || comicInfo.Series != previousComicInfo.Series || comicInfo.Summary != previousComicInfo.Summary || comicInfo.Title != previousComicInfo.Title || comicInfo.Volume != previousComicInfo.Volume || comicInfo.Writer.Any(x => !previousComicInfo.Writer.Contains(x)) || previousComicInfo.Writer.Any(x => !comicInfo.Writer.Contains(x))) { using (var memoryStream = new MemoryStream()) { comicInfo.Save(memoryStream); memoryStream.Position = 0; zipFile.BeginUpdate(); zipFile.Add(new DataSource(memoryStream), "ComicInfo.xml"); zipFile.CommitUpdate(); Console.WriteLine("Modified {0}", fileName); } } } } } if (!options.DisableRepairAndErrorTracking && File.Exists(string.Format("{0}.txt", filePath))) { using (chapter.Populate()) { ComicInfo comicInfo; var hasBrokenPages = false; using (var zipFile = new ZipFile(filePath)) { var zipEntry = zipFile.GetEntry("ComicInfo.xml"); if (zipEntry == null) { return; } comicInfo = ComicInfo.Load(zipFile.GetInputStream(zipEntry)); } using (var publisher = new Publisher(filePath, options, provider, true)) { using (var repair = new Repair(publisher, chapter, comicInfo, File.ReadAllLines(string.Format("{0}.txt", filePath)))) { repair.Populate(); hasBrokenPages = publisher.HasBrokenPages; hasFailed = publisher.HasFailed = repair.HasFailed; } } if (!hasBrokenPages && File.Exists(string.Format("{0}.txt", filePath))) { File.Delete(string.Format("{0}.txt", filePath)); } } } } } while (hasFailed); Persist(persistencePath, persistence); } } } }