Example #1
0
        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 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;
            }
        }
Example #3
0
        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);
        }
Example #4
0
        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;
            }
        }