Example #1
0
        public string PutTransform(string name, TransformerDefinition definition)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            name = name.Trim();

            var existingDefinition = IndexDefinitionStorage.GetTransformerDefinition(name);

            if (existingDefinition != null)
            {
                switch (existingDefinition.LockMode)
                {
                case TransformerLockMode.Unlock:
                    if (existingDefinition.Equals(definition))
                    {
                        return(name);                        // no op for the same transformer
                    }
                    break;

                case TransformerLockMode.LockedIgnore:
                    Log.Info("Transformer {0} not saved because it was lock (with ignore)", name);
                    return(name);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            var generator = IndexDefinitionStorage.CompileTransform(definition);

            if (existingDefinition != null)
            {
                IndexDefinitionStorage.RemoveTransformer(existingDefinition.TransfomerId);
            }

            TransactionalStorage.Batch(accessor =>
            {
                definition.TransfomerId = (int)Database.Documents.GetNextIdentityValueWithoutOverwritingOnExistingDocuments("TransformerId", accessor);
            });

            IndexDefinitionStorage.CreateAndPersistTransform(definition, generator);
            IndexDefinitionStorage.AddTransform(definition.TransfomerId, definition);

            TransactionalStorage.ExecuteImmediatelyOrRegisterForSynchronization(() => Database.Notifications.RaiseNotifications(new TransformerChangeNotification()
            {
                Name = name,
                Type = TransformerChangeTypes.TransformerAdded,
            }));

            return(name);
        }
Example #2
0
        public string PutTransform(string name, TransformerDefinition definition)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            name = name.Trim();

            var existingDefinition = IndexDefinitionStorage.GetTransformerDefinition(name);

            if (existingDefinition != null && existingDefinition.Equals(definition))
            {
                return(name); // no op for the same transformer
            }
            var generator = IndexDefinitionStorage.CompileTransform(definition);

            if (existingDefinition != null)
            {
                IndexDefinitionStorage.RemoveTransformer(existingDefinition.TransfomerId);
            }

            TransactionalStorage.Batch(accessor =>
            {
                definition.TransfomerId = (int)Database.Documents.GetNextIdentityValueWithoutOverwritingOnExistingDocuments("TransformerId", accessor);
            });

            IndexDefinitionStorage.CreateAndPersistTransform(definition, generator);
            IndexDefinitionStorage.AddTransform(definition.TransfomerId, definition);

            TransactionalStorage.ExecuteImmediatelyOrRegisterForSynchronization(() => Database.Notifications.RaiseNotifications(new TransformerChangeNotification()
            {
                Name = name,
                Type = TransformerChangeTypes.TransformerAdded,
            }));

            return(name);
        }