private object DrawReference(MemberInfoAndInspectAttr fieldOrPropertyInfo, object reference) { InspectionType inspectionType = fieldOrPropertyInfo.InspectAttribute.InspectionType; if (reference is UnityEngine.Object && inspectionType == InspectionType.DropableObject) { return(BuiltInDrawers.DrawDropableObject(fieldOrPropertyInfo, (UnityEngine.Object)reference, false)); } else if (reference is UnityEngine.Object && inspectionType == InspectionType.DropableObjectAllowSceneObjects) { return(BuiltInDrawers.DrawDropableObject(fieldOrPropertyInfo, (UnityEngine.Object)reference, true)); } else { if (reference == null) { DrawNull(fieldOrPropertyInfo.Info.Name); return(null); } else { bool show = EditorGUILayout.Foldout(true, fieldOrPropertyInfo.Info.Name); EditorGUI.indentLevel++; ReflectInspector(reference); EditorGUI.indentLevel--; return(reference); } } }
public ActionResult DeleteConfirmed(Guid id) { InspectionType InspectionType = db.InspectionTypes.Single(r => r.InspectionTypeID == id); db.InspectionTypes.DeleteOnSubmit(InspectionType); db.SubmitChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> DeleteConfirmed(Guid id) { InspectionType inspectionType = await db.InspectionTypes.FindAsync(id); db.InspectionTypes.Remove(inspectionType); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
// // GET: /AdminArea/InspectionTypes/Edit/5 public ActionResult Edit(Guid id) { InspectionType InspectionType = db.InspectionTypes.Single(r => r.InspectionTypeID == id); if (InspectionType == null) { return(HttpNotFound()); } return(View(InspectionType)); }
private static void AssertThrows <TException, TInspected>(Inspected <TInspected> inspected, Action <Inspected <TInspected> > assert, InspectionType inspectionType, string badValueName) where TException : ContractViolationException { var exception = Assert.Throws <TException>(() => assert(inspected)); exception.BadValue.Type.Should().Be(inspectionType); exception.BadValue.Name.Should().Be(badValueName); }
public async Task <ActionResult> Edit([Bind(Include = "InspectionTypeID,InspectionType1,InspectionTypeCode")] InspectionType inspectionType) { if (ModelState.IsValid) { db.Entry(inspectionType).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(inspectionType)); }
public async Task <ActionResult> Create([Bind(Include = "InspectionType1,InspectionTypeCode")] InspectionType inspectionType) { if (ModelState.IsValid) { inspectionType.InspectionTypeID = Guid.NewGuid(); db.InspectionTypes.Add(inspectionType); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(inspectionType)); }
public LocalizedString[] RequestInspectorWokflowOutcomes(InspectionType inspectionType) { if (inspectionType == InspectionType.Device) { } else if (inspectionType == InspectionType.DeviceBrand) { var strings = Enum.GetValues(typeof(DevicesBrands)).Cast <DevicesBrands>().Select(s => T(s.ToString())); return(strings.ToArray()); } return(new[] { T("Unknown") }); }
/// <summary> /// Handles saving the document before a scan /// </summary> /// <returns></returns> public static bool SaveBefore(InspectionType inspectionType) { try { if (DataModel.Instance.CurrentWorkbook.Workbook.Path.Length <= 0) { //If there already exists a file with the same name in the same location save this file appended by the current minute. Not 100% save // but for the first few files its ok if ( DataModel.Instance.WorkbookModels.Any( workbookModel => workbookModel.Workbook.Name.Equals(DataModel.Instance.CurrentWorkbook.Workbook.Name + "." + XlFileFormat.xlWorkbookDefault))) { DataModel.Instance.CurrentWorkbook.Workbook.SaveAs( DataModel.Instance.CurrentWorkbook.Workbook.Name + DateTime.Now.Minute + ". " + XlFileFormat.xlWorkbookDefault); } else { DataModel.Instance.CurrentWorkbook.Workbook.SaveAs(); } DataModel.Instance.CurrentWorkbook.Inspect(inspectionType); return(true); } else { // Inspect the current workbook DataModel.Instance.CurrentWorkbook.Inspect(inspectionType); return(true); } } // COMException gets raised: 1. when User cancles save process // 2. User starts a scan while a cell with formulas is opened // 3. A File with the same name is already saved at this location // Please add future additional reasons since this COMException seems to happen for a couple of reasons. Even with Same HResult the reasons may differ catch (COMException ex) { //File is not saved if (DataModel.Instance.CurrentWorkbook.Workbook.Path.Length <= 0) { ScanUnsuccessful(Resources.tl_Scan_needssave); } // Cell is getting eddited else { ScanUnsuccessful(Resources.tl_stopEdit); } return(false); } }
public static string Inspect(object result, InspectionType type = InspectionType.Fields) { switch (result) { case null: return("null"); case string str: return(str); } Type rType = result.GetType(); var sb = new StringBuilder(); sb.AppendLine($"[{rType}]"); sb.AppendLine($"{result}"); FieldInfo[] fields = rType.GetFields(BindingFlags.Public | BindingFlags.Instance).OrderBy(x => x.Name).ToArray(); PropertyInfo[] properties = rType.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(x => x.Name).ToArray(); if (fields.Length == 0) { type = InspectionType.Properties; } if (properties.Length == 0) { type = InspectionType.Fields; } switch (type) { case InspectionType.Fields: foreach (FieldInfo field in fields) { AppendMemberInfo(result, field, sb); } break; case InspectionType.Properties: foreach (PropertyInfo property in properties) { AppendMemberInfo(result, property, sb); } break; } return(sb.ToString()); }
public async Task <ActionResult> Delete(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } InspectionType inspectionType = await db.InspectionTypes.FindAsync(id); if (inspectionType == null) { return(HttpNotFound()); } return(View(inspectionType)); }
public ActionResult Create(InspectionType InspectionType) { if (ModelState.IsValid) { if (db.InspectionTypes.Any(p => p.InspectionTypeID == InspectionType.InspectionTypeID) == false) { //if InspectionType does not exist yet db.InspectionTypes.InsertOnSubmit(InspectionType); db.SubmitChanges(); } return(RedirectToAction("Index")); } return(View(InspectionType)); }
public List<Category> Categories(InspectionType inspectionType) { if (!ModelState.IsValid) { return null; } List<Category> categories = new List<Category>(); Int32.TryParse(ClaimsPrincipal.Current.Claims.Where(c => c.Type == "Id").Select(c => c.Value).FirstOrDefault(), out userId); List<int> categoryIds = dal.GetCategoryIds((int)inspectionType, userId); foreach (int id in categoryIds) { categories.Add(dal.GetCategory(id)); } return categories; }
public List<Inspection> Inspections(InspectionType inspectionType) { if (!ModelState.IsValid) { return null; } Int32.TryParse(ClaimsPrincipal.Current.Claims.Where(c => c.Type == "Id").Select(c => c.Value).FirstOrDefault(), out userId); List<Inspection> inspections = new List<Inspection>(); List<string> inspectionUUIDs = dal.GetInspectionUUIDs((int)inspectionType, userId); foreach (string uuid in inspectionUUIDs) { Inspection inspection = dal.GetInspection(uuid); inspections.Add(inspection); } return inspections; }
/// <summary> /// 根据请求类型及故障分类编号获取字段信息描述 /// </summary> /// <param name="requestTypeID">请求类型</param> /// <param name="typeID">故障分类编号</param> /// <returns>字段信息描述</returns> public static string GetDescFaultType(int requestTypeID, int typeID) { switch (requestTypeID) { case RequestTypes.Repair: return(FaultTypes.GetFaultTypeDesc(typeID)); case RequestTypes.Maintain: return(MaintainType.GetMaintainTypeDesc(typeID)); case RequestTypes.Inspection: return(InspectionType.GetInspectionDesc(typeID)); case RequestTypes.AdverseEvent: return(AdverseEventType.GetAdverseEventDesc(typeID)); default: return(""); } }
/// <summary> /// 根据请求类型、故障分类编号获取故障分类字段描述 /// </summary> /// <param name="requestType">请求类型</param> /// <param name="faultType">故障分类编号</param> /// <returns>故障分类字段描述</returns> public static string GetFaultTypeDesc(int requestType, int faultType) { switch (requestType) { case Repair: return(MachineStatuses.GetMachineStatusesDesc(faultType)); case Maintain: return(MaintainType.GetMaintainTypeDesc(faultType)); case Inspection: return(InspectionType.GetInspectionDesc(faultType)); case AdverseEvent: return(AdverseEventType.GetAdverseEventDesc(faultType)); default: return(""); } }
public ActionResult Edit(InspectionType InspectionType) { try { if (ModelState.IsValid) { db.InspectionTypes.Attach(InspectionType); db.Refresh(RefreshMode.KeepCurrentValues, InspectionType); db.SubmitChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(View(InspectionType)); }
/// <summary> /// Launches an inspection job for this workbook. /// </summary> public void Inspect(InspectionMode inspectionMode, InspectionType inspectionType) { // Save a copy of this workbook temporarily string workbookFile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + System.IO.Path.DirectorySeparatorChar + Guid.NewGuid().ToString() + ".xls"; this.Workbook.SaveCopyAs(workbookFile); // Create the rules var xmlDoc = new XDocument(); switch (inspectionMode) { case InspectionMode.All: xmlDoc.Add(this.Accept(new Sprudel1_5XMLVisitor(inspectionType)) as XElement); //TODO add static break; case InspectionMode.Dynamic: xmlDoc.Add(this.Accept(new Sprudel1_5XMLVisitor(inspectionType)) as XElement); break; case InspectionMode.Static: //TODO change to static xmlDoc.Add(this.Accept(new Sprudel1_5XMLVisitor(inspectionType)) as XElement); break; } ; Debug.WriteLine(xmlDoc.ToString()); var x = xmlDoc.Element(XName.Get("policyList")); var a = x.Element(XName.Get("dynamicPolicy")); var b = a.Element(XName.Get("spreadsheetFilePath")); b.Value = workbookFile; xmlDoc.Validate(XMLPartManager.Instance.GetRequestSchema(), null); // Enqueue this inspectio InspectionEngine.Instance.InspectionQueue.Add(new InspectionJob(this, workbookFile, xmlDoc)); }
public Sprudel1_5XMLVisitor(InspectionType scanningType) { type = scanningType; }
///<summary>Standard constructor</summary> public Inspected(TValue value, InspectionType type, string name = "") { _inspectedValues = new[] { new InspectedValue <TValue>(value, type, name) }; }
private void DrawFieldsAndProperties(object target, List <MemberInfoAndInspectAttr> fieldOrPropertyInfos) { foreach (var fieldOrPropertyInfo in fieldOrPropertyInfos) { MemberInfo memberInfo = fieldOrPropertyInfo.Info; InspectionType inspectionType = fieldOrPropertyInfo.InspectAttribute.InspectionType; if (fieldOrPropertyInfo.CanRead == false) { Warn("The following property cannot be read from: " + memberInfo.Name); } else if (inspectionType == InspectionType.Readonly || fieldOrPropertyInfo.CanWrite == false) { string text = fieldOrPropertyInfo.GetValue(target).ToString(); EditorGUILayout.LabelField(memberInfo.Name, text); } else if (inspectionType == InspectionType.ReadonlySelectable) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(memberInfo.Name); string text = fieldOrPropertyInfo.GetValue(target).ToString(); EditorGUILayout.SelectableLabel(text); EditorGUILayout.EndHorizontal(); } else { object origValueOrRef = fieldOrPropertyInfo.GetValue(target); object newValueOrRef; Func <MemberInfoAndInspectAttr, object, object> drawer; if (fieldOrPropertyInfo.RealType.IsEnum) { newValueOrRef = _drawersLookup["$"](fieldOrPropertyInfo, origValueOrRef); } else { string aqtn = fieldOrPropertyInfo.RealType.AssemblyQualifiedName; if (_drawersLookup.TryGetValue(aqtn, out drawer)) { //TODO better null checking (string) if (origValueOrRef != null || fieldOrPropertyInfo.RealType == typeof(string)) { newValueOrRef = drawer(fieldOrPropertyInfo, origValueOrRef); } else { DrawNull(memberInfo.Name); newValueOrRef = origValueOrRef; } } else { if (origValueOrRef != null && fieldOrPropertyInfo.RealType.IsValueType) { Warn("The following value-type has no drawer: " + memberInfo.DeclaringType.FullName + "." + memberInfo.Name); newValueOrRef = origValueOrRef; } else { newValueOrRef = DrawReference(fieldOrPropertyInfo, origValueOrRef); } } } if (origValueOrRef != newValueOrRef) { fieldOrPropertyInfo.SetValue(target, newValueOrRef); } } } }
///<summary>Standard constructor</summary> public InspectedValue(TValue value, InspectionType type, string name = "") : base(type, name) { Value = value; }
/// <summary> /// Launches an inspection job for this workbook. /// </summary> public void Inspect(InspectionMode inspectionMode, InspectionType inspectionType) { // Save a copy of this workbook temporarily var workbookFile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + System.IO.Path.DirectorySeparatorChar + Guid.NewGuid().ToString() + ".xls"; this.Workbook.SaveCopyAs(workbookFile); // Create the rules var xmlDoc = new XDocument(); switch (inspectionMode) { case InspectionMode.All: xmlDoc.Add(this.Accept(new Sprudel1_3XMLVisitor()) as XElement); //TODO add static break; case InspectionMode.Dynamic: xmlDoc.Add(this.Accept(new Sprudel1_3XMLVisitor()) as XElement); break; case InspectionMode.Static: //TODO change to static xmlDoc.Add(this.Accept(new Sprudel1_3XMLVisitor()) as XElement); break; }; Debug.WriteLine(xmlDoc.ToString()); xmlDoc.Validate(XMLPartManager.Instance.GetRequestSchema(), null); // Enqueue this inspectio InspectionEngine.Instance.InspectionQueue.Add(new InspectionJob(this, workbookFile, xmlDoc)); }
/// <summary> /// Launches an inspection job for this workbook with all available tests. /// </summary> public void Inspect(InspectionType inspectionType) { this.Inspect(InspectionMode.All, inspectionType); }
/// <summary> /// Sets the <see cref="InspectionType"/> to <see cref="InspectionType.Default"/>. /// </summary> public InspectAttribute() { InspectionType = InspectionType.Default; }
private static Inspected <TParameter> CreateInspected <TParameter>(Expression <Func <TParameter> >[] arguments, InspectionType inspectionType) { //Yes the loop is not as pretty as a linq expression but this is performance critical code that might run in tight loops. If it was not I would be using linq. var inspected = new InspectedValue <TParameter> [arguments.Length]; for (var i = 0; i < arguments.Length; i++) { inspected[i] = new InspectedValue <TParameter>( value: ContractsExpression.ExtractValue(arguments[i]), type: inspectionType, name: ContractsExpression.ExtractName(arguments[i])); } return(new Inspected <TParameter>(inspected)); }
/// <summary> /// Launches an inspection job for this workbook. /// </summary> public void Inspect(InspectionMode inspectionMode, InspectionType inspectionType) { Globals.ThisAddIn.Application.StatusBar = Resources.tl_ProcessingScan; Globals.Ribbons.Ribbon.scanButton.Enabled = false; Globals.Ribbons.Ribbon.scanButton.Label = Resources.tl_NoScanPossible; // Save a copy of this workbook temporarily string workbookFile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + System.IO.Path.DirectorySeparatorChar + Guid.NewGuid().ToString() + ".xls"; Workbook.SaveCopyAs(workbookFile); var xmlDoc = new XDocument(); // Create the rules switch (inspectionMode) { case InspectionMode.All: xmlDoc.Add(Accept(new Sprudel1_5XMLVisitor(inspectionType)) as XElement); //TODO add static break; case InspectionMode.Dynamic: xmlDoc.Add(Accept(new Sprudel1_5XMLVisitor(inspectionType)) as XElement); break; case InspectionMode.Static: //TODO change to static xmlDoc.Add(Accept(new Sprudel1_5XMLVisitor(inspectionType)) as XElement); break; } var x = xmlDoc.Element(XName.Get("policyList")); var a = x.Element(XName.Get("dynamicPolicy")); var b = a.Element(XName.Get("spreadsheetFilePath")); b.Value = workbookFile; xmlDoc.Validate(XMLPartManager.Instance.GetRequestSchema(), null); // Enqueue this inspection InspectionEngine.Instance.InspectionQueue.Add(new InspectionJob(this, workbookFile, xmlDoc)); }
/// <summary> /// Handles saving the document before a scan /// </summary> /// <returns></returns> public static bool SaveBefore(InspectionType inspectionType) { try { if (DataModel.Instance.CurrentWorkbook.Workbook.Path.Length <= 0) { //If there already exists a file with the same name in the same location save this file appended by the current minute. Not 100% save // but for the first few files its ok if ( DataModel.Instance.WorkbookModels.Any( workbookModel => workbookModel.Workbook.Name.Equals(DataModel.Instance.CurrentWorkbook.Workbook.Name + "." + XlFileFormat.xlWorkbookDefault))) { DataModel.Instance.CurrentWorkbook.Workbook.SaveAs( DataModel.Instance.CurrentWorkbook.Workbook.Name + DateTime.Now.Minute + ". " + XlFileFormat.xlWorkbookDefault); } else { DataModel.Instance.CurrentWorkbook.Workbook.SaveAs(); } DataModel.Instance.CurrentWorkbook.Inspect(inspectionType); return true; } else { // Inspect the current workbook DataModel.Instance.CurrentWorkbook.Inspect(inspectionType); return true; } } // COMException gets raised: 1. when User cancles save process // 2. User starts a scan while a cell with formulas is opened // 3. A File with the same name is already saved at this location // Please add future additional reasons since this COMException seems to happen for a couple of reasons. Even with Same HResult the reasons may differ catch (COMException ex) { //File is not saved if (DataModel.Instance.CurrentWorkbook.Workbook.Path.Length <= 0) { ScanUnsuccessful(Resources.tl_Scan_needssave); } // Cell is getting eddited else { ScanUnsuccessful(Resources.tl_stopEdit); } return false; } }
/// <summary> /// Allows a custom <see cref="InspectionType"/>. /// </summary> public InspectAttribute(InspectionType inspectionType) { InspectionType = inspectionType; }