public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jo = JObject.Load(reader);

            string operationRaw = jo.Properties().First().Name;

            BulkMetadataBase     metadata = jo[operationRaw].ToObject <BulkMetadataBase>();
            BulkResultItemStatus status   = jo[operationRaw].ToObject <BulkResultItemStatus>();

            var item = new BulkResultItem();

            item.Populate(metadata, status);

            Enum.TryParse(operationRaw, true, out Operation operation);
            item.Operation = operation;

            return(item);
        }
Example #2
0
        private void SendOperations(Dictionary <int, FindDocument> operations)
        {
            ProviderClient      client           = (ProviderClient)this.Client;
            List <int>          intList          = new List <int>(operations.Count);
            List <FindDocument> findDocumentList = new List <FindDocument>(operations.Count);

            foreach (KeyValuePair <int, FindDocument> operation in operations)
            {
                if (operation.Value == null)
                {
                    intList.Add(operation.Key);
                }
                else
                {
                    findDocumentList.Add(operation.Value);
                }
            }
            if (intList.Count > 0)
            {
                FilterBuilder <FindDocument> filter = client.BuildFilter <FindDocument>();
                foreach (int num in intList)
                {
                    int documentId = num;
                    filter = filter.Or((Expression <Func <FindDocument, Filter> >)(doc => doc.CatalogEntryId.Match(documentId)));
                }
                client.Delete <FindDocument>((Expression <Func <FindDocument, Filter> >)(_ => (Filter)filter));
            }
            if (findDocumentList.Count <= 0)
            {
                return;
            }
            BulkResultItem bulkResultItem = client.Index((IEnumerable)findDocumentList).Items.FirstOrDefault <BulkResultItem>((Func <BulkResultItem, bool>)(r => !r.Ok));

            if (bulkResultItem != null)
            {
                throw new Exception(string.Format("Indexing error: {0}", (object)bulkResultItem.Error));
            }
        }