public SceneImageChangedEventArgs(DisplayImageChangedType type, bool isDefault) { status = type; callFromContactManager = false; newSceneImage = null; this.isDefault = isDefault; }
/// <summary> /// Set the scene image and the scheme color for the owner. /// </summary> /// <param name="imageScene">Set this to null or the default display image if you want the default MSN scene.</param> /// <param name="schemeColor"></param> /// <returns> /// The result will return false if the image scene and color are the same, compared to the current one. /// </returns> public bool SetScene(Image imageScene, Color schemeColor) { if (imageScene == SceneImage.Image && schemeColor == ColorScheme) { return(false); } ColorScheme = schemeColor; if (imageScene != SceneImage.Image) { if (imageScene != null) { MemoryStream sms = new MemoryStream(); imageScene.Save(sms, imageScene.RawFormat); SceneImage = new SceneImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), sms); } else { SceneImage = new SceneImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), true); } SaveOriginalSceneImageAndFireSceneImageChangedEvent( new SceneImageChangedEventArgs(SceneImage, DisplayImageChangedType.TransmissionCompleted, false)); } else { NSMessageHandler.ContactService.Deltas.Save(true); } if (NSMessageHandler != null) { NSMessageHandler.SetSceneData(SceneImage, ColorScheme); } return(true); }
/// <summary> /// Sets the scene image and scheme context. /// </summary> internal void SetSceneData(SceneImage scimg, Color sccolor) { if (Owner == null) throw new MSNPSharpException("Not a valid owner"); PersonalMessage pm = Owner.PersonalMessage; pm.ColorScheme = sccolor; pm.Scene = scimg.IsDefaultImage ? String.Empty : scimg.ContextPlain; SetPresenceStatus(Owner.Status, Owner.LocalEndPointIMCapabilities, Owner.LocalEndPointIMCapabilitiesEx, Owner.LocalEndPointPECapabilities, Owner.LocalEndPointPECapabilitiesEx, Owner.EpName, pm, true); }
protected virtual void SaveImage(SceneImage sceneImage) { if (NSMessageHandler.ContactService.Deltas == null || sceneImage == null) return; if (sceneImage.Image == null || string.IsNullOrEmpty(sceneImage.Sha)) return; if (NSMessageHandler.ContactService.Deltas.SaveImageAndRelationship(SiblingString, sceneImage.Sha, sceneImage.GetRawData(), false)) { NSMessageHandler.ContactService.Deltas.Save(true); } }
protected virtual void LoadImageFromDeltas(SceneImage image) { if (NSMessageHandler.ContactService.Deltas == null) return; if (sceneImage != null && !sceneImage.IsDefaultImage) //Not default, no need to restore. return; string Sha = string.Empty; byte[] rawImageData = NSMessageHandler.ContactService.Deltas.GetRawImageDataBySiblingString(SiblingString, out Sha, false); if (rawImageData != null) { sceneImage = new SceneImage(Account, new MemoryStream(rawImageData)); Trace.WriteLineIf(Settings.TraceSwitch.TraceVerbose, "User " + ToString() + "'s scene image" + "restored.\r\n " + "Old SHA: " + Sha + "\r\n " + "Current SHA: " + displayImage.Sha + "\r\n"); } }
internal bool SetSceneImageAndFireSceneImageChangedEvent(SceneImage image) { if (image == null) return false; SceneImageChangedEventArgs sceneImageChangedArg = null; { sceneImageChangedArg = new SceneImageChangedEventArgs(image, DisplayImageChangedType.TransmissionCompleted, false); } if (!object.ReferenceEquals(sceneImage, image)) { sceneImage = image; } SaveOriginalSceneImageAndFireSceneImageChangedEvent(sceneImageChangedArg); return true; }
internal void SetSceneImage(SceneImage scene) { sceneImage = scene; }
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> /// This method will lead to fire <see cref="Contact.SceneImageContextChanged"/> event if the SceneImage.Sha has been changed. /// </summary> /// <param name="updatedImageContext"></param> /// <returns> /// false: No event was fired.<br/> /// true: The <see cref="Contact.SceneImageContextChanged"/> was fired. /// </returns> internal bool FireSceneImageContextChangedEvent(string updatedImageContext) { if (SceneImage == updatedImageContext) return false; // If Delta already has image, just call SceneImageChanged instead if (NSMessageHandler.ContactService.Deltas.HasImage(SiblingString, GetSHA(updatedImageContext), false)) { string Sha = string.Empty; byte[] rawImageData = NSMessageHandler.ContactService.Deltas.GetRawImageDataBySiblingString(SiblingString, out Sha, false); if (rawImageData != null) sceneImage = new SceneImage(Account, new MemoryStream(rawImageData)); NSMessageHandler.ContactService.Deltas.Save(true); OnSceneImageChanged(new SceneImageChangedEventArgs(sceneImage, DisplayImageChangedType.TransmissionCompleted, false)); return true; } OnSceneImageContextChanged(new SceneImageChangedEventArgs(DisplayImageChangedType.UpdateTransmissionRequired, updatedImageContext == string.Empty)); 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; }
internal SceneImageChangedEventArgs(SceneImage sceneImage, DisplayImageChangedType type, bool needSync) { status = type; callFromContactManager = needSync; newSceneImage = sceneImage; }
/// <summary> /// Set the scene image and the scheme color for the owner. /// </summary> /// <param name="imageScene">Set this to null or the default display image if you want the default MSN scene.</param> /// <param name="schemeColor"></param> /// <returns> /// The result will return false if the image scene and color are the same, compared to the current one. /// </returns> public bool SetScene(Image imageScene, Color schemeColor) { if (imageScene == SceneImage.Image && schemeColor == ColorScheme) return false; ColorScheme = schemeColor; if (imageScene != SceneImage.Image) { if (imageScene != null) { MemoryStream sms = new MemoryStream(); imageScene.Save(sms, imageScene.RawFormat); SceneImage = new SceneImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), sms); } else SceneImage = new SceneImage(NSMessageHandler.Owner.Account.ToLowerInvariant(), true); SaveOriginalSceneImageAndFireSceneImageChangedEvent( new SceneImageChangedEventArgs(SceneImage, DisplayImageChangedType.TransmissionCompleted, false)); } else NSMessageHandler.ContactService.Deltas.Save(true); if (NSMessageHandler != null) NSMessageHandler.SetSceneData(SceneImage, ColorScheme); return true; }