Esempio n. 1
0
 public INode Get(int id)
 {
     lock (DeviceList)
     {
         return(DeviceList.ContainsKey(id) ? DeviceList[id] : null);
     }
 }
        /// <summary>
        /// Handler method for special system events, e.g. initialization
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void SystemEventHandler(
            object sender, StateMachineEventArgs args)
        {
            // Initialize
            if (args.EventName == "OnInit" &&
                args.EventType == StateMachineEventType.Command)
            {
                foreach (var dev in DeviceList)
                {
                    try
                    {
                        MethodInfo initMethod
                            = dev.Value.GetType().GetMethod("OnInit");
                        initMethod.Invoke(dev.Value, new object[] { });
                        RaiseDeviceManagerEvent(
                            "DeviceCommand - Initialization device", dev.Key);
                    }
                    catch (Exception ex)
                    {
                        RaiseDeviceManagerEvent(
                            "DeviceCommand - Initialization error device " + dev.Key,
                            ex.ToString());
                    }
                }

                // Notification handling
                // because we use UI to trigger transitions devices would
                // trigger normally themselves. Nevertheless, this is common,
                // if SW user interfaces control devices
                // View and device managers communicate on system event bus
                // and use notifications to trigger state machine as needed!
                if (args.EventType == StateMachineEventType.Command)
                {
                    // Check for right condition
                    if (args.EventName == "OnInit")
                    {
                        return;
                    }
                    if (DeviceList.ContainsKey(args.Target) == false)
                    {
                        return;
                    }

                    // Dispatch command to device
                    DeviceCommandHandler(this, args);
                }
            }
        }
Esempio n. 3
0
        public INode FactoryShallowCopy(int newId, int newIdNum, String newImei)
        {
            lock (DeviceList)
            {
                if (DeviceList.ContainsKey(newId))
                {
                    return(DeviceList[newId]);
                }

                var nuevo = (BaseCodec)MemberwiseClone();
                nuevo.OnMemberwiseClone();
                nuevo.Id          = newId;
                nuevo.IdNum       = newIdNum;
                nuevo.Imei        = newImei;
                nuevo._deviceLock = new AutoResetEvent(true);
                DeviceList.Add(newId, nuevo);
                return(nuevo);
            }
        }
Esempio n. 4
0
        private void WriteMessages()
        {
            if (Logging && m_IdList.Count > 0)
            {
                if (m_IsNewFile)
                {
                    System.IO.File.WriteAllText(m_LogFileLocation, String.Empty);
                }
                using (StreamWriter outfile = new StreamWriter(m_LogFileLocation, true))
                {
                    if (m_IsNewFile)
                    {
                        StringBuilder heading = new StringBuilder();
                        heading.Append("clientTime" + m_cSeparator);
                        foreach (int i in m_IdList)
                        {
                            NavicoJson.IncomingDataInfo.Info info = m_DataInformation [i];
                            if (info != null)
                            {
                                if (info.numInstances > 1)
                                {
                                    for (int instIndex = 0; instIndex < info.instanceInfo.Length; instIndex++)
                                    {
                                        heading.Append(info.lname).Append(" (").Append(info.unit.Replace("&deg;", "°"))
                                        .Append(")").Append(" [").Append(info.instanceInfo [instIndex].str).Append("]")
                                        .Append(m_cSeparator);
                                    }
                                }
                                else if (m_N2kNameDict.ContainsKey(i))
                                {
                                    foreach (String n2kName in m_N2kNameDict[i])
                                    //for (int n2kIndex = 0; n2kIndex < info.n2kNames.Count; n2kIndex++)
                                    {
                                        String n2kNameText;
                                        if (DeviceList.ContainsKey(n2kName))
                                        {
                                            n2kNameText = DeviceList [n2kName].ModelId + " : " + DeviceList [n2kName].SerialNumber;
                                        }
                                        else
                                        {
                                            n2kNameText = n2kName;
                                        }


                                        heading.Append(info.lname).Append(" (").Append(info.unit.Replace("&deg;", "°"))
                                        .Append(")").Append(" [").Append(n2kNameText).Append("]")
                                        .Append(m_cSeparator);
                                    }
                                }
                                else
                                {
                                    heading.Append(info.lname).Append(" (").Append(info.unit.Replace("&deg;", "°")).Append(")")
                                    .Append(m_cSeparator);
                                }
                            }
                            else
                            {
                                heading.Append(i.ToString()).Append(m_cSeparator);
                            }
                        }
                        heading.Remove(heading.Length - 1, 1);

                        outfile.WriteLine(heading.ToString());
                        m_IsNewFile = false;
                    }
                    foreach (String s in m_EntryList)
                    {
                        outfile.WriteLine(s);
                    }
                }
                m_EntryList.Clear();
            }
            if (WriteComplete != null)
            {
                WriteComplete(this, new EventArgs());
            }
        }