예제 #1
0
        internal void SyncUserTile(string usertitleURL, bool syncToOwner, GetUsertitleByURLhandler callBackHandler, GetUsertitleByURLhandler errorHandler)
        {
            try
            {
                Uri uri = new Uri(usertitleURL);

                HttpWebRequest fwr = (HttpWebRequest)WebRequest.Create(uri);
                NSMessageHandler.ConnectivitySettings.SetupWebRequest(fwr);
                fwr.Timeout = 30000;
                fwr.BeginGetResponse(delegate(IAsyncResult result)
                {
                    try
                    {
                        Stream stream = ((WebRequest)result.AsyncState).EndGetResponse(result).GetResponseStream();
                        SerializableMemoryStream ms = new SerializableMemoryStream();
                        byte[] data = new byte[8192];
                        int read;
                        while ((read = stream.Read(data, 0, data.Length)) > 0)
                        {
                            ms.Write(data, 0, read);
                        }
                        stream.Close();

                        if (syncToOwner)
                        {
                            DisplayImage newDisplayImage = new DisplayImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), ms);

                            NSMessageHandler.Owner.DisplayImage = newDisplayImage;
                        }

                        if (callBackHandler != null)
                        {
                            callBackHandler(ms);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (errorHandler != null)
                        {
                            errorHandler(ex);
                        }

                        return;
                    }
                }, fwr);
            }
            catch (Exception e)
            {
                if (errorHandler != null)
                {
                    errorHandler(e);
                }

                return;
            }
        }
예제 #2
0
        internal void CreateDefaultDisplayImage(SerializableMemoryStream sms)
        {
            if (sms == null)
            {
                sms = new SerializableMemoryStream();
                Image msnpsharpDefaultImage = Properties.Resources.MSNPSharp_logo.Clone() as Image;
                msnpsharpDefaultImage.Save(sms, msnpsharpDefaultImage.RawFormat);
            }

            DisplayImage displayImage = new DisplayImage(Account.ToLowerInvariant(), sms);

            this.DisplayImage = displayImage;
        }
예제 #3
0
        /// <summary>
        /// Update the display photo of current user.
        /// <list type="bullet">
        /// <item>GetProfile with scenario = "RoamingIdentityChanged"</item>
        /// <item>UpdateDynamicItem</item>
        /// </list>
        /// </summary>
        /// <param name="photo">New photo to display</param>
        /// <param name="photoName">The resourcename</param>
        /// <param name="syncToOwner">Whether synchronize the updated image to Messenger.Owner.DisplayImage after update succeed.</param>
        public bool UpdateProfile(Image photo, string photoName, bool syncToOwner)
        {
            if (NSMessageHandler.ContactService.Deltas == null)
            {
                OnServiceOperationFailed(this, new ServiceOperationFailedEventArgs("UpdateProfile", new MSNPSharpException("You don't have access right on this action anymore.")));
                return(false);
            }

            if (NSMessageHandler.ContactService.Deltas.Profile.HasExpressionProfile == false)  //Non-expression id or provisioned account.
            {
                NSMessageHandler.ContactService.Deltas.Profile.Photo.Name         = photoName;
                NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage = new SerializableMemoryStream();
                photo.Save(NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage, photo.RawFormat);
                NSMessageHandler.ContactService.Deltas.Save(true);

                if (syncToOwner)
                {
                    DisplayImage newDisplayImage = new DisplayImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage);

                    NSMessageHandler.Owner.DisplayImage = newDisplayImage;
                }

                Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, "No expression profile exists, new profile is saved locally.");
                return(true);
            }

            if (NSMessageHandler.MSNTicket != MSNTicket.Empty)
            {
                SerializableMemoryStream mem = SerializableMemoryStream.FromImage(photo);

                // 1. Get the old profile, don't syn it to owner.
                //NSMessageHandler.ContactService.Deltas.Profile = GetProfileImpl(PartnerScenario.RoamingIdentityChanged, false);

                bool updateDocumentResult = false;
                // 1.1 UpdateDocument
                if (NSMessageHandler.Owner.CoreProfile.ContainsKey(CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId))
                {
                    updateDocumentResult = UpdatePhotoDocumentSync(PartnerScenario.LivePlatformSyncChangesToServer0,
                                                                   NSMessageHandler.ContactService.Deltas.Profile.Photo.Name,
                                                                   NSMessageHandler.Owner.CoreProfile[CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId].ToString(),
                                                                   mem.ToArray());

                    // UpdateDynamicItem
                    // Currently I found no UpdateDynamicItem any more
                    //if (updateDocumentResult)
                    //{
                    //    updateDocumentResult = UpdateDynamicItemSync(PartnerScenario.RoamingIdentityChanged);
                    //}
                }
                else
                {
                    string resourceId = string.Empty;
                    CreatePhotoDocumentSync(PartnerScenario.LivePlatformSyncChangesToServer0, out resourceId, photoName, mem.ToArray());
                    //UpdateDynamicItemSync(PartnerScenario.RoamingIdentityChanged);
                }

                // Then get the updated profile and sync to the owner.
                //NSMessageHandler.ContactService.Deltas.Profile = GetProfileImpl(PartnerScenario.RoamingIdentityChanged, syncToOwner);
                if (NSMessageHandler.Owner != null)
                {
                    NSMessageHandler.Owner.GetCoreProfile();
                }
                return(true);
            }

            return(false);
        }
예제 #4
0
        private InternalOperationReturnValues GetProfileLiteSync(string scenario, out string profileResourceId, out string expressionProfileResourceId, bool syncToOwner)
        {
            MsnServiceState serviceState   = new MsnServiceState(scenario, "GetProfile", false);
            StorageService  storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState);

            GetProfileRequestType getprofileRequest = new GetProfileRequestType();

            Alias alias = new Alias();

            alias.NameSpace = "MyCidStuff";
            alias.Name      = Convert.ToString(NSMessageHandler.Owner.CID);

            Handle pHandle = new Handle();

            pHandle.RelationshipName = "MyProfile";
            pHandle.Alias            = alias;

            getprofileRequest.profileHandle     = pHandle;
            getprofileRequest.profileAttributes = new profileAttributes();

            ExpressionProfileAttributesType expAttrib = CreateFullExpressionProfileAttributes();

            getprofileRequest.profileAttributes.ExpressionProfileAttributes = expAttrib;

            try
            {
                ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, getprofileRequest);
                GetProfileResponse response = storageService.GetProfile(getprofileRequest);

                #region Process Profile
                profileResourceId = response.GetProfileResult.ResourceID;

                if (response.GetProfileResult.ExpressionProfile == null)
                {
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, "Get profile cannot get expression profile of this owner.");
                    NSMessageHandler.ContactService.Deltas.Profile.HasExpressionProfile = false;
                    NSMessageHandler.ContactService.Deltas.Profile.DisplayName          = NSMessageHandler.Owner.Name;

                    expressionProfileResourceId = string.Empty;
                    return(InternalOperationReturnValues.NoExpressionProfile);
                }
                else
                {
                    NSMessageHandler.ContactService.Deltas.Profile.HasExpressionProfile           = true;
                    NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile.ResourceID   = response.GetProfileResult.ExpressionProfile.ResourceID;
                    NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile.DateModified = response.GetProfileResult.ExpressionProfile.DateModified;

                    expressionProfileResourceId = response.GetProfileResult.ExpressionProfile.ResourceID;
                }

                NSMessageHandler.ContactService.Deltas.Profile.DateModified = response.GetProfileResult.DateModified;
                NSMessageHandler.ContactService.Deltas.Profile.ResourceID   = response.GetProfileResult.ResourceID;

                // Display name
                NSMessageHandler.ContactService.Deltas.Profile.DisplayName = response.GetProfileResult.ExpressionProfile.DisplayName;

                // Personal status
                if (response.GetProfileResult.ExpressionProfile.PersonalStatus != null)
                {
                    NSMessageHandler.ContactService.Deltas.Profile.PersonalMessage = response.GetProfileResult.ExpressionProfile.PersonalStatus;
                }

                NSMessageHandler.ContactService.Deltas.Save(true);

                // Display photo
                if (null != response.GetProfileResult.ExpressionProfile.Photo)
                {
                    foreach (DocumentStream docStream in response.GetProfileResult.ExpressionProfile.Photo.DocumentStreams)
                    {
                        if (docStream.DocumentStreamType != "UserTileStatic")
                        {
                            continue;
                        }

                        if (NSMessageHandler.ContactService.Deltas.Profile.Photo.PreAthURL == docStream.PreAuthURL)
                        {
                            if (syncToOwner)
                            {
                                DisplayImage newDisplayImage = new DisplayImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage);

                                NSMessageHandler.Owner.DisplayImage = newDisplayImage;
                            }
                        }
                        else
                        {
                            string requesturi = docStream.PreAuthURL;
                            if (requesturi.StartsWith("/"))
                            {
                                requesturi = "http://blufiles.storage.msn.com" + requesturi;  //I found it http://byfiles.storage.msn.com is also ok
                            }

                            // Don't urlencode t= :))
                            string usertitleURL = requesturi + "?t=" + System.Web.HttpUtility.UrlEncode(NSMessageHandler.MSNTicket.SSOTickets[SSOTicketType.Storage].Ticket.Substring(2));
                            SyncUserTile(usertitleURL,
                                         syncToOwner,
                                         delegate(object imageStream)
                            {
                                SerializableMemoryStream ms = imageStream as SerializableMemoryStream;
                                NSMessageHandler.ContactService.Deltas.Profile.Photo.Name         = response.GetProfileResult.ExpressionProfile.Photo.Name;
                                NSMessageHandler.ContactService.Deltas.Profile.Photo.DateModified = response.GetProfileResult.ExpressionProfile.Photo.DateModified;
                                NSMessageHandler.ContactService.Deltas.Profile.Photo.ResourceID   = response.GetProfileResult.ExpressionProfile.Photo.ResourceID;
                                NSMessageHandler.ContactService.Deltas.Profile.Photo.PreAthURL    = docStream.PreAuthURL;
                                if (ms != null)
                                {
                                    NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage = ms;
                                }

                                NSMessageHandler.ContactService.Deltas.Save(true);
                            },
                                         delegate(object param)
                            {
                                Exception ex = param as Exception;
                                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "Get DisplayImage error: " + ex.Message, GetType().Name);
                                if (NSMessageHandler.Owner.UserTileURL != null)
                                {
                                    SyncUserTile(NSMessageHandler.Owner.UserTileURL.AbsoluteUri, syncToOwner, null, null);
                                }
                            });
                        }
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("GetProfile", ex));
                Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "GetProfile error: " + ex.Message, GetType().FullName);
                expressionProfileResourceId = string.Empty;
                profileResourceId           = string.Empty;

                if (ex.Message.ToLowerInvariant().Contains("does not exist"))
                {
                    return(InternalOperationReturnValues.ProfileNotExist);
                }


                return(InternalOperationReturnValues.RequestFailed);
            }

            return(InternalOperationReturnValues.Succeed);
        }
예제 #5
0
        internal void SyncProfileToDeltas()
        {
            if (CoreProfile.ContainsKey(CoreProfileAttributeName.PublicProfile_ResourceId))
            {
                if (NSMessageHandler.ContactService.Deltas.Profile == null)
                {
                    NSMessageHandler.ContactService.Deltas.Profile = new OwnerProfile();
                }

                NSMessageHandler.ContactService.Deltas.Profile.ResourceID = CoreProfile[CoreProfileAttributeName.PublicProfile_ResourceId].ToString();

                if (CoreProfile.ContainsKey(CoreProfileAttributeName.LastModified))
                {
                    NSMessageHandler.ContactService.Deltas.Profile.DateModified = CoreProfile[CoreProfileAttributeName.LastModified].ToString();
                }
            }


            if (CoreProfile.ContainsKey(CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId))
            {
                NSMessageHandler.ContactService.Deltas.Profile.Photo.ResourceID = CoreProfile[CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId].ToString();
            }

            if (CoreProfile.ContainsKey(CoreProfileAttributeName.UserTileStaticUrl))
            {
                NSMessageHandler.ContactService.Deltas.Profile.Photo.PreAthURL = CoreProfile[CoreProfileAttributeName.UserTileStaticUrl].ToString();
            }



            if (CoreProfile.ContainsKey(CoreProfileAttributeName.ExpressionProfile_ResourceId))
            {
                NSMessageHandler.ContactService.Deltas.Profile.HasExpressionProfile = true;
                if (NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile == null)
                {
                    NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile = new ProfileResource();
                }
                NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile.ResourceID = CoreProfile[CoreProfileAttributeName.ExpressionProfile_ResourceId].ToString();

                if (CoreProfile.ContainsKey(CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId))
                {
                    NSMessageHandler.ContactService.Deltas.Profile.Photo.ResourceID = CoreProfile[CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId].ToString();
                }



                if (CoreProfile.ContainsKey(CoreProfileAttributeName.ExpressionProfile_DisplayName_LastModified))
                {
                    NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile.DateModified = CoreProfile[CoreProfileAttributeName.ExpressionProfile_DisplayName_LastModified].ToString();
                }

                if (CoreProfile.ContainsKey(CoreProfileAttributeName.ExpressionProfile_PersonalStatus))
                {
                    NSMessageHandler.ContactService.Deltas.Profile.PersonalMessage = CoreProfile[CoreProfileAttributeName.ExpressionProfile_PersonalStatus].ToString();
                    PersonalMessage newPersonalMessage = PersonalMessage == null ? new PersonalMessage(NSMessageHandler.ContactService.Deltas.Profile.PersonalMessage) : PersonalMessage;
                    newPersonalMessage.Message = NSMessageHandler.ContactService.Deltas.Profile.PersonalMessage;
                    PersonalMessage            = newPersonalMessage;
                }
            }

            NSMessageHandler.ContactService.Deltas.Profile.DisplayName = Name;
            NSMessageHandler.ContactService.Deltas.Save(true);

            if (CoreProfile.ContainsKey(CoreProfileAttributeName.UserTileStaticUrl))
            {
                NSMessageHandler.StorageService.SyncUserTile(CoreProfile[CoreProfileAttributeName.UserTileStaticUrl].ToString(), true,
                                                             delegate(object param)
                {
                    SerializableMemoryStream ms = param as SerializableMemoryStream;
                    if (ms != null)
                    {
                        NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage = ms;
                        NSMessageHandler.ContactService.Deltas.Save(true);
                    }

                    Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, "Get owner's display image from: " + CoreProfile[CoreProfileAttributeName.UserTileStaticUrl] +
                                      " succeeded.");
                },
                                                             delegate(object param)
                {
                    Exception ex = param as Exception;
                    if (ex != null)
                    {
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "An error occurred while getting owner's display image from:" +
                                          CoreProfile[CoreProfileAttributeName.UserTileStaticUrl] + "\r\n" +
                                          ex.Message);
                    }
                }
                                                             );
            }

            if (Name != PreferredName)
            {
                try
                {
                    NSMessageHandler.SetScreenName(PreferredName);
                    SetName(PreferredName);
                }
                catch (Exception ex)
                {
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceError, ex.Message);
                }
            }
        }