コード例 #1
0
        public async Task CreateCodeTimeEvent(string typeVal, string nameVal, string descriptionVal)
        {
            CodeTimeEvent        ctEvent      = new CodeTimeEvent(typeVal, nameVal, descriptionVal);
            List <CodeTimeEvent> existingList = GetCodeTimeEventList();

            existingList.Add(ctEvent);

            // create a json array
            JsonArray jsonArray = new JsonArray(existingList.Count);

            foreach (CodeTimeEvent existingEvent in existingList)
            {
                jsonArray.Add(existingEvent.GetAsJson());
            }

            string file = FileManager.getCodeTimeEventsFile();

            if (FileManager.CodeTimeEventsFileExists())
            {
                File.SetAttributes(file, FileAttributes.Normal);
            }

            try
            {
                string content = jsonArray.ToString();
                content = content.Replace("\r\n", string.Empty).Replace("\n", string.Empty).Replace("\r", string.Empty);
                File.WriteAllText(file, content, System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
                //
            }
        }
コード例 #2
0
        public List <CodeTimeEvent> GetCodeTimeEventList()
        {
            List <CodeTimeEvent> ctEvents = new List <CodeTimeEvent>();
            string file = FileManager.getCodeTimeEventsFile();

            if (FileManager.CodeTimeEventsFileExists())
            {
                File.SetAttributes(file, FileAttributes.Normal);
            }

            string eventsData = FileManager.getCodeTimeEventsData();

            // it'll be a map of file to events objects
            JsonArray jsonArrayObj = (JsonArray)SimpleJson.DeserializeObject(eventsData, new JsonArray());

            foreach (JsonObject jsonObj in jsonArrayObj)
            {
                CodeTimeEvent ctEvent = new CodeTimeEvent();
                try
                {
                    ctEvent.CloneFromDictionary(jsonObj);
                }
                catch (Exception e)
                {
                    //
                }

                ctEvents.Add(ctEvent);
            }

            return(ctEvents);
        }