示例#1
0
        public static void WriteCallNotes(string filePath, string fileName, IList <CallNote> callNotes)
        {
            if (Logger.IsDebugEnabled)
            {
                Logger.Debug("[CallNoteFileHelper::WriteCallNotes] Starting writing all CallNotes. FilePath: {}, FileName: {}", filePath, fileName);
            }

            try
            {
                if (callNotes == null)
                {
                    throw new ArgumentNullException(nameof(callNotes), "callNotes should not be null.");
                }

                var jArray  = new JArray();
                var jObject = new JObject {
                    ["CallNotes"] = jArray
                };

                foreach (var callNote in callNotes)
                {
                    if (callNote != null)
                    {
                        jArray.Add(CallNoteToJToken(callNote));
                    }
                }

                JsonFileHelper.WriteJsonFile(filePath, fileName, jObject);

                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug(
                        "[CallNoteFileHelper::WriteCallNotes] Writing all CallNotes Successfully. callNotes: {}",
                        callNotes);
                }
            }
            catch (FileNotFoundException e)
            {
                Logger.Error(e,
                             "[CallNoteFileHelper::WriteCallNotes] Writing all CallNotes Failed. Can not find file. FilePath: {}, FileName: {}",
                             filePath, fileName);
                throw new FileNotFoundException("[CallNoteFileHelper::WriteCallNotes] Writing all CallNotes Failed. Can not find file.", e);
            }
            catch (Exception e)
            {
                Logger.Error(e,
                             "[CallNoteFileHelper::WriteCallNotes] Writing all CallNotes Failed. FilePath: {}, FileName: {}",
                             filePath, fileName);
                throw new DataAccessException("[CallNoteFileHelper::WriteCallNotes] Writing all CallNotes Failed.", e);
            }
        }
示例#2
0
        public static IList <CallNote> ReadCallNotes(string filePath, string fileName)
        {
            if (Logger.IsDebugEnabled)
            {
                Logger.Debug("[CallNoteFileHelper::ReadCallNotes] Starting reading all CallNotes. FilePath: {}, FileName: {}", filePath, fileName);
            }

            try
            {
                var jObject = JsonFileHelper.ReadJsonFile(filePath, fileName);

                var callNotes = jObject["CallNotes"].Select(JTokenToCallNote).ToList();

                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug(
                        "[CallNoteFileHelper::ReadCallNotes] Reading all CallNotes Successfully. callNotes: {}",
                        callNotes);
                }

                return(callNotes);
            }
            catch (FileNotFoundException e)
            {
                Logger.Error(e,
                             "[CallNoteFileHelper::ReadCallNotes] Reading all CallNotes Failed. Can not find file. FilePath: {}, FileName: {}",
                             filePath, fileName);
                throw new FileNotFoundException("[CallNoteFileHelper::ReadCallNotes] Reading all CallNotes Failed. Can not find file.", e);
            }
            catch (Exception e)
            {
                Logger.Error(e,
                             "[CallNoteFileHelper::ReadCallNotes] Reading all CallNotes Failed. FilePath: {}, FileName: {}",
                             filePath, fileName);
                throw new DataAccessException("[CallNoteFileHelper::ReadCallNotes] Reading all CallNotes Failed.", e);
            }
        }
示例#3
0
        public static int GetIdSeq()
        {
            if (Logger.IsDebugEnabled)
            {
                Logger.Debug("[IdSeqGenerator::GetIdSeq] Getting IdSeq.");
            }

            try
            {
                // if IdSeq file not exist, create a new one
                if (!File.Exists(Path.Combine(IdSeqFilePath, IdSeqFileName)))
                {
                    var jObject = new JObject {
                        ["IdSeq"] = Constants.InitIdSeq
                    };
                    JsonFileHelper.WriteJsonFile(IdSeqFilePath, IdSeqFileName, jObject);
                }

                var jObj  = JsonFileHelper.ReadJsonFile(IdSeqFilePath, IdSeqFileName);
                var idSeq = (int)jObj["IdSeq"];
                idSeq++;
                jObj["IdSeq"] = idSeq;
                JsonFileHelper.WriteJsonFile(IdSeqFilePath, IdSeqFileName, jObj);

                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug("[IdSeqGenerator::GetIdSeq] Get IdSeq successfully. IdSeq: {}", idSeq);
                }
                return(idSeq);
            }
            catch (Exception e)
            {
                Logger.Error(e, "[IdSeqGenerator::GetIdSeq] Get IdSeq error.");
                throw new DataAccessException("IdSeqGenerator::GetIdSeq: Get IdSeq error.", e);
            }
        }