示例#1
0
        public static KeyWord EditKeyWord(KeyWord keyWord, out string errorMessage)
        {
            KeyWord        newKeyWord   = null;
            bool           foundKeyWord = false;
            StringBuilder  sb;
            List <KeyWord> listWithKeyWords;
            int            i;

            try
            {
                errorMessage     = null;
                listWithKeyWords = GetKeyWords();

                if (keyWord.Id == listWithKeyWords[0].Id)
                {
                    listWithKeyWords[0].Note = keyWord.Note;
                    foundKeyWord             = true;
                    newKeyWord = listWithKeyWords[0];
                }

                sb = new StringBuilder(SerializeKeyWord(listWithKeyWords[0]));

                for (i = 1; i < listWithKeyWords.Count; i++)
                {
                    if (keyWord.Id == listWithKeyWords[i].Id)
                    {
                        listWithKeyWords[i].Note = keyWord.Note;
                        foundKeyWord             = true;
                        newKeyWord = listWithKeyWords[i];
                    }

                    sb.Append(string.Format("\r\n\r\n---------- New key word ----------\r\n\r\n{0}", SerializeKeyWord(listWithKeyWords[i])));
                }

                if (!foundKeyWord)
                {
                    errorMessage = "Error! Can not find the key word!";
                }
                else
                {
                    Utility.CreateNewFile(_fileNameFullPathKeyWords, sb.ToString());
                }
            }
            catch (Exception e)
            {
                errorMessage = string.Format("ERROR!! An Exception occured in method UpdateKeyWord! e.Message:\r\n{0}", e.Message);
                return(null);
            }

            return(newKeyWord);
        }
示例#2
0
        public static KeyWord AddKeyWord(KeyWord keyWord, out string errorMessage) //keyWord not complete. newKeyWord will be complete
        {
            KeyWord        newKeyWord = null;
            string         keyWordSerialized, fileContents;
            List <KeyWord> listWithKeyWords;
            ArrayList      arrayListWithPhrases;
            int            i;

            try
            {
                errorMessage = null;

                listWithKeyWords = GetKeyWords();

                arrayListWithPhrases = new ArrayList();

                for (i = 0; i < listWithKeyWords.Count; i++)
                {
                    arrayListWithPhrases.Add(listWithKeyWords[i].Phrase.ToLower());
                }

                if (arrayListWithPhrases.IndexOf(keyWord.Phrase.ToLower()) >= 0)
                {
                    errorMessage = "The phrase exists already!";
                    return(null);
                }

                newKeyWord        = new KeyWord(1 + arrayListWithPhrases.Count, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), keyWord.Phrase, keyWord.Note);
                keyWordSerialized = SerializeKeyWord(newKeyWord);

                fileContents = Utility.ReturnFileContents(_fileNameFullPathKeyWords);

                if (string.IsNullOrEmpty(fileContents))
                {
                    Utility.AppendToFile(_fileNameFullPathKeyWords, keyWordSerialized);
                }
                else
                {
                    Utility.AppendToFile(_fileNameFullPathKeyWords, string.Format("\r\n\r\n---------- New key word ----------\r\n\r\n{0}", keyWordSerialized));
                }
            }
            catch (Exception e)
            {
                errorMessage = string.Format("ERROR!! An Exception occured in method AddKeyWord! e.Message:\r\n{0}", e.Message);
                return(null);
            }

            return(newKeyWord);
        }
示例#3
0
 private static string SerializeKeyWord(KeyWord keyWord)
 {
     return(string.Format("{0}\r\n\r\n----- New property -----\r\n\r\n{1}\r\n\r\n----- New property -----\r\n\r\n{2}\r\n\r\n----- New property -----\r\n\r\n{3}", keyWord.Id.Value.ToString(), keyWord.Created, keyWord.Phrase, keyWord.Note));
 }