private bool UpdatePhotoDocumentSync(string scenario, string photoName, string documentResourceId, byte[] photoData) { if (string.IsNullOrEmpty(documentResourceId) || photoData == null) { return(false); } MsnServiceState serviceState = new MsnServiceState(scenario, "UpdateDocument", false); StorageService storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState); UpdateDocumentRequestType request = new UpdateDocumentRequestType(); request.document = new Photo(); if (!string.IsNullOrEmpty(photoName)) { request.document.Name = photoName; } else { request.document.Name = "?"; } request.document.ResourceID = documentResourceId; request.document.DocumentStreams = new PhotoStream[] { new PhotoStream() }; request.document.DocumentStreams[0].DataSize = 0; request.document.DocumentStreams[0].MimeType = "image/png"; request.document.DocumentStreams[0].DocumentStreamType = "UserTileStatic"; request.document.DocumentStreams[0].Data = photoData; try { ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, request); storageService.UpdateDocument(request); } catch (Exception ex) { OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("UpdateDocument", ex)); Trace.WriteLineIf(Settings.TraceSwitch.TraceError, ex.Message, GetType().Name); 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); }
private bool UpdatePhotoDocumentSync(string scenario, string photoName, string documentResourceId, byte[] photoData) { if (string.IsNullOrEmpty(documentResourceId) || photoData == null) return false; MsnServiceState serviceState = new MsnServiceState(scenario, "UpdateDocument", false); StorageService storageService = (StorageService)CreateService(MsnServiceType.Storage, serviceState); UpdateDocumentRequestType request = new UpdateDocumentRequestType(); request.document = new Photo(); if (!string.IsNullOrEmpty(photoName)) { request.document.Name = photoName; } else { request.document.Name = "?"; } request.document.ResourceID = documentResourceId; request.document.DocumentStreams = new PhotoStream[] { new PhotoStream() }; request.document.DocumentStreams[0].DataSize = 0; request.document.DocumentStreams[0].MimeType = "image/png"; request.document.DocumentStreams[0].DocumentStreamType = "UserTileStatic"; request.document.DocumentStreams[0].Data = photoData; try { ChangeCacheKeyAndPreferredHostForSpecifiedMethod(storageService, MsnServiceType.Storage, serviceState, request); storageService.UpdateDocument(request); } catch (Exception ex) { OnServiceOperationFailed(storageService, new ServiceOperationFailedEventArgs("UpdateDocument", ex)); Trace.WriteLineIf(Settings.TraceSwitch.TraceError, ex.Message, GetType().Name); 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; }