コード例 #1
0
 public static bool ValidateTopicHeader(string[] header, int recordNumber)
 {
     bool correctHeader = false;
     IStructuralEquatable actualHeader = header;
     string[] expectedHeader = {"Topic_ID*", "Topic_Name*", "Parent_Topic*", "Keywords*", "Organizational_Unit*", "Location_State*", "Location_County",
         "Location_City", "Location_Zip", "Overview*", "Icon" };
        
     correctHeader = InsertResources.HeaderValidation(header, expectedHeader, "Topics");          
     return correctHeader;
 }
コード例 #2
0
        public async static Task GetResources(string accessToken, string filePath)
        {
            clientHttp.BaseAddress = new Uri(ConfigurationManager.AppSettings["apiUrl"]);
            clientHttp.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            clientHttp.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            try
            {
                InsertResources obj           = new InsertResources();
                List <dynamic>  resourcesList = new List <dynamic>();
                var             resources     = obj.CreateJsonFromCSV(filePath);
                if (resources == null || resources.Count == 0)
                {
                    MessageBox.Show("Please check Error log file to correct errors");
                }
                else
                {
                    foreach (var resourceList in resources)
                    {
                        var     serializedResult = JsonConvert.SerializeObject(resourceList);
                        JObject jsonResult       = (JObject)JsonConvert.DeserializeObject(serializedResult);
                        resourcesList.Add(jsonResult);
                    }

                    var topicTag = await clientHttp.GetAsync("api/topics-resources/topics/all").ConfigureAwait(false);

                    var     topicResult    = topicTag.Content.ReadAsStringAsync().Result;
                    dynamic topicTagResult = JsonConvert.DeserializeObject(topicResult);
                    foreach (var resourceList in resourcesList)
                    {
                        if (resourceList.topicTags != null)
                        {
                            for (int iterator = 0; iterator < resourceList.topicTags.Count; iterator++)
                            {
                                string name  = resourceList.topicTags[iterator].id;
                                string state = resourceList.location[0].state;
                                if (topicTagResult.Count > 0)
                                {
                                    foreach (var topic in topicTagResult)
                                    {
                                        dynamic topicName     = null;
                                        dynamic topicTagId    = null;
                                        dynamic locationValue = null;
                                        foreach (JProperty field in topic)
                                        {
                                            if (field.Name == "name")
                                            {
                                                topicName = field.Value.ToString();
                                            }

                                            if (field.Name == "id")
                                            {
                                                topicTagId = field.Value.ToString();
                                            }

                                            if (name == topicName)
                                            {
                                                if (field.Name == "location")
                                                {
                                                    locationValue = field.Value.ToString();
                                                    var location = JsonConvert.DeserializeObject(locationValue);
                                                    foreach (var loc in location)
                                                    {
                                                        foreach (JProperty locationTopic in loc)
                                                        {
                                                            if (locationTopic.Name == "state")
                                                            {
                                                                if (state == locationTopic.Value.ToString())
                                                                {
                                                                    resourceList.topicTags[iterator].id = topicTagId;
                                                                    break;
                                                                }
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    var           serializedResources = JsonConvert.SerializeObject(resourcesList);
                    StringContent content             = new StringContent(serializedResources, Encoding.UTF8, "application/json");
                    var           response            = await clientHttp.PostAsync("api/topics-resources/resources/documents/upsert", content).ConfigureAwait(false);

                    var json = response.Content.ReadAsStringAsync().Result;
                    response.EnsureSuccessStatusCode();
                    if (response.IsSuccessStatusCode == true)
                    {
                        string fileName = $@"Resource{DateTime.Now.Ticks}.txt";
                        LogHelper.DataLogging(json, fileName);
                        MessageBox.Show("File got processed");
                    }
                    else
                    {
                        MessageBox.Show("Please correct errors" + "\n" + response);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }