Esempio n. 1
0
        private void GetDataWorkItem(string id, string _credentials, HttpClient clientWI)
        {
            ids_WiLOCAL = _repWI.ConsultaWorkItem();

            bool WI_toINSERT = !(ids_WiLOCAL.Where(k => k.Key.Equals(Convert.ToInt32(id))).Count() > 0);

            HttpResponseMessage WIKR = clientWI.GetAsync("_apis/wit/workitems/" + id + "/").Result;

            HttpResponseMessage WIKR_Revisions = clientWI.GetAsync("_apis/wit/workitems/" + id + "/revisions?&fields=System.Id,System.Title,System.State&api-version=2.2").Result;

            if (WIKR.IsSuccessStatusCode && WIKR_Revisions.IsSuccessStatusCode)
            {
                var response_WorkItem = WIKR.Content.ReadAsStringAsync().Result;            //ok

                var response_Revisions = WIKR_Revisions.Content.ReadAsStringAsync().Result; //ok

                if (WI_toINSERT)
                {
                    InsertWorkItem(id, response_WorkItem);
                }
                else
                {
                    UpdateWorkItem(id, response_WorkItem);
                }

                InsertRevisions(id, response_Revisions);
            }
        }
Esempio n. 2
0
        public void GetTfsData()
        {
            String dtRegistroLocal = _dtParam.ConsultaDtParametro();

            string _credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", PersonalAccessToken)));

            ids_WiLOCAL = _repWI.ConsultaWorkItem(); // todos os workitens em LOCAL antes de insercao ou atualizacao

            //lista TODOS os workitens
            using (var client = new HttpClient())
            {
                var wiql = new
                {
                    query = "Select [Id] " +
                            " From WorkItems " +
                            " AND [ONS.Fornecedor] = 'BRQ' "
                };
                HttpResponseMessage _client = ValidateClient(url, client, _credentials, wiql);

                if (_client.IsSuccessStatusCode)
                {
                    //lista todos os workitens
                    WorkItemQueryResult workItemQueryResult = _client.Content.ReadAsAsync <WorkItemQueryResult>().Result;
                    //lista todos workitens local
                    Dictionary <int, string> wiToDelete = ids_WiLOCAL;

                    foreach (var item in workItemQueryResult.workItems)
                    {
                        //Se existe no TFS remove da listagem de local
                        wiToDelete.Remove(item.id);
                    }

                    //faz a delecao logica dos itens, com todos os wi local q NAO estao no TFS
                    DeleteWorkItem(wiToDelete.Keys.ToList());
                }
                else
                {
                    string erro  = _client.StatusCode.ToString();
                    string etapa = _client.RequestMessage.RequestUri.ToString();
                    RegisterLog(erro, etapa);
                }
            }

            using (var client = new HttpClient())
            {
                var wiql = new
                {
                    query = "Select [Id] " +
                            " From WorkItems " +
                            " Where [System.ChangedDate] >= '" + dtRegistroLocal + "' " + //pega so qm teve changedDate superior a
                            " AND [ONS.Fornecedor] = 'BRQ' "
                };
                HttpResponseMessage _client = ValidateClient(url, client, _credentials, wiql);

                if (_client.IsSuccessStatusCode)
                {
                    WorkItemQueryResult workItemQueryResult = _client.Content.ReadAsAsync <WorkItemQueryResult>().Result;

                    foreach (var item in workItemQueryResult.workItems)
                    {
                        var id = item.id;

                        // verifica se o item do retorno REST esta na base local
                        bool WI_toINSERT = !(ids_WiLOCAL.Where(k => k.Key.Equals(Convert.ToInt32(id))).Count() > 0);

                        GetDataWorkItem(id.ToString(), _credentials, client, WI_toINSERT);
                    }
                }
                else
                {
                    string erro  = _client.StatusCode.ToString();
                    string etapa = _client.RequestMessage.RequestUri.ToString();
                    RegisterLog(erro, etapa);
                }
            }
        }