コード例 #1
0
        /// <summary>
        /// While creating a media entity, we could only post with its binary media resource.
        /// If we want to add values to its non-media properties, we need to to update/patch the entity
        /// instance with those property values.
        /// </summary>
        /// <returns></returns>
        private async Task UpdateNonMediaProperty(IODataEntity entity, string value)
        {
            string keyProeprtyName = "pk";
            string propertyName    = "title";

            // We do not update the key property. Only remains those proeprties to be updated.
            entity.Properties.Remove(keyProeprtyName);

            var prop = new ODataProperty(propertyName);

            prop.Value = value;
            entity.Properties[propertyName] = prop;
            var req = new ODataRequestParametersSingle(entity.EditResourcePath, RequestMode.Update, entity);

            req.Etag = entity.Etag;

            try
            {
                var exec = Store.ScheduleRequest(req);
                await exec.Response;
            }
            catch (Exception ex)
            {
                result.Text += ex.Message + "\n";
            }
        }
コード例 #2
0
        private async Task showEntityAsync()
        {
            if (storeOperator != null)
            {
                IODataEntity entity = await storeOperator.QueryTheLastEntity();

                if (entity != null)
                {
                    var resp = await storeOperator.GetStreamFromEntity(entity);

                    MemoryStream ms = new MemoryStream();
                    resp.InputStream.CopyTo(ms);
                    var stream = ms.AsRandomAccessStream();
                    stream.Seek(0);

                    var image = new BitmapImage();
                    image.SetSource(stream);
                    this.ImageBox.Source = image;
                }
                else
                {
                    this.ImageBox.Source = null;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Get the last entity
        /// </summary>
        /// <returns></returns>
        public async Task <IODataEntity> QueryTheLastEntity()
        {
            IODataEntity ent   = null;
            int          count = await QueryEntityCount("Photos");

            result.Text += string.Format("Total Count: {0}", count) + "\n";

            StringBuilder  builder  = new StringBuilder();
            IODataResponse response = await QueryOfflineStore("Photos");

            IODataEntitySet entitySet = (IODataEntitySet)((IODataResponseSingle)response).Payload;

            foreach (IODataEntity entity in entitySet)
            {
                ent = entity;
            }

            // Display the title of the current entity.
            if (ent != null)
            {
                string propertyName  = "title";
                string propertyValue = (string)ent.Properties[propertyName].Value;
                result.Text += string.Format("Property {0} = {1}", propertyName, propertyValue) + "\n";
            }

            return(ent);
        }
コード例 #4
0
        private async void Delete_ClickAsync(object sender, RoutedEventArgs e)
        {
            if (storeOperator != null)
            {
                IODataEntity entity = await storeOperator.QueryTheLastEntity();

                if (entity != null)
                {
                    await storeOperator.DeleteStreamEntity(entity);
                    await showEntityAsync();
                }
            }
        }
コード例 #5
0
        public async Task <IODataDownloadMediaResource> GetStreamFromEntity(IODataEntity mediaEntity)
        {
            IODataMediaRequestExecution exec;

            try
            {
                exec = Store.ScheduleReadMediaResource(mediaEntity.MediaLink);
                return(await exec.Response);
            } catch (Exception ex)
            {
                result.Text += ex.Message + "\n";
                return(null);
            }
        }
コード例 #6
0
        public async Task <bool> DeleteStreamEntity(IODataEntity mediaEntity)
        {
            ODataRequestParametersSingle req;
            IODataResponse         resp;
            IODataRequestExecution exec;

            req = new ODataRequestParametersSingle(mediaEntity.EditResourcePath, RequestMode.Delete, mediaEntity);

            try
            {
                exec = Store.ScheduleRequest(req);
                resp = await exec.Response;
                return(true);
            }
            catch (Exception ex)
            {
                result.Text += ex.Message + "\n";
                return(false);
            }
        }
コード例 #7
0
        public async Task <bool> UpdateStreamEntity(IODataEntity mediaEntity)
        {
            var stream = await pickAPicture();

            if (stream == null)
            {
                return(false);
            }

            Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer((uint)stream.Size);
            await stream.ReadAsync(buffer, (uint)stream.Size, InputStreamOptions.None);

            DataReader dataReader = DataReader.FromBuffer(buffer);

            byte[] bytes = new byte[buffer.Length];
            dataReader.ReadBytes(bytes);

            ODataRequestParametersSingle req;
            IODataResponse         resp;
            IODataRequestExecution exec;

            req      = new ODataRequestParametersSingle(mediaEntity.EditMediaLink.ToString(), RequestMode.Update, new ODataUploadMediaResource(bytes, stream.ContentType));
            req.Etag = mediaEntity.MediaEtag;

            try
            {
                exec = Store.ScheduleRequest(req);
                resp = await exec.Response;
                await UpdateNonMediaProperty(mediaEntity, "Updated at: " + DateTime.Now.ToString());

                return(true);
            }
            catch (Exception ex)
            {
                result.Text += ex.Message + "\n";
                return(false);
            }
        }