예제 #1
0
 public void AddParameter(MtuForm form)
 {
     Parameter[] addMtuParams = form.GetParameters();
     foreach (Parameter parameter in addMtuParams)
     {
         mparameters.Add(parameter);
     }
 }
예제 #2
0
        private ActionResult CreateActionResultUsingInterface(
            dynamic map          = null,
            Mtu mtutype          = null,
            MtuForm form         = null,
            dynamic actionParams = null,
            string actionType    = "ReadMTU")
        {
            InterfaceParameters[] parameters = configuration.getAllInterfaceFields(mtutype.Id, actionType);

            ActionResult result = new ActionResult();

            foreach (InterfaceParameters parameter in parameters)
            {
                if (parameter.Name.Equals("MtuVoltageBattery"))
                {
                }

                if (parameter.Name.Equals("Port"))
                {
                    for (int i = 0; i < mtutype.Ports.Count; i++)
                    {
                        result.addPort(ReadPort(i, parameter.Parameters.ToArray(), map, mtutype));
                    }
                }
                else
                {
                    try
                    {
                        if (ValidateCondition(parameter.Conditional, map, mtutype, "", actionParams))
                        {
                            //if ( parameter.Source == null )
                            //    parameter.Source = "";

                            string sourceWhere    = string.Empty;
                            string sourceProperty = string.Empty;

                            if (!string.IsNullOrEmpty(parameter.Source))
                            {
                                string[] sources = parameter.Source.Split(new char[] { '.' });
                                sourceWhere    = sources[0];
                                sourceProperty = sources[1];
                            }

                            Parameter paramToAdd = null;
                            switch (sourceWhere)
                            {
                            case "Action":
                                string action_property_value = GetProperty(sourceProperty);
                                if (action_property_value != null)
                                {
                                    paramToAdd = new Parameter(parameter.Name, parameter.Display, action_property_value);
                                }
                                break;

                            case "MeterType":
                                break;

                            case "MtuType":
                                paramToAdd = new Parameter(parameter.Name, parameter.Display, mtutype.GetProperty(sourceProperty));
                                break;

                            case "MemoryMap":
                                paramToAdd = new Parameter(sourceProperty, parameter.Display, map.GetProperty(sourceProperty).Value.ToString());
                                break;

                            case "Form":
                                if (form.ContainsParameter(sourceProperty))
                                {
                                    paramToAdd = form.GetParameter(sourceProperty);
                                }
                                break;

                            case "ActionParams":
                                paramToAdd = new Parameter(parameter.Name, parameter.Display,
                                                           actionParams.GetType().GetProperty(sourceProperty)
                                                           .GetValue(actionParams, null).ToString());
                                break;

                            default:
                                try
                                {
                                    paramToAdd = new Parameter(parameter.Name, parameter.Display, map.GetProperty(parameter.Name).Value.ToString());
                                }
                                catch (Exception e)
                                {
                                    paramToAdd = null;
                                }

                                break;
                            }

                            if (paramToAdd != null)
                            {
                                result.AddParameter(paramToAdd);
                            }
                            else
                            {
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message + "\r\n" + e.StackTrace);
                    }
                }
            }
            return(result);
        }
예제 #3
0
        public void Run(MtuForm mtuForm = null)
        {
            if (canceled)
            {
                throw new Exception("Canceled Action can not be Executed");
            }
            else
            {
                List <object> parameters = new List <object>();

                switch (type)
                {
                case ActionType.ReadMtu:
                    comm.OnReadMtu += Comm_OnReadMtu;
                    break;

                case ActionType.AddMtu:
                case ActionType.AddMtuAddMeter:
                case ActionType.AddMtuReplaceMeter:
                case ActionType.ReplaceMTU:
                case ActionType.ReplaceMeter:
                case ActionType.ReplaceMtuReplaceMeter:
                    comm.OnAddMtu   += Comm_OnAddMtu;
                    comm.OnProgress += Comm_OnProgress;
                    // Interactive and Scripting
                    if (mtuForm != null)
                    {
                        parameters.AddRange(new object[] { (AddMtuForm)mtuForm, this.user, type });
                    }
                    else
                    {
                        parameters.Add(this);
                    }
                    break;

                case ActionType.TurnOffMtu:
                    comm.OnTurnOffMtu += Comm_OnTurnOffMtu;
                    break;

                case ActionType.TurnOnMtu:
                    comm.OnTurnOnMtu += Comm_OnTurnOnMtu;
                    break;

                case ActionType.MtuInstallationConfirmation:
                    comm.OnReadMtu  += Comm_OnReadMtu;
                    comm.OnProgress += Comm_OnProgress;
                    break;

                case ActionType.ReadData:
                    Parameter param = mparameters.Find(x => (x.Type == Parameter.ParameterType.DaysOfRead));
                    if (param == null)
                    {
                        this.OnError();      //this, new ActionErrorArgs("Days Of Read parameter Not Defined or Invalid"));
                        break;
                    }
                    int DaysOfRead = 0;
                    if (!Int32.TryParse(param.Value, out DaysOfRead) || DaysOfRead <= 0)
                    {
                        this.OnError();      //this, new ActionErrorArgs("Days Of Read parameter Invalid"));
                        break;
                    }
                    comm.OnReadMtuData += Comm_OnReadMtuData;
                    parameters.Add(DaysOfRead);
                    break;

                case ActionType.BasicRead:
                    comm.OnBasicRead += Comm_OnBasicRead;
                    break;
                }

                // Is more easy to control one point of invokation
                // than N, one for each action/new task to launch
                comm.LaunchActionThread(type, parameters.ToArray());
            }
        }
예제 #4
0
        private async Task <ActionResult> CreateActionResultUsingInterface(
            dynamic map  = null,
            Mtu mtu      = null,
            MtuForm form = null)  //,
        //ActionType actionType = ActionType.ReadMtu )
        {
            Parameter    paramToAdd;
            Global       global = this.config.Global;
            Puck         puck   = Singleton.Get.Puck;
            Type         gType  = global.GetType();
            ActionResult result = new ActionResult();

            InterfaceParameters[] parameters = configuration.getAllInterfaceFields(mtu, ActionType.ReadMtu);    //, actionType );

            foreach (InterfaceParameters parameter in parameters)
            {
                if (parameter.Name.Equals(IFACE_PORT))
                {
                    for (int i = 0; i < mtu.Ports.Count; i++)
                    {
                        result.addPort(await ReadPort(i + 1, parameter.Parameters.ToArray(), map, mtu));
                    }
                }
                else
                {
                    if (await ValidateCondition(parameter.Conditional, map, mtu))
                    {
                        string value          = string.Empty;
                        string sourceWhere    = string.Empty;
                        string sourceProperty = parameter.Name;

                        if (!string.IsNullOrEmpty(parameter.Source) &&
                            Regex.IsMatch(parameter.Source, NET_IDS + "." + NET_IDS))
                        {
                            string[] sources = parameter.Source.Split(new char[] { '.' });
                            sourceWhere    = sources[0];
                            sourceProperty = sources[1];
                        }

                        paramToAdd = null;
                        try
                        {
                            switch (sourceWhere)
                            {
                            case IFACE_ACTION: value = this.GetProperty(sourceProperty); break;

                            case IFACE_MTU: value = mtu.GetProperty(sourceProperty); break;

                            case IFACE_PUCK: value = puck.GetProperty(sourceProperty); break;

                            case IFACE_FORM: paramToAdd = form.GetParameter(sourceProperty); break;

                            case IFACE_DATA: value = (string.IsNullOrEmpty(value = Data.Get[sourceProperty]) ? string.Empty : value); break;

                            default: value = (await map[sourceProperty].GetValue()).ToString(); break;                          // MemoryMap.ParameterName
                            }
                        }
                        catch (Exception e)
                        {
                            Utils.Print("Interface: Map Error: " + sourceProperty);
                            throw new Exception();
                        }

                        if (!sourceWhere.Equals(IFACE_FORM) &&
                            !string.IsNullOrEmpty(value))
                        {
                            string display = (parameter.Display.ToLower().StartsWith("global.")) ?
                                             gType.GetProperty(parameter.Display.Split(new char[] { '.' })[1]).GetValue(global, null).ToString() :
                                             parameter.Display;

                            paramToAdd = new Parameter(parameter.Name, display, value, parameter.Source);
                        }
                        // To change "name" attribute to show in IFACE_FORM case
                        else
                        {
                            paramToAdd.CustomParameter = parameter.Name;
                            paramToAdd.source          = parameter.Source;
                        }

                        if (paramToAdd != null)
                        {
                            paramToAdd.Value = this.FormatLength(paramToAdd.Value, parameter.Length, parameter.Fill);
                            result.AddParameter(paramToAdd);
                        }
                    }
                }
            }

            // Add additional parameters for all actions except for the Add
            if (form == null)
            {
                foreach (Parameter param in this.AdditionalParameters)
                {
                    result.AddParameter(param);
                }
            }

            return(result);
        }
예제 #5
0
        public void Run(MtuForm mtuForm = null)
        {
            if (canceled)
            {
                throw new Exception("Canceled Action can not be Executed");
            }
            else
            {
                List <object> parameters = new List <object>();

                comm.OnProgress -= Comm_OnProgress;
                comm.OnProgress += Comm_OnProgress;

                switch (type)
                {
                case ActionType.ReadFabric:
                    comm.OnReadFabric -= Comm_OnReadFabric;
                    comm.OnReadFabric += Comm_OnReadFabric;
                    break;

                case ActionType.ReadMtu:
                case ActionType.MtuInstallationConfirmation:
                    comm.OnReadMtu -= Comm_OnReadMtu;
                    comm.OnReadMtu += Comm_OnReadMtu;
                    break;

                case ActionType.AddMtu:
                case ActionType.AddMtuAddMeter:
                case ActionType.AddMtuReplaceMeter:
                case ActionType.ReplaceMTU:
                case ActionType.ReplaceMeter:
                case ActionType.ReplaceMtuReplaceMeter:
                    comm.OnAddMtu -= Comm_OnAddMtu;
                    comm.OnAddMtu += Comm_OnAddMtu;
                    // Interactive and Scripting
                    if (mtuForm != null)
                    {
                        parameters.AddRange(new object[] { (AddMtuForm)mtuForm, this.user, this });
                    }
                    else
                    {
                        parameters.Add(this);
                    }
                    break;

                case ActionType.TurnOffMtu:
                case ActionType.TurnOnMtu:
                    comm.OnTurnOffMtu -= Comm_OnTurnOnOffMtu;
                    comm.OnTurnOffMtu += Comm_OnTurnOnOffMtu;
                    break;

                case ActionType.ReadData:
                    comm.OnReadMtuData -= Comm_OnReadMtuData;
                    comm.OnReadMtuData += Comm_OnReadMtuData;
                    break;

                case ActionType.BasicRead:
                    comm.OnBasicRead -= Comm_OnBasicRead;
                    comm.OnBasicRead += Comm_OnBasicRead;
                    break;
                }

                // Is more easy to control one point of invokation
                // than N, one for each action/new task to launch
                comm.LaunchActionThread(type, parameters.ToArray());
            }
        }