Exemple #1
0
        private async void GetWorkItemTypesBehaviors(GetWorkItemTypesBehaviorsEventArgs args)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    Results.InitializeHttpClient(client, args.Organization.PAT);

                    // TODO(crhodes)
                    // Update Uri  Use args for parameters.
                    var requestUri = $"{args.Organization.Uri}/_apis"
                                     + $"/work/processes/{args.Process.id}/"
                                     + $"/workitemtypesbehaviors/{args.WorkItemType.referenceName}"
                                     + "/behaviors"
                                     + "?api-version=6.1-preview.1";

                    var exchange = Results.InitializeExchange(client, requestUri);

                    using (HttpResponseMessage response = await client.GetAsync(requestUri))
                    {
                        Results.RecordExchangeResponse(response, exchange);

                        response.EnsureSuccessStatusCode();

                        string outJson = await response.Content.ReadAsStringAsync();

                        JObject o = JObject.Parse(outJson);

                        WorkItemTypesBehaviorsRoot resultRoot = JsonConvert.DeserializeObject <WorkItemTypesBehaviorsRoot>(outJson);

                        Results.ResultItems = new ObservableCollection <WorkItemTypesBehavior>(resultRoot.value);

                        IEnumerable <string> continuationHeaders = default;

                        bool hasContinuationToken = response.Headers.TryGetValues("x-ms-continuationtoken", out continuationHeaders);

                        Results.Count = Results.ResultItems.Count;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, Common.LOG_CATEGORY);
                ExceptionDialogService.DisplayExceptionDialog(DialogService, ex);
            }

            EventAggregator.GetEvent <HttpExchangeEvent>().Publish(Results.RequestResponseExchange);
        }
        //public RESTResult<DType> Results { get; set; } = new RESTResult<DType>();

        #endregion

        #region Event Handlers (none)


        #endregion

        #region Public Methods (none)

        #endregion

        #region Protected Methods (none)


        #endregion

        #region Private Methods

        private async void GetList(EArgs args)
        {
            Int64 startTicks = Log.EVENT_HANDLER($"Enter: ({args.GetType()})", Common.LOG_CATEGORY);

            try
            {
                // NOTE(crhodes)
                // This is easy

                var domainType = new DType();

                // Until we want to pass arguments to the DType Constructor

                //Type dType = typeof(DType);

                //var domainType = Activator.CreateInstance(dType, new object[] { EventAggregator, DialogService });

                MethodInfo getListMethod = domainType.GetType().GetMethod("GetList");

                Task <RESTResult <DType> > almostResults = (Task <RESTResult <DType> >)getListMethod.Invoke(domainType, new object[] { args });

                await almostResults;

                Results.ResultItems = almostResults.Result.ResultItems;

                // NOTE(crhodes)
                // Magic
                Results.ResultItem = almostResults.Result.ResultItem;

                Results.Count = Results.ResultItems.Count();
                Results.RequestResponseExchange = almostResults.Result.RequestResponseExchange;
            }
            catch (Exception ex)
            {
                Log.Error(ex, Common.LOG_CATEGORY);
                ExceptionDialogService.DisplayExceptionDialog(DialogService, ex);
            }
            finally
            {
                // NOTE(crhodes)
                // Always publish the exchange so we can see what we were trying to access
                // TODO(crhodes)
                // May need to catch exceptions in getListMethod so can always return Results.
                EventAggregator.GetEvent <HttpExchangeEvent>().Publish(Results.RequestResponseExchange);
            }

            Log.EVENT_HANDLER($"Exit: ({args.GetType()})", Common.LOG_CATEGORY, startTicks);
        }
Exemple #3
0
        private async void GetWidgets(GetWidgetsEventArgs args)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    Results.InitializeHttpClient(client, args.Organization.PAT);

                    var requestUri = $"{args.Organization.Uri}/{args.Project.id}/{args.Team.id}/_apis/dashboard/dashboards/{args.Dashboard}?api-version=6.1-preview.1";

                    //var exchange = Results.InitializeExchange(client, requestUri);
                    var exchange = Results.InitializeExchange(client, requestUri);

                    using (HttpResponseMessage response = await client.GetAsync(requestUri))
                    {
                        Results.RecordExchangeResponse(response, exchange);

                        response.EnsureSuccessStatusCode();

                        string outJson = await response.Content.ReadAsStringAsync();

                        JObject o = JObject.Parse(outJson);

                        //WidgetsRoot resultRoot = JsonConvert.DeserializeObject<WidgetsRoot>(outJson);

                        //Widgets.ResultItems = new ObservableCollection<Domain.Widget>(resultRoot.value);

                        IEnumerable <string> continuationHeaders = default;

                        bool hasContinuationToken = response.Headers.TryGetValues("x-ms-continuationtoken", out continuationHeaders);

                        Results.Count = Results.ResultItems.Count;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, Common.LOG_CATEGORY);
                ExceptionDialogService.DisplayExceptionDialog(DialogService, ex);
            }

            EventAggregator.GetEvent <HttpExchangeEvent>().Publish(Results.RequestResponseExchange);
        }