예제 #1
0
        internal int SendCircleNotifyRML(Guid circleId, string hostDomain, RoleLists lists)
        {
            string payload = "<ml><d n=\""
            + hostDomain + "\"><c n=\"" + circleId.ToString("D") + "\" l=\"" +
            ((int)lists).ToString() + "\" t=\"" +
            ((int)IMAddressInfoType.Circle).ToString() + "\"/></d></ml>";

            NSPayLoadMessage nsMessage = new NSPayLoadMessage("RML", payload);
            MessageProcessor.SendMessage(nsMessage);
            return nsMessage.TransactionID;
        }
예제 #2
0
        /// <summary>
        /// Send the initial ADL command to NS server. 
        /// </summary>
        /// <param name="scene">
        /// A <see cref="Scenario"/>
        /// </param>
        /// <remarks>
        /// The first ADL command MUST be a contact ADL. If you send a circle ADL instead,
        /// you will receive 201 server error for the following circle PUT command.
        /// </remarks>
        internal void SendInitialADL(Scenario scene)
        {
            if (scene == Scenario.None)
                return;

            NSMessageProcessor nsmp = (NSMessageProcessor)MessageProcessor;

            if (nsmp == null)
                return;

            Dictionary<string, RoleLists> hashlist = new Dictionary<string, RoleLists>();

            #region Process Contacts

            if ((scene & Scenario.SendInitialContactsADL) != Scenario.None)
            {
                // Combine initial ADL for Contacts
                hashlist = new Dictionary<string, RoleLists>(ContactList.Count);
                lock (ContactList.SyncRoot)
                {
                    foreach (Contact contact in ContactList.All)
                    {
                        if (contact.ADLCount == 0)
                            continue;

                        contact.ADLCount--;

                        string ch = contact.Hash;
                        RoleLists l = RoleLists.None;

                        if (contact.OnForwardList)
                            l |= RoleLists.Forward;

                        if (contact.OnAllowedList)
                            l |= RoleLists.Allow;

                        if (contact.AppearOffline)
                            l |= RoleLists.Hide;

                        if (l != RoleLists.None && !hashlist.ContainsKey(ch))
                            hashlist.Add(ch, l);
                    }
                }
                string[] adls = ContactList.GenerateMailListForAdl(hashlist, true);

                if (adls.Length > 0)
                {
                    foreach (string payload in adls)
                    {
                        NSPayLoadMessage message = new NSPayLoadMessage("ADL", payload);
                        message.TransactionID = nsmp.IncreaseTransactionID();
                        adlState.InitialADLs.Add(message.TransactionID, message);
                    }
                }
                scene |= adlState.IgnoredSenario;
                adlState.ContactADLProcessed = true;
            }

            #endregion

            #region Process Circles

            if ((scene & Scenario.SendInitialCirclesADL) != Scenario.None)
            {
                if (adlState.ContactADLProcessed)
                {
                    // Combine initial ADL for Circles
                    if (CircleList.Count > 0)
                    {
                        hashlist = new Dictionary<string, RoleLists>(CircleList.Count);
                        lock (ContactList.SyncRoot)
                        {
                            foreach (Contact circle in CircleList.Values)
                            {
                                if (circle.ADLCount == 0)
                                    continue;

                                circle.ADLCount--;
                                string ch = circle.Hash;
                                RoleLists l = circle.Lists;
                                hashlist.Add(ch, l);
                            }
                        }

                        string[] circleadls = ContactList.GenerateMailListForAdl(hashlist, true);

                        if (circleadls.Length > 0)
                        {
                            foreach (string payload in circleadls)
                            {
                                NSPayLoadMessage message = new NSPayLoadMessage("ADL", payload);
                                message.TransactionID = nsmp.IncreaseTransactionID();
                                adlState.InitialADLs.Add(message.TransactionID, message);
                            }
                        }
                    }
                }
                else
                {
                    adlState.IgnoredSenario |= Scenario.SendInitialCirclesADL;
                }
            }

            #endregion

            // Send All Initial ADLs...
            Dictionary<int, NSPayLoadMessage> initialADLsCopy = null;
            lock (adlState.InitialADLs)
            {
                initialADLsCopy = new Dictionary<int, NSPayLoadMessage>(adlState.InitialADLs);
            }
            foreach (NSPayLoadMessage nsPayload in initialADLsCopy.Values)
            {
                nsmp.SendMessage(nsPayload, nsPayload.TransactionID);
            }
        }
예제 #3
0
        private void SendInitialServiceADL()
        {
            NSMessageProcessor nsmp = MessageProcessor as NSMessageProcessor;

            if (nsmp == null)
                return;

            if (adlState.ServiceADL == 0)
            {
                adlState.ServiceADL = nsmp.IncreaseTransactionID();

                string[] ownerAccount = Owner.Account.Split('@');
                string payload = "<ml><d n=\"" + ownerAccount[1] + "\"><c n=\"" + ownerAccount[0] + "\" t=\"1\"><s l=\"3\" n=\"IM\" /><s l=\"3\" n=\"PE\" /><s l=\"3\" n=\"PD\" /><s l=\"3\" n=\"PF\"/></c></d></ml>";

                NSPayLoadMessage nsPayload = new NSPayLoadMessage("ADL", payload);
                nsPayload.TransactionID = adlState.ServiceADL;
                nsmp.SendMessage(nsPayload, nsPayload.TransactionID);
            }
        }