Пример #1
0
        private void CreateOrUpdateCounterListItem(NotificationContainer notification, ErrorContainer error)
        {
            CounterListItemType counterListItem = null;
            DateTime            now             = DateTime.Now;
            string                   mac_address;
            NotificationBase         notificationBase    = null;
            ExtendedNotificationBase extNotificationBase = null;

            if (notification != null)
            {
                mac_address      = notification.Item.mac_address;
                notificationBase = notification.Item as NotificationBase;
                if (notification.Item is ExtendedNotificationBase)
                {
                    extNotificationBase = notification.Item as ExtendedNotificationBase;
                }
            }
            else if (error != null)
            {
                mac_address         = error.mac_address;
                notificationBase    = error as NotificationBase;
                extNotificationBase = error as ExtendedNotificationBase;
            }
            else
            {
                return;
            }

            counterListItem = GetCounterListItemByMacAddress(mac_address);
            if (counterListItem == null)
            {
                counterListItem = new CounterListItemType();
                counterList.Add(counterListItem);
                counterListItem.mac_address          = mac_address;
                counterListItem.registered_timestamp = now;
                counterListItem.updated_timestamp    = now;
                counterListItem.notifications_count  = 0;
                counterListItem.errors_count         = 0;
            }

            if (extNotificationBase != null)
            {
                if (!string.Equals(extNotificationBase.ip_address, counterListItem.ip_address))
                {
                    counterListItem.ip_address        = extNotificationBase.ip_address;
                    counterListItem.updated_timestamp = now;
                }
            }

            if (notificationBase != null)
            {
                if (!string.Equals(notificationBase.customer_ID, counterListItem.customer_ID))
                {
                    counterListItem.customer_ID       = notificationBase.customer_ID;
                    counterListItem.updated_timestamp = now;
                }
            }

            if (notification != null)
            {
                counterListItem.last_notification_ID        = notification.Item.notification_ID;
                counterListItem.last_notification_timestamp = notification.Item.timestamp;
                counterListItem.last_notification_type      = notification.Item.task_type;
                counterListItem.notifications_count++;
            }
            else if (error != null)
            {
                counterListItem.last_error_ID        = error.notification_ID;
                counterListItem.last_error_timestamp = error.timestamp;
                counterListItem.last_error_reason    = error.error_reason;
                counterListItem.errors_count++;
            }

            counterListItem.changed = true;
        }
Пример #2
0
        private Task[] CreateCounterTaskList(NotificationBase notification)
        {
            List <Task> tasks = new List <Task>();

            if (notification != null)
            {
                foreach (ServerTaskListItemType taskItem in taskList)
                {
                    if ((taskItem.taskStatus == TaskStatusType.SERVER) ||
                        ((taskItem.taskStatus == TaskStatusType.SERVER_DEL) && (taskItem.task is TaskWithActivity)))
                    {
                        if (taskItem.taskStatus == TaskStatusType.SERVER_DEL)
                        {
                            (taskItem.task as TaskWithActivity).activity_state = false;
                        }

                        bool addItem = false;
                        switch (taskItem.taskDestinationMatchingField)
                        {
                        case TaskDestinationMatchingFieldType.DONT_CARE:
                            addItem = true;
                            break;

                        case TaskDestinationMatchingFieldType.CUSTOMER_ID:
                            if (notification.customer_ID == taskItem.taskDestinationMatchingFieldValue)
                            {
                                addItem = true;
                            }
                            break;

                        case TaskDestinationMatchingFieldType.IP_ADDRESS:
                            if ((notification is ExtendedNotificationBase) &&
                                ((notification as ExtendedNotificationBase).ip_address == taskItem.taskDestinationMatchingFieldValue))
                            {
                                addItem = true;
                            }
                            else
                            {
                                CounterListItemType counterItem = GetCounterListItemByIpAddress(taskItem.taskDestinationMatchingFieldValue);
                                if ((counterItem != null) && (counterItem.mac_address.ToUpper() == notification.mac_address.ToUpper()))
                                {
                                    addItem = true;
                                }
                            }
                            break;

                        case TaskDestinationMatchingFieldType.MAC_ADDRESS:
                            if (notification.mac_address.ToUpper() == taskItem.taskDestinationMatchingFieldValue.ToUpper())
                            {
                                addItem = true;
                            }
                            break;
                        }

                        if (addItem)
                        {
                            if (taskItem.taskStatus == TaskStatusType.SERVER)
                            {
                                taskItem.taskStatus = TaskStatusType.COUNTER;
                            }
                            else if (taskItem.taskStatus == TaskStatusType.SERVER_DEL)
                            {
                                taskItem.taskStatus = TaskStatusType.COUNTER_DEL;
                            }

                            tasks.Add(taskItem.task);
                        }
                    }
                }
            }

            return(tasks.ToArray());
        }