Пример #1
0
        /// <summary>
        /// Subscribe to the given publishing endpoint.
        /// </summary>
        /// <param name="publishName">The name of the publishing endpoint.</param>
        /// <param name="arguments">Arguments to the publish function.</param>
        /// <typeparam name="RecordType">The type of the record in the collection.</typeparam>
        public Subscription Subscribe(string publishName, params object[] arguments)
        {
            string requestId = string.Format("{0}-{1}", publishName, this.NextId());

            // Setup backing store.
            if (Subscriptions.Contains(requestId))
            {
                return(Subscriptions [requestId]);
            }
            else
            {
                Subscriptions.Add(new Subscription()
                {
                    name = requestId
                });
            }

            Send(new SubscribeMessage()
            {
                name   = publishName,
                Params = arguments,
                id     = requestId
            });

            return(Subscriptions [requestId]);
        }
Пример #2
0
 private void DeleteSubscription(object obj)
 {
     if (Subscriptions.Contains((UserSubscription)obj))
     {
         Subscriptions.Remove((UserSubscription)obj);
         SecurityPicker.ExcludeSecurities.Add(((UserSubscription)obj).Security);
     }
 }
Пример #3
0
 internal bool ContainsSubscriptions(SubscriptionBase sub)
 {
     _subscriptionLock.EnterReadLock();
     try
     {
         return(Subscriptions.Contains(sub));
     }
     finally
     {
         _subscriptionLock.ExitReadLock();
     }
 }
Пример #4
0
 internal void AddSubscription(SubscriptionBase sub)
 {
     _subscriptionLock.EnterUpgradeableReadLock();
     try
     {
         if (!Subscriptions.Contains(sub))
         {
             _subscriptionLock.EnterWriteLock();
             Subscriptions.Add(sub);
             _subscriptionLock.ExitWriteLock();
         }
     }
     finally
     {
         _subscriptionLock.ExitUpgradeableReadLock();
     }
 }
Пример #5
0
        private void AddSubscription(long APartnerKey, string APublicationCode, string AConsentCode)
        {
            TVerificationResultCollection VerificationResult;

            List <string>  Subscriptions;
            List <string>  PartnerTypes;
            string         DefaultEmailAddress;
            string         DefaultPhoneMobile;
            string         DefaultPhoneLandline;
            PartnerEditTDS MainDS = TSimplePartnerEditWebConnector.GetPartnerDetails(APartnerKey,
                                                                                     out Subscriptions,
                                                                                     out PartnerTypes,
                                                                                     out DefaultEmailAddress,
                                                                                     out DefaultPhoneMobile,
                                                                                     out DefaultPhoneLandline);

            if (!Subscriptions.Contains(APublicationCode))
            {
                Subscriptions.Add(APublicationCode);
            }

            string EmailChangeObject = "{\"PartnerKey\":\"" + APartnerKey + "\",\"Type\":\"email address\"," +
                                       "\"Value\":\"" + DefaultEmailAddress + "\",\"ChannelCode\":\"PHONE\",\"Permissions\":\"" + AConsentCode + "\"," +
                                       "\"ConsentDate\":\"" + DateTime.Today.ToString("yyyy-MM-dd") + "\"," +
                                       "\"Valid\":true}";

            bool SendMail = true;
            bool result   = TSimplePartnerEditWebConnector.SavePartner(MainDS,
                                                                       Subscriptions,
                                                                       PartnerTypes,
                                                                       new List <string>()
            {
                EmailChangeObject
            },
                                                                       SendMail,
                                                                       DefaultEmailAddress,
                                                                       DefaultPhoneMobile,
                                                                       DefaultPhoneLandline,
                                                                       out VerificationResult);

            Assert.IsTrue(result, "AddSubscription.SavePartner");
        }
Пример #6
0
 public bool IsSubscribed(PvPBattle battle)
 {
     return(battle != null && !battle.Deleted && Subscriptions.Contains(battle));
 }
Пример #7
0
        void HandleOnTextMessageRecv(string socketMessage)
        {
            if (Logging)
            {
                Debug.LogError(socketMessage);
            }

            IDictionary m = socketMessage.Deserialize() as IDictionary;

            if (m == null)
            {
                return;
            }

            var msg = m ["msg"] as string;

            switch (msg)
            {
            case AddedMessage.added:
                var collection = m ["collection"] as string;
                if (Collections.Contains(collection))
                {
                    Collections[collection].Added(socketMessage);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record add. Creating a collection to handle it.\nMessage:\n{0}", socketMessage));
                }
                break;

            case ChangedMessage.changed:
                ChangedMessage cm = socketMessage.Deserialize <ChangedMessage>();
                if (Collections.Contains(cm.collection))
                {
                    Collections[cm.collection].Changed(cm.id, cm.cleared, cm.fields);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record change. Cannot recover this record later.\nMessage:\n{0}", socketMessage));
                }
                break;

            case RemovedMessage.removed:
                RemovedMessage rm = socketMessage.Deserialize <RemovedMessage>();
                if (Collections.Contains(rm.collection))
                {
                    Collections[rm.collection].Removed(rm.id);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record remove.\nMessage:\n{0}", socketMessage));
                }
                break;

            case ReadyMessage.ready:
                ReadyMessage readym = socketMessage.Deserialize <ReadyMessage>();
                foreach (string sub in readym.subs)
                {
                    if (Subscriptions.Contains(sub))
                    {
                        Subscriptions [sub].ready = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: A subscription ready message was received, but the subscription could not be found.\nSubscription: {0}", sub));
                    }
                }
                break;

            case ConnectedMessage.connected:
                ConnectedMessage connm = socketMessage.Deserialize <ConnectedMessage>();

                if (WillConnect != null)
                {
                    WillConnect(connm.session);
                }

                if (DidConnect != null)
                {
                    DidConnect(connm.session);
                }

                break;

            case ResultMessage.result:
                ResultMessage resultm = null;
                resultm = socketMessage.Deserialize <ResultMessage>();
                if (methods.ContainsKey(resultm.id))
                {
                    methods[resultm.id].Callback(resultm.error, resultm.methodResult);
                }
                else
                {
                    Debug.LogError(string.Format("LiveData: A result message was received, but the method could not be found.\nMethod: {0}", resultm.id));
                }
                break;

            case UpdatedMessage.updated:
                UpdatedMessage updatedm = socketMessage.Deserialize <UpdatedMessage>();
                foreach (var method in updatedm.methods)
                {
                    if (methods.ContainsKey(method))
                    {
                        methods [method].Updated = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: An updated message was received, but the method could not be found.\nMethod: {0}", method));
                    }
                }
                break;

            default:
                if (!socketMessage.Contains("server_id"))
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled message.\nMessage:\n{0}", socketMessage));
                }
                break;
            }
        }
Пример #8
0
        void HandleOnTextMessageRecv(string socketMessage)
        {
            if (Logging)
            {
                Debug.Log(socketMessage);
            }

            IDictionary m = socketMessage.Deserialize() as IDictionary;

            if (m == null)
            {
                return;
            }

            var msg = m ["msg"] as string;

            switch (msg)
            {
            case AddedMessage.added:
                var collection = m ["collection"] as string;
                if (Collections.Contains(collection))
                {
                    Collections [collection].Added(socketMessage);
                }
                else
                {
                    var addedm = socketMessage.Deserialize <AddedMessage <Hashtable> > ();
                    if (Logging)
                    {
                        Debug.Log(string.Format("LiveData: Unhandled record add. Creating a collection to handle it.\nMessage:\n{0}", socketMessage));
                    }
                    var handlingCollection = new TemporaryCollection(collection);
                    Collections.Add(handlingCollection);
                    handlingCollection.Added(addedm.id, addedm.fields);
                }
                break;

            case ChangedMessage.changed:
                ChangedMessage cm = socketMessage.Deserialize <ChangedMessage> ();
                if (Collections.Contains(cm.collection))
                {
                    Collections [cm.collection].Changed(cm.id, cm.cleared, cm.fields);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record change. Cannot recover this record later.\nMessage:\n{0}", socketMessage));
                }
                break;

            case RemovedMessage.removed:
                RemovedMessage rm = socketMessage.Deserialize <RemovedMessage> ();
                if (Collections.Contains(rm.collection))
                {
                    Collections [rm.collection].Removed(rm.id);
                }
                else
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled record remove.\nMessage:\n{0}", socketMessage));
                }
                break;

            case ReadyMessage.ready:
                ReadyMessage readym = socketMessage.Deserialize <ReadyMessage> ();
                foreach (string sub in readym.subs)
                {
                    if (Subscriptions.Contains(sub))
                    {
                        Subscriptions [sub].ready = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: A subscription ready message was received, but the subscription could not be found.\nSubscription: {0}", sub));
                    }
                }
                break;

            case ConnectedMessage.connected:
                ConnectedMessage connm = socketMessage.Deserialize <ConnectedMessage> ();

                if (WillConnect != null)
                {
                    WillConnect(connm.session);
                }

                if (DidConnect != null)
                {
                    DidConnect(connm.session);
                }

                break;

            case FailedMessage.failed:
                FailedMessage failedMessage = socketMessage.Deserialize <FailedMessage> ();
                SendConnectMessage(failedMessage.version);
                break;

            case ResultMessage.result:
                ResultMessage resultm = null;
                resultm = socketMessage.Deserialize <ResultMessage> ();
                if (resultm.methodError != null)
                {
                    int    code   = (int)resultm.methodError["error"];
                    string reason = (string)resultm.methodError["reason"];
                    string type   = (string)resultm.methodError["errorType"];
                    throw new MeteorException(code, reason);
                }
                if (methods.ContainsKey(resultm.id))
                {
                    methods [resultm.id].Callback(resultm.error, resultm.methodResult);
                }
                else
                {
                    Debug.LogError(string.Format("LiveData: A result message was received, but the method could not be found.\nMethod: {0}", resultm.id));
                }
                break;

            case UpdatedMessage.updated:
                UpdatedMessage updatedm = socketMessage.Deserialize <UpdatedMessage> ();
                foreach (var method in updatedm.methods)
                {
                    if (methods.ContainsKey(method))
                    {
                        methods [method].Updated = true;
                    }
                    else
                    {
                        Debug.LogError(string.Format("LiveData: An updated message was received, but the method could not be found.\nMethod: {0}", method));
                    }
                }
                break;

            case PingMessage.ping:
                PingMessage pingMessage = socketMessage.Deserialize <PingMessage> ();
                var         pongMessage = new PongMessage()
                {
                    id = pingMessage.id
                };
                Send(pongMessage);
                break;

            case PongMessage.pong:
                break;

            case NosubMessage.nosub:
                NosubMessage nosubm = null;
                nosubm = socketMessage.Deserialize <NosubMessage> ();
                if (nosubm.Error != null)
                {
                    string id     = nosubm.id;
                    int    code   = (int)nosubm.Error["error"];
                    string reason = (string)nosubm.Error["reason"];
                    string type   = (string)nosubm.Error["errorType"];
                    throw new MeteorException(code, reason);
                }
                break;

            default:
                if (!socketMessage.Contains("server_id"))
                {
                    Debug.LogWarning(string.Format("LiveData: Unhandled message.\nMessage:\n{0}", socketMessage));
                }
                break;
            }
        }
Пример #9
0
 public bool IsSubscribed(string message)
 {
     return(null != Subscriptions && Subscriptions.Contains(message));
 }