/// <summary> /// Sets a warning with the given text to run on the warning system. /// If multiple warnings are occurring at once, the text will slide by. /// To stop the warning, use the StopWarning() method /// </summary> /// <param name="text">The warning message teo display</param> public void SetWarning(string text, bool fromRobot = false) { // If it's already being warned of or it's in the ignore list, don't do anything if (WarningList.Contains(text) || IgnoreList.Contains(text)) { return; } // If the warning is being sent from the robot, add it to the robot's list of warnings if (fromRobot) { NtAddedWarnings.Add(text); } WarningList.Add(text); // Set the counter so that this warning is displayed next. counter = WarningList.IndexOf(text) - 1; if (WarningList.Count > 1) { // Execute once to start right away Execute(); StartExecuting(); } else { WarningMessage = text; StartExecuting(false); } }
private void BindData() { int intID = 0; if (int.TryParse(Request.QueryString["WarningID"], out intID)) { using (MMSProDBDataContext db = new MMSProDBDataContext(ConfigurationManager.ConnectionStrings["mmsConString"].ConnectionString)) { WarningList a = db.WarningList.SingleOrDefault(c => c.WarningID == intID); if (a != null) { this.txtMaterialName.Text = a.MaterialInfo.MaterialChildType.MaterialMainType.MaterialMainTypeCode + a.MaterialInfo.MaterialChildType.MaterialChildTypeCode + "|" + a.MaterialInfo.MaterialChildType.MaterialMainType.MaterialMainTypeName + "-" + a.MaterialInfo.MaterialChildType.MaterialChildTypeName; this.txtGentaojian.Text = a.QuantityGentaojian.ToString(); this.txtMetre.Text = a.QuantityMetre.ToString(); this.txtTon.Text = a.QuantityTon.ToString(); //this.ddlMaterialType.SelectedValue = di.MaterialchildTypeID.ToString(); } } } else { Response.Redirect("WarningManager.aspx"); } }
void btnSave_Click(object sender, EventArgs e) { //值为0不报警 decimal a, b, c; if (!decimal.TryParse(this.txtGentaojian.Text.Trim(), out a)) { a = 0; } if (!decimal.TryParse(this.txtMetre.Text.Trim(), out b)) { b = 0; } if (!decimal.TryParse(this.txtTon.Text.Trim(), out c)) { c = 0; } if (a == 0 && b == 0 && c == 0) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('至少填写一项预警值!')</script>"); return; } using (MMSProDBDataContext db = new MMSProDBDataContext(ConfigurationManager.ConnectionStrings["mmsConString"].ConnectionString)) { WarningList wl = db.WarningList.SingleOrDefault(t => t.WarningID == int.Parse(Request.QueryString["WarningID"])); wl.QuantityGentaojian = a; wl.QuantityMetre = b; wl.QuantityTon = c; db.SubmitChanges(); } Response.Redirect("WarningManager.aspx"); }
public void AddWarning(string message) { WarningList.Add(new Warning { Message = message }); }
private void ValidarCabecera(Facturas model) { if (model.fechadocumento == null) { throw new ValidationException(string.Format(General.ErrorCampoObligatorio, RFacturas.Fechadocumento)); } if (model.fkclientes == null) { throw new ValidationException(string.Format(General.ErrorCampoObligatorio, RFacturas.Fkclientes)); } if (!model.fkmonedas.HasValue) { throw new ValidationException(string.Format(General.ErrorCampoObligatorio, RFacturas.Fkmonedas)); } if (!model.fkformaspago.HasValue) { throw new ValidationException(string.Format(General.ErrorCampoObligatorio, RFacturas.Fkformaspago)); } var clienteObj = _db.Clientes.Single(f => f.empresa == model.empresa && f.fkcuentas == model.fkclientes); var serieObj = _db.Series.Single(f => f.empresa == model.empresa && f.tipodocumento == "FRA" && f.id == model.fkseries); if (serieObj.fkmonedas.HasValue && serieObj.fkmonedas != clienteObj.fkmonedas) { throw new ValidationException(RFacturas.ErrorMonedaClienteSerie); } if (!ValidaRangoEjercicio(model)) { throw new ValidationException(RFacturas.ErrorFechaEjercicio); } var formapagoobj = _db.FormasPago.Single(f => f.id == model.fkformaspago); if (formapagoobj.mandato.HasValue && formapagoobj.mandato.Value && string.IsNullOrEmpty(model.fkbancosmandatos)) { var mandato = _db.BancosMandatos.SingleOrDefault( f => f.fkcuentas == model.fkclientes && f.defecto == true && !string.IsNullOrEmpty(f.idmandato)); var vector = model.fkestados.Split('-'); var tipoestado = Funciones.Qint(vector[0]); var idestado = vector[1]; var estadoObj = _db.Estados.Single(f => f.documento == tipoestado && f.id == idestado); if (mandato == null && estadoObj.tipoestado == (int)TipoEstado.Finalizado) { throw new ValidationException(RFacturas.ErrorFormaPagoMandatoRequerido); } else { WarningList.Add(RFacturas.WarningFormaPagoMandatoRequerido); } model.fkbancosmandatos = mandato?.id; } CalcularComisiones(model); }
public void ResetWarningList() { try { WarningList.Clear(); } catch (Exception ex) { } }
private static void CreateCompactSignature(Method method, WarningList warnings) { try { method.InParameterSignature = GetCompactSignature(method.Overloads.Select(overload => overload.InParameters.ToArray())); method.OutParameterSignature = GetCompactSignature(method.Overloads.Select(overload => overload.OutParameters.ToArray())); } catch (Exception e) { warnings.Add(method.MethodPosition, WarningType.ToolLimitation, "Error determining method signature. {0}", e.Message); } }
public void ResetWarningList() { try { WarningList.Clear(); } catch (Exception ex) { WebErrorLog.ErrorInstence.StartErrorLog(ex); } }
/// <summary> /// Called in order to change the text being displayed on the warning. /// </summary> private void Execute(object sender = null, EventArgs e = null) { // Increment the counter. counter++; // Make sure that that that index location exists. if (WarningList.Count <= counter) { counter = 0; } WarningMessage = WarningList.ElementAt(counter); }
/// <summary> /// Updates the networktables warning array every time a warning is added or removed. /// </summary> private void UpdateNTArray() { // If it was the dashboard that did the change, don't keep changing it and calling this method over and over. if (justUpdatedWarningArray) { justUpdatedWarningArray = false; return; } else { master._Dashboard_NT.SetStringArray(NTCURRENTWARNINGS, WarningList.ToArray <string>()); justUpdatedWarningArray = true; } }
void btnSave_Click(object sender, EventArgs e) { //值为0不报警 decimal a, b, c; if (!decimal.TryParse(this.txtGentaojian.Text.Trim(), out a)) { a = 0; } if (!decimal.TryParse(this.txtMetre.Text.Trim(), out b)) { b = 0; } if (!decimal.TryParse(this.txtTon.Text.Trim(), out c)) { c = 0; } if (a == 0 && b == 0 && c == 0) { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('至少填写一项预警值!')</script>"); return; } using (MMSProDBDataContext db = new MMSProDBDataContext(ConfigurationManager.ConnectionStrings["mmsConString"].ConnectionString)) { var li = GetCheckedID(); if (li.Count == 1) { WarningList wl = new WarningList(); wl.MaterialID = int.Parse(li[0].ToolTip); wl.QuantityGentaojian = a; wl.QuantityMetre = b; wl.QuantityTon = c; db.WarningList.InsertOnSubmit(wl); db.SubmitChanges(); } else { ClientScript.RegisterClientScriptBlock(typeof(string), "ShowMessage", "<script>alert('请选择一条,且仅一条物质作为预警设置对象!')</script>"); } } Response.Redirect("WarningCreater.aspx"); }
public ReturnedSaveFuncInfo AddReturnedValue(ReturnedSaveFuncInfo returnedSaveFuncInfo) { try { if (returnedSaveFuncInfo?.ErrorList?.Count > 0) { ErrorList.AddRange(returnedSaveFuncInfo.ErrorList); } if (returnedSaveFuncInfo?.WarningList?.Count > 0) { WarningList.AddRange(returnedSaveFuncInfo.WarningList); } if (returnedSaveFuncInfo?.InformationList?.Count > 0) { InformationList.AddRange(returnedSaveFuncInfo.InformationList); } } catch (Exception ex) { WebErrorLog.ErrorInstence.StartErrorLog(ex); } return(returnedSaveFuncInfo); }
public void AddReturnedValue(ReturnedState returnedState, string value) { try { switch (returnedState) { case ReturnedState.Information: InformationList.Add(value); break; case ReturnedState.Error: ErrorList.Add(value); break; case ReturnedState.Warning: WarningList.Add(value); break; } } catch (Exception ex) { } }
/// <summary> /// Removes the warning with the given text from the warning queue /// </summary> /// <param name="text">The texr warning to stop.</param> public void StopWarning(string text, bool fromRobot = false) { if (WarningList.Contains(text)) { WarningList.Remove(text); } // If the warning had been dispatched from the robot, remove it. if (fromRobot && NtAddedWarnings.Contains(text)) { NtAddedWarnings.Remove(text); } // If we have no text to show, stop executing if (WarningList.Count <= 0) { StopAnimation(); } else if (WarningList.Count == 1) { StopExecuting(); WarningMessage = WarningList.ElementAt(0); } }
public void AddReturnedValue(ReturnedState returnedState, string description) { try { switch (returnedState) { case ReturnedState.Information: InformationList.Add(description); break; case ReturnedState.Error: ErrorList.Add(description); break; case ReturnedState.Warning: WarningList.Add(description); break; } } catch (Exception ex) { WebErrorLog.ErrorInstence.StartErrorLog(ex); } }
private static void ParseMethodDocumentation(MoaiClass moaiClass, Annotation[] annotations, string methodBody, MethodPosition methodPosition, TypeCollection types, WarningList warnings) { Method method = CreateMethod(moaiClass, annotations, methodPosition, types, warnings); if (method == null) { return; } // Fill method body method.Body = methodBody; // Create compact method signature CreateCompactSignature(method, warnings); // Determine if overloads are static foreach (MethodOverload overload in method.Overloads) { var firstInParam = overload.InParameters.FirstOrDefault(); overload.IsStatic = firstInParam == null || firstInParam.Name != "self"; } }
public static void ParseClassDefinitions(string code, FilePosition filePosition, TypeCollection types, WarningList warnings) { // Find all class definitions var matches = classDefinitionRegex.Matches(code); // Parse class definitions foreach (Match match in matches) { string className = match.Groups["className"].Value; var classPosition = new ClassPosition(filePosition, className); // Parse annotations, filtering out unknown ones Annotation[] annotations = match.Groups["annotation"].Captures .Cast <Capture>() .Select(capture => Annotation.Create(capture.Value, classPosition, warnings)) .ToArray(); foreach (var unknownAnnotation in annotations.OfType <UnknownAnnotation>()) { warnings.Add(classPosition, WarningType.UnexpectedAnnotation, "Unknown annotation command '{0}'.", unknownAnnotation.Command); } annotations = annotations .Where(annotation => !(annotation is UnknownAnnotation)) .ToArray(); // Get base class names, ignoring all template classes and primitive types MoaiClass[] baseClasses = match.Groups["baseClassName"].Captures .Cast <Capture>() .Where(capture => !capture.Value.Contains("<")) .Select(capture => types.GetOrCreate(capture.Value, null)) .OfType <MoaiClass>() .ToArray(); // Parse annotation block MoaiClass moaiClass = types.GetOrCreate(className, classPosition) as MoaiClass; if (moaiClass != null) { moaiClass.ClassPosition = classPosition; if (annotations.Any()) { ParseClassDocumentation(moaiClass, annotations, baseClasses, classPosition, warnings); } } } }
private static Method CreateMethod(MoaiClass moaiClass, Annotation[] annotations, MethodPosition methodPosition, TypeCollection types, WarningList warnings) { // Get @lua annotation var luaNameAnnotation = GetNameAnnotation(moaiClass, annotations, methodPosition, warnings); if (luaNameAnnotation == null) { return(null); } // Check that there is a single @text annotation CheckTextAnnotation(annotations, methodPosition, warnings); // Parse annotations var method = new Method { MethodPosition = methodPosition, Name = luaNameAnnotation.Value, OwningClass = moaiClass, }; moaiClass.Members.Add(method); MethodOverload currentOverload = null; foreach (var annotation in annotations) { if (annotation is LuaNameAnnotation) { // Nothing to do - name has already been set. } else if (annotation is TextAnnotation) { // Set method description method.Description = ((TextAnnotation)annotation).Value; } else if (annotation is ParameterAnnotation) { if (currentOverload == null) { currentOverload = new MethodOverload { OwningMethod = method }; method.Overloads.Add(currentOverload); } var parameterAnnotation = (ParameterAnnotation)annotation; string paramName = parameterAnnotation.Name; if (annotation is InParameterAnnotation | annotation is OptionalInParameterAnnotation) { // Add input parameter if (currentOverload.InParameters.Any(param => param.Name == paramName)) { warnings.Add(methodPosition, WarningType.UnexpectedValue, "Found multiple params with name '{0}' for single overload.", paramName); } var inParameter = new InParameter { Name = paramName, Description = parameterAnnotation.Description, Type = types.GetOrCreate(parameterAnnotation.Type, methodPosition), IsOptional = annotation is OptionalInParameterAnnotation }; currentOverload.InParameters.Add(inParameter); } else { // Add output parameter var outParameter = new OutParameter { Name = paramName, Type = types.GetOrCreate(parameterAnnotation.Type, methodPosition), Description = parameterAnnotation.Description }; currentOverload.OutParameters.Add(outParameter); } } else if (annotation is OverloadAnnotation) { // Let the next parameter annotation start a new override currentOverload = null; } else { warnings.Add(methodPosition, WarningType.UnexpectedAnnotation, "Unexpected {0} annotation.", annotation.Command); } } return(method); }
private static void CheckTextAnnotation(Annotation[] annotations, MethodPosition methodPosition, WarningList warnings) { int textAnnotationCount = annotations.OfType <TextAnnotation>().Count(); if (textAnnotationCount == 0) { warnings.Add(methodPosition, WarningType.MissingAnnotation, "Missing @text annotation."); } else if (textAnnotationCount > 1) { warnings.Add(methodPosition, WarningType.UnexpectedAnnotation, "Multiple @text annotations."); } }
private static LuaNameAnnotation GetNameAnnotation(MoaiClass moaiClass, Annotation[] annotations, MethodPosition methodPosition, WarningList warnings) { // Check that there is a single @lua annotation and that it isn't a duplicate. Otherwise exit. int luaNameAnnotationCount = annotations.OfType <LuaNameAnnotation>().Count(); if (luaNameAnnotationCount == 0) { warnings.Add(methodPosition, WarningType.MissingAnnotation, "Missing @lua annotation."); return(null); } if (luaNameAnnotationCount > 1) { warnings.Add(methodPosition, WarningType.UnexpectedAnnotation, "Multiple @lua annotations."); } var nameAnnotation = annotations.OfType <LuaNameAnnotation>().First(); if (moaiClass.Members.Any(member => member.Name == nameAnnotation.Value)) { warnings.Add(methodPosition, WarningType.UnexpectedValue, "There is already a member with Lua name '{0}'.", nameAnnotation.Value); return(null); } return(nameAnnotation); }
public static void ParseMoaiCodeFile(FileInfo codeFile, FilePosition filePosition, TypeCollection types, WarningList warnings) { string code = codeFile.ReadAllText(); ParseMoaiCodeFile(code, filePosition, types, warnings); }
public static void ParseMoaiCodeFile(string code, FilePosition filePosition, TypeCollection types, WarningList warnings) { ClassParser.ParseClassDefinitions(code, filePosition, types, warnings); MethodParser.ParseMethodDefinitions(code, filePosition, types, warnings); }
private static void ParseClassDocumentation(MoaiClass moaiClass, Annotation[] annotations, MoaiClass[] baseClasses, ClassPosition classPosition, WarningList warnings) { // Check that there is a single @lua annotation int nameAnnotationCount = annotations.OfType <LuaNameAnnotation>().Count(); if (nameAnnotationCount == 0) { warnings.Add(classPosition, WarningType.MissingAnnotation, "Missing @lua annotation."); } else if (nameAnnotationCount > 1) { warnings.Add(classPosition, WarningType.UnexpectedAnnotation, "Multiple @lua annotations."); } // Check that there is a single @text annotation int textAnnotationCount = annotations.OfType <TextAnnotation>().Count(); if (textAnnotationCount == 0) { warnings.Add(classPosition, WarningType.MissingAnnotation, "Missing @text annotation."); } else if (textAnnotationCount > 1) { warnings.Add(classPosition, WarningType.UnexpectedAnnotation, "Multiple @text annotations."); } // Store base classes moaiClass.BaseClasses.AddRange(baseClasses); // Parse annotations foreach (var annotation in annotations) { if (annotation is LuaNameAnnotation) { // Nothing to do. Name is already set. Just make sure the annotation is correct. var nameAnnotation = (LuaNameAnnotation)annotation; if (nameAnnotation.Value != moaiClass.Name) { warnings.Add(classPosition, WarningType.UnexpectedValue, "@lua annotation has inconsistent value '{0}'. Expected '{1}'.", nameAnnotation.Value, moaiClass.Name); } } else if (annotation is TextAnnotation) { // Set class description moaiClass.Description = ((TextAnnotation)annotation).Value; } else if (annotation is FieldAnnotation) { // Add field (constant, flag, or attribute) var fieldAnnotation = (FieldAnnotation)annotation; Field field = (annotation is ConstantAnnotation) ? new Constant() : (annotation is FlagAnnotation) ? (Field) new Flag() : new Attribute(); field.OwningClass = moaiClass; field.Name = fieldAnnotation.Name; field.Description = fieldAnnotation.Description; moaiClass.Members.Add(field); } else { warnings.Add(classPosition, WarningType.UnexpectedAnnotation, "Unexpected {0} annotation.", annotation.Command); } } }
public static void ParseMethodDefinitions(string code, FilePosition filePosition, TypeCollection types, WarningList warnings) { // Find all method definitions var matches = methodDefinitionRegex.Matches(code); // Parse method definitions foreach (Match match in matches) { string className = match.Groups["className"].Value; string nativeMethodName = match.Groups["methodName"].Value; var methodPosition = new MethodPosition(filePosition, className, nativeMethodName); // Parse annotations, filtering out unknown ones Annotation[] annotations = match.Groups["annotation"].Captures .Cast <Capture>() .Select(capture => Annotation.Create(capture.Value, methodPosition, warnings)) .ToArray(); foreach (var unknownAnnotation in annotations.OfType <UnknownAnnotation>()) { warnings.Add(methodPosition, WarningType.UnexpectedAnnotation, "Unknown annotation command '{0}'.", unknownAnnotation.Command); } annotations = annotations .Where(annotation => !(annotation is UnknownAnnotation)) .ToArray(); // Get method body int openingBraceIndex = match.Index + match.Length - 1; int blockLength = BlockParser.GetBlockLength(code, openingBraceIndex); string methodBody = code.Substring(openingBraceIndex + 1, blockLength - 2); // Parse annotation block MoaiClass moaiClass = types.GetOrCreate(className, methodPosition) as MoaiClass; if (moaiClass != null) { if (annotations.Any()) { ParseMethodDocumentation(moaiClass, annotations, methodBody, methodPosition, types, warnings); } else if (nativeMethodName.StartsWith("_")) { warnings.Add(methodPosition, WarningType.MissingAnnotation, "Missing method documentation."); } } } }