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; } }
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; }
private void RequestDisplayImage(Contact remoteContact, DisplayImage updateImage) { if (remoteContact.P2PVersionSupported != P2PVersion.None && remoteContact.ClientType == IMAddressInfoType.WindowsLive && updateImage != remoteContact.UserTileLocation) { if (updateImage == null) updateImage = remoteContact.DisplayImage; ObjectTransfer ot = _messenger.RequestMsnObject(remoteContact, updateImage); ot.TransferFinished += delegate { Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, "MSNObject transfered... See contact.DisplayImageChanged event"); }; } }
protected virtual void SaveImage(DisplayImage dispImage) { if (NSMessageHandler.ContactService.Deltas == null || dispImage == null) return; if (dispImage.Image == null || string.IsNullOrEmpty(dispImage.Sha)) return; if (NSMessageHandler.ContactService.Deltas.SaveImageAndRelationship(SiblingString, dispImage.Sha, dispImage.GetRawData(), true)) { NSMessageHandler.ContactService.Deltas.Save(true); } }
protected virtual void LoadImageFromDeltas(DisplayImage image) { if (NSMessageHandler.ContactService.Deltas == null) return; if (displayImage != null && !displayImage.IsDefaultImage) //Not default, no need to restore. return; string Sha = string.Empty; byte[] rawImageData = NSMessageHandler.ContactService.Deltas.GetRawImageDataBySiblingString(SiblingString, out Sha, true); if (rawImageData != null) { displayImage = new DisplayImage(Account, new MemoryStream(rawImageData)); Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "User " + ToString() + "'s displayimage" + "restored.\r\n " + "Old SHA: " + Sha + "\r\n " + "Current SHA: " + displayImage.Sha + "\r\n"); } }
/// <summary> /// This method will lead to fire <see cref="Contact.DisplayImageChanged"/> event if the DisplayImage.Image has been changed. /// </summary> /// <param name="image"></param> /// <returns> /// false: No event was fired.<br/> /// true: The <see cref="Contact.DisplayImageChanged"/> event was fired. /// </returns> internal bool SetDisplayImageAndFireDisplayImageChangedEvent(DisplayImage image) { if (image == null) return false; DisplayImageChangedEventArgs displayImageChangedArg = null; //if ((displayImage != null && displayImage.Sha != image.Sha && displayImage.IsDefaultImage && image.Image != null) || //Transmission completed. default Image -> new Image // (displayImage != null && displayImage.Sha != image.Sha && !displayImage.IsDefaultImage && image.Image != null) || //Transmission completed. old Image -> new Image. // (displayImage != null && object.ReferenceEquals(displayImage, image) && displayImage.Image != null) || //Transmission completed. old Image -> updated old Image. // (displayImage == null)) { displayImageChangedArg = new DisplayImageChangedEventArgs(image, DisplayImageChangedType.TransmissionCompleted, false); } if (!object.ReferenceEquals(displayImage, image)) { displayImage = image; } SaveOriginalDisplayImageAndFireDisplayImageChangedEvent(displayImageChangedArg); return true; }
protected internal Contact(Guid abId, string acc, IMAddressInfoType cliType, long cid, NSMessageHandler handler) { GenerateNewDCKeys(); NSMessageHandler = handler; addressBookId = abId; account = acc.ToLowerInvariant(); clientType = cliType; cId = cid; SetName(account); siblingString = ClientType.ToString() + ":" + account; hash = MakeHash(Account, ClientType); if (NSMessageHandler != null) { NSMessageHandler.ContactManager.Add(this); } displayImage = DisplayImage.CreateDefaultImage(Account); sceneImage = SceneImage.CreateDefaultImage(Account); personalMessage = new PersonalMessage(); if (Account == RemoteNetworkGateways.FaceBookGatewayAccount || Account == RemoteNetworkGateways.LinkedInGateway) { IsHiddenContact = true; } }
/// <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; }
public DisplayImageChangedEventArgs(DisplayImage dispImage, DisplayImageChangedType type) { status = type; callFromContactManager = false; newDisplayImage = dispImage; }
internal DisplayImageChangedEventArgs(DisplayImageChangedEventArgs arg, bool needSync) { status = arg.Status; callFromContactManager = needSync; newDisplayImage = arg.NewDisplayImage; }
internal DisplayImageChangedEventArgs(DisplayImage dispImage, DisplayImageChangedType type, bool needSync) { status = type; callFromContactManager = needSync; newDisplayImage = dispImage; }
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; }
private bool CreatePhotoDocumentSync(string scenario, out string documentResourceId, string photoName, byte[] photoData) { if (photoData == null) { documentResourceId = string.Empty; return false; } MsnServiceState serviceState = new MsnServiceState(scenario, "CreateDocument", false); StorageService storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState); CreateDocumentRequestType createDocRequest = new CreateDocumentRequestType(); createDocRequest.relationshipName = "ProfilePhoto"; Handle parenthandle = new Handle(); parenthandle.RelationshipName = @"/MyProfile/ExpressionProfile"; Alias alias = new Alias(); alias.NameSpace = "MyCidStuff"; alias.Name = Convert.ToString(NSMessageHandler.Owner.CID); parenthandle.Alias = alias; createDocRequest.parentHandle = parenthandle; createDocRequest.document = new Photo(); createDocRequest.document.Name = photoName; PhotoStream photoStream = new PhotoStream(); photoStream.DataSize = 0; photoStream.MimeType = @"image/png"; photoStream.DocumentStreamType = "UserTileStatic"; photoStream.Data = photoData; createDocRequest.document.DocumentStreams = new PhotoStream[] { photoStream }; DisplayImage displayImage = new DisplayImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), new MemoryStream(photoData)); NSMessageHandler.Owner.DisplayImage = displayImage; try { ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, createDocRequest); CreateDocumentResponseType createDocResponse = storageService.CreateDocument(createDocRequest); documentResourceId = createDocResponse.CreateDocumentResult; } catch (Exception ex) { OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("CreateDocument", ex)); Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "CreateDocument error: " + ex.Message, GetType().Name); documentResourceId = string.Empty; return false; } NSMessageHandler.ContactService.Deltas.Profile.Photo.Name = photoName; NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage = new SerializableMemoryStream(); NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage.Write(photoData, 0, photoData.Length); NSMessageHandler.ContactService.Deltas.Save(true); return true; }
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; } }
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); }
private bool CreatePhotoDocumentSync(string scenario, out string documentResourceId, string photoName, byte[] photoData) { if (photoData == null) { documentResourceId = string.Empty; return(false); } MsnServiceState serviceState = new MsnServiceState(scenario, "CreateDocument", false); StorageService storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState); CreateDocumentRequestType createDocRequest = new CreateDocumentRequestType(); createDocRequest.relationshipName = "ProfilePhoto"; Handle parenthandle = new Handle(); parenthandle.RelationshipName = @"/MyProfile/ExpressionProfile"; Alias alias = new Alias(); alias.NameSpace = "MyCidStuff"; alias.Name = Convert.ToString(NSMessageHandler.Owner.CID); parenthandle.Alias = alias; createDocRequest.parentHandle = parenthandle; createDocRequest.document = new Photo(); createDocRequest.document.Name = photoName; PhotoStream photoStream = new PhotoStream(); photoStream.DataSize = 0; photoStream.MimeType = @"image/png"; photoStream.DocumentStreamType = "UserTileStatic"; photoStream.Data = photoData; createDocRequest.document.DocumentStreams = new PhotoStream[] { photoStream }; DisplayImage displayImage = new DisplayImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), new MemoryStream(photoData)); NSMessageHandler.Owner.DisplayImage = displayImage; try { ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, createDocRequest); CreateDocumentResponseType createDocResponse = storageService.CreateDocument(createDocRequest); documentResourceId = createDocResponse.CreateDocumentResult; } catch (Exception ex) { OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("CreateDocument", ex)); Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "CreateDocument error: " + ex.Message, GetType().Name); documentResourceId = string.Empty; return(false); } NSMessageHandler.ContactService.Deltas.Profile.Photo.Name = photoName; NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage = new SerializableMemoryStream(); NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage.Write(photoData, 0, photoData.Length); NSMessageHandler.ContactService.Deltas.Save(true); return(true); }
public override bool ProcessData(P2PBridge bridge, byte[] data, bool reset) { if (sending) { // We are sender but remote client want to kill me :) return false; } if (reset) { // Data prep or TFCombination.First objStream.SetLength(0); } if (data.Length > 0) { objStream.Write(data, 0, data.Length); Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, String.Format("Received {0} / {1}", objStream.Length, msnObject.Size), GetType().Name); if (objStream.Length == msnObject.Size) { // Finished transfer byte[] allData = new byte[msnObject.Size]; objStream.Seek(0, SeekOrigin.Begin); objStream.Read(allData, 0, allData.Length); string dataSha = Convert.ToBase64String(new SHA1Managed().ComputeHash(allData)); if (dataSha != msnObject.Sha) { Trace.WriteLineIf(Settings.TraceSwitch.TraceWarning, "Object hash doesn't match data hash, data invalid", GetType().Name); return false; } MemoryStream ms = new MemoryStream(allData); ms.Position = 0; // Data CHECKSUM is ok, update MsnObject if (msnObject.ObjectType == MSNObjectType.UserDisplay) { DisplayImage newDisplayImage = new DisplayImage(Remote.Account.ToLowerInvariant(), ms); Remote.SetDisplayImageAndFireDisplayImageChangedEvent(newDisplayImage); msnObject = newDisplayImage; } else if (msnObject.ObjectType == MSNObjectType.Scene) { SceneImage newSceneImage = new SceneImage(Remote.Account.ToLowerInvariant(), ms); Remote.SetSceneImageAndFireSceneImageChangedEvent(newSceneImage); msnObject = newSceneImage; } else if (msnObject.ObjectType == MSNObjectType.Emoticon) { ((Emoticon)msnObject).Image = Image.FromStream(objStream); } else if (msnObject.ObjectType == MSNObjectType.Wink) { Stream s = ((Wink)msnObject).OpenStream(); s.Write(allData, 0, allData.Length); } objStream.Close(); OnTransferFinished(EventArgs.Empty); if (P2PSession != null) P2PSession.Close(); // Send first BYE } } return true; }
/// <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); }
/// <summary> /// This method will lead to fire <see cref="Contact.DisplayImageContextChanged"/> event if the DisplayImage.Sha has been changed. /// </summary> /// <param name="updatedImageContext"></param> /// <returns> /// false: No event was fired.<br/> /// true: The <see cref="Contact.DisplayImageContextChanged"/> was fired. /// </returns> internal bool FireDisplayImageContextChangedEvent(string updatedImageContext) { if (DisplayImage == updatedImageContext) return false; // If Delta already has image, just call DisplayImageChanged instead if (NSMessageHandler.ContactService.Deltas.HasImage(SiblingString, GetSHA(updatedImageContext), true)) { string Sha = string.Empty; byte[] rawImageData = NSMessageHandler.ContactService.Deltas.GetRawImageDataBySiblingString(SiblingString, out Sha, true); if (rawImageData != null) displayImage = new DisplayImage(Account, new MemoryStream(rawImageData)); NSMessageHandler.ContactService.Deltas.Save(true); OnDisplayImageChanged(new DisplayImageChangedEventArgs(displayImage, DisplayImageChangedType.TransmissionCompleted, false)); return true; } OnDisplayImageContextChanged(new DisplayImageChangedEventArgs(null, DisplayImageChangedType.UpdateTransmissionRequired)); return true; }