Viewer to Server

This commit is contained in:
2023-02-16 15:17:31 -07:00
parent 5c50078c04
commit a25dc93610
968 changed files with 16395 additions and 2385 deletions

243
Archive/.editorconfig Normal file
View File

@ -0,0 +1,243 @@
[*.cs]
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true
csharp_prefer_braces = false
csharp_prefer_simple_default_expression = true:warning
csharp_prefer_simple_using_statement = true:warning
csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
csharp_style_allow_embedded_statements_on_same_line_experimental = true
csharp_style_conditional_delegate_call = true
csharp_style_deconstructed_variable_declaration = false
csharp_style_expression_bodied_accessors = when_on_single_line:warning
csharp_style_expression_bodied_constructors = when_on_single_line:warning
csharp_style_expression_bodied_indexers = when_on_single_line:warning
csharp_style_expression_bodied_lambdas = when_on_single_line:warning
csharp_style_expression_bodied_local_functions = when_on_single_line:warning
csharp_style_expression_bodied_methods = when_on_single_line:warning
csharp_style_expression_bodied_operators = when_on_single_line:warning
csharp_style_expression_bodied_properties = when_on_single_line:warning
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
csharp_style_inlined_variable_declaration = false
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_pattern_local_over_anonymous_function = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_prefer_index_operator = false:warning
csharp_style_prefer_not_pattern = true:warning
csharp_style_prefer_null_check_over_type_check = true
csharp_style_prefer_pattern_matching = true:warning
csharp_style_prefer_range_operator = false:warning
csharp_style_prefer_switch_expression = true:warning
csharp_style_throw_expression = true
csharp_style_unused_value_assignment_preference = discard_variable:warning
csharp_style_unused_value_expression_statement_preference = discard_variable:warning
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = false:warning
csharp_using_directive_placement = outside_namespace
dotnet_code_quality_unused_parameters = all
dotnet_code_quality_unused_parameters = non_public # IDE0060: Remove unused parameter
dotnet_code_quality.CAXXXX.api_surface = private, internal
dotnet_diagnostic.CA1825.severity = warning # CA1823: Avoid zero-length array allocations
dotnet_diagnostic.CA1829.severity = warning # CA1829: Use Length/Count property instead of Count() when available
dotnet_diagnostic.CA1834.severity = warning # CA1834: Consider using 'StringBuilder.Append(char)' when applicable
dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name
dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2");
dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary
dotnet_diagnostic.IDE0047.severity = warning # IDE0047: Parentheses can be removed
dotnet_diagnostic.IDE0060.severity = warning # IDE0060: Remove unused parameter
dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.abstract_method_should_be_pascal_case.symbols = abstract_method
dotnet_naming_rule.class_should_be_pascal_case.severity = warning
dotnet_naming_rule.class_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.class_should_be_pascal_case.symbols = class
dotnet_naming_rule.delegate_should_be_pascal_case.severity = warning
dotnet_naming_rule.delegate_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.delegate_should_be_pascal_case.symbols = delegate
dotnet_naming_rule.enum_should_be_pascal_case.severity = warning
dotnet_naming_rule.enum_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.enum_should_be_pascal_case.symbols = enum
dotnet_naming_rule.event_should_be_pascal_case.severity = warning
dotnet_naming_rule.event_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.event_should_be_pascal_case.symbols = event
dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.method_should_be_pascal_case.severity = warning
dotnet_naming_rule.method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.method_should_be_pascal_case.symbols = method
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.private_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.private_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.private_method_should_be_pascal_case.symbols = private_method
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.severity = warning
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.style = private_of_internal_field
dotnet_naming_rule.private_or_internal_field_should_be_private_of_internal_field.symbols = private_or_internal_field
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.severity = warning
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.style = private_of_internal_field
dotnet_naming_rule.private_or_internal_static_field_should_be_private_of_internal_field.symbols = private_or_internal_static_field
dotnet_naming_rule.property_should_be_pascal_case.severity = warning
dotnet_naming_rule.property_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.property_should_be_pascal_case.symbols = property
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.severity = warning
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.style = private_of_internal_field
dotnet_naming_rule.public_or_protected_field_should_be_private_of_internal_field.symbols = public_or_protected_field
dotnet_naming_rule.static_field_should_be_pascal_case.severity = warning
dotnet_naming_rule.static_field_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.static_field_should_be_pascal_case.symbols = static_field
dotnet_naming_rule.static_method_should_be_pascal_case.severity = warning
dotnet_naming_rule.static_method_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.static_method_should_be_pascal_case.symbols = static_method
dotnet_naming_rule.struct_should_be_pascal_case.severity = warning
dotnet_naming_rule.struct_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.struct_should_be_pascal_case.symbols = struct
dotnet_naming_rule.types_should_be_pascal_case.severity = warning
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_style.begins_with_i.capitalization = pascal_case
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.private_of_internal_field.capitalization = pascal_case
dotnet_naming_style.private_of_internal_field.required_prefix = _
dotnet_naming_style.private_of_internal_field.required_suffix =
dotnet_naming_style.private_of_internal_field.word_separator =
dotnet_naming_symbols.abstract_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.abstract_method.applicable_kinds = method
dotnet_naming_symbols.abstract_method.required_modifiers = abstract
dotnet_naming_symbols.class.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.class.applicable_kinds = class
dotnet_naming_symbols.class.required_modifiers =
dotnet_naming_symbols.delegate.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.delegate.applicable_kinds = delegate
dotnet_naming_symbols.delegate.required_modifiers =
dotnet_naming_symbols.enum.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.enum.applicable_kinds = enum
dotnet_naming_symbols.enum.required_modifiers =
dotnet_naming_symbols.event.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.event.applicable_kinds = event
dotnet_naming_symbols.event.required_modifiers =
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.method.applicable_accessibilities = public
dotnet_naming_symbols.method.applicable_kinds = method
dotnet_naming_symbols.method.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.private_method.applicable_accessibilities = private
dotnet_naming_symbols.private_method.applicable_kinds = method
dotnet_naming_symbols.private_method.required_modifiers =
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
dotnet_naming_symbols.private_or_internal_field.required_modifiers =
dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected
dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field
dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static
dotnet_naming_symbols.property.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.property.applicable_kinds = property
dotnet_naming_symbols.property.required_modifiers =
dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected
dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field
dotnet_naming_symbols.public_or_protected_field.required_modifiers =
dotnet_naming_symbols.static_field.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.static_field.applicable_kinds = field
dotnet_naming_symbols.static_field.required_modifiers = static
dotnet_naming_symbols.static_method.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.static_method.applicable_kinds = method
dotnet_naming_symbols.static_method.required_modifiers = static
dotnet_naming_symbols.struct.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.struct.applicable_kinds = struct
dotnet_naming_symbols.struct.required_modifiers =
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.required_modifiers =
dotnet_remove_unnecessary_suppression_exclusions = 0
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false
dotnet_style_allow_multiple_blank_lines_experimental = false:warning
dotnet_style_allow_statement_immediately_after_block_experimental = true
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true:warning
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_namespace_match_folder = true
dotnet_style_null_propagation = true:warning
dotnet_style_object_initializer = true:warning
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true
dotnet_style_prefer_auto_properties = true:warning
dotnet_style_prefer_compound_assignment = true:warning
dotnet_style_prefer_conditional_expression_over_assignment = false
dotnet_style_prefer_conditional_expression_over_return = false
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
dotnet_style_prefer_inferred_tuple_names = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
dotnet_style_prefer_simplified_boolean_expressions = true:warning
dotnet_style_prefer_simplified_interpolation = true
dotnet_style_qualification_for_event = false:error
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_readonly_field = true:warning
dotnet_style_require_accessibility_modifiers = for_non_interface_members
end_of_line = crlf
file_header_template = unset
indent_size = 4
indent_style = space
insert_final_newline = false
root = true
tab_width = 4
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1822
# https://github.com/dotnet/aspnetcore/blob/main/.editorconfig
# https://github.com/dotnet/project-system/blob/main/.editorconfig

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Services;
using System;
using System.IO;
@ -8,13 +8,13 @@ using System.IO;
namespace OI.Metrology.Archive.ApiControllers;
public class AttachmentsController : Controller
{
private readonly IMetrologyRepo _Repo;
private readonly IAttachmentsService _AttachmentsService;
private readonly IMetrologyRepository _MetrologyRepository;
public AttachmentsController(IMetrologyRepo repo, IAttachmentsService attachmentsService)
public AttachmentsController(IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService)
{
_Repo = repo;
_AttachmentsService = attachmentsService;
_MetrologyRepository = metrologyRepository;
}
// this endpoint was created in hope that it would make retrieving attachments to display in OpenInsight easier
@ -27,7 +27,7 @@ public class AttachmentsController : Controller
string title,
string filename)
{
ToolType tt = _Repo.GetToolTypeByName(toolTypeName);
ToolType tt = _MetrologyRepository.GetToolTypeByName(toolTypeName);
bool header = !string.Equals(tabletype.Trim(), "data", StringComparison.OrdinalIgnoreCase);

View File

@ -1,17 +1,17 @@
using Microsoft.AspNetCore.Mvc;
namespace OI.Metrology.Archive.ApiContollers;
namespace OI.Metrology.Archive.ApiControllers;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Models.Stateless;
using System.Text.Json;
// this controller is for the Awaiting Dispo functionality
public class AwaitingDispoController : Controller
{
private readonly IMetrologyRepo _Repo;
private readonly IMetrologyRepository _MetrologyRepository;
public AwaitingDispoController(IMetrologyRepo repo) => _Repo = repo;
public AwaitingDispoController(IMetrologyRepository metrologyRepository) => _MetrologyRepository = metrologyRepository;
// returns the data to show in the Awaiting Dispo grid
// marked no-cache, just-in-case since igniteUI automatically adds a query string parameter to prevent caching
@ -21,7 +21,7 @@ public class AwaitingDispoController : Controller
{
var r = new
{
Results = _Repo.GetAwaitingDispo()
Results = _MetrologyRepository.GetAwaitingDisposition()
};
return Json(r, new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
}
@ -30,7 +30,7 @@ public class AwaitingDispoController : Controller
[HttpPost("/api/awaitingdispo/markasreviewed")]
public IActionResult MarkAsReviewed([FromQuery] long headerid, [FromQuery] int tooltypeid)
{
_ = _Repo.UpdateReviewDate(tooltypeid, headerid, false);
_ = _MetrologyRepository.UpdateReviewDate(tooltypeid, headerid, false);
return Ok();
}
@ -38,7 +38,7 @@ public class AwaitingDispoController : Controller
[HttpPost("/api/awaitingdispo/markasawaiting")]
public IActionResult MarkAsAwaiting([FromQuery] long headerid, [FromQuery] int tooltypeid)
{
if (_Repo.UpdateReviewDate(tooltypeid, headerid, true) <= 1)
if (_MetrologyRepository.UpdateReviewDate(tooltypeid, headerid, true) <= 1)
return Ok();
else
return StatusCode(444);

View File

@ -4,30 +4,30 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Services;
using System;
using System.Collections.Generic;
using System.Linq;
namespace OI.Metrology.Archive.ApiContollers;
namespace OI.Metrology.Archive.ApiControllers;
[ApiController]
public class InboundController : ControllerBase
{
private readonly ILogger _Logger;
private readonly IMetrologyRepo _Repo;
private readonly AppSettings _AppSettings;
private readonly IAttachmentsService _AttachmentService;
private readonly IInboundDataService _InboundDataService;
private readonly IMetrologyRepository _MetrologyRepository;
public InboundController(AppSettings appSettings, ILogger<InboundController> logger, IMetrologyRepo repo, IInboundDataService inboundDataService, IAttachmentsService attachmentService)
public InboundController(AppSettings appSettings, ILogger<InboundController> logger, IMetrologyRepository metrologyRepository, IInboundDataService inboundDataService, IAttachmentsService attachmentService)
{
_Repo = repo;
_Logger = logger;
_AppSettings = appSettings;
_AttachmentService = attachmentService;
_InboundDataService = inboundDataService;
_MetrologyRepository = metrologyRepository;
}
// this class represents the API response back to the client
@ -61,9 +61,9 @@ public class InboundController : ControllerBase
return Unauthorized(r);
}
ToolType toolType = _Repo.GetToolTypeByName(tooltype);
ToolType toolType = _MetrologyRepository.GetToolTypeByName(tooltype);
if (toolType == null)
if (toolType is null)
{
r.Errors.Add("Invalid tool type: " + tooltype);
return BadRequest(r);
@ -71,9 +71,9 @@ public class InboundController : ControllerBase
// get metadata
List<ToolTypeMetadata> metaData = _Repo.GetToolTypeMetadataByToolTypeID(toolType.ID).ToList();
List<ToolTypeMetadata> metaData = _MetrologyRepository.GetToolTypeMetadataByToolTypeID(toolType.ID).ToList();
if (metaData == null)
if (metaData is null)
{
r.Errors.Add("Invalid metadata for tool type: " + tooltype);
return BadRequest(r);
@ -81,7 +81,7 @@ public class InboundController : ControllerBase
// validate fields
if (jsonbody != null)
if (jsonbody is not null)
_InboundDataService.ValidateJSONFields(jsonbody, 0, metaData, r.Errors, r.Warnings);
else
r.Errors.Add("Invalid json");
@ -118,12 +118,12 @@ public class InboundController : ControllerBase
return Unauthorized("Remote IP is not on allowed list");
}
ToolType toolType = _Repo.GetToolTypeByName(tooltype);
ToolType toolType = _MetrologyRepository.GetToolTypeByName(tooltype);
if (toolType == null)
if (toolType is null)
return BadRequest($"Invalid tool type: {tooltype}");
if (Request.Form == null)
if (Request.Form is null)
return BadRequest($"Invalid form");
if (Request.Form.Files.Count != 1)

View File

@ -0,0 +1,99 @@
using Microsoft.AspNetCore.Mvc;
using System.Linq;
namespace OI.Metrology.Archive.ApiControllers;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.Models.Stateless;
using System.Text.Json;
public class ReactorsController : Controller
{
private readonly AppSettings _AppSettings;
private readonly IMetrologyRepository _MetrologyRepository;
public ReactorsController(AppSettings appSettings, IMetrologyRepository metrologyRepository)
{
_AppSettings = appSettings;
_MetrologyRepository = metrologyRepository;
}
private static int[] EvenReactors()
{
int[] results = new int[] {
20,
22,
24,
26,
28,
30,
32,
34,
36,
38,
40,
42,
44,
46,
48,
50,
52,
54,
56,
58,
60,
62,
64,
66,
68,
70,
72,
74
};
return results;
}
private static int[] OddReactors()
{
int[] results = new int[] {
21,
23,
25,
27,
29,
31,
33,
35,
37,
39,
41,
43,
45,
47,
49,
51,
53,
55,
57,
59,
61,
63,
65,
73,
75,
77,
79
};
return results;
}
[HttpGet("/api/reactors/{even}")]
public IActionResult Index(bool even)
{
int[] n = even ? EvenReactors() : OddReactors();
var r = n.Select(l => new { Name = $"R{l}", Id = l });
return Json(r, new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
}
}

View File

@ -4,11 +4,11 @@ using System;
using System.IO;
using System.Linq;
namespace OI.Metrology.Archive.ApiContollers;
namespace OI.Metrology.Archive.ApiControllers;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Services;
using System.Collections.Generic;
using System.Text.Json;
@ -21,15 +21,15 @@ public class ToolTypesController : Controller
// it is named after the /api/tooltypes prefix
// the URL pattern is RESTful and the tool type is the root of every request
private readonly IMetrologyRepo _Repo;
private readonly AppSettings _AppSettings;
private readonly IAttachmentsService _AttachmentsService;
private readonly IMetrologyRepository _MetrologyRepository;
public ToolTypesController(AppSettings appSettings, IMetrologyRepo repo, IAttachmentsService attachmentsService)
public ToolTypesController(AppSettings appSettings, IMetrologyRepository metrologyRepository, IAttachmentsService attachmentsService)
{
_Repo = repo;
_AppSettings = appSettings;
_AttachmentsService = attachmentsService;
_MetrologyRepository = metrologyRepository;
}
// Get a list of tooltypes, returns just Name and ID
@ -38,7 +38,7 @@ public class ToolTypesController : Controller
{
var r = new
{
Results = _Repo.GetToolTypes().Select(tt => new { tt.ToolTypeName, tt.ID })
Results = _MetrologyRepository.GetToolTypes().Select(tt => new { tt.ToolTypeName, tt.ID })
};
return Json(r, new JsonSerializerOptions { PropertyNamingPolicy = null, WriteIndented = true });
}
@ -48,8 +48,8 @@ public class ToolTypesController : Controller
[HttpGet("/api/tooltypes/{id}")]
public IActionResult GetToolTypeMetadata(int id, string sortby = "")
{
ToolType tt = _Repo.GetToolTypeByID(id);
IEnumerable<ToolTypeMetadata> md = _Repo.GetToolTypeMetadataByToolTypeID(id);
ToolType tt = _MetrologyRepository.GetToolTypeByID(id);
IEnumerable<ToolTypeMetadata> md = _MetrologyRepository.GetToolTypeMetadataByToolTypeID(id);
if (string.Equals(sortby, "grid", StringComparison.OrdinalIgnoreCase))
md = md.OrderBy(f => f.GridDisplayOrder).ToList();
@ -80,7 +80,7 @@ public class ToolTypesController : Controller
{
long totalRecs;
System.Data.DataTable dt = _Repo.GetHeaders(id, datebegin, dateend, page, pagesize, headerid, out totalRecs);
System.Data.DataTable dt = _MetrologyRepository.GetHeaders(id, datebegin, dateend, page, pagesize, headerid, out totalRecs);
var r = new
{
@ -101,7 +101,7 @@ public class ToolTypesController : Controller
{
long totalRecs;
IEnumerable<HeaderCommon> dt = _Repo.GetHeaderTitles(id, page, pagesize, out totalRecs);
IEnumerable<HeaderCommon> dt = _MetrologyRepository.GetHeaderTitles(id, page, pagesize, out totalRecs);
var r = new
{
@ -121,7 +121,7 @@ public class ToolTypesController : Controller
{
var r = new
{
Results = _Repo.GetHeaderFields(id, headerid).Select(x => new { Column = x.Key, x.Value }).ToList()
Results = _MetrologyRepository.GetHeaderFields(id, headerid).Select(x => new { Column = x.Key, x.Value }).ToList()
};
string json = JsonConvert.SerializeObject(r);
@ -137,7 +137,7 @@ public class ToolTypesController : Controller
var r = new
{
Results = _Repo.GetDataSharePoint(id, title)
Results = _MetrologyRepository.GetDataSharePoint(id, title)
};
string json = JsonConvert.SerializeObject(r);
@ -152,7 +152,7 @@ public class ToolTypesController : Controller
var r = new
{
Results = _Repo.GetData(id, headerid)
Results = _MetrologyRepository.GetData(id, headerid)
};
string json = JsonConvert.SerializeObject(r);
@ -168,7 +168,7 @@ public class ToolTypesController : Controller
string filename)
{
ToolType tt = _Repo.GetToolTypeByID(toolTypeId);
ToolType tt = _MetrologyRepository.GetToolTypeByID(toolTypeId);
bool header = !string.Equals(tabletype.Trim(), "data", StringComparison.OrdinalIgnoreCase);
@ -191,7 +191,7 @@ public class ToolTypesController : Controller
public IActionResult OIExport(int toolTypeId, long headerid)
{
// Call the export stored procedure
System.Data.DataSet ds = _Repo.GetOIExportData(toolTypeId, headerid);
System.Data.DataSet ds = _MetrologyRepository.GetOIExportData(toolTypeId, headerid);
try
{
@ -213,7 +213,7 @@ public class ToolTypesController : Controller
foreach (object o in ds.Tables[1].Rows[0].ItemArray)
{
if ((o != null) && (!Convert.IsDBNull(o)))
if ((o is not null) && (!Convert.IsDBNull(o)))
_ = sb.Append(Convert.ToString(o));
_ = sb.Append('\t');
}
@ -223,7 +223,7 @@ public class ToolTypesController : Controller
{
foreach (object o in dr.ItemArray)
{
if ((o != null) && (!Convert.IsDBNull(o)))
if ((o is not null) && (!Convert.IsDBNull(o)))
_ = sb.Append(Convert.ToString(o));
_ = sb.Append('\t');
}

View File

@ -15,7 +15,7 @@ public class ErrorHandlerController : Controller
public IActionResult Index()
{
IExceptionHandlerFeature error = HttpContext.Features.Get<IExceptionHandlerFeature>();
if (error == null)
if (error is null)
{
return Redirect("~/");
}
@ -24,7 +24,7 @@ public class ErrorHandlerController : Controller
_Logger.LogError("Unhandled exception: " + error.Error.ToString());
dynamic r = new
{
Message = error.Error == null ? "Error" : error.Error.Message
Message = error.Error is null ? "Error" : error.Error.Message
};
return StatusCode(StatusCodes.Status500InternalServerError, r);
}

View File

@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.ViewModels;
using System;
using System.Collections.Generic;
@ -17,14 +17,14 @@ public class ExportController : Controller
{
private readonly ILogger _Logger;
private readonly bool _IsTestDatabase;
private readonly IMetrologyRepo _Repo;
private readonly AppSettings _AppSettings;
private readonly IMetrologyRepository _MetrologyRepository;
public ExportController(AppSettings appSettings, ILogger<ExportController> logger, IMetrologyRepo repo)
public ExportController(AppSettings appSettings, ILogger<ExportController> logger, IMetrologyRepository metrologyRepository)
{
_Repo = repo;
_Logger = logger;
_AppSettings = appSettings;
_MetrologyRepository = metrologyRepository;
_IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase);
}
@ -40,7 +40,6 @@ public class ExportController : Controller
{
Export model = new()
{
ToolType = "",
StartTime = DateTime.Now.AddMonths(-1),
EndTime = DateTime.Now
};
@ -60,7 +59,7 @@ public class ExportController : Controller
{
if (model.StartTime > model.EndTime)
ModelState.AddModelError("EndTime", "End time must be after start time");
IEnumerable<ToolType> toolTypes = _Repo.GetToolTypes();
IEnumerable<ToolType> toolTypes = _MetrologyRepository.GetToolTypes();
toolType = toolTypes.Where(tt => tt.ID.ToString() == model.ToolType).SingleOrDefault();
if (toolType is null)
ModelState.AddModelError("ToolType", "Invalid selection");
@ -94,7 +93,7 @@ public class ExportController : Controller
string fileName = string.Format("Export_{0}_{1:yyyyMMddHHmm}_to_{2:yyyyMMddHHmm}.csv", toolTypeName, startTime, endTime);
StringBuilder sb = new();
System.Data.DataTable dt = _Repo.ExportData(spName, startTime, endTime);
System.Data.DataTable dt = _MetrologyRepository.ExportData(spName, startTime, endTime);
_ = sb.AppendLine(GetColumnHeaders(dt));

View File

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.ViewModels;
using System;
@ -13,12 +14,12 @@ public class PagesController : Controller
{
private readonly bool _IsTestDatabase;
private readonly IRdsMaxRepo _RdsMaxRepo;
private readonly IMetrologyRepo _MetrologyRepo;
private readonly IMetrologyRepository _MetrologyRepo;
public PagesController(AppSettings appSettings, IMetrologyRepo metrologyRepo, IRdsMaxRepo rdsMaxRepo)
public PagesController(AppSettings appSettings, IMetrologyRepository metrologyRepository, IRdsMaxRepo rdsMaxRepo)
{
_RdsMaxRepo = rdsMaxRepo;
_MetrologyRepo = metrologyRepo;
_MetrologyRepo = metrologyRepository;
_IsTestDatabase = appSettings.ConnectionString.Contains("test", StringComparison.InvariantCultureIgnoreCase);
}
@ -122,4 +123,9 @@ public class PagesController : Controller
return View(results);
}
[HttpGet]
[Route("/Reactor")]
[Route("/Metrology/Reactor")]
public IActionResult Reactor() => View(new RunInfo());
}

View File

@ -1,61 +1,24 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace OI.Metrology.Archive.Models;
public class AppSettings
public record AppSettings(string ApiLoggingContentTypes,
string ApiLoggingPathPrefixes,
string ApiLogPath,
string AttachmentPath,
string BuildNumber,
string Company,
string ConnectionString,
string GitCommitSeven,
string InboundApiAllowedIPList,
string MonAResource,
string MonASite,
string Oi2SqlConnectionString,
string OIExportPath,
string URLs,
string WorkingDirectoryName)
{
public string ApiLoggingContentTypes { init; get; }
public string ApiLoggingPathPrefixes { init; get; }
public string ApiLogPath { init; get; }
public string AttachmentPath { init; get; }
public string BuildNumber { init; get; }
public string Company { init; get; }
public string ConnectionString { init; get; }
public string GitCommitSeven { init; get; }
public string InboundApiAllowedIPList { init; get; }
public string MonAResource { init; get; }
public string MonASite { init; get; }
public string OIExportPath { init; get; }
public string Oi2SqlConnectionString { init; get; }
public string URLs { init; get; }
public string WorkingDirectoryName { init; get; }
[JsonConstructor]
public AppSettings(string apiLoggingContentTypes,
string apiLoggingPathPrefixes,
string apiLogPath,
string attachmentPath,
string buildNumber,
string company,
string connectionString,
string gitCommitSeven,
string inboundApiAllowedIPList,
string monAResource,
string monASite,
string oi2SqlConnectionString,
string oiExportPath,
string urls,
string workingDirectoryName)
{
ApiLoggingContentTypes = apiLoggingContentTypes;
ApiLoggingPathPrefixes = apiLoggingPathPrefixes;
ApiLogPath = apiLogPath;
AttachmentPath = attachmentPath;
BuildNumber = buildNumber;
Company = company;
ConnectionString = connectionString;
GitCommitSeven = gitCommitSeven;
InboundApiAllowedIPList = inboundApiAllowedIPList;
MonAResource = monAResource;
MonASite = monASite;
Oi2SqlConnectionString = oi2SqlConnectionString;
OIExportPath = oiExportPath;
URLs = urls;
WorkingDirectoryName = workingDirectoryName;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Configuration;
using System;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
@ -36,6 +37,38 @@ public class AppSettings
private static Models.AppSettings Get(AppSettings appSettings)
{
Models.AppSettings result;
if (appSettings is null)
throw new NullReferenceException(nameof(appSettings));
if (appSettings.ApiLoggingContentTypes is null)
throw new NullReferenceException(nameof(ApiLoggingContentTypes));
if (appSettings.ApiLoggingPathPrefixes is null)
throw new NullReferenceException(nameof(ApiLoggingPathPrefixes));
if (appSettings.ApiLogPath is null)
throw new NullReferenceException(nameof(ApiLogPath));
if (appSettings.AttachmentPath is null)
throw new NullReferenceException(nameof(AttachmentPath));
if (appSettings.BuildNumber is null)
throw new NullReferenceException(nameof(BuildNumber));
if (appSettings.Company is null)
throw new NullReferenceException(nameof(Company));
if (appSettings.ConnectionString is null)
throw new NullReferenceException(nameof(ConnectionString));
if (appSettings.GitCommitSeven is null)
throw new NullReferenceException(nameof(GitCommitSeven));
if (appSettings.InboundApiAllowedIPList is null)
throw new NullReferenceException(nameof(InboundApiAllowedIPList));
if (appSettings.MonAResource is null)
throw new NullReferenceException(nameof(MonAResource));
if (appSettings.MonASite is null)
throw new NullReferenceException(nameof(MonASite));
if (appSettings.Oi2SqlConnectionString is null)
throw new NullReferenceException(nameof(Oi2SqlConnectionString));
if (appSettings.OIExportPath is null)
throw new NullReferenceException(nameof(OIExportPath));
if (appSettings.URLs is null)
throw new NullReferenceException(nameof(URLs));
if (appSettings.WorkingDirectoryName is null)
throw new NullReferenceException(nameof(WorkingDirectoryName));
result = new(
appSettings.ApiLoggingContentTypes,
appSettings.ApiLoggingPathPrefixes,

View File

@ -12,8 +12,11 @@
<Nullable>disable</Nullable>
<OutputType>Exe</OutputType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="Tests" />
</ItemGroup>
<ItemGroup>
<Compile Remove="logs\**" />
<Content Remove="logs\**" />
@ -26,28 +29,22 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="jQuery" Version="3.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.AspNetCore.Ingestion" Version="1.0.0-dev-00021" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="jQuery" Version="3.6.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
<PackageReference Include="Serilog.AspNetCore.Ingestion" Version="1.0.0-dev-00032" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\Shared\OI.Metrology.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="moves\" />

View File

@ -9,6 +9,7 @@ using OI.Metrology.Archive.Models;
using OI.Metrology.Archive.Repositories;
using OI.Metrology.Archive.Services;
using OI.Metrology.Shared.Models;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Services;
using Serilog;
@ -21,6 +22,8 @@ namespace OI.Metrology.Archive;
public class Program
{
internal readonly AppSettings _AppSettings;
private static (string, WebApplicationOptions) Get(string[] args)
{
string webRootPath;
@ -50,10 +53,10 @@ public class Program
(string assemblyName, WebApplicationOptions _) = Get(args);
WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args);
_ = webApplicationBuilder.Configuration.AddUserSecrets<Program>();
AppSettings appSettings = Models.Binder.AppSettings.Get(webApplicationBuilder.Configuration);
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
AppSettings _AppSettings = Models.Binder.AppSettings.Get(webApplicationBuilder.Configuration);
if (string.IsNullOrEmpty(_AppSettings.WorkingDirectoryName))
throw new Exception("Working directory name must have a value!");
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assemblyName, appSettings.WorkingDirectoryName);
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assemblyName, _AppSettings.WorkingDirectoryName);
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, webApplicationBuilder.Configuration);
_ = SerilogHostBuilderExtensions.UseSerilog(webApplicationBuilder.Host);
@ -63,13 +66,13 @@ public class Program
{
_ = webApplicationBuilder.Services.Configure<ApiBehaviorOptions>(options => options.SuppressModelStateInvalidFilter = true);
_ = webApplicationBuilder.Services.AddControllersWithViews();
_ = new MetrologyRepo(new SQLDbConnectionFactory(appSettings), null);
_ = new MetrologyRepository(new SQLDbConnectionFactory(_AppSettings), null);
_ = webApplicationBuilder.Services.AddDistributedMemoryCache();
_ = webApplicationBuilder.Services.AddMemoryCache();
_ = webApplicationBuilder.Services.AddSingleton<AppSettings, AppSettings>(_ => appSettings);
_ = webApplicationBuilder.Services.AddSingleton<AppSettings, AppSettings>(_ => _AppSettings);
_ = webApplicationBuilder.Services.AddScoped<IAttachmentsService, AttachmentsService>();
_ = webApplicationBuilder.Services.AddScoped<IInboundDataService, InboundDataService>();
_ = webApplicationBuilder.Services.AddScoped<IMetrologyRepo, MetrologyRepo>();
_ = webApplicationBuilder.Services.AddScoped<IMetrologyRepository, MetrologyRepository>();
_ = webApplicationBuilder.Services.AddScoped<IRdsMaxRepo, RdsMaxRepo>();
_ = webApplicationBuilder.Services.AddSingleton<IDbConnectionFactory, SQLDbConnectionFactory>();
_ = webApplicationBuilder.Services.AddSwaggerGen();
@ -85,8 +88,10 @@ public class Program
_ = webApplicationBuilder.Services.AddSingleton<IHostLifetime, WindowsServiceLifetime>();
_ = webApplicationBuilder.Logging.AddEventLog(settings =>
{
#pragma warning disable CA1416
if (string.IsNullOrEmpty(settings.SourceName))
settings.SourceName = webApplicationBuilder.Environment.ApplicationName;
#pragma warning restore
});
}
WebApplication webApplication = webApplicationBuilder.Build();
@ -97,7 +102,7 @@ public class Program
}
else
{
if (string.IsNullOrEmpty(appSettings.URLs))
if (string.IsNullOrEmpty(_AppSettings.URLs))
{
Environment.ExitCode = -1;
webApplication.Lifetime.StopApplication();

View File

@ -2,6 +2,7 @@
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json.Linq;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Repositories;
using System;
using System.Collections.Generic;
@ -12,12 +13,12 @@ using System.Transactions;
namespace OI.Metrology.Archive.Repositories;
public class MetrologyRepo : IMetrologyRepo
public class MetrologyRepository : IMetrologyRepository
{
private readonly IDbConnectionFactory _DBConnectionFactory;
private readonly IMemoryCache _Cache;
public MetrologyRepo(IDbConnectionFactory dbConnectionFactory, IMemoryCache memoryCache)
public MetrologyRepository(IDbConnectionFactory dbConnectionFactory, IMemoryCache memoryCache)
{
_DBConnectionFactory = dbConnectionFactory;
_Cache = memoryCache;
@ -28,20 +29,6 @@ public class MetrologyRepo : IMetrologyRepo
protected DbProviderFactory GetDbProviderFactory(IDbConnection conn) =>
DbProviderFactories.GetFactory(conn.GetType().Namespace);
public bool IsTestDatabase()
{
int c = 0;
using (DbConnection conn = GetDbConnection())
{
c = conn.Query<int>(
"SELECT COUNT(*) " +
"FROM Configuration " +
"WHERE KeyName = 'TestDatabase' " +
"AND ValueString = '1'").FirstOrDefault();
}
return c > 0;
}
public TransactionScope StartTransaction() => new();
protected void CacheItem(string key, object v)
@ -136,10 +123,10 @@ public class MetrologyRepo : IMetrologyRepo
// build field map
foreach (ToolTypeMetadata f in fields)
{
if ((f.ApiName != null) && f.ApiName.Contains('\\'))
if ((f.ApiName is not null) && f.ApiName.Contains('\\'))
{
string n = f.ApiName.Split('\\')[0].Trim().ToUpper();
if (containerField == null)
if (containerField is null)
containerField = n;
else if (!string.Equals(containerField, n))
throw new Exception("Only one container field is allowed");
@ -153,7 +140,7 @@ public class MetrologyRepo : IMetrologyRepo
}
}
if (containerField == null)
if (containerField is null)
{
// No container field, just insert a single row
@ -164,7 +151,7 @@ public class MetrologyRepo : IMetrologyRepo
// Find the container field in the json
JProperty contJP = jsonrow.Children<JProperty>().Where(c => string.Equals(c.Name.Trim(), containerField, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
if ((contJP != null) && (contJP.Value is JArray array))
if ((contJP is not null) && (contJP.Value is JArray array))
{
JArray contRows = array;
@ -227,14 +214,13 @@ public class MetrologyRepo : IMetrologyRepo
parmnumber += 1;
object sqlValue = ((JValue)jp.Value).Value;
if (sqlValue == null)
sqlValue = DBNull.Value;
sqlValue ??= DBNull.Value;
AddParameter(cmd, parmname, sqlValue);
}
}
if ((containerrow != null) && (containerFieldmap != null))
if ((containerrow is not null) && (containerFieldmap is not null))
{
foreach (JProperty jp in containerrow.Children<JProperty>())
@ -251,8 +237,7 @@ public class MetrologyRepo : IMetrologyRepo
parmnumber += 1;
object sqlValue = ((JValue)jp.Value).Value;
if (sqlValue == null)
sqlValue = DBNull.Value;
sqlValue ??= DBNull.Value;
AddParameter(cmd, parmname, sqlValue);
}
@ -266,7 +251,7 @@ public class MetrologyRepo : IMetrologyRepo
cmd.CommandText = columns.TrimEnd(',') + parms.TrimEnd(',') + ";SELECT SCOPE_IDENTITY();";
object o = cmd.ExecuteScalar();
if ((o == null) || Convert.IsDBNull(o))
if ((o is null) || Convert.IsDBNull(o))
throw new Exception("Unexpected query result");
return Convert.ToInt64(o);
}
@ -306,7 +291,7 @@ public class MetrologyRepo : IMetrologyRepo
{
if (!firstField)
_ = sb.Append(',');
if (f.GridAttributes != null && f.GridAttributes.Contains("isNull"))
if (f.GridAttributes is not null && f.GridAttributes.Contains("isNull"))
{
_ = sb.AppendFormat("{0}", "ISNULL(" + f.ColumnName + ", '')[" + f.ColumnName + "]");
}
@ -324,11 +309,11 @@ public class MetrologyRepo : IMetrologyRepo
public DataTable GetHeaders(int toolTypeId, DateTime? startTime, DateTime? endTime, int? pageNo, int? pageSize, long? headerId, out long totalRecords)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
IEnumerable<ToolTypeMetadata> md = GetToolTypeMetadataByToolTypeID(toolTypeId);
if (md == null)
if (md is null)
throw new Exception("Invalid tool type metadata");
DataTable dt = new();
@ -420,11 +405,11 @@ public class MetrologyRepo : IMetrologyRepo
public DataTable GetData(int toolTypeId, long headerid)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
IEnumerable<ToolTypeMetadata> md = GetToolTypeMetadataByToolTypeID(toolTypeId);
if (md == null)
if (md is null)
throw new Exception("Invalid tool type metadata");
DataTable dt = new();
@ -531,11 +516,11 @@ public class MetrologyRepo : IMetrologyRepo
public DataTable GetDataSharePoint(int toolTypeId, string headerid)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
IEnumerable<ToolTypeMetadata> md = GetToolTypeMetadataByToolTypeID(toolTypeId);
if (md == null)
if (md is null)
throw new Exception("Invalid tool type metadata");
DataTable dt = new();
@ -626,7 +611,7 @@ public class MetrologyRepo : IMetrologyRepo
public Guid GetHeaderAttachmentID(int toolTypeId, long headerId)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -639,7 +624,7 @@ public class MetrologyRepo : IMetrologyRepo
public Guid GetDataAttachmentID(int toolTypeId, long headerId, string title)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -658,7 +643,7 @@ public class MetrologyRepo : IMetrologyRepo
public DataSet GetOIExportData(int toolTypeId, long headerid)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
if (string.IsNullOrWhiteSpace(tt.OIExportSPName))
@ -684,10 +669,13 @@ public class MetrologyRepo : IMetrologyRepo
return ds;
}
public IEnumerable<HeaderCommon> GetHeaderTitles(int toolTypeId, int? pageNo, int? pageSize, out long totalRecords)
public HeaderCommon[] GetHeaderTitles(int? toolTypeId, int? pageNo, int? pageSize, out long totalRecords)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (toolTypeId is null)
throw new Exception("Invalid tool type ID");
ToolType tt = GetToolTypeByID(toolTypeId.Value);
if (tt is null)
throw new Exception("Invalid tool type ID");
DbConnection conn = GetDbConnection();
@ -695,17 +683,17 @@ public class MetrologyRepo : IMetrologyRepo
{
string sql = $"SELECT ID, InsertDate, AttachmentID, Title, [Date] FROM {tt.HeaderTableName} ORDER BY [Date] DESC ";
IEnumerable<HeaderCommon> headers;
HeaderCommon[] headers;
if (pageNo.HasValue && pageSize.HasValue)
{
sql += "OFFSET @PageNum * @PageSize ROWS FETCH NEXT @PageSize ROWS ONLY";
headers = conn.Query<HeaderCommon>(sql, param: new { PageNum = pageNo.Value, PageSize = pageSize.Value }).ToList();
headers = conn.Query<HeaderCommon>(sql, param: new { PageNum = pageNo.Value, PageSize = pageSize.Value }).ToArray();
}
else
{
headers = conn.Query<HeaderCommon>(sql).ToList();
headers = conn.Query<HeaderCommon>(sql).ToArray();
}
sql = $"SELECT COUNT(*) FROM [{tt.HeaderTableName}] ";
@ -719,11 +707,11 @@ public class MetrologyRepo : IMetrologyRepo
public IEnumerable<KeyValuePair<string, string>> GetHeaderFields(int toolTypeId, long headerid)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
IEnumerable<ToolTypeMetadata> md = GetToolTypeMetadataByToolTypeID(toolTypeId);
if (md == null)
if (md is null)
throw new Exception("Invalid tool type metadata");
List<KeyValuePair<string, string>> r = new();
@ -751,10 +739,10 @@ public class MetrologyRepo : IMetrologyRepo
foreach (ToolTypeMetadata m in md.Where(m => m.Header == true && m.TableDisplayOrder > 0).OrderBy(m => m.TableDisplayOrder))
{
string v = "";
if (dr != null)
if (dr is not null)
{
object o = dr[m.ColumnName];
if (o != null && !Convert.IsDBNull(o))
if (o is not null && !Convert.IsDBNull(o))
v = Convert.ToString(o);
}
KeyValuePair<string, string> kvp = new(m.DisplayTitle, v);
@ -764,16 +752,16 @@ public class MetrologyRepo : IMetrologyRepo
return r;
}
public IEnumerable<AwaitingDispo> GetAwaitingDispo()
public IEnumerable<AwaitingDisposition> GetAwaitingDisposition()
{
using DbConnection conn = GetDbConnection();
return conn.Query<AwaitingDispo>("GetAwaitingDispo", commandType: CommandType.StoredProcedure);
return conn.Query<AwaitingDisposition>("GetAwaitingDispo", commandType: CommandType.StoredProcedure);
}
// Jonathan changed this to remove the reviewDate update on the database.
public int UpdateReviewDate(int toolTypeId, long headerId, bool clearDate)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -794,7 +782,7 @@ public class MetrologyRepo : IMetrologyRepo
public Guid GetHeaderAttachmentIDByTitle(int toolTypeId, string title)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -806,7 +794,7 @@ public class MetrologyRepo : IMetrologyRepo
public Guid GetDataAttachmentIDByTitle(int toolTypeId, string title)
{
ToolType tt = GetToolTypeByID(toolTypeId);
if (tt == null)
if (tt is null)
throw new Exception("Invalid tool type ID");
using DbConnection conn = GetDbConnection();
@ -815,8 +803,8 @@ public class MetrologyRepo : IMetrologyRepo
return conn.ExecuteScalar<Guid>(sql, param: new { Title = title });
}
string IMetrologyRepo.GetHeaderInsertDate(int toolTypeId, long headerId) => throw new NotImplementedException();
void IMetrologyRepo.SetHeaderDirName(string tableName, long headerId, string dateDir) => throw new NotImplementedException();
string IMetrologyRepo.GetDataInsertDate(int toolTypeId, long headerId, string title) => throw new NotImplementedException();
void IMetrologyRepo.SetDataDirName(string tableName, long headerId, string title, string dateDir) => throw new NotImplementedException();
string IMetrologyRepository.GetHeaderInsertDate(int toolTypeId, long headerId) => throw new NotImplementedException();
void IMetrologyRepository.SetHeaderDirName(string tableName, long headerId, string dateDir) => throw new NotImplementedException();
string IMetrologyRepository.GetDataInsertDate(int toolTypeId, long headerId, string title) => throw new NotImplementedException();
void IMetrologyRepository.SetDataDirName(string tableName, long headerId, string title, string dateDir) => throw new NotImplementedException();
}

View File

@ -6,27 +6,27 @@ namespace OI.Metrology.Archive.Services;
using OI.Metrology.Archive.Models;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Services;
using System.Data.SqlClient;
public class AttachmentsService : IAttachmentsService
{
private readonly IMetrologyRepo _Repo;
private readonly AppSettings _AppSettings;
private readonly IMetrologyRepository _MetrologyRepository;
public AttachmentsService(AppSettings appSettings, IMetrologyRepo repo)
public AttachmentsService(AppSettings appSettings, IMetrologyRepository metrologyRepository)
{
_Repo = repo;
_AppSettings = appSettings;
_MetrologyRepository = metrologyRepository;
}
protected Stream GetAttachmentStream(string tableName, Guid attachmentId, string filename)
{
if (attachmentId.Equals(Guid.Empty))
throw new Exception("No attachments found");
DateTime insertDate = Convert.ToDateTime(_Repo.GetAttachmentInsertDateByGUID(tableName, attachmentId));
DateTime insertDate = Convert.ToDateTime(_MetrologyRepository.GetAttachmentInsertDateByGUID(tableName, attachmentId));
int year = insertDate.Year;
DateTime d = insertDate;
CultureInfo cul = CultureInfo.CurrentCulture;
@ -63,7 +63,7 @@ public class AttachmentsService : IAttachmentsService
public Stream GetAttachmentStreamByTitle(ToolType toolType, bool header, string title, string filename)
{
if (toolType == null)
if (toolType is null)
throw new Exception("Invalid tool type");
string queryString = "SELECT * FROM " + toolType.DataTableName + " WHERE AttachmentId = @attachmentId";
@ -103,19 +103,19 @@ public class AttachmentsService : IAttachmentsService
if (header)
{
tableName = toolType.HeaderTableName;
attachmentId = _Repo.GetHeaderAttachmentIDByTitle(toolType.ID, title);
attachmentId = _MetrologyRepository.GetHeaderAttachmentIDByTitle(toolType.ID, title);
}
else
{
tableName = toolType.DataTableName;
attachmentId = _Repo.GetDataAttachmentIDByTitle(toolType.ID, title);
attachmentId = _MetrologyRepository.GetDataAttachmentIDByTitle(toolType.ID, title);
}
return GetAttachmentStream(tableName, attachmentId, filename);
}
public Stream GetAttachmentStreamByAttachmentId(ToolType toolType, bool header, Guid attachmentId, string filename)
{
if (toolType == null)
if (toolType is null)
throw new Exception("Invalid tool type");
string tableName;
if (header)
@ -126,7 +126,7 @@ public class AttachmentsService : IAttachmentsService
}
public Stream GetAttachmentStreamByAttachmentIdArchive(ToolType toolType, bool header, Guid attachmentId, string filename)
{
if (toolType == null)
if (toolType is null)
throw new Exception("Invalid tool type");
string tableName;
if (header)
@ -139,21 +139,21 @@ public class AttachmentsService : IAttachmentsService
private void SaveAttachment(ToolType toolType, long headerId, string dataUniqueId, string filename, Microsoft.AspNetCore.Http.IFormFile uploadedFile)
{
if (toolType == null)
if (toolType is null)
throw new Exception("Invalid tool type");
using System.Transactions.TransactionScope trans = _Repo.StartTransaction();
using System.Transactions.TransactionScope trans = _MetrologyRepository.StartTransaction();
Guid attachmentId = Guid.Empty;
string tableName = "";
if (string.IsNullOrWhiteSpace(dataUniqueId))
{
attachmentId = _Repo.GetHeaderAttachmentID(toolType.ID, headerId);
attachmentId = _MetrologyRepository.GetHeaderAttachmentID(toolType.ID, headerId);
tableName = toolType.HeaderTableName;
}
else
{
attachmentId = _Repo.GetDataAttachmentID(toolType.ID, headerId, dataUniqueId);
attachmentId = _MetrologyRepository.GetDataAttachmentID(toolType.ID, headerId, dataUniqueId);
tableName = toolType.DataTableName;
}
if (Equals(attachmentId, Guid.Empty))

View File

@ -1,6 +1,6 @@
using Newtonsoft.Json.Linq;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Services;
using System;
using System.Collections.Generic;
@ -10,9 +10,9 @@ namespace OI.Metrology.Archive.Services;
public class InboundDataService : IInboundDataService
{
private readonly IMetrologyRepo _Repo;
private readonly IMetrologyRepository _MetrologyRepository;
public InboundDataService(IMetrologyRepo repo) => _Repo = repo;
public InboundDataService(IMetrologyRepository metrologyRepository) => _MetrologyRepository = metrologyRepository;
public long DoSQLInsert(JToken jsonbody, ToolType toolType, List<ToolTypeMetadata> metaData)
{
@ -37,11 +37,11 @@ public class InboundDataService : IInboundDataService
long headerId = 0;
using (System.Transactions.TransactionScope transScope = _Repo.StartTransaction())
using (System.Transactions.TransactionScope transScope = _MetrologyRepository.StartTransaction())
{
try
{
_Repo.PurgeExistingData(toolType.ID, uniqueId);
_MetrologyRepository.PurgeExistingData(toolType.ID, uniqueId);
}
catch (Exception ex)
{
@ -50,7 +50,7 @@ public class InboundDataService : IInboundDataService
try
{
headerId = _Repo.InsertToolDataJSON(jsonbody, -1, metaData, toolType.HeaderTableName);
headerId = _MetrologyRepository.InsertToolDataJSON(jsonbody, -1, metaData, toolType.HeaderTableName);
}
catch (Exception ex)
{
@ -60,11 +60,11 @@ public class InboundDataService : IInboundDataService
int detailrow = 1;
try
{
if (detailsArray != null)
if (detailsArray is not null)
{
foreach (JToken detail in detailsArray)
{
_ = _Repo.InsertToolDataJSON(detail, headerId, metaData, toolType.DataTableName);
_ = _MetrologyRepository.InsertToolDataJSON(detail, headerId, metaData, toolType.DataTableName);
detailrow += 1;
}
}
@ -133,7 +133,7 @@ public class InboundDataService : IInboundDataService
if (jp.First is JArray array)
detailsArray = array;
else if ((jp.First is JValue value) && (value.Value == null))
else if ((jp.First is JValue value) && (value.Value is null))
detailsArray = null;
else
errors.Add("Invalid details field");
@ -169,7 +169,7 @@ public class InboundDataService : IInboundDataService
}
// if a Details container if found, process it by recursion
if (detailsArray != null)
if (detailsArray is not null)
{
int i = 1;
foreach (JToken detail in detailsArray)
@ -189,7 +189,7 @@ public class InboundDataService : IInboundDataService
{
// get the json data for this container field, ex: Points
JProperty contJP = jsonbody.Children<JProperty>().Where(jp => string.Equals(jp.Name, containerField, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
if ((contJP != null) && (contJP.Value is JArray array))
if ((contJP is not null) && (contJP.Value is JArray array))
{
JArray contJPArray = array;

View File

@ -0,0 +1,377 @@
@model OI.Metrology.Shared.ViewModels.RunInfo
@{
ViewData["Title"] = "Reactor";
}
<style>
#RunGridDiv,
#DetailsGridDiv {
font-size: 12px;
}
</style>
<h4>Reactor</h4>
<form class="form-inline mb-4">
<div class="form-group" id="EvenReactorDiv">
<button for="EvenReactor">Even Reactor</button>
<label for="EvenReactor">Even Reactor</label>
<div class="form-control" id="EvenReactor" hidden></div>
</div>
<div class="form-group" id="OddReactorDiv">
<button for="OddReactor">Odd Reactor</button>
<label for="OddReactor">Odd Reactor</label>
<div class="form-control" id="OddReactor" hidden></div>
</div>&nbsp;&nbsp;
<div class="form-group">
<input class="btn btn-primary" type="button" value="Load Runs" id="LoadRunsButton" />
</div>&nbsp;&nbsp;
</form>
<div style="height: 300px;" id="RunGridDiv">
<span id="EvenReactorID" hidden></span>
<span id="OddReactorID" hidden></span>
<table id="RunGrid"></table>
</div>
<div class="row" style="margin-top: 10px; margin-bottom: 20px;">
<div class="col-xs-1">
<input type="button" class="btn" id="GetDataButton" value="Get Data" disabled />
</div>
</div>
<script>
var EvenReactor = null;
var OddReactor = null;
function LoadRunGrid() {
var EvenReactorID = $("#EvenReactor").igCombo("value");
$("#EvenReactorID").text(EvenReactorID);
HideDetailsDiv();
DisableHeaderButtons();
$("#HeaderId").text("");
$("#HeaderAttachmentId").text("");
$("#HeaderDate").text("");
$("#SPHeaderID").text("");
var gridCreated = $("#RunGrid").data("igGrid");
if (gridCreated)
$("#RunGrid").igGrid("destroy");
$.ajax({
type: "GET",
url: "@Url.Content("~/api/EvenReactors/")" + EvenReactorID + "?sortby=grid",
success: function (r) {
if ((r.Results == null) || (r.Results.EvenReactor == null) || (r.Results.Metadata == null))
ShowErrorMessage("Invalid Even Reactor: " + EvenReactorID);
else {
EvenReactor = r.Results.EvenReactor;
EvenReactorMetaData = r.Results.Metadata;
RequestHeaderData();
}
},
error: function (e) {
DisplayWSMessage("error", "There was an error getting EvenReactor info.", e);
}
});
}
function DisableHeaderButtons() {
$("#GetDataButton").prop("disabled", true);
$("#ReviewButton").prop("disabled", true);
}
function EnableHeaderButtons() {
$("#GetDataButton").prop("disabled", false);
$("#ReviewButton").prop("disabled", false);
}
function HideDetailsDiv() {
$("#DetailsDiv").prop("hidden", true);
$("#DataAttachmentFrame").prop("src", "");
}
function ShowDetailsDiv() {
$("#DetailsDiv").prop("hidden", false);
$("#ExportDiv").prop("hidden", true);
if ((EvenReactor != null) && (EvenReactor.OIExportSPName != null) && (EvenReactor.OIExportSPName.length > 0)) {
$("#ExportDiv").prop("hidden", false);
$("#OIExportResult").text('');
}
$("#DataAttachmentFrame").prop("hidden", true);
$("#HeaderAttachmentFrame").prop("hidden", true);
if (EvenReactor != null) {
var visibleFrames = 0;
if (EvenReactor.DisplayDataAttachment && EvenReactor.DisplayDataAttachment.length > 0) {
visibleFrames += 1;
$("#DataAttachmentFrame").prop("hidden", false);
}
if (EvenReactor.DisplayHeaderAttachment && EvenReactor.DisplayHeaderAttachment.length > 0) {
visibleFrames += 1;
$("#HeaderAttachmentFrame").prop("hidden", false);
}
var frameWidth = (98 / visibleFrames) + "%";
$("#DataAttachmentFrame,#HeaderAttachmentFrame").css('width', frameWidth);
}
}
function HeaderSelectionChanged(evt, ui) {
if (ui.row.index >= 0) {
if ($("#HeaderId").text() == ui.row.id) {
EnableHeaderButtons();
return;
}
}
DisableHeaderButtons();
HideDetailsDiv();
if (ui.row.index >= 0) {
EnableHeaderButtons();
$("#HeaderId").text(ui.row.id);
var rowData = ui.owner.grid.dataSource.dataView()[ui.row.index];
$("#HeaderAttachmentId").text(rowData.AttachmentID);
$("#HeaderDate").text(rowData.Date);
$("#SPHeaderID").text(rowData.Title);
}
}
function CancelHandler(evt, ui) {
return false;
}
function DetailSelectionChanged(evt, ui) {
$("#DataAttachmentFrame").prop("src", "");
if (ui.row.index >= 0) {
var rowData = ui.owner.grid.dataSource.dataView()[ui.row.index];
var EvenReactorID = $("#EvenReactorID").text();
var attachmentUrlBase = '@Url.Content("~/api/EvenReactors/")' + EvenReactorID;
var attachmentId = rowData.AttachmentID;
var test = rowData.date
if ((attachmentId == null) || (attachmentId === ''))
return;
if ((EvenReactor.DisplayDataAttachment == null) || (EvenReactor.DisplayDataAttachment === ''))
return;
$("#DataAttachmentFrame").prop("src", attachmentUrlBase + "/data/files/" + attachmentId + "/" + EvenReactor.DisplayDataAttachment);
}
}
function LoadHeaderAttachment() {
var EvenReactorID = $("#EvenReactorID").text();
var attachmentUrlBase = '@Url.Content("~/api/EvenReactors/")' + EvenReactorID;
var attachmentId = $("#HeaderAttachmentId").text();
var dateToUse = new Date($("#HeaderDate").text());
var month = dateToUse.getMonth + 1;
var year = dateToUse.getFullYear;
if ((attachmentId == null) || (attachmentId === '') || (EvenReactor.DisplayHeaderAttachment == null) || (EvenReactor.DisplayHeaderAttachment === '')) {
$("#HeaderAttachmentFrame").prop("src", "");
} else {
$("#HeaderAttachmentFrame").prop("src", attachmentUrlBase + "/header/files/" + attachmentId + "/" + EvenReactor.DisplayHeaderAttachment + "?date=" + dateToUse);
}
$("#DataAttachmentFrame").prop("src", "");
}
function CheckDate() {
var date = new Date($("#HeaderDate").text());
return date;
}
function LoadDetails() {
ShowDetailsDiv();
LoadHeaderAttachment();
var dateToUse = $("#HeaderDate").text();
var gridCreated = $("#DetailsGrid").data("igGrid");
if (gridCreated)
$("#DetailsGrid").igGrid("destroy");
var dateID = Date.parse($("#HeaderDate").text());
var cutoffDt = Date.parse('2019-07-08')
var headerId = $("#HeaderId").text();
var EvenReactorID = $("#EvenReactorID").text();
var spHeaderID = $("#SPHeaderID").text();
if (dateID < cutoffDt) {
detailsURL = "@Url.Content("~/api/EvenReactors/")" + EvenReactorID + "/headers/" + spHeaderID + "/data/isSharePoint";
}
else {
var detailsURL = "@Url.Content("~/api/EvenReactors/")" + EvenReactorID + "/headers/" + headerId + "/data";
}
var gridColumns = [
{ key: "AttachmentID", dataType: "string", hidden: true },
{ key: "Title", dataType: "string", hidden: true },
];
for (var i = 0; i < EvenReactorMetaData.length; i++) {
var f = EvenReactorMetaData[i];
if ((f.Header == false) && (f.GridDisplayOrder > 0)) {
var col = {
key: f.ColumnName,
headerText: f.DisplayTitle,
width: "150px",
};
if (f.GridAttributes != null)
jQuery.extend(col, JSON.parse(f.GridAttributes));
if (col.formatter != null) {
if (col.formatter == "boolToYesNo")
col.formatter = boolToYesNo;
else
col.formatter = null;
}
gridColumns.push(col);
}
}
var date = EvenReactorMetaData[2];
var gridParms = {
autoGenerateColumns: false,
primaryKey: "ID",
features: [
{ name: "Selection", mode: "row", rowSelectionChanging: DetailSelectionChanged },
{ name: "Resizing" },
{ name: "Sorting", type: "local" }
],
columns: gridColumns,
dataSource: detailsURL,
responseDataKey: "Results"
};
if ((EvenReactor != null) && (EvenReactor.DataGridAttributes != null)) {
jQuery.extend(gridParms, JSON.parse(EvenReactor.DataGridAttributes));
}
$("#DetailsGrid").igGrid(gridParms);
}
var initialHeaderId = @Model.HeaderID;
var initialHeaderAttachmentId = "@Model.HeaderAttachmentID";
function RequestHeaderData() {
var startDate = $("#StartDate").igDatePicker("value");
var startTime = $("#StartTime").igTimePicker("value");
var endDate = $("#EndDate").igDatePicker("value");
var endTime = $("#EndTime").igTimePicker("value");
var parms = {
datebegin: new Date(
startDate.getFullYear(), startDate.getMonth(), startDate.getDate(),
startTime.getHours(), startTime.getMinutes(), startTime.getSeconds()).toISOString(),
dateend: new Date(
endDate.getFullYear(), endDate.getMonth(), endDate.getDate(),
endTime.getHours(), endTime.getMinutes(), endTime.getSeconds()).toISOString(),
}
var headerId = 0;
if (initialHeaderId > 0) {
headerId = initialHeaderId;
parms.headerid = headerId;
$("#HeaderId").text(headerId);
$("#HeaderAttachmentId").text(initialHeaderAttachmentId);
initialHeaderId = -1;
}
var headerURL = "@Url.Content("~/api/EvenReactors/")" + EvenReactor.ID + "/headers?" + $.param(parms);
var gridColumns = [
{ key: "ID", dataType: "number", hidden: true },
{ key: "AttachmentID", dataType: "string", hidden: true },
{ key: "Title", dataType: "string", hidden: true },
];
for (var i = 0; i < EvenReactorMetaData.length; i++) {
var f = EvenReactorMetaData[i];
if ((f.Header == true) && (f.GridDisplayOrder > 0)) {
var col = {
key: f.ColumnName,
headerText: f.DisplayTitle,
width: "150px",
};
if (f.GridAttributes != null)
jQuery.extend(col, JSON.parse(f.GridAttributes));
if (col.formatter != null) {
if (col.formatter == "boolToYesNo")
col.formatter = boolToYesNo;
else
col.formatter = null;
}
gridColumns.push(col);
}
}
var gridParms = {
autoGenerateColumns: false,
primaryKey: "ID",
height: "100%",
width: "100%",
features: [
{ name: "Paging", type: "local", recordCountKey: "TotalRows", pageSize: 100, pageSizeList: [50, 100, 250, 500], pageSizeUrlKey: "pageSize", "pageIndexUrlKey": "page" },
{ name: "Selection", mode: "row", rowSelectionChanged: HeaderSelectionChanged },
{ name: "Filtering", type: "local" },
{ name: 'Resizing' },
{ name: "Sorting", type: "local" }
],
columns: gridColumns,
dataSource: headerURL,
responseDataKey: "Results",
};
if ((EvenReactor != null) && (EvenReactor.RunGridAttributes != null)) {
jQuery.extend(gridParms, JSON.parse(EvenReactor.RunGridAttributes));
}
$("#RunGrid").igGrid(gridParms);
if (headerId > 0) {
LoadDetails();
}
}
$(document).ready(function () {
$("#EvenReactor").igCombo({
dataSource: '@Url.Content("~/api/reactors/true")',
responseDataKey: "Results",
textKey: "Name",
valueKey: "Id",
mode: "dropdown",
width: 150,
itemsRendered: function (evt, ui) {
LoadRunGrid();
},
selectionChanged: LoadRunGrid,
initialSelectedItems: [{ value: @Model.HeaderID }]
});
$("#OddReactor").igCombo({
dataSource: '@Url.Content("~/api/reactors/false")',
responseDataKey: "Results",
textKey: "Name",
valueKey: "Id",
mode: "dropdown",
width: 150,
itemsRendered: function (evt, ui) {
LoadRunGrid();
},
selectionChanged: LoadRunGrid,
initialSelectedItems: [{ value: @Model.HeaderID }]
});
$("#EvenReactorDiv").prop("hidden", true);
$("#OddReactorDiv").prop("hidden", true);
$("#RunGrid").on("dblclick", "tr", LoadDetails);
$("#LoadRunsButton").click(LoadRunGrid);
$("#GetDataButton").click(LoadDetails);
});
</script>