コード例 #1
0
        public MsgFileSaver()
        {
            processer = new QueueProcesser <T>((s) =>
            {
                string fullpath   = Path.GetFullPath(FolderName);
                List <Task> tasks = new List <Task>();

                var groups = s.GroupBy(x => x.Source);
                foreach (var group in groups)
                {
                    {
                        string path = Path.Combine(fullpath, DateTime.Today.ToString("yyyyMMdd"));
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        var fileName = Path.Combine(path, group.Key + ".csv");
                        Console.WriteLine(fileName);
                        if (!File.Exists(fileName))
                        {
                            StringBuilder stringBuilder = new StringBuilder();
                            var propertyInfos           = typeof(T).GetProperties();
                            stringBuilder.Append("Date Time,");
                            foreach (var p in propertyInfos)
                            {
                                stringBuilder.Append($"{p.Name},");
                            }
                            stringBuilder.AppendLine();
                            File.AppendAllText(fileName, stringBuilder.ToString());
                        }

                        StringBuilder sb = new StringBuilder();
                        foreach (var v in group)
                        {
                            sb.Append($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}," +
                                      $"{string.Join(",", v.GetType().GetProperties().Select(x => x.GetValue(v, null) ?? ""))}");
                            sb.AppendLine();
                        }
                        File.AppendAllText(fileName, sb.ToString());
                    }
                    //));
                }
                //     Task.WaitAll(tasks.ToArray());
            });
        }
コード例 #2
0
 public MsgDBSaver()
 {
     processer = new QueueProcesser <TestSpecViewModel>((s) =>
     {
         using (DataAccess db = new DataAccess())
         {
             try
             {
                 db.SaveTestSpecs(s);
             }
             catch (Exception ex)
             {
                 Event.Publish(new MsgItem {
                     Level = "E", Time = DateTime.Now, Value = ex.Message
                 });
             }
         }
     });
 }