public static void RegenerateResourceFile(out string message) { List <Resource> listWithAllResources; ResourcePresentationInSearch resourcePresentationInSearch; string commaSeparatedListWithKeyWords, serializedResourcePresentationInSearch, errorMessage; DateTime created; StringBuilder sb; int i; message = null; try { listWithAllResources = ResourceUtility.ReturnListWithResources(ResourcesType.All, out errorMessage); if (errorMessage != null) { message = errorMessage; return; } sb = new StringBuilder(); for (i = 0; i < listWithAllResources.Count; i++) { created = Utility.ReturnDateTimeFromString(listWithAllResources[i].Created); commaSeparatedListWithKeyWords = KeyWordUtility.ReturnCommaSeparatedListWithKeyWords(listWithAllResources[i].KeyWords); resourcePresentationInSearch = new ResourcePresentationInSearch(listWithAllResources[i].Id, listWithAllResources[i].ResourcesType, created, listWithAllResources[i].Title, commaSeparatedListWithKeyWords); serializedResourcePresentationInSearch = SerializeResourcePresentationInSearch(resourcePresentationInSearch); if (i > 0) { sb.Append(string.Format("{0}{1}", "\r\n\r\n---------- New resource ----------\r\n\r\n", serializedResourcePresentationInSearch)); } else { sb.Append(serializedResourcePresentationInSearch); } } Utility.CreateNewFile(_fileNameFullPathToResources, sb.ToString()); message = string.Format("Resources.txt was successfully regenerated with {0} resources.", listWithAllResources.Count.ToString()); } catch (Exception e) { message = string.Format("ERROR!! An Exception occured in method RegenerateResourceFile! e.Message:\r\n{0}", e.Message); return; } }
public static List <ThumbUpLocationInfo> GetLocations(bool isDefaultLocation, out string errorMessage) { List <ThumbUpLocationInfo> list = new List <ThumbUpLocationInfo>(); errorMessage = null; try { ArrayList locationName, locationNameSortAlias, id, location, title, note; string locationAlias; int i, index; locationName = ResourceUtility.ReturnActualLocations(isDefaultLocation, out errorMessage, out locationNameSortAlias); if (!string.IsNullOrEmpty(errorMessage)) { return(null); } List <Resource> thumbUpLocationResources = ResourceUtility.ReturnListWithResources(ResourcesType.ThumbUpLocation, out errorMessage); id = new ArrayList(); location = new ArrayList(); title = new ArrayList(); note = new ArrayList(); for (i = 0; i < thumbUpLocationResources.Count; i++) { id.Add(thumbUpLocationResources[i].Id); location.Add(thumbUpLocationResources[i].ThumbUpLocation); title.Add(thumbUpLocationResources[i].Title); note.Add(thumbUpLocationResources[i].Note); } Utility.Sort(locationNameSortAlias, locationName); for (i = 0; i < locationName.Count; i++) { index = location.IndexOf((string)locationName[i]); if (index == -1) { errorMessage = string.Format("ERROR!! There is no ThumbUpLocation resource for location {0}", (string)locationName[i]); return(null); } else { locationAlias = ResourceUtility.ReturnLocationAlias((string)locationName[i], out errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { return(null); } list.Add(new ThumbUpLocationInfo((int)id[index], (string)locationName[i], locationAlias, (string)title[index], (string)note[index] ?? "")); } } } catch (Exception e) { errorMessage = string.Format("ERROR!! An Exception occured in method GetDefaultLocations! e.Message:\r\n{0}", e.Message); return(null); } return(list); }
public static void CheckResourceFile(out string message) { string commaSeparatedListWithKeyWords, errorMessage; List <Resource> listWithAllResources; List <ResourcePresentationInSearch> listWithResourcePresentationInSearch; int id; message = null; try { listWithAllResources = ResourceUtility.ReturnListWithResources(ResourcesType.All, out errorMessage); if (errorMessage != null) { message = errorMessage; return; } listWithResourcePresentationInSearch = ReturnListWithAllResourcePresentationInSearch(); if (listWithResourcePresentationInSearch.Count != listWithAllResources.Count) { message = string.Format("Number of resource in Resources.txt, {0} resources, is not the same as the actual number of resources, {1} resources!", listWithResourcePresentationInSearch.Count.ToString(), listWithAllResources.Count.ToString()); return; } id = 1; while ((id <= listWithResourcePresentationInSearch.Count) && (message == null)) { if (listWithResourcePresentationInSearch[id - 1].Id != id) { message = string.Format("ResourcePresentationInSearch number {0} in file Resources.txt does not have id = {1} as expected", id.ToString(), id.ToString()); } else if (listWithResourcePresentationInSearch[id - 1].ResourcesType != listWithAllResources[id - 1].ResourcesType) { message = string.Format("ResourcePresentationInSearch number {0} in file Resources.txt does not have resource type = {1} as expected", id.ToString(), listWithAllResources[id - 1].ResourcesType.ToString()); } else if (listWithResourcePresentationInSearch[id - 1].Created.ToString("yyyy-MM-dd HH:mm:ss") != listWithAllResources[id - 1].Created) { message = string.Format("ResourcePresentationInSearch number {0} in file Resources.txt does not have created date = {1} as expected", id.ToString(), listWithAllResources[id - 1].Created); } else if (listWithResourcePresentationInSearch[id - 1].Title != listWithAllResources[id - 1].Title) { message = string.Format("ResourcePresentationInSearch number {0} in file Resources.txt does not have title = {1} as expected", id.ToString(), listWithAllResources[id - 1].Title); } if (message == null) { commaSeparatedListWithKeyWords = KeyWordUtility.ReturnCommaSeparatedListWithKeyWords(listWithAllResources[id - 1].KeyWords); if (commaSeparatedListWithKeyWords != listWithResourcePresentationInSearch[id - 1].KeyWords) { message = string.Format("ResourcePresentationInSearch number {0} in file Resources.txt does not have key words = {1} as expected", id.ToString(), commaSeparatedListWithKeyWords); } } id++; } if (message == null) { message = string.Format("All {0} ResourcePresentationInSearch in file Resources.txt are correct!", listWithResourcePresentationInSearch.Count.ToString()); } } catch (Exception e) { message = string.Format("ERROR!! An Exception occured in method CheckResourceFile! e.Message:\r\n{0}", e.Message); return; } }