示例#1
0
        /// <summary>
        /// Save data to hard drive
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            try
            {
                DiagnosticDataPath = Save(Record, $"{Id}-attachment");
                ReportPath         = Save(Record.Report, $"{Id}-report");

                // get minidump information
                MiniDumpPath = Record.Report?.MinidumpFile ?? string.Empty;
                Size        += MiniDumpPath == string.Empty ? 0 : new FileInfo(MiniDumpPath).Length;

                //save record
                RecordPath = Path.Combine(_path, $"{Id}-record.json");
                //check current record size
                var    json = JsonConvert.SerializeObject(this);
                byte[] file = Encoding.UTF8.GetBytes(json);
                //add record size
                Size += file.Length;
                //save it again with actual record size
                RecordWriter.Write(this, $"{Id}-record");
                return(true);
            }
            catch (IOException io)
            {
                Trace.WriteLine($"Received {nameof(IOException)} while saving data to database.");
                Debug.WriteLine($"Message {io.Message}");
                return(false);
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Received {nameof(Exception)} while saving data to database.");
                Debug.WriteLine($"Message {ex.Message}");
                return(false);
            }
        }
        /// <summary>
        /// Save data to hard drive
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            try
            {
                var diagnosticDataJson = Record.ToJson();
                DiagnosticDataPath = Save(diagnosticDataJson, string.Format("{0}-attachment", Id));
                var reportJson = Record.Report.ToJson();
                ReportPath = Save(reportJson, string.Format("{0}-report", Id));

                // get minidump information
                MiniDumpPath = Record.Report != null
                    ? Record.Report.MinidumpFile ?? string.Empty
                    : string.Empty;
                Size += MiniDumpPath == string.Empty ? 0 : new FileInfo(MiniDumpPath).Length;

                //save record
                RecordPath = Path.Combine(_path, string.Format("{0}-record.json", Id));
                //check current record size
                var    json = ToJson();
                byte[] file = Encoding.UTF8.GetBytes(json);
                //add record size
                Size += file.Length;
                //save it again with actual record size
                string recordJson = ToJson();
                RecordWriter.Write(recordJson, string.Format("{0}-record", Id));
                return(true);
            }
            catch (IOException io)
            {
                Debug.Log(string.Format("Received {0} while saving data to database.",
                                        "IOException"));
                Debug.Log(string.Format("Message {0}", io.Message));
                return(false);
            }
            catch (Exception ex)
            {
                Debug.Log(string.Format("Received {0} while saving data to database.", ex.GetType().Name));
                Debug.Log(string.Format("Message {0}", ex.Message));
                return(false);
            }
        }