//Usamos BillingConceptDictionary para optimizar el numero de llamadas realizadas a la API de Jira //BillingConcept toma el siguiente valor: //1.- RelatedProject si existe //2.- Si no existe, EpicName si existe //3.- Si no existe, BillingConcept del padre //4.- Si no hay padre, Title propio private string CalculateSingleBillingConcept(RowImputation rowImputation) { var billingConcept = string.Empty; try { if (BillingConceptDictionary.ContainsKey(rowImputation.Key)) { billingConcept = BillingConceptDictionary[rowImputation.Key]; } else { if ((rowImputation.RelatedProject != string.Empty) && (rowImputation.RelatedProject != Resources.BusinessResources.EmptyLiteralText)) { billingConcept = rowImputation.RelatedProject; } else if (rowImputation.EpicName != string.Empty) { billingConcept = rowImputation.EpicName; } else { string parentKey = GetParentKey(rowImputation.Title); if (rowImputation.Title != parentKey && parentKey.Length < 15) { Counter++; RowImputation rowImputationParent = DataAccessJira.GetDataFromParentKey(parentKey); billingConcept = CalculateSingleBillingConcept(rowImputationParent); // Añadimos la key y BC del parent al diccionario para no tener que volver a buscarlo if (!BillingConceptDictionary.ContainsKey(rowImputationParent.Key)) { BillingConceptDictionary.Add(rowImputationParent.Key, billingConcept); } } else { billingConcept = rowImputation.Title; } } // Añadimos la key y BC de la row al diccionario para no tener que volver a buscarlo if (!BillingConceptDictionary.ContainsKey(rowImputation.Key)) { BillingConceptDictionary.Add(rowImputation.Key, billingConcept); } } } catch (Exception ex) { throw new BusinessException(ex.Message, ex.InnerException); } return(billingConcept); }
public RowImputation GetDataFromParentKey(string parentkey) { RowImputation rowImputation = new RowImputation(); rowImputation.Key = parentkey; try { using (WebClient webClient = new WebClient()) { webClient.Headers.Set("Authorization", "Basic " + EncodedCredentials); // Obtenemos la seccion del Json que queremos var result = webClient.DownloadString(string.Concat(Resources.JiraResources.WebApiJiraUrl, parentkey)); var data = (JObject)JsonConvert.DeserializeObject(result); var dataFields = data["issues"][0]["fields"]; // Obtenemos el Title si existe en la seccion del Json if (dataFields[Resources.JiraResources.TitleTag] != null) { string accentedStr = dataFields[Resources.JiraResources.TitleTag].Value <string>(); byte[] tempBytes = Encoding.GetEncoding(Resources.JiraResources.ISO8859Encoding).GetBytes(accentedStr); rowImputation.Title = Encoding.UTF8.GetString(tempBytes); } // Obtenemos el EpicName si existe en la seccion del Json if (dataFields[Resources.JiraResources.EpicNameTag] != null) { string accentedStr = dataFields[Resources.JiraResources.EpicNameTag].Value <string>(); byte[] tempBytes = Encoding.GetEncoding(Resources.JiraResources.ISO8859Encoding).GetBytes(accentedStr); rowImputation.EpicName = Encoding.UTF8.GetString(tempBytes); } // Obtenemos el RelatedProject si existe en la seccion del Json if (dataFields[Resources.JiraResources.RelatedProjectTag] != null) { string accentedStr = dataFields[Resources.JiraResources.RelatedProjectTag].Value <string>(); byte[] tempBytes = Encoding.GetEncoding(Resources.JiraResources.ISO8859Encoding).GetBytes(accentedStr); rowImputation.RelatedProject = Encoding.UTF8.GetString(tempBytes); } } } catch (Exception ex) { throw new DataAccessException(ex.Message, ex.InnerException); } return(rowImputation); }
private RowImputation SetImputationValues(string[] values) { var imputation = new RowImputation(); try { imputation.Project = values[0]; imputation.Type = values[1]; imputation.Key = values[2]; imputation.Title = values[3]; imputation.Creator = values[4]; imputation.EpicName = values[6]; imputation.RelatedProject = values[7]; imputation.ImputationDate = DateTime.Parse(values[8]); imputation.PersonName = values[9]; imputation.ImputedHours = float.Parse(values[10]); } catch (Exception ex) { throw new DataAccessException(ex.Message, ex.InnerException); } return(imputation); }