Ejemplo n.º 1
0
        private async Task <WindowConfigViewModel> InitializeJiraIssueViewModel <T>(JiraConfig jiraConfig, JiraQuery jiraQuery,
                                                                                    JiraStatusCategory jiraStatusCategory) where T : JiraIssueViewModelBase, new()
        {
            string url = $"https://{jiraConfig.ApiHost}";
            var    jiraConfigPassword = Encoding.UTF8.GetString(Convert.FromBase64String(jiraConfig.Password));
            var    projectsResult     = await _apiRequestService.MakeRequestWithBasicAuthAsync <List <ProjectApiModel> >(new Uri($"{url}/project"),
                                                                                                                         jiraConfig.Username, jiraConfigPassword, string.Empty);

            var viewModel = new T
            {
                Width        = jiraConfig.Width,
                Height       = jiraConfig.Height,
                PageSize     = jiraConfig.PageSize,
                StatusColors = jiraConfig.StatusColors
            };

            if (projectsResult.StatusCode == 200)
            {
                viewModel.Projects = JiraApiService.ParseProjects(projectsResult, Convert.ToInt32(jiraConfig.Width));
            }

            InitializeIssueAutoUpdate(url, jiraConfig, jiraQuery, viewModel, _jiraApiService, jiraStatusCategory);

            return(viewModel);
        }
Ejemplo n.º 2
0
        private async Task SetupJiraWindow(string url, string apiBase,
                                           bool lastPage, int startAt,
                                           JiraConfig jiraConfig, JiraQuery jiraQuery, JiraIssueViewModelBase viewModel,
                                           JiraApiService jiraApiService, int issuesTotal, JiraStatusCategory status)
        {
            while (!lastPage)
            {
                var at = startAt;

                await MakeAsyncRequest(url, apiBase, jiraConfig, jiraQuery, viewModel, jiraApiService, at);

                lastPage = IsLastPage(50, startAt, issuesTotal);

                if (!lastPage)
                {
                    startAt += 50;
                }
            }

            var lastUpdate       = DateTime.Now;
            var refreshRate      = jiraConfig.RefreshRate;
            var lastPageUpdate   = DateTime.Now;
            var lastCleanup      = DateTime.Now;
            var pageRotation     = jiraConfig.PageRotation;
            var pageRotationRate = jiraConfig.PageRotationRate;

            AppHeartbeatTimer.Elapsed += delegate
            {
                Dispatcher.Invoke(async() =>
                {
                    if (DateTime.Now.Subtract(lastCleanup) > TimeSpan.FromHours(1))
                    {
                        viewModel.Cleanup();
                        lastCleanup = DateTime.Now;
                    }

                    if (pageRotation)
                    {
                        if (DateTime.Now.Subtract(lastPageUpdate) > TimeSpan.FromSeconds(pageRotationRate))
                        {
                            Logger.Trace($"Page update {viewModel.GetType().Name}");
                            viewModel.TurnPageCommand.Execute(null);
                            lastPageUpdate = DateTime.Now;
                        }
                    }

                    if (DateTime.Now.Subtract(lastUpdate) > TimeSpan.FromSeconds(refreshRate))
                    {
                        Logger.Trace($"Try update {Enum.GetName(typeof(JiraStatusCategory),status)}");
                        MakeAsyncRequest(url, apiBase, jiraConfig, new JiraQuery().UpdatedSince(-15, JiraTimeDifference.Minutes).OrderBy("updated"), viewModel, jiraApiService, 0);
                        lastUpdate = DateTime.Now;
                    }
                });
            };
        }
Ejemplo n.º 3
0
        public MainWindow()
        {
            _configService     = new ConfigService();
            _jiraApiService    = new JiraApiService();
            _apiRequestService = new ApiRequestService();

            InitializeComponent();

            AppHeartbeatTimer.Start();

            var files             = Directory.GetFiles(".", "appsettings*.json");
            var applicationConfig = _configService.GetConfig <ApplicationConfig>(files.First());
            var windowViewModel   = new WindowViewModel
            {
                Windows = new ObservableCollection <ViewModelBase>(), IsDebugMode = applicationConfig.IsDebugMode
            };

            DataContext = windowViewModel;

            Dispatcher.InvokeAsync(() =>
            {
                return(InitialLoad(windowViewModel, applicationConfig));
            });
        }
Ejemplo n.º 4
0
        private async Task MakeAsyncRequest(string url, string apiBase, JiraConfig jiraConfig,
                                            JiraQuery jiraQuery, JiraIssueViewModelBase viewModel, JiraApiService jiraApiService, int startAt)
        {
            async void Callback()
            {
                var issueResult = await _apiRequestService.MakeRequestWithBasicAuthAsync <APIIssueRequestRoot>(
                    new Uri($"{url}{apiBase}"), jiraConfig.Username, Encoding.UTF8.GetString(Convert.FromBase64String(jiraConfig.Password)), $"{jiraQuery}&startAt={startAt}");

                if (issueResult.StatusCode == 200)
                {
                    viewModel.AddOrUpdateNewIssues(jiraApiService.ParseIssues(issueResult));
                    viewModel.Refresh();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            await Task.Run(() => Dispatcher.Invoke(Callback));
        }
Ejemplo n.º 5
0
        private async void InitializeIssueAutoUpdate(string url, JiraConfig jiraConfig,
                                                     JiraQuery jiraQuery, JiraIssueViewModelBase viewModel, JiraApiService jiraApiService,
                                                     JiraStatusCategory jiraStatusCategory)
        {
            const string apiBase = "/search";

            var issueResult = await _apiRequestService.MakeRequestWithBasicAuthAsync <APIIssueRequestRoot>(new Uri($"{url}{apiBase}"),
                                                                                                           jiraConfig.Username, Encoding.UTF8.GetString(Convert.FromBase64String(jiraConfig.Password)), jiraQuery.ToString());

            if (issueResult.StatusCode == 200)
            {
                viewModel.IssuesTotal = issueResult.Data.total;
                viewModel.AddOrUpdateNewIssues(jiraApiService.ParseIssues(issueResult));
                viewModel.Refresh();
            }

            var lastPage = IsLastPage(50, issueResult.Data.startAt, issueResult.Data.total);

            var startAt = 0;

            if (!lastPage)
            {
                startAt += issueResult.Data.issues.Length;
            }

            await SetupJiraWindow(url, apiBase, lastPage, startAt, jiraConfig, jiraQuery,
                                  viewModel, jiraApiService, issueResult.Data.total, jiraStatusCategory);
        }