コード例 #1
0
 /// <summary>
 /// Returns a list of projections.
 /// </summary>
 /// <returns></returns>
 public List <string> ReadFromDownloadUsageGroup()
 {
     try
     {
         using (var r = new StreamReader(ApplicationService.GetUserGroupsFilePath()))
         {
             var json       = r.ReadToEnd();
             var userGroups = JsonConvert.DeserializeObject <List <string> >(json);
             Log.Debug("Read from download usage group file");
             r.Close();
             return(userGroups);
         }
     }
     catch (Exception e)
     {
         Log.Error(e, "Read from download usage group file");
         return(new List <string>());
     }
 }
コード例 #2
0
        /// <summary>
        /// Write list of download usage to file in case registry api won't respond
        /// </summary>
        /// <param name="userGroups">list of user groups</param>
        public void WriteToUsageGroupFile(List <string> userGroups)
        {
            var serializer = new JsonSerializer();

            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            try
            {
                using (var outputFile = new StreamWriter(ApplicationService.GetUserGroupsFilePath(), false))
                    using (JsonWriter writer = new JsonTextWriter(outputFile))
                    {
                        serializer.Serialize(writer, userGroups);
                        Log.Debug("Write to download usage file");
                        writer.Close();
                    }
            }
            catch (Exception e)
            {
                Log.Error(e, "Write to download usage file");
            }
        }