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; } }
public static void CreateTask(string shortNameTitle, out string message) { message = null; try { string shortName, title, fileNameFullPath, fileContents, str, dateStr = "", keyWords, taskFolderNameShort, taskFolderNameLong; bool todaysDateInFileDayDatetxt = false; DateTime tmpDate, dateToday; string[] v, kWords; int day = 0, index, i, taskId, nextTaskId, folderIndex; List <Work> list; Resource r1, r2; index = shortNameTitle.IndexOf(' '); shortName = shortNameTitle.Substring(0, index); title = shortNameTitle.Substring(index).Trim(); list = ReturnListWithWorks(out message); if (!string.IsNullOrEmpty(message)) { return; } index = -1; i = 0; while (i < list.Count && index == -1) { if (shortName == list[i].ShortName) { index = i; } else { i++; } } if (index == -1) { message = string.Format("Can not find shortName \"{0}\" in the config file \"{1}\"!", shortName, _fileNameFullPathToConfigFile); return; } kWords = new string[2] { "Task", list[index].FullName }; keyWords = KeyWordUtility.ReplaceWithKeyWordId(kWords, out message); if (!string.IsNullOrEmpty(message)) { return; } fileNameFullPath = string.Format("{0}\\DayDate.txt", list[index].Folder); if (!System.IO.File.Exists(fileNameFullPath)) { message = string.Format("The following file does not exist as expected: {0}", fileNameFullPath); return; } fileContents = Utility.ReturnFileContents(fileNameFullPath); v = fileContents.Split(new string[] { "\r\n" }, StringSplitOptions.None); if (v.Length >= 1) { str = v[0]; v = str.Split(' '); if (v.Length == 2) { tmpDate = DateTime.Now; dateToday = new DateTime(tmpDate.Year, tmpDate.Month, tmpDate.Day); dateStr = dateToday.ToString("yyyy-MM-dd"); if (dateStr == v[1]) { todaysDateInFileDayDatetxt = true; } day = int.Parse(v[0]); } } if (!todaysDateInFileDayDatetxt) { message = string.Format("Today's date is not registered in file {0}!", fileNameFullPath); return; } fileNameFullPath = string.Format("{0}\\NextTaskId.txt", list[index].Folder); if (!System.IO.File.Exists(fileNameFullPath)) { message = string.Format("The following file does not exist as expected: {0}", fileNameFullPath); return; } fileContents = Utility.ReturnFileContents(fileNameFullPath); taskId = int.Parse(fileContents); nextTaskId = 1 + taskId; folderIndex = taskId / 100; if ((taskId % 100) != 0) { folderIndex++; } taskFolderNameShort = string.Format("Task{0}_Day{1}_Date{2}{3}{4}_{5}", taskId.ToString(), day.ToString(), dateStr.Substring(2, 2), dateStr.Substring(5, 2), dateStr.Substring(8, 2), title); taskFolderNameLong = string.Format("{0}\\Tasks\\Task{1}\\{2}", list[index].Folder, folderIndex, taskFolderNameShort); System.IO.Directory.CreateDirectory(taskFolderNameLong); Utility.CreateNewFile(fileNameFullPath, nextTaskId.ToString()); Utility.CreateNewFile(string.Format("{0}\\Task{1}.txt", taskFolderNameLong, taskId.ToString()), string.Format("Task{0}:", taskId.ToString())); r1 = new Resource(0, ResourcesType.Self, DateTime.Now.ToString("yyyy-MM-dd"), taskFolderNameShort, keyWords, null, 0, 0, null, null, taskFolderNameLong, null); r2 = ResourceUtility.AddResource(r1, out message); if (!string.IsNullOrEmpty(message)) { return; } message = string.Format("Task number {0} and resource {1} were successfully created for {2}", taskId, r2.Id, list[index].FullName); } catch (Exception e) { message = string.Format("ERROR!! An Exception occured in method CreateTask! e.Message:\r\n{0}", e.Message); return; } }