Exemplo n.º 1
0
        private static void RecordAppData(string fileName, string content)
        {
            try
            {
                FolderService.AssureAppDataFolder();

                var appDataFilePath = FolderService.GetAppDataFilePath(fileName);

                UpdateText(appDataFilePath, content);
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Failed to record log to AppData.\r\n{ex}");
            }
        }
Exemplo n.º 2
0
        private static void Save <T>(T placement)
        {
            try
            {
                FolderService.AssureAppDataFolder();

                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}");
            }
        }
Exemplo n.º 3
0
        public static async Task RecordAsync(string fileName, string result)
        {
            try
            {
                var content = $"[Date: {DateTime.Now:HH:mm:ss fff}]" + Environment.NewLine
                              + result.TrimEnd() + Environment.NewLine + Environment.NewLine;

                FolderService.AssureAppDataFolder();

                var filePath = FolderService.GetAppDataFilePath(fileName);

                if (File.Exists(filePath) && (File.GetLastWriteTime(filePath) < DateTime.Now.AddHours(-1)))
                {
                    FolderService.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}");
            }
        }