Esempio n. 1
0
 private void Init(string name)
 {
     Progress = new MultiProgress(new IProgress[] { new ConsoleProgress {
                                                        ShowVerbose = true
                                                    }, _stringBuilderProgress });
     RootFolder = new TemporaryFolder("ChorusTest-" + name + "-" + Guid.NewGuid());
 }
        /// <summary>
        /// Make folder-browsing controls invisible, and add in some progress controls for the MakeClone procedure:
        /// </summary>
        private void SwitchControlsForCloning()
        {
            panel.Visible       = false;
            progressBar.Visible = false;

            var logBox = new LogBox
            {
                Location = new Point(panel.Location.X, panel.Location.Y + 50),
                Width    = panel.Width,
                Height   = panel.Height - 50,
                Anchor   = panel.Anchor,
                ShowCopyToClipboardMenuItem = true,
                ShowDetailsMenuItem         = true,
                ShowDiagnosticsMenuItem     = true,
                ShowFontMenuItem            = true
            };

            var progressIndicator = new SimpleProgressIndicator
            {
                Location = new Point(panel.Location.X, panel.Location.Y + 35),
                Width    = panel.Width,
                Height   = 10,
                Style    = ProgressBarStyle.Marquee,
                Anchor   = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top,
                MarqueeAnimationSpeed = 50
            };

#if MONO
            progressIndicator.MarqueeAnimationSpeed = 3000;
#else
#endif
            progressIndicator.IndicateUnknownProgress();

            _clonerStatusLabel = new TextBox
            {
                Anchor      = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
                BackColor   = SystemColors.Control,
                BorderStyle = BorderStyle.None,
                Font        = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point, ((0))),
                Location    = panel.Location,
                Multiline   = true,
                Name        = "_clonerStatusLabel",
                ReadOnly    = true,
                Size        = new Size(panel.Width, 25)
            };

            Controls.Add(logBox);
            Controls.Add(progressIndicator);
            Controls.Add(_clonerStatusLabel);

            _clonerMultiProgess = new MultiProgress();
            _clonerMultiProgess.AddMessageProgress(logBox);
            logBox.ProgressIndicator = progressIndicator;
            _clonerMultiProgess.ProgressIndicator = progressIndicator;

            _clonerStatusLabel.Text = string.Format(LocalizationManager.GetString("Messages.Getting", "Getting {0}..."), RepositoryKindLabel);
        }
Esempio n. 3
0
        public void ErrorsEncountered_ErrorOriginatesWithOneHandler_MultiProgressHasErrorsEncountered()
        {
            var multiProgress  = new MultiProgress();
            var statusProgress = new StatusProgress();

            multiProgress.Add(statusProgress);
            var consoleProgress = new ConsoleProgress();

            multiProgress.AddMessageProgress(consoleProgress);
            statusProgress.WriteError("some error happened!");
            Assert.That(multiProgress.ErrorEncountered, Is.True);
        }
Esempio n. 4
0
        public void ErrorsEncountered_ErrorOriginatesWithMultiProgress_BothHandlersHaveErrorsEncountered()
        {
            var multiProgress  = new MultiProgress();
            var statusProgress = new StatusProgress();

            multiProgress.Add(statusProgress);
            var consoleProgress = new ConsoleProgress();

            multiProgress.AddMessageProgress(consoleProgress);
            multiProgress.WriteError("error!");
            Assert.That(consoleProgress.ErrorEncountered, Is.True);
            Assert.That(statusProgress.ErrorEncountered, Is.True);
        }
Esempio n. 5
0
        public SyncControlModel(ProjectFolderConfiguration projectFolderConfiguration,
                                SyncUIFeatures uiFeatureFlags,
                                IChorusUser user)
        {
            _user          = user;
            _progress      = new MultiProgress();
            StatusProgress = new SimpleStatusProgress();
            _progress.Add(StatusProgress);
            Features          = uiFeatureFlags;
            _synchronizer     = Synchronizer.FromProjectConfiguration(projectFolderConfiguration, _progress);
            _backgroundWorker = new BackgroundWorker();
            _backgroundWorker.WorkerSupportsCancellation = true;
            _backgroundWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(_backgroundWorker_RunWorkerCompleted);
            _backgroundWorker.DoWork += worker_DoWork;

            //clients will normally change these
            SyncOptions = new SyncOptions();
            SyncOptions.CheckinDescription = "[" + Application.ProductName + ": " + Application.ProductVersion + "] sync";
            SyncOptions.DoPullFromOthers   = true;
            SyncOptions.DoMergeWithOthers  = true;
            SyncOptions.RepositorySourcesToTry.AddRange(GetRepositoriesToList().Where(r => r.Enabled));
        }
Esempio n. 6
0
        public TestEnvironment(string testName, ApiServerType type)
        {
            Local    = new RepositorySetup(testName + "-local");
            Remote   = new RepositorySetup(testName + "-remote");
            Progress = new ProgressForTest();
            switch (type)
            {
            case ApiServerType.Dummy:
                ApiServer = new DummyApiServerForTest(testName);
                break;

            case ApiServerType.Pull:
                ApiServer = new PullHandlerApiServerForTest(Remote.Repository, Progress);
                break;

            case ApiServerType.Push:
                ApiServer = new PushHandlerApiServerForTest(Remote.Repository, Progress);
                break;
            }
            Label         = testName;
            MultiProgress = new MultiProgress(new IProgress[] { new ConsoleProgress {
                                                                    ShowVerbose = true
                                                                }, Progress });
        }
Esempio n. 7
0
 public GetCloneFromInternetModel()
 {
     _showCloneSpecificSettings = false;
     _progress = new MultiProgress();
 }
Esempio n. 8
0
 public GetCloneFromInternetModel(string parentDirectoryToPutCloneIn)
 {
     _showCloneSpecificSettings  = true;
     ParentDirectoryToPutCloneIn = parentDirectoryToPutCloneIn;
     _progress = new MultiProgress();
 }
Esempio n. 9
0
        /// <summary>
        /// Upload bloom books in the specified folder to the bloom library.
        /// Folders that contain exactly one .htm file are interpreted as books and uploaded.
        /// Other folders are searched recursively for children that appear to be bloom books.
        /// The parent folder of a bloom book is searched for a .bloomCollection file and, if one is found,
        /// the book is treated as part of that collection (e.g., for determining vernacular language).
        /// If the .bloomCollection file is not found, the book is not uploaded.
        /// N.B. The bulk upload process will go ahead and upload templates and books that are already on the server
        /// (over-writing the existing book) without informing the user.
        /// </summary>
        /// <remarks>This method is triggered by starting Bloom with "upload" on the cmd line.</remarks>
        public void BulkUpload(ApplicationContainer container, UploadParameters options)
        {
            BookUpload.Destination = options.Dest;

            using (var progress = new MultiProgress())
            {
                var logFilePath = Path.Combine(options.Path, "BloomBulkUploadLog.txt");

                progress.Add(new Bloom.Utils.ConsoleProgress());

                progress.Add(new FileLogProgress(logFilePath));

                if (!_singleBookUploader.IsThisVersionAllowedToUpload())
                {
                    var oldVersionMsg = LocalizationManager.GetString("PublishTab.Upload.OldVersion",
                                                                      "Sorry, this version of Bloom Desktop is not compatible with the current version of BloomLibrary.org. Please upgrade to a newer version.");
                    progress.WriteMessage(oldVersionMsg);
                    return;
                }

                Debug.Assert(!String.IsNullOrWhiteSpace(options.UploadUser));

                if (!_singleBookUploader.ParseClient.AttemptSignInAgainForCommandLine(options.UploadUser, options.Dest, progress))
                {
                    progress.WriteError("Problem logging in. See messages above.");
                    System.Environment.Exit(1);
                }

                progress.WriteMessage("Uploading books as user {0}", options.UploadUser);

                var bookParams = new BookUploadParameters(options);

                BulkRepairInstanceIds(options.Path);
                ProjectContext
                    context = null;                     // Expensive to create; hold each one we make until we find a book that needs a different one.
                try
                {
                    _collectionFoldersUploaded = new HashSet <string>();
                    _newBooksUploaded          = 0;
                    _booksUpdated    = 0;
                    _booksSkipped    = 0;
                    _booksWithErrors = 0;

                    progress.WriteMessageWithColor("green", $"\n\nStarting upload at {DateTime.Now.ToString()}\n");

                    progress.WriteMessageWithColor("Magenta", $"Looking in '{bookParams.Folder}'...");
                    UploadCollectionOrKeepLookingDeeper(progress, container, bookParams, ref context);

                    if (_collectionFoldersUploaded.Count > 0)
                    {
                        progress.WriteMessageWithColor("green", "\n\nAll finished!");
                        progress.WriteMessage("Processed {0} collection folders.", _collectionFoldersUploaded.Count);
                    }
                    else
                    {
                        progress.WriteError("Did not find any collections to upload.");
                    }

                    progress.WriteMessage("Uploaded {0} new books.", _newBooksUploaded);
                    progress.WriteMessage("Updated {0} books that had changed.", _booksUpdated);
                    progress.WriteMessage("Skipped {0} books that had not changed.", _booksSkipped);
                    if (_booksSkipped > 0)
                    {
                        progress.WriteMessage("(If you don't want Bloom to skip books it thinks have not changed, you can use the --force argument to force all books to re-upload, or just use the Bloom UI to force upload this one book).");
                    }

                    if (_booksWithErrors > 0)
                    {
                        progress.WriteError("Failed to upload {0} books. See \"{1}\" for details.", _booksWithErrors,
                                            logFilePath);
                    }
                }
                finally
                {
                    context?.Dispose();
                }
            }
        }
Esempio n. 10
0
 public InternetCloneSettingsModel(string parentDirectoryToPutCloneIn)
 {
     ParentDirectoryToPutCloneIn = parentDirectoryToPutCloneIn;
     _progress = new MultiProgress();
 }
Esempio n. 11
0
 public InternetCloneSettingsModel()
 {
     _progress = new MultiProgress();
 }
Esempio n. 12
0
        void ILoadingManager.Start()
        {
            m_Complete = false;

            m_Progress = new MultiProgress(m_Commands.Select((iter) => iter.Command).ToArray());

            System.Threading.EventWaitHandle @event = new System.Threading.AutoResetEvent(true);
            var context = System.Threading.SynchronizationContext.Current;

            Task.Run(
                () =>
            {
                //копия для возможности перезагрузки игры
                List <CommandItem> commands = new List <CommandItem>(m_Commands);
                Prepare();

                //пока есть комманды
                while (commands.Count > 0)
                {
                    //получаем комманды, для которых нет зависимостей
                    ILoadingCommand cmd = null;
                    while ((cmd = GetNextCommand()) != null)
                    {
                        //запускаем выполнение комманды
                        context.Post(
                            (postCommand) =>
                        {
                            ((ILoadingCommand)postCommand).Exec(this,
                                                                (cmd) =>
                            {
                                //удаляем из зависимостей
                                RemoveDependency(cmd);
                                @event.Set();
                            });
                        }, cmd);
                    }

                    //ожидание выполнения комманд
                    while ([email protected](15))
                    {
                        foreach (var iter in m_Commands)
                        {
                            context.Post(
                                (postCommand) =>
                            {
                                cmd = postCommand as ILoadingCommand;
                                m_Progress.SetProgress(cmd, cmd.GetProgress());
                            }, iter.Command);
                        }
                    }
                }

                //финализация прогресса
                context.Post(
                    (state) =>
                {
                    m_Progress.SetDone();
                    m_Complete = true;
                    m_OnLoadComplete?.Invoke();
                }, null);


                ILoadingCommand GetNextCommand()
                {
                    var item = commands
                               .FirstOrDefault((iter) => !iter.Dependency.HasDependency);
                    if (item != null)
                    {
                        commands.Remove(item);
                    }
                    return(item?.Command ?? null);
                }

                void RemoveDependency(ILoadingCommand command)
                {
                    foreach (var iter in commands)
                    {
                        iter.Dependency.Remove(command);
                    }
                }

                void Prepare()
                {
                    foreach (var iter in commands)
                    {
                        iter.Dependency.Rebuild(this);
                    }
                }
            });
        }