예제 #1
0
        public Mtu GetMtuTypeById(int mtuId)
        {
            Mtu mtu = mtuTypes.FindByMtuId(mtuId);

            if (mtu == null)
            {
                Errors.LogErrorNow(new MtuTypeIsNotFoundException());
            }

            return(mtu);
        }
예제 #2
0
        public Mtu GetMtuTypeById(int mtuId)
        {
            Mtu mtu = mtuTypes.FindByMtuId(mtuId);

            // Is not valid MTU ID ( not present in Mtu.xml )
            if (mtu == null)
            {
                Errors.LogErrorNow(new MtuMissingException());
            }

            return(mtu);
        }
예제 #3
0
        /// <summary>
        /// Both options will log all registered exceptions that remain, but in
        /// the first case previously the last exception launched will be added
        /// </summary>
        /// <param name="e">Exception that represents the last error happened</param>
        public static void LogRemainExceptions(
            Exception e)
        {
            // Last exception was not added yet
            if (!Errors.GetInstance().IsLastExceptionUsed(e))
            {
                Errors.LogErrorNow(e, -1, false);
            }

            // Last exception was already added
            else
            {
                Errors.LogRegisteredErrors();
            }
        }
예제 #4
0
        private void buildScriptActions(String base_path, ISerial serial_device, Script script)
        {
            actions = new List <Action>();

            int step = 0;

            // Using invalid log file/path
            if (string.IsNullOrEmpty(script.LogFile) ||
                !Regex.IsMatch(script.LogFile, @"^[a-zA-Z_][a-zA-Z0-9_-]*.xml$"))
            {
                Errors.LogErrorNow(new ScriptLogfileInvalidException());
            }
            else
            {
                ActionType type;
                foreach (Xml.ScriptAction action in script.Actions)
                {
                    // Action string is not present in ActionType enum
                    if (!Enum.TryParse <ActionType> (action.Type, out type))
                    {
                        Errors.LogErrorNow(new ScriptActionTypeInvalidException(action.Type));
                        return;
                    }

                    Action new_action = new Action(Configuration.GetInstance(), serial_device, type, script.UserName, script.LogFile);
                    Type   actionType = action.GetType();

                    foreach (PropertyInfo parameter in action.GetType().GetProperties())
                    {
                        try
                        {
                            var  paramValue = actionType.GetProperty(parameter.Name).GetValue(action, null);
                            Type valueType  = paramValue.GetType();

                            if (valueType.Name.ToLower().Contains("actionparameter"))
                            {
                                List <ActionParameter> list = new List <ActionParameter> ();

                                // If the parameter is an Array is a field for
                                // a port, and if not is a field for the MTU
                                if (!paramValue.GetType().IsArray)
                                {
                                    list.Add(( ActionParameter   )paramValue);
                                }
                                else
                                {
                                    list.AddRange(( ActionParameter[] )paramValue);
                                }

                                foreach (ActionParameter aParam in list)
                                {
                                    new_action.AddParameter(
                                        new Parameter(
                                            parseParameterType(parameter.Name),
                                            aParam.Value,
                                            aParam.Port));
                                }
                            }
                        }
                        catch (Exception e)
                        {
                        }
                    }

                    new_action.order       = step;
                    new_action.OnProgress += Action_OnProgress;
                    new_action.OnFinish   += Action_OnFinish;
                    new_action.OnError    += Action_OnError;

                    actions.Add(new_action);
                    step++;
                }
            }
        }