Esempio n. 1
0
        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.");
            }
        }
Esempio n. 2
0
        /// <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);
            }
        }
Esempio n. 3
0
 public void AddWarning(string message)
 {
     WarningList.Add(new Warning
     {
         Message = message
     });
 }
Esempio n. 4
0
        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.");
                    }
                }
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
                    }
                }
            }
        }
        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)
            {
            }
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
0
        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);
                }
            }
        }
Esempio n. 12
0
        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);
        }