Пример #1
0
        /// <summary>
        /// Extracts information from an error to use as the contents of an error file.
        /// </summary>
        /// <param name="error">Error to extract.</param>
        /// <returns>File contents.</returns>
        public static ErrorReportData GenerateReport(Exception error)
        {
            // Validate
            if (error == null)
            {
                throw new ArgumentNullException("error");
            }

            // Write application and version information at top
            var application     = Application.Current;
            var applicationType = application.GetType();
            var report          = new ErrorReportData
            {
                Id                 = Guid.NewGuid(),
                SourceId           = LoadSourceId(),
                SourceAssemblyName = applicationType.AssemblyQualifiedName,
                EventDate          = DateTime.UtcNow,
                Message            = error.GetFullMessage(),
                ErrorTypeFullName  = error.GetType().Name,
                StackTrace         = error.StackTrace
            };

            // Return result
            return(report);
        }
 /// <summary>
 /// Reads properties of a <see cref="ErrorReportData"/> from a data reader.
 /// </summary>
 public static void Read(this ErrorReportData entity, SqlDataReader reader, bool skipKeys)
 {
     if (!skipKeys)
     {
         GuidDataKeyAdapter.Read(entity, reader);
     }
     entity.SourceId           = reader.Get <Guid>("SourceId");
     entity.SourceAssemblyName = reader.GetString("SourceAssemblyName");
     entity.EventDate          = reader.Get <DateTimeOffset>("EventDate");
     entity.Message            = reader.Get <string>("Message");
     entity.ErrorTypeFullName  = reader.GetNullable <string>("ErrorTypeFullName");
     entity.StackTrace         = reader.GetNullable <string>("StackTrace");
 }
 /// <summary>
 /// Sets data command parameter values for a <see cref="ErrorReportData"/>.
 /// </summary>
 public static void Set(
     this ErrorReportData entity, SqlParameterCollection parameters, bool skipKeys)
 {
     if (!skipKeys)
     {
         GuidDataKeyAdapter.Set(entity, parameters);
     }
     parameters["@sourceId"].Value           = entity.SourceId;
     parameters["@sourceAssemblyName"].Value = entity.SourceAssemblyName;
     parameters["@eventDate"].Value          = entity.EventDate;
     parameters["@message"].Value            = entity.Message;
     parameters["@errorTypeFullName"].Value  = entity.ErrorTypeFullName;
     parameters["@stackTrace"].Value         = entity.StackTrace;
 }
Пример #4
0
        /// <summary>
        /// Creates an <see cref="ErrorReportData"/> test object.
        /// </summary>
        private static ErrorReportData CreateTestReport()
        {
            var report = new ErrorReportData
            {
                Id                 = Guid.NewGuid(),
                SourceId           = Guid.NewGuid(),
                SourceAssemblyName = Assembly.GetExecutingAssembly().GetName().ToString(),
                EventDate          = DateTime.UtcNow,
                Message            = "Some argument was null, oh no!",
                ErrorTypeFullName  = typeof(ArgumentNullException).FullName,
                StackTrace         = new StackTrace().ToString()
            };

            return(report);
        }
Пример #5
0
        /// <summary>
        /// Adds an error to the store.
        /// </summary>
        /// <param name="contents">Contents to write.</param>
        /// <returns>File name.</returns>
        public static string Add(ErrorReportData contents)
        {
            // Open local storage folder
            var storage = ApplicationData.Current.LocalFolder;

            // Open or create errors folder
            var errorsFolder = storage.CreateFolder(FolderName);

            // Generate a unique file name
            var fileName = String.Format(CultureInfo.InvariantCulture, FileNameFormat, DateTime.UtcNow);

            // Write error to file
            var file = errorsFolder.CreateFile(fileName);

            file.WriteAllText(contents.SerializeXml(true));

            // Return file name
            return(fileName);
        }
Пример #6
0
        /// <summary>
        /// Reads properties of a <see cref="ErrorReportData"/> from a data reader.
        /// </summary>
        public static void Read(this ErrorReportData entity, SqlDataReader reader, bool skipKeys)
        {
            // Validate.
            if (entity is null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            // Read entity.
            if (!skipKeys)
            {
                GuidDataKeyAdapter.Read(entity, reader);
            }
            entity.SourceId           = reader.Get <Guid>("SourceId");
            entity.SourceAssemblyName = reader.GetString("SourceAssemblyName");
            entity.EventDate          = reader.Get <DateTimeOffset>("EventDate");
            entity.Message            = reader.Get <string>("Message");
            entity.ErrorTypeFullName  = reader.GetNullable <string>("ErrorTypeFullName");
            entity.StackTrace         = reader.GetNullable <string>("StackTrace");
        }
Пример #7
0
        /// <summary>
        /// Sets data command parameter values for a <see cref="ErrorReportData"/>.
        /// </summary>
        public static void Set(this ErrorReportData entity, SqlParameterCollection parameters, bool skipKeys)
        {
            // Validate.
            if (entity is null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (parameters is null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            // Set parameters.
            if (!skipKeys)
            {
                GuidDataKeyAdapter.Set(entity, parameters);
            }
            parameters["@sourceId"].Value           = entity.SourceId;
            parameters["@sourceAssemblyName"].Value = entity.SourceAssemblyName;
            parameters["@eventDate"].Value          = entity.EventDate;
            parameters["@message"].Value            = entity.Message;
            parameters["@errorTypeFullName"].Value  = entity.ErrorTypeFullName;
            parameters["@stackTrace"].Value         = entity.StackTrace;
        }
Пример #8
0
 /// <summary>
 /// Sets data command parameter values for a <see cref="ErrorReportData"/>.
 /// </summary>
 public static void Set(
     this ErrorReportData entity, SqlParameterCollection parameters)
 {
     Set(entity, parameters, false);
 }
Пример #9
0
 /// <summary>
 /// Reads properties of a <see cref="ErrorReportData"/> from a data reader.
 /// </summary>
 public static void Read(this ErrorReportData entity, SqlDataReader reader)
 {
     Read(entity, reader, false);
 }
Пример #10
0
        public static ErrorReportVM GetErrorReportVMFromModel(ErrorReport ErrorReport)
        {
            ErrorReportVM vm = new ViewModels.Reports.ErrorReportVM();

            vm.User1       = ErrorReport.Role1Name;
            vm.User2       = ErrorReport.Role2Name;
            vm.ErrorReport = ErrorReport;
            ErrorReportData data = new ErrorReportData();

            data.DataType     = "Reactions";
            data.AddedCount   = ErrorReport.AddedReactions;
            data.DeletedCount = ErrorReport.DeletedReactions;
            data.UpdatedCount = 0;
            data.CommonCount  = ErrorReport.CommonReactions;
            data.Percentage   = (double)((double)ErrorReport.CommonReactions / (double)(ErrorReport.AddedReactions + ErrorReport.DeletedReactions + ErrorReport.CommonReactions)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Stages";
            data.AddedCount   = ErrorReport.AddedStages;
            data.DeletedCount = ErrorReport.DeletedStages;
            data.UpdatedCount = 0;
            data.CommonCount  = ErrorReport.CommonStages;
            data.Percentage   = (double)((double)ErrorReport.CommonStages / (double)(ErrorReport.AddedStages + ErrorReport.DeletedStages + ErrorReport.CommonStages)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Products";
            data.AddedCount   = ErrorReport.AddedProducts;
            data.DeletedCount = ErrorReport.DeletedProducts;
            data.UpdatedCount = ErrorReport.UpdatedProducts;
            data.CommonCount  = ErrorReport.CommonProducts;
            data.Percentage   = (double)((double)ErrorReport.CommonProducts / (double)(ErrorReport.AddedProducts + ErrorReport.DeletedProducts + ErrorReport.UpdatedProducts + ErrorReport.CommonProducts)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Reactants";
            data.AddedCount   = ErrorReport.AddedReactants;
            data.DeletedCount = ErrorReport.DeletedReactants;
            data.UpdatedCount = ErrorReport.UpdatedReactants;
            data.CommonCount  = ErrorReport.CommonReactants;
            data.Percentage   = (double)((double)ErrorReport.CommonReactants / (double)(ErrorReport.AddedReactants + ErrorReport.DeletedReactants + ErrorReport.UpdatedReactants + ErrorReport.CommonReactants)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Solvents";
            data.AddedCount   = ErrorReport.AddedSolvents;
            data.DeletedCount = ErrorReport.DeletedSolvents;
            data.UpdatedCount = ErrorReport.UpdatedSolvents;
            data.CommonCount  = ErrorReport.CommonSolvents;
            data.Percentage   = (double)((double)ErrorReport.CommonSolvents / (double)(ErrorReport.AddedSolvents + ErrorReport.DeletedSolvents + ErrorReport.UpdatedSolvents + ErrorReport.CommonSolvents)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Agents";
            data.AddedCount   = ErrorReport.AddedAgents;
            data.DeletedCount = ErrorReport.DeletedAgents;
            data.UpdatedCount = ErrorReport.UpdatedAgents;
            data.CommonCount  = ErrorReport.CommonAgents;
            data.Percentage   = (double)((double)ErrorReport.CommonAgents / (double)(ErrorReport.AddedAgents + ErrorReport.DeletedAgents + ErrorReport.UpdatedAgents + ErrorReport.CommonAgents)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Catalyst";
            data.AddedCount   = ErrorReport.AddedCatalysts;
            data.DeletedCount = ErrorReport.DeletedCatalysts;
            data.UpdatedCount = ErrorReport.UpdatedCatalysts;
            data.CommonCount  = ErrorReport.CommonCatalysts;
            data.Percentage   = (double)((double)ErrorReport.CommonCatalysts / (double)(ErrorReport.AddedCatalysts + ErrorReport.DeletedCatalysts + ErrorReport.UpdatedCatalysts + ErrorReport.CommonCatalysts)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Time";
            data.AddedCount   = ErrorReport.AddedTime;
            data.DeletedCount = ErrorReport.DeletedTime;
            data.UpdatedCount = ErrorReport.UpdatedTime;
            data.CommonCount  = ErrorReport.CommonTime;
            data.Percentage   = (double)((double)ErrorReport.CommonTime / (double)(ErrorReport.AddedTime + ErrorReport.DeletedTime + ErrorReport.UpdatedTime + ErrorReport.CommonTime)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Temperature";
            data.AddedCount   = ErrorReport.AddedTemperature;
            data.DeletedCount = ErrorReport.DeletedTemperature;
            data.UpdatedCount = ErrorReport.UpdatedTemperature;
            data.CommonCount  = ErrorReport.CommonTemperature;
            data.Percentage   = (double)((double)ErrorReport.CommonTemperature / (double)(ErrorReport.AddedTemperature + ErrorReport.DeletedTemperature + ErrorReport.UpdatedTemperature + ErrorReport.CommonTemperature)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Pressure";
            data.AddedCount   = ErrorReport.AddedPressure;
            data.DeletedCount = ErrorReport.DeletedPressure;
            data.UpdatedCount = ErrorReport.UpdatedPressure;
            data.CommonCount  = ErrorReport.CommonPressure;
            data.Percentage   = (double)((double)ErrorReport.CommonPressure / (double)(ErrorReport.AddedPressure + ErrorReport.DeletedPressure + ErrorReport.UpdatedPressure + ErrorReport.CommonPressure)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "pH";
            data.AddedCount   = ErrorReport.AddedpH;
            data.DeletedCount = ErrorReport.DeletedpH;
            data.UpdatedCount = ErrorReport.UpdatedpH;
            data.CommonCount  = ErrorReport.CommonpH;
            data.Percentage   = (double)((double)ErrorReport.CommonpH / (double)(ErrorReport.AddedpH + ErrorReport.DeletedpH + ErrorReport.UpdatedpH + ErrorReport.CommonpH)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "Comments";
            data.AddedCount   = ErrorReport.AddedComments;
            data.DeletedCount = ErrorReport.DeletedComments;
            data.UpdatedCount = 0;
            data.CommonCount  = ErrorReport.CommonComments;
            data.Percentage   = (double)((double)ErrorReport.CommonComments / (double)(ErrorReport.AddedComments + ErrorReport.DeletedComments + ErrorReport.UpdatedComments + ErrorReport.CommonComments)) * 100;
            vm.ErrorReportData.Add(data);
            //data = new ErrorReportData();
            //data.DataType = "Rsns";
            //data.AddedCount = ErrorReport.AddedRsns;
            //data.DeletedCount = ErrorReport.DeletedRsns;
            //data.UpdatedCount = ErrorReport.UpdatedRsns;
            //data.CommonCount = ErrorReport.CommonRsns;
            //data.Percentage = (double) ((double)ErrorReport.CommonRsns / (double)(ErrorReport.AddedRsns + ErrorReport.DeletedRsns + ErrorReport.UpdatedRsns + ErrorReport.CommonRsns)) * 100;
            //vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "CVTs";
            data.AddedCount   = ErrorReport.AddedCVTS;
            data.DeletedCount = ErrorReport.DeletedCVTS;
            data.CommonCount  = ErrorReport.CommonCVTS;
            data.Percentage   = (double)((double)ErrorReport.CommonCVTS / (double)(ErrorReport.AddedCVTS + ErrorReport.DeletedCVTS + ErrorReport.CommonCVTS)) * 100;
            vm.ErrorReportData.Add(data);
            data              = new ErrorReportData();
            data.DataType     = "FreeText";
            data.AddedCount   = ErrorReport.AddedFreeText;
            data.DeletedCount = ErrorReport.DeletedFreeText;
            data.CommonCount  = ErrorReport.CommonFreeText;
            data.Percentage   = (double)((double)ErrorReport.CommonFreeText / (double)(ErrorReport.AddedFreeText + ErrorReport.DeletedFreeText + ErrorReport.CommonFreeText)) * 100;
            vm.ErrorReportData.Add(data);
            return(vm);
        }