Exemple #1
0
        private void ValidateAndExecuteURL(string _)
        {
            bool isValidUrl = Uri.TryCreate(_, UriKind.Absolute, out var target);

            if (isValidUrl)
            {
                isValidUrl &= (target.Scheme == Uri.UriSchemeHttp || target.Scheme == Uri.UriSchemeHttps);
                isValidUrl &= (target.Host == "github.com");
            }

            if (isValidUrl)
            {
                try
                {
                    DispatcherHelper.DispatchAction(() =>
                    {
                        new ApiUrl(GuiState).SetApiSegments();
                        new GitHubBranchList(GuiState).SetBranchesList(true);
                        GuiState.IsValidRepoURL = true;
                    });
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.Message, "Error");
                }
            }

            DispatcherHelper.DispatchAction(() => GuiState.IsValidRepoURL = false);
        }
 private void addLog(string log)
 {
     DispatcherHelper.DispatchAction(() =>
     {
         GuiModelData.Logs += string.Format("{0} {1}", DateTime.Now, log) + Environment.NewLine;
     });
 }
Exemple #3
0
        private Action getDownloadTask(GitHubEntry localItem, string outFolder)
        {
            Action action = () =>
            {
                try
                {
                    Downloader.DownloadFile(
                        url: localItem.DownloadUrl,
                        outFolder: outFolder,
                        expectedFileSize: localItem.Size,
                        cancellationToken: _cancellationToken.Token,
                        onPercentChange: downloadPercent =>
                    {
                        localItem.DownloadPercent = downloadPercent;
                        if (downloadPercent == 100)
                        {
                            DispatcherHelper.DispatchAction(
                                () => _guiModelData.GitHubEntries.Remove(localItem));
                        }
                    });
                }
                catch (Exception ex)
                {
                    AppMessenger.Messenger.NotifyColleagues("ShowLog",
                                                            string.Format("{0} -> {1}", localItem.DownloadUrl, ex.Message));
                }
            };

            return(action);
        }
 void doRecalculate(string data)
 {
     Task.Factory.StartNew(() =>
     {
         try
         {
             if (string.IsNullOrWhiteSpace(MainWindowGuiData.OpenedFilePath))
             {
                 return;
             }
             MainWindowGuiData.IsBusy = true;
             Sync.RecalculateRowNumbers(subtitleItemsDataInternal, MainWindowGuiData.OpenedFilePath);
             showConflicts();
         }
         catch (Exception ex)
         {
             ExceptionLogger.LogExceptionToFile(ex);
             LogWindow.AddMessage(LogType.Error, ex.Message);
         }
         finally
         {
             DispatcherHelper.DispatchAction(enableButtons);
             MainWindowGuiData.IsBusy = false;
         }
     });
 }
        void doOpenFile()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(MainWindowGuiData.OpenedFilePath))
                {
                    clearSrtPanel();
                    return;
                }

                MainWindowGuiData.IsBusy = true;

                var parser = new ParseSrt();
                subtitleItemsDataInternal    = parser.ToObservableCollectionFromFile(MainWindowGuiData.OpenedFilePath);
                MainWindowGuiData.HeaderText = MainWindowGuiData.OpenedFilePath;

                setFlowDir(parser.IsRtl);
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogExceptionToFile(ex);
                LogWindow.AddMessage(LogType.Error, ex.Message);
            }
            finally
            {
                DispatcherHelper.DispatchAction(enableButtons);
                MainWindowGuiData.IsBusy = false;
            }
        }
 public HttpResponseMessage Post([FromBody] CommandResult commandResult)
 {
     commandResult.ReceivedId  = IdGenerator.GetId();
     commandResult.JsonContent = this.Request.Content.ReadAsStringAsync().Result.ToFormattedJson();
     DispatcherHelper.DispatchAction(() =>
                                     AppMessenger.Messenger.NotifyColleagues("AddCommandResult", commandResult));
     return(new HttpResponseMessage(HttpStatusCode.Created));
 }
Exemple #7
0
 private void showPdf(IPdfReportData rpt)
 {
     if (rpt == null)
     {
         return;
     }
     DispatcherHelper.DispatchAction(() => _acroPdf.ShowPdf(rpt.FileName));
     Task.Factory.StartNew(() => BrowserGuiData.PdfFilePath = rpt.FileName);
 }
Exemple #8
0
 private void addException(Exception ex)
 {
     DispatcherHelper.DispatchAction(() =>
     {
         AppExceptionsGuiData.AppExceptionsList.Add(new AppException
         {
             Message = ex.Message,
             Details = ExceptionLogger.GetExceptionCallStack(ex)
         });
         PluginContext.NotifyPluginsHost(NotificationType.Update, 1);
     });
 }
        private void processListOfEntries(IEnumerable <GitHubEntry> entries, string baseFoler)
        {
            var outFolder = string.Empty;

            try
            {
                var waitingList = new List <Task>();
                foreach (var item in entries)
                {
                    var localItem = item;

                    if (localItem.Type.Equals("dir"))
                    {
                        var subEntries = getGitHubEntries(localItem.Path, _GuiState.SelectedBranch);
                        if (!subEntries.Any())
                        {
                            continue;
                        }

                        processListOfEntries(subEntries, baseFoler);
                    }
                    else if (localItem.Type.Equals("file"))
                    {
                        DispatcherHelper.DispatchAction(() => _GuiState.GitHubEntries.Add(localItem));

                        outFolder = GetOutputFolder(localItem, baseFoler);
                        var action = getDownloadTask(localItem, outFolder);
                        var task   = Task.Factory.StartNew(
                            action,
                            _cancellationToken.Token,
                            TaskCreationOptions.None,
                            _parallelTasksQueue);
                        waitingList.Add(task);
                    }
                }
                Task.WaitAll(waitingList.ToArray(), _cancellationToken.Token);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message, "Error");
            }
            finally
            {
                Finished(outFolder);
            }
        }
Exemple #10
0
        private void runSample(Type sample)
        {
            IPdfReportData rpt = null;
            var            performanceResult = Performance.RunActionMeasurePerformance(() => rpt = SamplesList.GeneratePdf(sample));

            if (rpt == null)
            {
                return;
            }

            DispatcherHelper.DispatchAction(() =>
                                            BrowserGuiData.IntegrationTests.Add(
                                                new TestResultItem
            {
                TestName    = sample.ToString().Split('.')[2],
                PdfFilePath = rpt.FileName,
                ElapsedTime = performanceResult.Item2.ToString(),
                FileSize    = string.IsNullOrWhiteSpace(rpt.FileName) ? string.Empty : new FileInfo(rpt.FileName).Length.FormatSize(),
                MemoryUsage = performanceResult.Item1.FormatSize().ToString(CultureInfo.InvariantCulture)
            })
                                            );
        }
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                DispatcherHelper.DispatchAction(
                    () => _GuiState.GitHubEntries.Clear());
                if (!NetworkStatus.IsConnectedToInternet())
                {
                    Trace.WriteLine("Internet connection is not avalaible.", "Error");
                    return;
                }

                var entries = getGitHubEntries(_GuiState.RepositorySubDir, _GuiState.SelectedBranch);
                if (!entries.Any())
                {
                    Trace.WriteLine("The folder is empty.", "Error");
                    return;
                }

                var baseFolder = getBaseFolder();
                processListOfEntries(entries, baseFolder);
            }).ContinueWith(obj => Finished(getApiRootUrl()));
        }
Exemple #12
0
        public MainWindowViewModel()
        {
            GuiState = new GuiModel
            {
                GitHubToken = PersistentConfig.GetConfigData("GitHubToken")
            };

            GuiState.WhenAnyValue(p => p.RepositoryFolderFullUrl)
            .Throttle(TimeSpan.FromMilliseconds(250))
            .Subscribe(_ => ValidateAndExecuteURL(_));

            _gitHubDownloader = new GitHubDownloader(GuiState)
            {
                Finished = url =>
                {
                    Trace.WriteLine($"Finished {url}.", "Info");
                    DispatcherHelper.DispatchAction(() => GuiState.HasStarted = false);
                }
            };

            StartCommand      = ReactiveCommand.Create(() => StartDownload(), CanStartDownloadExecute);
            StopCommand       = ReactiveCommand.Create(() => StopDownload());
            OpenFolderCommand = ReactiveCommand.Create(() => GetSaveFolder());
        }
Exemple #13
0
        public static TSqlScript GetSqlFragment(string tSql, string sqlHash, int timeoutSeconds = 7, bool readFromCache = true)
        {
            var runner = TimedRunner.RunWithTimeout(() =>
            {
                try
                {
                    return(getSqlFragment(tSql, sqlHash, readFromCache));
                }
                catch (Exception ex)
                {
                    new ExceptionLogger().LogExceptionToFile(ex, AppMessenger.LogFile);
                    DispatcherHelper.DispatchAction(() => AppMessenger.Messenger.NotifyColleagues("ShowException", ex));
                    return(null);
                }
            }, timeoutSeconds);

            if (runner.IsTimedOut)
            {
                throw new TimeoutException(string.Format("Timed out parsing SqlFragment:{0}{1}",
                                                         Environment.NewLine, tSql));
            }

            return(runner.Result);
        }