예제 #1
0
        public void EmitEventTypes(bool updatedEvents)
        {
            EnergyEventsProxy proxy = null;
            EnergyEventsEventInfo[] eventTypes;

            try
            {
                NodeReaderWriterLock.AcquireReaderLock(3000);
                proxy = new EnergyEventsProxy();
                int count = 0;
                foreach (DeviceManagerBase mgr in ManagerManager.RunningDeviceManagers)
                    foreach (Device.DeviceBase dev in mgr.GenericDeviceList)
                        foreach (Device.EnergyEventStatus status in dev.EventStatusList)
                            count += status.EmitEvents.Count;

                eventTypes = new EnergyEventsEventInfo[count];
                if (count > 0)
                {
                    count = 0;
                    foreach (DeviceManagerBase mgr in ManagerManager.RunningDeviceManagers)
                        foreach (Device.DeviceBase dev in mgr.GenericDeviceList)
                            foreach(Device.EnergyEventStatus status in dev.EventStatusList)
                                foreach(Device.DeviceEventConfig eEvent in status.EmitEvents)
                                {
                                    eventTypes[count].Id.Name = eEvent.EventName;
                                    eventTypes[count].Type = eEvent.EventType.ToString();
                                    eventTypes[count].Description = "";
                                    eventTypes[count].FeedInYield = eEvent.UseForFeedIn && eEvent.EventType == EventType.Yield;
                                    eventTypes[count].FeedInConsumption = eEvent.UseForFeedIn && eEvent.EventType == EventType.Consumption;
                                    count++;
                                }

                    proxy.AvailableEventList(updatedEvents, eventTypes);
                }
            }
            catch (Exception e)
            {
                SystemServices.LogMessage("EmitEventTypes", "Exception: " + e.Message, LogEntryType.ErrorMessage);
            }

            try
            {
                if (proxy != null)
                    proxy.Close();
            }
            catch (Exception e)
            {
                SystemServices.LogMessage("EmitEventTypes", "Closing proxy - Exception: " + e.Message, LogEntryType.ErrorMessage);
            }
            finally
            {
                if (NodeReaderWriterLock.IsReaderLockHeld)
                    NodeReaderWriterLock.ReleaseReaderLock();
            }
        }
예제 #2
0
        private void EmitPendingEvents()
        {
            bool havePendingMutex = false;
            EnergyEventsProxy proxy = null;
            try
            {
                NodeReaderWriterLock.AcquireReaderLock(3000);
                proxy = new EnergyEventsProxy();
                EventPending node;
                while(PendingEvents.Count > 0)
                {
                    // lock out access briefly so that event add to list proceeds unhindered
                    havePendingMutex = PendingListMutex.WaitOne();
                    node = PendingEvents[0];
                    PendingEvents.RemoveAt(0);
                    if (havePendingMutex)
                    {
                        PendingListMutex.ReleaseMutex();
                        havePendingMutex = false;
                    }

                    EnergyEventsEventId id;
                    id.Name = node.Name;

                    if (node.PendingType == PendingType.Energy)
                    {
                        if (node.EmitEventType == "Yield")
                            proxy.OnYieldEvent(id, node.EventTime, node.EnergyToday, node.CurrentPower);
                        else if (node.EmitEventType == "Consumption")
                            proxy.OnConsumptionEvent(id, node.EventTime, node.EnergyToday, node.CurrentPower);
                        else
                            proxy.OnEnergyEvent(id, node.EventTime, node.EnergyToday, node.CurrentPower);

                        if (SystemServices.LogEvent)
                            SystemServices.LogMessage("EmitPendingEvents", "Type: " + node.EmitEventType + " - Name: " + node.Name + " - Time: " + node.EventTime +
                                " - Power: " + node.CurrentPower + " - Energy: " + node.EnergyToday, LogEntryType.Event);
                    }
                    else if (node.PendingType == PendingType.Status)
                    {
                        proxy.OnStatusChangeEvent(node.StatusType, node.EventTime, node.StatusText);
                        if (SystemServices.LogEvent)
                            SystemServices.LogMessage("EmitPendingEvents", "StatusType: " + node.StatusType + " - Time: " + node.EventTime +
                                " - StatusText: " + node.StatusText, LogEntryType.Event);
                    }
                }
            }
            catch (Exception e)
            {
                // Limit logging to one per minute
                if (LastEmitErrorReported < DateTime.Now.AddMinutes(-1.0))
                {
                    SystemServices.LogMessage("EmitPendingEvents", "Exception: " + e.Message, LogEntryType.ErrorMessage);
                    LastEmitErrorReported = DateTime.Now;
                }
                PendingEvents.Clear();
            }

            try
            {
                if (havePendingMutex)
                    PendingListMutex.ReleaseMutex();

                if (proxy != null)
                    proxy.Close();
            }
            catch (Exception e)
            {
                SystemServices.LogMessage("EmitPendingEvents", "Closing proxy - Exception: " + e.Message, LogEntryType.ErrorMessage);
            }
            finally
            {
                if (NodeReaderWriterLock.IsReaderLockHeld)
                    NodeReaderWriterLock.ReleaseReaderLock();
            }
        }