예제 #1
0
        public static ReturnKnowType SubscribeByCommmanName(ServerCallBack ClientCallBack, String ClientSessionID, STATIONNAME StationName, DEVICECATEGORY DeviceName, String CommandName)
        {
            try
            {
                SubscribeStructure.SubscribeType SubscribeType = GetSubscribeType(StationName, DeviceName, CommandName);
                DuplicationSubscribeChecking(SubscribeType, ClientSessionID, StationName, DeviceName, CommandName);

                SubscribeStructure ThisSubscribe = SubscribeList.FirstOrDefault(Item => Item.StationName == StationName && Item.DeviceName == DeviceName && Item.CommandName == CommandName);

                if (ThisSubscribe == null)
                {
                    ClientSubscription ThisClient = new ClientSubscription();
                    ThisClient.ClientCallBack  = ClientCallBack;
                    ThisClient.ClientSessionID = ClientSessionID;

                    ThisSubscribe             = new SubscribeStructure();
                    ThisSubscribe.StationName = StationName;
                    ThisSubscribe.DeviceName  = DeviceName;
                    ThisSubscribe.CommandName = CommandName;
                    ThisSubscribe.Type        = SubscribeType;

                    ThisSubscribe.ClientList = new List <ClientSubscription>();
                    ThisSubscribe.ClientList.Add(ThisClient);
                }
                else
                {
                    ClientSubscription ThisClient = ThisSubscribe.ClientList.FirstOrDefault(Item => Item.ClientSessionID == ClientSessionID);

                    if (ThisClient == null)
                    {
                        ThisClient = new ClientSubscription();
                        ThisClient.ClientCallBack  = ClientCallBack;
                        ThisClient.ClientSessionID = ClientSessionID;

                        ThisSubscribe.ClientList.Add(ThisClient);
                    }
                    else
                    {
                        return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, "Your request is already exist in subscribe list. Please check."));
                    }
                }

                return(ReturnKnowType.DefineReturn(ReturnStatus.SUCESSFUL, null));
            }
            catch (Exception e)
            {
                return(ReturnKnowType.DefineReturn(ReturnStatus.FAILED, "Failed to subscribe information see. (" + e.Message + ")"));
            }
        }
예제 #2
0
        private static void DuplicationSubscribeChecking(SubscribeStructure.SubscribeType Type, String ClientSessionID, STATIONNAME StationName, DEVICECATEGORY DeviceName, String CommandName)
        {
            if (Type == SubscribeStructure.SubscribeType.Device)
            {
                List <SubscribeStructure> ThisSubscribe = SubscribeList.Where(Item => Item.StationName == StationName && Item.DeviceName == DeviceName).ToList();

                for (int i = 0; i < ThisSubscribe.Count; i++)
                {
                    ThisSubscribe[i].ClientList.RemoveAll(Item => Item.ClientSessionID == ClientSessionID);
                }
            }
            else if (Type == SubscribeStructure.SubscribeType.Site)
            {
                List <SubscribeStructure> ThisSubscribe = SubscribeList.Where(Item => Item.StationName == StationName).ToList();

                for (int i = 0; i < ThisSubscribe.Count; i++)
                {
                    ThisSubscribe[i].ClientList.RemoveAll(Item => Item.ClientSessionID == ClientSessionID);
                }
            }
        }