Exemple #1
0
        public BulkResult Index(IEnumerable objectsToIndex, bool deleteLanguageRoutingDuplicatesOnIndex)
        {
            objectsToIndex.ValidateNotNullOrEmptyArgument(nameof(objectsToIndex));
            List <BulkAction> bulkActionList = new List <BulkAction>();

            foreach (object obj in objectsToIndex)
            {
                string id = this.Conventions.IdConvention.GetId(obj);
                if (deleteLanguageRoutingDuplicatesOnIndex)
                {
                    BulkDeleteAction bulkDeleteAction1 = new BulkDeleteAction(this.DefaultIndex, this.GetTypeName(obj), id);
                    bulkDeleteAction1.ActionAndMeta.LanguageRouting = (LanguageRouting)null;
                    BulkDeleteAction bulkDeleteAction2 = bulkDeleteAction1;
                    bulkActionList.Add((BulkAction)bulkDeleteAction2);
                }
                BulkIndexAction bulkIndexAction = new BulkIndexAction((IndexName)this.DefaultIndex, (TypeName)this.GetTypeName(obj), (DocumentId)id, obj);
                bulkIndexAction.ActionAndMeta.TimeToLive = this.Conventions.TimeToLiveConvention.GetTimeToLive(obj);
                if (this.Conventions.LanguageRoutingConvention.HasLanguageRouting(obj))
                {
                    LanguageRouting languageRouting = this.Conventions.LanguageRoutingConvention.GetLanguageRouting(obj);
                    if (languageRouting == null)
                    {
                        throw new ArgumentException(string.Format("Language missing for the object with id: {0}.", (object)id));
                    }
                    bulkIndexAction.ActionAndMeta.LanguageRouting = this.GetSupportedLanguageRoutingOrDefault(languageRouting);
                }
                bulkActionList.Add((BulkAction)bulkIndexAction);
            }
            BulkCommand bulkCommand = this.commands.Bulk((IEnumerable <BulkAction>)bulkActionList);

            this.PrepareSerializerUsingConventions(bulkCommand.CommandContext.Serializer);
            return(bulkCommand.Execute());
        }
Exemple #2
0
 private LanguageRouting GetSupportedLanguageRoutingOrDefault(LanguageRouting languageRouting)
 {
     if (languageRouting == null)
     {
         return((LanguageRouting)null);
     }
     if ((!this.Settings.Languages.Any <Language>((Func <Language, bool>)(l => l.FieldSuffix.Equals(languageRouting.FieldSuffix))) ? 0 : (languageRouting.IsValid() ? 1 : 0)) == 0)
     {
         return(new LanguageRouting(Language.None.FieldSuffix));
     }
     return(languageRouting);
 }
Exemple #3
0
        public DeleteResult Delete(Type type, DocumentId id, LanguageRouting languageRouting, Action <DeleteCommand> commandAction)
        {
            DeleteCommand deleteCommand = this.commands.Delete(this.DefaultIndex, this.GetTypeName(type), (string)id);

            if (languageRouting.IsNotNull() && languageRouting.IsValid())
            {
                deleteCommand.LanguageRouting = this.GetSupportedLanguageRoutingOrDefault(languageRouting);
            }
            if (commandAction.IsNotNull())
            {
                commandAction(deleteCommand);
            }
            return(deleteCommand.Execute());
        }
Exemple #4
0
        public GetResult <TSource> GetWithMeta <TSource>(DocumentId id, LanguageRouting languageRouting, Action <GetCommand <TSource> > commandAction)
        {
            GetCommand <TSource> getCommand = this.commands.Get <TSource>(this.DefaultIndex, this.GetTypeName <TSource>(), (string)id);

            if (languageRouting != null)
            {
                getCommand.LanguageRouting = this.GetSupportedLanguageRoutingOrDefault(languageRouting);
            }
            this.PrepareSerializerUsingConventions(getCommand.CommandContext.Serializer);
            if (!typeof(TSource).IsAssignableFrom(typeof(TSource)))
            {
                getCommand.Fields = (IList <string>) this.GetFields <TSource>(getCommand.CommandContext);
            }
            if (commandAction.IsNotNull())
            {
                commandAction(getCommand);
            }
            return(getCommand.Execute());
        }
Exemple #5
0
        public IEnumerable <GetResult <TSource> > Get <TSource>(IEnumerable <Tuple <DocumentId, LanguageRouting> > ids)
        {
            ids = (IEnumerable <Tuple <DocumentId, LanguageRouting> >)ids.ToList <Tuple <DocumentId, LanguageRouting> >();
            ids.ValidateNotNullOrEmptyArgument(nameof(ids));
            List <IdAndType> idAndTypeList = new List <IdAndType>();

            foreach (Tuple <DocumentId, LanguageRouting> id in ids)
            {
                LanguageRouting routingOrDefault = id.Item2;
                if (routingOrDefault != null && routingOrDefault.IsValid())
                {
                    routingOrDefault = this.GetSupportedLanguageRoutingOrDefault(routingOrDefault);
                }
                idAndTypeList.Add(new IdAndType(id.Item1, (TypeName)this.Conventions.TypeNameConvention.GetTypeName(typeof(TSource)), routingOrDefault, this.DefaultIndex));
            }
            MultiGetCommand <TSource> multiGetCommand = this.commands.MultiGet <TSource>((IndexName)this.DefaultIndex, (IEnumerable <IdAndType>)idAndTypeList);

            this.PrepareSerializerUsingConventions(multiGetCommand.CommandContext.Serializer);
            return(multiGetCommand.Execute().Results);
        }
Exemple #6
0
        public IndexResult Index(object objectToIndex, Action <IndexCommand> commandAction)
        {
            objectToIndex.ValidateNotNullArgument(nameof(objectToIndex));
            IndexCommand indexCommand = this.commands.Index(this.DefaultIndex, this.GetTypeName(objectToIndex), objectToIndex);

            indexCommand.Id         = (DocumentId)this.Conventions.IdConvention.GetId(objectToIndex);
            indexCommand.TimeToLive = this.Conventions.TimeToLiveConvention.GetTimeToLive(objectToIndex);
            if (this.Conventions.LanguageRoutingConvention.HasLanguageRouting(objectToIndex))
            {
                LanguageRouting languageRouting = this.Conventions.LanguageRoutingConvention.GetLanguageRouting(objectToIndex);
                if (languageRouting == null)
                {
                    throw new ArgumentException(string.Format("Language missing for the object with id: {0}.", (object)indexCommand.Id));
                }
                indexCommand.LanguageRouting = this.GetSupportedLanguageRoutingOrDefault(languageRouting);
            }
            if (commandAction.IsNotNull())
            {
                commandAction(indexCommand);
            }
            this.PrepareSerializerUsingConventions(indexCommand.CommandContext.Serializer);
            return(indexCommand.Execute());
        }
Exemple #7
0
        public IndexResult Update <TSource>(DocumentId id, UpdateRequestBody requestBody, LanguageRouting languageRouting, Action <UpdateCommand> commandAction)
        {
            UpdateCommand <TSource> updateCommand = this.commands.Update <TSource>((IndexName)this.DefaultIndex, (TypeName)this.GetTypeName <TSource>(), id);

            if (languageRouting.IsNotNull() && languageRouting.IsValid())
            {
                updateCommand.LanguageRouting = this.GetSupportedLanguageRoutingOrDefault(languageRouting);
            }
            updateCommand.Body = requestBody.Clone();
            this.PrepareSerializerUsingConventions(updateCommand.CommandContext.Serializer);
            return(updateCommand.Execute());
        }
Exemple #8
0
 public IndexResult Update <TSource>(DocumentId id, UpdateRequestBody requestBody, LanguageRouting languageRouting)
 {
     return(this.Update <TSource>(id, requestBody, languageRouting, (Action <UpdateCommand>)null));
 }
Exemple #9
0
 public DeleteResult Delete <T>(DocumentId id, LanguageRouting languageRouting, Action <DeleteCommand> commandAction)
 {
     return(this.Delete(typeof(T), id, languageRouting, commandAction));
 }
Exemple #10
0
 public DeleteResult Delete <T>(DocumentId id, LanguageRouting languageRouting)
 {
     return(this.Delete <T>(id, languageRouting, (Action <DeleteCommand>)null));
 }
Exemple #11
0
 public TSource Get <TSource>(DocumentId id, LanguageRouting languageRouting, Action <GetCommand <TSource> > commandAction)
 {
     return(this.GetWithMeta <TSource>(id, commandAction).Source);
 }
Exemple #12
0
 public TSource Get <TSource>(DocumentId id, LanguageRouting languageRouting)
 {
     return(this.Get <TSource>(id, languageRouting, (Action <GetCommand <TSource> >)null));
 }