Пример #1
0
        private void ProcessMessengerAndIMAvailabilityMemberships(ServiceType messengerService, ref Service messengerServiceClone)
        {
            #region Messenger Service memberhips

            foreach (Membership membership in messengerService.Memberships)
            {
                RoleId memberrole = membership.MemberRole;
                RoleLists msnlist = ContactList.GetMSNList(memberrole);

                if (null != membership.Members && msnlist != RoleLists.None)
                {
                    List<BaseMember> members = new List<BaseMember>(membership.Members);
                    members.Sort(CompareBaseMembers);

                    foreach (BaseMember bm in members)
                    {
                        long cid;
                        string account;
                        IMAddressInfoType type;
                        string displayname;

                        if (DetectBaseMember(bm, out account, out type, out cid, out displayname))
                        {
                            if (bm.Deleted)
                            {
                                #region Members deleted in other clients.

                                if (HasMemberhip(messengerServiceClone.ServiceType, account, type, memberrole) &&
                                    WebServiceDateTimeConverter.ConvertToDateTime(MembershipList[messengerServiceClone.ServiceType].Memberships[memberrole][Contact.MakeHash(account, type)].LastChanged)
                                    < WebServiceDateTimeConverter.ConvertToDateTime(bm.LastChanged))
                                {
                                    RemoveMemberhip(messengerServiceClone.ServiceType, account, type, memberrole);
                                }

                                if (NSMessageHandler.ContactList.HasContact(account, type))
                                {
                                    Contact contact = NSMessageHandler.ContactList.GetContact(account, type);
                                    if (cid != 0)
                                        contact.CID = cid;

                                    if (contact.HasLists(msnlist))
                                    {
                                        contact.RemoveFromList(msnlist);

                                        // Send a list remove event
                                        NSMessageHandler.ContactService.OnContactRemoved(new ListMutateEventArgs(contact, msnlist));
                                    }
                                }

                                #endregion
                            }
                            else
                            {
                                #region Newly added memberships.

                                if (false == MembershipList[messengerServiceClone.ServiceType].Memberships.ContainsKey(memberrole) ||
                                    /*new*/ false == MembershipList[messengerServiceClone.ServiceType].Memberships[memberrole].ContainsKey(Contact.MakeHash(account, type)) ||
                                    /*probably membershipid=0*/ WebServiceDateTimeConverter.ConvertToDateTime(bm.LastChanged)
                                    > WebServiceDateTimeConverter.ConvertToDateTime(MembershipList[messengerServiceClone.ServiceType].Memberships[memberrole][Contact.MakeHash(account, type)].LastChanged))
                                {
                                    AddMemberhip(messengerServiceClone.ServiceType, account, type, memberrole, bm);
                                }

                                Contact contact = NSMessageHandler.ContactList.GetContact(account, displayname, type);
                                if (cid != 0)
                                    contact.CID = cid;

                                if (!contact.HasLists(msnlist))
                                {
                                    contact.AddToList(msnlist);
                                    NSMessageHandler.ContactService.OnContactAdded(new ListMutateEventArgs(contact, msnlist));

                                    // Added by other place, this place hasn't synchronized this contact yet.
                                    if (contact.OnForwardList && contact.OnPendingList)
                                    {
                                        contact.OnPendingList = false;
                                    }
                                    // At this phase, we requested all memberships including pending.
                                    // FriendshipRequested (2/2): After SignedIn
                                    else if (contact.OnPendingList && NSMessageHandler.IsSignedIn)
                                    {
                                        NSMessageHandler.ContactService.OnFriendshipRequested(new ContactEventArgs(contact));
                                    }
                                }

                                #endregion
                            }
                        }
                    }
                }
            }

            #endregion
        }
Пример #2
0
        private void ProcessOtherMemberships(ServiceType service, ref Service serviceClone)
        {
            foreach (Membership membership in service.Memberships)
            {
                if (null != membership.Members)
                {
                    RoleId memberrole = membership.MemberRole;
                    List<BaseMember> members = new List<BaseMember>(membership.Members);
                    members.Sort(CompareBaseMembers);

                    foreach (BaseMember bm in members)
                    {
                        long cid;
                        string account;
                        IMAddressInfoType type;
                        string displayname;

                        if (DetectBaseMember(bm, out account, out type, out cid, out displayname))
                        {
                            if (bm.Deleted)
                            {
                                RemoveMemberhip(serviceClone.ServiceType, account, type, memberrole);

                                if (serviceClone.ServiceType == ServiceName.SocialNetwork)
                                {
                                    Contact contact = NSMessageHandler.ContactList.GetContactWithCreate(account, type);

                                    if (memberrole == RoleId.OneWayRelationship)
                                    {
                                        contact.SetFriendshipStatus(RoleId.None, true);
                                    }
                                    if (memberrole == RoleId.TwoWayRelationship)
                                    {
                                        contact.SetFriendshipStatus(RoleId.OneWayRelationship, true);
                                    }
                                }
                            }
                            else
                            {
                                AddMemberhip(serviceClone.ServiceType, account, type, memberrole, bm);

                                if (serviceClone.ServiceType == ServiceName.SocialNetwork)
                                {
                                    Contact contact = NSMessageHandler.ContactList.GetContactWithCreate(account, type);
                                    if (cid != 0)
                                        contact.CID = cid;

                                    contact.SetFriendshipStatus(memberrole, true);

                                    // FriendshipRequested (2/2): After SignedIn
                                    if (memberrole == RoleId.Pending && NSMessageHandler.IsSignedIn)
                                    {
                                        NSMessageHandler.ContactService.OnFriendshipRequested(new ContactEventArgs(contact));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        private bool UpdateDynamicItemSync(string scenario)
        {
            if (NSMessageHandler.MSNTicket != MSNTicket.Empty)
            {
                //9. UpdateDynamicItem
                MsnServiceState serviceState = new MsnServiceState(scenario, "UpdateDynamicItem", false);
                ABServiceBinding abService = (ABServiceBinding)CreateService(MsnServiceType.AB, serviceState);

                UpdateDynamicItemRequestType updateDyItemRequest = new UpdateDynamicItemRequestType();
                updateDyItemRequest.abId = Guid.Empty.ToString();

                PassportDynamicItem passportDyItem = new PassportDynamicItem();
                passportDyItem.Type = "Passport";
                passportDyItem.PassportName = NSMessageHandler.Owner.Account;
                passportDyItem.Changes = "Notifications";

                NotificationDataType notification = new NotificationDataType();
                notification.Status = "Exist Access";
                notification.InstanceId = "0";
                notification.Gleam = false;
                notification.LastChanged = NSMessageHandler.ContactService.Deltas.Profile.DateModified;

                ServiceType srvInfo = new ServiceType();
                srvInfo.Changes = "";

                HandleType srvHandle = new HandleType();
                srvHandle.ForeignId = "MyProfile";
                srvHandle.Id = "0";
                srvHandle.Type = ServiceName.Profile;

                InfoType info = new InfoType();
                info.Handle = srvHandle;
                info.IsBot = false;
                info.InverseRequired = false;

                srvInfo.Info = info;
                notification.StoreService = srvInfo;
                passportDyItem.Notifications = new NotificationDataType[] { notification };
                updateDyItemRequest.dynamicItems = new PassportDynamicItem[] { passportDyItem };
                try
                {

                    ChangeCacheKeyAndPreferredHostForSpecifiedMethod(abService, MsnServiceType.AB, serviceState, updateDyItemRequest);
                    abService.UpdateDynamicItem(updateDyItemRequest);
                }
                catch (Exception ex)
                {
                    OnServiceOperationFailed(abService, new ServiceOperationFailedEventArgs("UpdateDynamicItem", ex));
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "UpdateDynamicItem error: You don't receive any contact updates, vice versa! " + ex.Message, GetType().Name);

                    AddDynamicItemRequestType addDynamicItemRequest = new AddDynamicItemRequestType();
                    addDynamicItemRequest.abId = updateDyItemRequest.abId;
                    addDynamicItemRequest.dynamicItems = updateDyItemRequest.dynamicItems;
                    foreach (BaseDynamicItemType dynamicItem in addDynamicItemRequest.dynamicItems)
                    {
                        dynamicItem.Notifications = null;
                        dynamicItem.Changes = null;
                        dynamicItem.LastChanged = null;
                    }

                    try
                    {
                        ChangeCacheKeyAndPreferredHostForSpecifiedMethod(abService, MsnServiceType.AB, serviceState, addDynamicItemRequest);
                        abService.AddDynamicItem(addDynamicItemRequest);
                    }
                    catch (Exception exAddDynamicItem)
                    {
                        OnServiceOperationFailed(abService, new ServiceOperationFailedEventArgs("AddDynamicItem", exAddDynamicItem));
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "AddDynamicItem error: You don't receive any contact updates, vice versa! " + exAddDynamicItem.Message, GetType().Name);
                        return false;
                    }
                    return true;
                }
                return true;
            }

            return false;
        }