Пример #1
0
        private static void RecordAppData(string fileName, string content)
        {
            try
            {
                FolderService.AssureFolderAppData();

                var filePathAppData = Path.Combine(FolderService.FolderAppDataPath, fileName);

                UpdateText(filePathAppData, content);
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Failed to record log to AppData.\r\n{ex}");
            }
        }
Пример #2
0
        private static void Save <T>(T instance) where T : class
        {
            try
            {
                FolderService.AssureFolderAppData();

                using (var fs = new FileStream(_settingsFilePath, FileMode.Create, FileAccess.Write))
                {
                    var serializer = new XmlSerializer(typeof(T));
                    serializer.Serialize(fs, instance);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to save settings.", ex);
            }
        }
Пример #3
0
        private static void Save <T>(T placement)
        {
            try
            {
                FolderService.AssureFolderAppData();

                using (var sw = new StreamWriter(_placementFilePath, false, Encoding.UTF8))                 // BOM will be emitted.
                    using (var xw = XmlWriter.Create(sw, new XmlWriterSettings {
                        Indent = true
                    }))
                    {
                        var serializer = new DataContractSerializer(typeof(T));
                        serializer.WriteObject(xw, placement);
                        xw.Flush();
                    }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Failed to save window placement.\r\n{ex}");
            }
        }
Пример #4
0
        public static async Task RecordStringAsync(string fileName, string result)
        {
            try
            {
                var content = $"[Date: {DateTime.Now:HH:mm:ss fff}]" + Environment.NewLine
                              + result.TrimEnd() + Environment.NewLine + Environment.NewLine;

                FolderService.AssureFolderAppData();

                var filePath = Path.Combine(FolderService.FolderAppDataPath, fileName);

                if (File.Exists(filePath) && (File.GetLastWriteTime(filePath) < DateTime.Now.AddHours(-1)))
                {
                    File.Delete(filePath);
                }

                using (var sw = new StreamWriter(filePath, true, Encoding.UTF8))                 // BOM will be emitted.
                    await sw.WriteAsync(content);
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Failed to record log to AppData.\r\n{ex}");
            }
        }