Пример #1
0
        public override void Delete(Expression <Func <T, bool> > where)
        {
            try
            {
                List <T> items = Get(where, null, 0, Int32.MaxValue);

                if (items != null && items.Count > 0)
                {
                    foreach (T item in items)
                    {
                        DeleteAttributesRequest deleteRequest = new DeleteAttributesRequest();
                        deleteRequest.DomainName = m_objectMapper.TableName;
                        deleteRequest.ItemName   = item.Id.ToString();

                        DeleteAttributesResponse response = m_simpleDBClient.DeleteAttributes(deleteRequest);

                        if (response.IsSetResponseMetadata())
                        {
                            ResponseMetadata responseMetadata = response.ResponseMetadata;
                            logger.Debug("Delete response: " + responseMetadata.RequestId);
                        }

                        if (Deleted != null)
                        {
                            Deleted(item);
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SimpleDBAssetPersistor Delete (for " + typeof(T).Name + "). " + excp.Message);
                throw;
            }
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DeleteAttributesResponse response = new DeleteAttributesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("DeleteAttributesResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
Пример #3
0
        public override void Delete(T asset)
        {
            try
            {
                DeleteAttributesRequest deleteRequest = new DeleteAttributesRequest();
                deleteRequest.DomainName = m_objectMapper.TableName;
                deleteRequest.ItemName   = asset.Id.ToString();

                DeleteAttributesResponse response = m_simpleDBClient.DeleteAttributes(deleteRequest);

                if (response.IsSetResponseMetadata())
                {
                    ResponseMetadata responseMetadata = response.ResponseMetadata;
                    logger.Debug("Delete response: " + responseMetadata.RequestId);
                }

                if (Deleted != null)
                {
                    Deleted(asset);
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SimpleDBAssetPersistor Delete (for " + typeof(T).Name + "). " + excp.Message);
                throw;
            }
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DeleteAttributesResponse response = new DeleteAttributesResponse();

            while (context.Read())
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
            }


            return(response);
        }
Пример #5
0
        private void btnDeletetAttributes_Click(object sender, RoutedEventArgs e)
        {
            SimpleDBResponseEventHandler <object, ResponseEventArgs> responseHandler = null;

            responseHandler = delegate(object senderAmazon, ResponseEventArgs args)
            {
                SimpleDB.Client.OnSimpleDBResponse -= responseHandler;
                DeleteAttributesResponse deleteResponse = args.Response as DeleteAttributesResponse;
                this.Dispatcher.BeginInvoke(() =>
                {
                    this.Attributes.Clear();
                    string message = string.Empty;
                    if (null != deleteResponse)
                    {
                        message = "Attribute(s) deleted successfully.";
                    }
                    else
                    {
                        AmazonSimpleDBException exception = args.Response as AmazonSimpleDBException;
                        if (null != exception)
                        {
                            message = "Error: " + exception.Message;
                        }
                    }
                    this.FetchingOrDeletingAttributeMessage = message;
                });
            };

            SimpleDB.Client.OnSimpleDBResponse += responseHandler;

            DeleteAttributesRequest deleteRequest = new DeleteAttributesRequest()
            {
                DomainName = this.DomainName, ItemName = this.ItemName
            };
            List <Amazon.SimpleDB.Model.Attribute> deleteItem = deleteRequest.Attribute;
            List <AttributeAndValue> aAndV = GetListAttributeAndValueFromString(this.AttributesAndValuesToPut);

            aAndV.ForEach(a => deleteItem.Add(new Amazon.SimpleDB.Model.Attribute().WithName(a.Attribute).WithValue(a.Value)));
            //deleteItem.Add(new Amazon.SimpleDB.Model.Attribute().WithName("Category").WithValue("Clothes"));
            //deleteItem.Add(new Amazon.SimpleDB.Model.Attribute().WithName("Subcategory").WithValue("Sweater"));

            SimpleDB.Client.DeleteAttributes(deleteRequest);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DeleteAttributesResponse response = new DeleteAttributesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("attributes", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Attribute, AttributeUnmarshaller>(AttributeUnmarshaller.Instance);
                    response.Attributes = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, DeleteAttributesResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                }
            }

            return;
        }
        public async Task DeleteNewsItem(string id)
        {
            var client = GetClient();

            DeleteAttributesRequest request = new DeleteAttributesRequest();

            //request.Attributes.Add(new Amazon.SimpleDB.Model.Attribute { Name = id });
            request.DomainName = Domain;
            request.ItemName   = id;

            try
            {
                DeleteAttributesResponse response = await client.DeleteAttributesAsync(request);
            }
            catch (AmazonSimpleDBException ex)
            {
                _logger.LogError(ex, $"Error Code: {ex.ErrorCode}, Error Type: {ex.ErrorType}");
                throw;
            }
        }