コード例 #1
0
        public static IDiagnosticResultDto ParseFile(Stream stream, DiagnosticTool tool, DiagnosticFileType type)
        {
            // Load Stream.
            string text;

            using (var reader = new StreamReader(stream))
            {
                // Read All Text.
                text = reader.ReadToEnd();
            }

            // Process.
            return(ParseFile(text, tool, type));
        }
コード例 #2
0
        public async Task <JsonCamelCaseResult> UploadDiagnosticResult(HttpPostedFileBase file, int requestId, int diagnosticToolId)
        {
            try
            {
                // Check File.
                if (file == null || file.ContentLength <= 0)
                {
                    throw new Exception("No File Found.");
                }

                DiagnosticTool diagnosticTool =
                    (DiagnosticTool)Enum.Parse(typeof(DiagnosticTool), diagnosticToolId.ToString());

                // Parse Upload File.
                var diag = DiagnosticFileParser.ParseFile(file.InputStream, diagnosticTool, DiagnosticFileType.XML);

                // Assign Request.
                diag.RequestId = requestId;

                // Save Result.
                var result = Factory.Save(diag);

                // Notify Clients.
                var messenger = new ScanRequestHubMessenger();
                await messenger.NotifyScanUpdated(requestId);

                // Return Update Result.
                return(new JsonCamelCaseResult(result.UpdateResult));
            }
            catch (Exception ex)
            {
                // Log Error.
                Logger.LogException(ex);

                // Prepare Result.
                var error = new
                {
                    Success = false,
                    Message = ex.Message
                };

                // Return Error Result.
                return(new JsonCamelCaseResult(error));
            }
        }
コード例 #3
0
        public static IDiagnosticResultDto ParseFile(string text, DiagnosticTool tool, DiagnosticFileType type)
        {
            // Create Result.
            IDiagnosticResultDto result = null;

            // Process File Text.
            switch (tool)
            {
            case DiagnosticTool.AutoEnginuity:
                switch (type)
                {
                case DiagnosticFileType.XML:
                    result = AutoEnginuity.XmlParser.GetDiagnosticResult(text);
                    break;

                case DiagnosticFileType.JSON:
                    result = AutoEnginuity.JsonParser.GetDiagnosticResult(text);
                    break;
                }
                break;

                /* TODO: Add Honda Parser APD-345.
                 * case DiagnosticTool.Honda:
                 *  break;
                 */
            }

            // Update Result.
            result = result ?? new DiagnosticResultDto();
            result.DiagnosticTool     = tool;
            result.DiagnosticFileType = type;
            result.DiagnosticFileText = text;

            // Set Default VIN on Blank.
            if (string.IsNullOrWhiteSpace(result.VehicleVin))
            {
                result.VehicleVin = DefaultVin;
            }

            return(result);
        }