Exemple #1
0
 public ShellViewModel(IShellView view, IShellService shellService,
                       ISyncService syncStartService,
                       IGuiInteractionService guiInteractionService,
                       Settings settings,
                       SyncSummary syncSummary,
                       IMessageService messageService,
                       ApplicationLogger applicationLogger, IApplicationUpdateService applicationUpdateService,
                       SystemTrayNotifierViewModel systemTrayNotifierViewModel, ChildContentViewFactory childContentViewFactory)
     : base(view)
 {
     _statusBuilder              = new StringBuilder();
     MessageService              = messageService;
     ApplicationLogger           = applicationLogger;
     Logger                      = applicationLogger.GetLogger(GetType());
     ApplicationUpdateService    = applicationUpdateService;
     ShellService                = shellService;
     SyncStartService            = syncStartService;
     GuiInteractionService       = guiInteractionService;
     Settings                    = settings;
     SyncSummary                 = syncSummary;
     SystemTrayNotifierViewModel = systemTrayNotifierViewModel;
     ChildContentViewFactory     = childContentViewFactory;
     view.Closing               += ViewClosing;
     view.Closed                += ViewClosed;
 }
Exemple #2
0
        public SyncSummary DeserializeSyncSummary()
        {
            var result = DeserializeSyncSummaryBackgroundTask();

            if (result == null)
            {
                return(SyncSummary.GetDefault());
            }
            return(result);
        }
Exemple #3
0
        private void SerializeSyncSummaryBackgroundTask(SyncSummary syncProfile)
        {
            if (!Directory.Exists(ApplicationDataDirectory))
            {
                Directory.CreateDirectory(ApplicationDataDirectory);
            }

            var serializer = new XmlSerializer <SyncSummary>();

            serializer.SerializeToFile(syncProfile, SettingsFilePath);
        }
        private void SerializeSyncSummaryBackgroundTask(SyncSummary syncProfile)
        {
            if (!Directory.Exists(ApplicationDataDirectory))
            {
                Directory.CreateDirectory(ApplicationDataDirectory);
            }
            int i = 0;

            while (File.Exists(SummaryFilePath))
            {
                _summaryFilePath = Path.Combine(_applicationDataDirectory, "Summary" + i++ + ".xml");
            }

            var serializer = new XmlSerializer <SyncSummary>();

            serializer.SerializeToFile(syncProfile, SummaryFilePath);
        }
 public void InitializeSyncDataBy(string id)
 {
     foreach (int type in Enum.GetValues(typeof(SyncType)))
     {
         var summary = new SyncSummary();
         summary.SyncMark = "-1";
         summary.Type     = (SyncType)Enum.Parse(typeof(SyncType), type.ToString());
         var syncData = new SyncData()
         {
             SyncType    = (SyncType)Enum.Parse(typeof(SyncType), type.ToString()),
             SyncParam   = SyncFlag.Synchronized,
             SyncContent = string.Empty,
             Datestamp   = "-1"
         };
         AddSyncData(id, syncData);
     }
 }
        public SyncSummary DeserializeSyncSummary()
        {
            var result = DeserializeSyncSummaryBackgroundTask();

            return(result ?? SyncSummary.GetDefault());
        }
 public bool SerializeSyncSummary(SyncSummary syncProfile)
 {
     SerializeSyncSummaryBackgroundTask(syncProfile);
     return(true);
 }
        public async Task <bool> SerializeSyncSummaryAsync(SyncSummary syncProfile)
        {
            await Run(() => SerializeSyncSummaryBackgroundTask(syncProfile));

            return(true);
        }
Exemple #9
0
        public static SyncSummary Sync(SyncOptions options, ConsoleEx consoleEx = null, HelixFileVersion fileVersion = null)
        {
            var sum = new SyncSummary();

            consoleEx ??= new ConsoleEx();
            consoleEx.Verbosity = options.Verbosity;

            consoleEx.WriteLine("Sync");
            if (options.WhatIf)
            {
                consoleEx.WriteLine("..Options: WhatIf");
            }
            consoleEx.WriteLine($"..DecrDir: {options.DecrDirectory}");
            consoleEx.WriteLine($"..EncrDir: {options.EncrDirectory}");
            //consoleEx.WriteLine($"..Direction: {options.Direction}");
            consoleEx.WriteLine($"..Verbosity: {options.Verbosity}");

            consoleEx.WriteLine();

            if (options.WhatIf)
            {
                consoleEx.WriteLine("** WhatIf Mode - No Changes Made **");
                consoleEx.WriteLine("");
            }


            DerivedBytesProvider derivedBytesProvider = DerivedBytesProvider.FromPassword(options.Password, options.KeyFile);

            using DirectoryPair pair = new DirectoryPair(options.DecrDirectory, options.EncrDirectory, derivedBytesProvider, options.WhatIf);
            pair.PreInitializationCheck();

            if (pair.InitializeFullNeeded())
            {
                if (options.Initialize)
                {
                    //continue, unprompted
                    if (pair.InitializeMergeWarning())
                    {
                        consoleEx.WriteLine("WARNING: Decrypted directory is not empty and will be merged");
                    }
                }
                else
                {
                    consoleEx.WriteLine("Directories require initialization...");

                    if (!consoleEx.PromptBool("Initialized encrypted and decrypted directories now? [y/N] ", false))
                    {
                        consoleEx.WriteErrorLine("Operation cancelled");
                        sum.Error = new InitializationCanceledException();
                        return(sum);
                    }

                    if (pair.InitializeMergeWarning())
                    {
                        if (!consoleEx.PromptBool("Decrypted directory is not empty and will be merged, continue? [y/N] ", false))
                        {
                            consoleEx.WriteErrorLine("Operation cancelled");
                            sum.Error = new InitializationCanceledException();
                            return(sum);
                        }
                    }
                }

                pair.InitializeFull(consoleEx);
            }

            pair.OpenEncr(consoleEx);

            if (pair.InitializeDecrNeeded())
            {
                if (options.Initialize)
                {
                    //continue, unprompted
                    if (pair.InitializeMergeWarning())
                    {
                        consoleEx.WriteLine("WARNING: Decrypted directory is not empty and will be merged");
                    }
                }
                else
                {
                    consoleEx.WriteLine("Decrypted directory require initialization...");

                    if (!consoleEx.PromptBool("Initialized decrypted directories now? [y/N] ", false))
                    {
                        consoleEx.WriteErrorLine("Operation cancelled");
                        sum.Error = new InitializationCanceledException();
                        return(sum);
                    }

                    if (pair.InitializeMergeWarning())
                    {
                        if (!consoleEx.PromptBool("Decrypted directory is not empty and will be merged, continue? [y/N] ", false))
                        {
                            consoleEx.WriteErrorLine("Operation cancelled");
                            sum.Error = new InitializationCanceledException();
                            return(sum);
                        }
                    }
                }

                pair.InitializeDecr(consoleEx);
            }

            pair.OpenDecr(consoleEx);

            pair.Cleanup(consoleEx);

            List <PreSyncDetails> changes = pair.FindChanges(clearCache: false, console: consoleEx);

            if (changes.Count == 0)
            {
                consoleEx.WriteLine("--No Changes--");
            }



            var defaultConflictAction = "";

            consoleEx.WriteLine(VerbosityLevel.Normal, 0, "Performing Sync...");
            foreach (PreSyncDetails change in changes)
            {
                consoleEx.WriteLine(change);

                if (change.SyncMode == PreSyncMode.Conflict)
                {
                    var decrModified = change.DecrInfo == null ? (object)null : change.DecrInfo.LastWriteTimeUtc.ToLocalTime();
                    var decrSize     = change.DecrInfo == null ? (object)null : HelixUtil.FormatBytes5(change.DecrInfo.Length);
                    var encrModified = change.EncrInfo == null ? (object)null : change.EncrInfo.LastWriteTimeUtc.ToLocalTime();
                    var encrSize     = change.EncrHeader == null ? (object)null : HelixUtil.FormatBytes5(change.EncrHeader.Length);


                    string response;
                    if (defaultConflictAction != "")
                    {
                        response = defaultConflictAction;
                    }
                    else
                    {
                        consoleEx.WriteLine($"    Decrypted - Modified: {decrModified}, Size: {decrSize}");
                        consoleEx.WriteLine($"    Encrypted - Modified: {encrModified}, Size: {encrSize}");
                        consoleEx.WriteLine($"");
                        consoleEx.WriteLine($"    D - Decrypted, E - Encrypted, S - Skip, + Always perform this action"); //todo: support newer, support always
                        response = consoleEx.PromptChoice("    Select Option [D,E,S,D+,E+,S+]? ", new string[] { "D", "E", "S", "D+", "E+", "S+" }, "S");
                        if (response.EndsWith("+"))
                        {
                            response = response.Substring(0, 1);
                            defaultConflictAction = response;
                        }
                    }
                    if (response == "D")
                    {
                        change.SyncMode = PreSyncMode.DecryptedSide;
                    }
                    else if (response == "E")
                    {
                        change.SyncMode = PreSyncMode.EncryptedSide;
                    }

                    if (change.SyncMode != PreSyncMode.Conflict)
                    {
                        consoleEx.WriteLine(change);
                    }
                }

                if (change.SyncMode == PreSyncMode.EncryptedSide)
                {
                    //todo: make display operation be the actual operation
                    if (change.DisplayOperation == PreSyncOperation.Add)
                    {
                        sum.EncrAdd++;
                    }
                    else if (change.DisplayOperation == PreSyncOperation.Remove)
                    {
                        sum.EncrRemove++;
                    }
                    else if (change.DisplayOperation == PreSyncOperation.Change)
                    {
                        sum.EncrChange++;
                    }
                    else
                    {
                        sum.EncrOther++;
                    }
                }
                else if (change.SyncMode == PreSyncMode.DecryptedSide)
                {
                    if (change.DisplayOperation == PreSyncOperation.Add)
                    {
                        sum.DecrAdd++;
                    }
                    else if (change.DisplayOperation == PreSyncOperation.Remove)
                    {
                        sum.DecrRemove++;
                    }
                    else if (change.DisplayOperation == PreSyncOperation.Change)
                    {
                        sum.DecrChange++;
                    }
                    else
                    {
                        sum.DecrOther++;
                    }
                }
                else if (change.SyncMode == PreSyncMode.Conflict)
                {
                    sum.Conflict++;
                }


                var syncResult = pair.TrySync(change, consoleEx);
                //todo: add to error log
                if (syncResult.Exception != null)
                {
                    consoleEx.WriteErrorLine("..." + syncResult.Exception.Message);
                }
            }

            consoleEx.WriteLine("== Summary ==");
            consoleEx.WriteLine(sum);

            //todo: fix unchanged
            consoleEx.WriteLine();


            //consoleEx.WriteLine(VerbosityLevel.Diagnostic, 0, "");
            //consoleEx.WriteLine(VerbosityLevel.Diagnostic, 0, "==Decr Directory==");
            //foreach (var entry in decrDirectory.FSDirectory.GetEntries(SearchOption.AllDirectories))
            //{
            //    if (entry is FSDirectory dirEntry)
            //        consoleEx.WriteLine(VerbosityLevel.Diagnostic, 1, $"<dir> {entry.RelativePath}");
            //    else if (entry is FSFile fileEntry)
            //        consoleEx.WriteLine(VerbosityLevel.Diagnostic, 1, $"{HelixUtil.FormatBytes5(entry.Length)} {entry.RelativePath}");
            //}

            //consoleEx.WriteLine(VerbosityLevel.Diagnostic, 0, "");
            //consoleEx.WriteLine(VerbosityLevel.Diagnostic, 0, "==Encr Directory==");
            //foreach (var entry in encrDirectory.FSDirectory.GetEntries(SearchOption.AllDirectories))
            //{
            //    if (entry is FSDirectory dirEntry)
            //        consoleEx.WriteLine(VerbosityLevel.Diagnostic, 1, $"<dir> {entry.RelativePath}");
            //    else if (entry is FSFile fileEntry)
            //        consoleEx.WriteLine(VerbosityLevel.Diagnostic, 1, $"{HelixUtil.FormatBytes5(entry.Length)} {entry.RelativePath}");
            //}

            return(sum);
        }
Exemple #10
0
        /// <exception cref="ImportCardinalityMismatchException">
        ///     There are zero exported objects with the contract name derived from
        ///     <paramref name="T" /> in the <see cref="CompositionContainer" />
        ///     .-or-There is more than one exported object with the contract name
        ///     derived from <paramref name="T" /> in the
        ///     <see cref="CompositionContainer" /> .
        /// </exception>
        /// <exception cref="CompositionContractMismatchException">
        ///     The underlying exported object cannot be cast to
        ///     <paramref name="T" /> .
        /// </exception>
        /// <exception cref="CompositionException">
        ///     An error occurred during composition.
        ///     <see cref="System.ComponentModel.Composition.CompositionException.Errors" />
        ///     will contain a collection of errors that occurred.
        /// </exception>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            DispatcherUnhandledException += AppDispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;

            catalog = new AggregateCatalog();
            // Add the WpfApplicationFramework assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ViewModel).Assembly));
            // Add the Common assembly to catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ApplicationLogger).Assembly));
            //Add Services assembly to catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ICalendarService).Assembly));
            //Add Authentication.Google assembly to catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(IAccountAuthenticationService).Assembly));
            //Add GoogleServices assembly to catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(IGoogleCalendarService).Assembly));
            //Add OutlookServices assembly to catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(IOutlookCalendarService).Assembly));
            //Add ExchangeWebServices assembly to catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(IExchangeWebCalendarService).Assembly));
            //Add SyncEngine assembly to catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ICalendarSyncEngine).Assembly));
            //Add Analytics assembly to catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(SyncAnalyticsService).Assembly));
            // Add the Application assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly));
            // Add the Presentation assembly to the catalog
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));

            //Composition Container
            container = new CompositionContainer(catalog, true);
            var batch = new CompositionBatch();

            batch.AddExportedValue(container);
            container.Compose(batch);

            //Load settings
            var settings = container.GetExportedValue <ISettingsProvider>().GetSettings();

            container.ComposeExportedValue(settings);

            //Load sync summary
            var syncSummary = new SyncSummary();

            container.ComposeExportedValue(syncSummary);

            //Get Application logger
            _applicationLogger = container.GetExportedValue <ApplicationLogger>();
            _applicationLogger.Setup();

            //Initialize Application Controller
            controller = container.GetExportedValue <IApplicationController>();

            controller.Initialize();
            if (settings.AppSettings.StartMinimized)
            {
                _startMinimized = true;
            }
            controller.Run(_startMinimized);
        }