Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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;
        }