Пример #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 && existingDefinition.Equals(definition))
                return name; // no op for the same transformer

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

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

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

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

            return name;
        }
Пример #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)
	        {
		        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;
        }
Пример #3
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

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

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

            return name;
        }
Пример #4
0
        public string CreateAndPersistTransform(TransformerDefinition transformerDefinition)
        {
            var transformer = AddAndCompileTransform(transformerDefinition);
			if (configuration.RunInMemory == false)
			{
				WriteTransformerDefinition(transformerDefinition);
			}
            return transformer.Name;
        }
Пример #5
0
		private void WriteTransformerDefinition(TransformerDefinition transformerDefinition)
		{
			if (configuration.RunInMemory)
				return;
			var fixedName = FixupIndexName(transformerDefinition.Name);
			var indexName = Path.Combine(path, MonoHttpUtility.UrlEncode(fixedName) + ".transform");
			// Hash the name if it's too long (as a path)
			File.WriteAllText(indexName, JsonConvert.SerializeObject(transformerDefinition, Formatting.Indented, Default.Converters));
		}
Пример #6
0
        public void AddTransform(int id, TransformerDefinition definition)
        {
            transformDefinitions.AddOrUpdate(id, definition, (s1, def) => definition);
            transformNameToId[definition.Name] = id;

            UpdateTransformerMappingFile();
        }
		private void UpdateFromTransformer(TransformerDefinition transformerDefinition)
		{
			Transformer = transformerDefinition;

			OnEverythingChanged();
		}
		public DynamicTransformerCompiler(
			TransformerDefinition transformerDefinition,
			InMemoryRavenConfiguration configuration, OrderedPartCollection<AbstractDynamicCompilationExtension> extensions, string name, string basePath) : base(configuration, extensions, name, basePath)
		{
			this.transformerDefinition = transformerDefinition;
		}
	    public AbstractTransformer CompileTransform(TransformerDefinition transformerDefinition)
        {
            var transformer = new DynamicTransformerCompiler(transformerDefinition, configuration, extensions,
                                                             transformerDefinition.Name, path);
            var generator = transformer.GenerateInstance();

            logger.Info("New transformer {0}:\r\n{1}\r\nCompiled to:\r\n{2}", transformer.Name,
                        transformer.CompiledQueryText,
                        transformer.CompiledQueryText);
			return generator;
        }
        public string CreateAndPersistTransform(TransformerDefinition transformerDefinition, AbstractTransformer transformer)
        {
			transformCache.AddOrUpdate(transformerDefinition.TransfomerId, transformer, (s, viewGenerator) => transformer);
            if (configuration.RunInMemory == false)
            {
                WriteTransformerDefinition(transformerDefinition);
            }
            return transformer.Name;
        }
        private void WriteTransformerDefinition(TransformerDefinition transformerDefinition)
        {
            if (configuration.RunInMemory)
                return;

            string transformerFileName = Path.Combine(path, transformerDefinition.TransfomerId + ".transform");

            File.WriteAllText(transformerFileName,
                              JsonConvert.SerializeObject(transformerDefinition, Formatting.Indented, Default.Converters));
        }
Пример #12
0
		public void AddTransform(string name, TransformerDefinition definition)
		{
			trasformDefinitions.AddOrUpdate(name, definition, (s1, def) => definition);
		}
Пример #13
0
		public string CreateAndPersistTransform(TransformerDefinition transformerDefinition)
		{
			var transformer = AddAndCompileTransform(transformerDefinition);
			if (configuration.RunInMemory == false)
			{
				var encodeIndexNameIfNeeded = FixupIndexName(transformerDefinition.Name, path);
				var indexName = Path.Combine(path, MonoHttpUtility.UrlEncode(encodeIndexNameIfNeeded) + ".transform");
				// Hash the name if it's too long (as a path)
				File.WriteAllText(indexName, JsonConvert.SerializeObject(transformerDefinition, Formatting.Indented, Default.Converters));
			}
			return transformer.Name;
		}
Пример #14
0
		public void UpdateTransformerDefinitionWithoutUpdatingCompiledTransformer(TransformerDefinition definition)
		{
			transformDefinitions.AddOrUpdate(definition.TransfomerId, s =>
			{
				throw new InvalidOperationException(
					"Cannot find transformer named: " +
					definition.TransfomerId);
			}, (s, transformerDefinition) => definition);
			WriteTransformerDefinition(definition);
		}
Пример #15
0
        private DynamicTransformerCompiler AddAndCompileTransform(TransformerDefinition transformerDefinition)
        {
			var fixedName = FixupIndexName(transformerDefinition.Name);
			var transformer = new DynamicTransformerCompiler(transformerDefinition, configuration, extensions, fixedName, path);
            var generator = transformer.GenerateInstance();
			transformCache.AddOrUpdate(fixedName, generator, (s, viewGenerator) => generator);

            logger.Info("New transformer {0}:\r\n{1}\r\nCompiled to:\r\n{2}", transformer.Name, transformer.CompiledQueryText,
                              transformer.CompiledQueryText);
            return transformer;
        }
Пример #16
0
		public void Init(TransformerDefinition def)
		{
			transformerDefinition = def;
		}
Пример #17
0
        public void AddTransform(string name, TransformerDefinition definition)
        {
			var fixedName = FixupIndexName(name);
			transformDefinitions.AddOrUpdate(fixedName, definition, (s1, def) => definition);
        }
Пример #18
0
 public bool Equals(TransformerDefinition other)
 {
     return(string.Equals(TransformResults, other.TransformResults));
 }
Пример #19
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 existingDefintition = IndexDefinitionStorage.GetTransformerDefinition(name);
			if (existingDefintition != null && existingDefintition.Equals(definition))
				return name; // no op for the same transformer

			IndexDefinitionStorage.CreateAndPersistTransform(definition);
			IndexDefinitionStorage.AddTransform(name, definition);

			return name;
		}
Пример #20
0
		private string DetermineName(TransformerDefinition transformer)
		{
			var name = transformer.Name;
			if (name.Contains("/") == false)
				return "No Group";
			var groups = name.Split('/');
			return groups[0];
		}
Пример #21
0
		public TransformerDefinitionModel()
		{
			ModelUrl = "/transformers/";
			Transformer = new TransformerDefinition();
            Errors = new ObservableCollection<TransformerDefinitionError>();
		}
Пример #22
0
 private void WriteTransformerDefinition(TransformerDefinition transformerDefinition)
 {
     if (configuration.RunInMemory)
         return;
     string indexName;
     int i = 0;
     while (true)
     {
         indexName = Path.Combine(path, i + ".transform");
         if (File.Exists(indexName) == false)
             break;
         i++;
     }
     File.WriteAllText(indexName,
                       JsonConvert.SerializeObject(transformerDefinition, Formatting.Indented, Default.Converters));
 }
Пример #23
0
        private void ReplicateSingleTransformer(ReplicationStrategy destination, TransformerDefinition definition)
        {
            try
            {
                var clonedTransformer = definition.Clone();
                clonedTransformer.TransfomerId = 0;

                var url = destination.ConnectionStringOptions.Url + "/transformers/" + Uri.EscapeUriString(definition.Name) + "?" + GetDebugInfomration();
                var replicationRequest = httpRavenRequestFactory.Create(url, "PUT", destination.ConnectionStringOptions, GetRequestBuffering(destination));
                replicationRequest.Write(RavenJObject.FromObject(clonedTransformer));
                replicationRequest.ExecuteRequest();
            }
            catch (Exception e)
            {
                HandleRequestBufferingErrors(e, destination);

                log.WarnException("Could not replicate transformer " + definition.Name + " to " + destination.ConnectionStringOptions.Url, e);
            }
        }
Пример #24
0
        public string PutTransform(string name, TransformerDefinition definition, bool isReplication = false)
        {
            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)
            {
                var newTransformerVersion = definition.TransformerVersion;
                var currentTransformerVersion = existingDefinition.TransformerVersion;

                // whether we update the transformer definition or not,
                // we need to update the transformer version
                existingDefinition.TransformerVersion = definition.TransformerVersion =
                    Math.Max(currentTransformerVersion ?? 0, newTransformerVersion ?? 0);

                switch (isReplication)
                {
                    case true:
                        if (newTransformerVersion != null && currentTransformerVersion != null &&
                            newTransformerVersion <= currentTransformerVersion)
                        {
                            //this new transformer is an older version of the current one
                            return null;
                        }

                        // we need to update the lock mode only if it was updated by another server
                        existingDefinition.LockMode = definition.LockMode;
                        break;
                    default:
                        switch (existingDefinition.LockMode)
                        {
                            case TransformerLockMode.Unlock:
                                if (existingDefinition.Equals(definition))
                                    return name; // no op for the same transformer

                                definition.TransformerVersion++;

                                break;
                            case TransformerLockMode.LockedIgnore:
                                Log.Info("Transformer {0} not saved because it was lock (with ignore)", name);
                                return name;
                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                        break;
                }
            }
            else if (isReplication == false)
            {
                // we're creating a new transformer,
                // we need to take the transformer version of the deleted transformer (if exists)
                definition.TransformerVersion = GetDeletedTransformerId(definition.Name);
                definition.TransformerVersion = (definition.TransformerVersion ?? 0) + 1;
            }

            if (definition.TransformerVersion == null)
                definition.TransformerVersion = 0;

            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,
                Version = definition.TransformerVersion
            }));

            return name;
        }