public static int AddAdhocResource(string fileNameFullPathToConfigFile, TemplateData templateData, out string errorMessage) { List <AdhocTemplate> listWithAdhocTemplates; Resource resource, newResource; try { errorMessage = null; listWithAdhocTemplates = ReturnListWithAdhocTemplates(fileNameFullPathToConfigFile, out errorMessage); if (errorMessage != null) { return(-1); } int resourceId = ResourceUtility.ReturnNextResourceId(); string filePrefix = "R"; string fileExtension = templateData.Id == 1 ? ".cs" : ".html"; string fileNameFullPathCjProjFile = listWithAdhocTemplates[templateData.Id - 1].CsProjFileFullPath; string folderPrefix = "Nr"; int currentResourceFolderIndex = listWithAdhocTemplates[templateData.Id - 1].CurrentResourceFolderIndex; int maxNumberOfFilesInAFolder = listWithAdhocTemplates[templateData.Id - 1].MaxNumberOfFilesInFolder; string resourceFolder = listWithAdhocTemplates[templateData.Id - 1].ResourceFolder; string textForNonIncludeFileToCreate; if (templateData.Id == 1) { textForNonIncludeFileToCreate = templateData.CodeText.Replace("\n", "\r\n").Replace("#####", resourceId.ToString()); } else { textForNonIncludeFileToCreate = templateData.CodeText.Replace("\n", "\r\n"); } int nextResourceFolderIndex; Utility.InsertNoneIncludeFileInCsProj( resourceId, filePrefix, fileExtension, fileNameFullPathCjProjFile, folderPrefix, currentResourceFolderIndex, maxNumberOfFilesInAFolder, resourceFolder, textForNonIncludeFileToCreate, out nextResourceFolderIndex, out errorMessage ); if (errorMessage != null) { return(-1); } if (nextResourceFolderIndex != currentResourceFolderIndex) { listWithAdhocTemplates[templateData.Id - 1].CurrentResourceFolderIndex = nextResourceFolderIndex; SaveListWithAdhocTemplates(fileNameFullPathToConfigFile, listWithAdhocTemplates); } int id = 0; ResourcesType resourcesType = templateData.Id == 1 ? ResourcesType.Self : ResourcesType.Html; string created = null; string title = templateData.Title; string keyWords = templateData.KeyWords; string note = templateData.Note; int previousResource = 0; int nextResource = 0; string thumbUpLocation = null; string htmlFile = templateData.Id == 1 ? null : string.Format("{0}\\Nr{1}\\R{2}.html", listWithAdhocTemplates[templateData.Id - 1].Href, currentResourceFolderIndex.ToString(), resourceId.ToString()); string files = templateData.Id == 1 ? string.Format("{0}\\Nr{1}\\R{2}.cs", listWithAdhocTemplates[templateData.Id - 1].ResourceFolder, currentResourceFolderIndex.ToString(), resourceId.ToString()) : null; string links = null; resource = new Resource( id, resourcesType, created, title, keyWords, note, previousResource, nextResource, thumbUpLocation, htmlFile, files, links); newResource = ResourceUtility.AddResource(resource, out errorMessage); if (errorMessage != null) { return(-1); } } catch (Exception e) { errorMessage = string.Format("ERROR!! An Exception occured in method AddAdhocResource! e.Message:\r\n{0}", e.Message); return(-1); } return(newResource.Id); }
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; } }