Beispiel #1
0
 public IndexWorker(
     ProcessorSettings settings,
     ParallelBackgroundContext context,
     BackgroundWorks works,
     DbHelper dbHelper)
     : base(settings.ElasticSearchClientSettings, works, dbHelper)
 {
     _settings = settings;
     _context  = context;
 }
Beispiel #2
0
        public void StartProcess(string path, ProcessorSettings settings)
        {
            Output.PrintMethod = this.Print;

            this.path = path;
            this.sett = settings;

            System.Threading.ThreadStart ts = new System.Threading.ThreadStart(this.Run);
            System.Threading.Thread      t  = new System.Threading.Thread(ts);
            t.Start();
        }
Beispiel #3
0
        public void InitializeProvider()
        {
            string moduleCode;
            using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Ancestry.QueryProcessor.Sql.Test.Module.dql")))
                moduleCode = reader.ReadToEnd();

            var settings = new ProcessorSettings();
            settings.RepositoryFactory = new SqlFactory("System.Data.SqlServerCe.4.0", "Data Source=TestDB.sdf;Persist Security Info=False;");
            _processor = new Processor(settings);
            _processor.Execute(moduleCode);
        }
        /// <summary>
        /// In order to terminate long running templates, we add timeout setting to DotLiquid rendering context,
        /// which throws a Timeout Exception when render process elapsed longer than timeout threshold.
        /// Reference: https://github.com/dotliquid/dotliquid/blob/master/src/DotLiquid/Context.cs
        /// </summary>
        private void InitializeConvertProcessors()
        {
            var processorSetting = new ProcessorSettings
            {
                TimeOut = (int)_convertDataConfiguration.OperationTimeout.TotalMilliseconds,
            };

            _converterMap.Add(DataType.Hl7v2, new Hl7v2Processor(processorSetting));
            _converterMap.Add(DataType.Ccda, new CcdaProcessor(processorSetting));
            _converterMap.Add(DataType.Json, new JsonProcessor(processorSetting));
        }
Beispiel #5
0
        public PartitionExceptionsTests()
        {
            processorSettings = new ProcessorSettings
            {
                CollectionSelfLink  = "selfLink",
                FeedPollDelay       = TimeSpan.FromMilliseconds(16),
                MaxItemCount        = 5,
                PartitionKeyRangeId = "keyRangeId",
                RequestContinuation = "initialToken"
            };

            var document = new Document();

            documents = new List <Document> {
                document
            };

            feedResponse = Mock.Of <IFeedResponse <Document> >();
            Mock.Get(feedResponse)
            .Setup(response => response.Count)
            .Returns(documents.Count);
            Mock.Get(feedResponse)
            .Setup(response => response.ResponseContinuation)
            .Returns("token");
            Mock.Get(feedResponse)
            .Setup(response => response.GetEnumerator())
            .Returns(documents.GetEnumerator());

            documentQuery = Mock.Of <IChangeFeedDocumentQuery <Document> >();
            Mock.Get(documentQuery)
            .Setup(query => query.HasMoreResults)
            .Returns(false);

            docClient = Mock.Of <IChangeFeedDocumentClient>();
            Mock.Get(docClient)
            .Setup(ex => ex.CreateDocumentChangeFeedQuery(processorSettings.CollectionSelfLink, It.IsAny <ChangeFeedOptions>()))
            .Returns(documentQuery);

            observer = Mock.Of <IChangeFeedObserver>();
            Mock.Get(observer)
            .Setup(feedObserver => feedObserver
                   .ProcessChangesAsync(It.IsAny <ChangeFeedObserverContext>(), It.IsAny <IReadOnlyList <Document> >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(false))
            .Callback(cancellationTokenSource.Cancel);

            var checkPointer = new Mock <IPartitionCheckpointer>();

            partitionProcessor = new PartitionProcessor(observer, docClient, processorSettings, checkPointer.Object);
        }
Beispiel #6
0
        public PartitionProcessorTests()
        {
            processorSettings = new ProcessorSettings
            {
                CollectionSelfLink  = "selfLink",
                FeedPollDelay       = TimeSpan.FromMilliseconds(16),
                MaxItemCount        = 5,
                PartitionKeyRangeId = "keyRangeId",
                StartContinuation   = "initialToken"
            };

            var document = new Document();

            documents = new List <Document> {
                document
            };

            feedResponse = Mock.Of <IFeedResponse <Document> >();
            Mock.Get(feedResponse)
            .Setup(response => response.Count)
            .Returns(documents.Count);
            Mock.Get(feedResponse)
            .Setup(response => response.ResponseContinuation)
            .Returns("token");
            Mock.Get(feedResponse)
            .Setup(response => response.GetEnumerator())
            .Returns(documents.GetEnumerator());

            documentQuery = Mock.Of <IChangeFeedDocumentQuery <Document> >();
            Mock.Get(documentQuery)
            .Setup(query => query.HasMoreResults)
            .Returns(false);

            Mock.Get(documentQuery)
            .Setup(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token)))
            .ReturnsAsync(() => feedResponse)
            .Callback(() => cancellationTokenSource.Cancel());

            observer = Mock.Of <IChangeFeedObserver>();
            var checkPointer = new Mock <IPartitionCheckpointer>();

            sut = new PartitionProcessor(
                new ObserverExceptionWrappingChangeFeedObserverDecorator(observer),
                documentQuery,
                new ChangeFeedOptions(),
                processorSettings,
                checkPointer.Object);
        }
Beispiel #7
0
        private static ProcessorSettings GetSettings()
        {
            var configuration = (QueryConfiguration)ConfigurationManager.GetSection("query");
            if (configuration == null)
                throw new Exception("'query' configuration section not configured.");

            var factoryType = System.Type.GetType(configuration.FactoryClass);
            var factory = (IRepositoryFactory)Activator.CreateInstance(factoryType);

            var settings = new ProcessorSettings { RepositoryFactory = factory };

            for (int i = 0; i < configuration.DefaultUsings.Count; i++)
            {
                var u = configuration.DefaultUsings[i];
                settings.DefaultOptions.DefaultUsings.Add(new Parse.Using { Target = Name.FromNative(u.Name).ToQualifiedIdentifier(), Version = Version.Parse(u.Version) });
            }

            // TODO: load more settings from configuration
            return settings;
        }
Beispiel #8
0
 public ProductsController(ProcessorSettings settings)
 {
     _settings = settings;
 }
Beispiel #9
0
 public InternalExternalProcessor(ProcessorSettings settings)
     : base(settings)
 {
     InternalHandler = settings.InternalHandler as InternalHandler;
     ExternalHandler = settings.InternalHandler as ExternalHandler;
 }
Beispiel #10
0
 /// <summary>
 /// Creates a new type visitor with the given settings
 /// </summary>
 /// <param name="settings">The processing settings</param>
 public TypeVisitor(ProcessorSettings settings)
 {
     TypeCollection = new ExtractedTypeCollection(settings);
 }
        /// <summary>
        /// Generates the scripts
        /// </summary>
        /// <returns>The script generation result</returns>
        public ScriptGenerationResult GenerateScripts(ScriptGenerationParameters parameters)
        {
            string        projectPath   = parameters.ProjectPath;
            ConfigOptions configOptions = ConfigParser.GetForProject(parameters.ProjectPath);

            if (parameters.TypeIterator == null)
            {
                return(new ScriptGenerationResult(false, $"A {typeof(ITypeIterator).Name} was not provided"));
            }

            if (configOptions == null || (!configOptions.Enabled && !parameters.Force))
            {
                return(new ScriptGenerationResult(false, $"Script generation is disabled in the configuration options."));
            }

            if (string.IsNullOrEmpty(configOptions.ServerObjectsResultFilepath))
            {
                return(new ScriptGenerationResult(false, "ResultFilePath is not specified in the configuration options."));
            }

            Uri projUri = new Uri(projectPath);

            Uri resultRelative;

            try
            {
                resultRelative = new Uri(configOptions.ServerObjectsResultFilepath, UriKind.RelativeOrAbsolute);
            }
            catch (UriFormatException)
            {
                return(new ScriptGenerationResult(false, "ResultFilePath is not in a valid format."));
            }

            Uri      resultAbsolute = resultRelative.IsAbsoluteUri ? resultRelative : new Uri(projUri, resultRelative);
            FileInfo fi             = new FileInfo(resultAbsolute.LocalPath);

            if (!fi.Directory.Exists)
            {
                return(new ScriptGenerationResult(false, $"The directory in ResultFilePath of the config file ({fi.Directory.FullName}) does not exist."));
            }

            ProcessorSettings processorSettings = new ProcessorSettings()
            {
                DefaultResultPath = resultAbsolute.LocalPath,
                ProjectPath       = projUri.LocalPath,
                NamingStrategy    = NamingStrategy.Create(configOptions.NameCasingConverter)
            };

            // At this point we are good
            TypeVisitor visitor = new TypeVisitor(processorSettings);

            parameters.TypeIterator.IterateTypes(visitor);

            ExtractedTypeCollection typeCollection        = visitor.TypeCollection;
            ScriptTemplateFactory   scriptTemplateFactory = new ScriptTemplateFactory(configOptions);

            // Write the object script text
            foreach (var typeGroup in typeCollection.GroupBy(t => t.TargetPath))
            {
                TypeWriteContext scriptContext = new TypeWriteContext(
                    typeGroup,
                    typeCollection,
                    typeGroup.Key
                    );

                var    typeTemplate = scriptTemplateFactory.CreateTypeTextTemplate();
                string scriptText   = typeTemplate.GetText(scriptContext);
                File.WriteAllText(typeGroup.Key, scriptText);
            }

            // Write MVC controllers
            FetchFunctionResolver fetchResolver = FetchFunctionResolver.FromConfig(projUri, configOptions);

            foreach (var controllerGroup in typeCollection.GetMvcControllers().GroupBy(c => c.ResultPath))
            {
                ControllerContext context = new ControllerContext(
                    controllerGroup,
                    controllerGroup.Key,
                    typeCollection,
                    fetchResolver
                    );

                var    controllerTemplate = scriptTemplateFactory.CreateControllerTextTemplate(context);
                string controllerScript   = controllerTemplate.GetText();
                File.WriteAllText(context.OutputPath, controllerScript);
            }

            return(new ScriptGenerationResult(true, null));
        }
Beispiel #12
0
 public BrandWorker(ProcessorSettings settings, BackgroundWorks works, DbHelper dbHelper)
     : base(settings.ElasticSearchClientSettings, works, dbHelper)
 {
     _settings = settings;
 }
Beispiel #13
0
        private static void Main(string[] args)
        {
#if DEBUG
            Console.WriteLine("DEBUG MODE ENABLED");
            args = new[] { "externalName" };
#endif
            var tasks = new List <Task>();
            var exes  = new ConcurrentBag <Exception>();


            foreach (var arg in args)
            {
                switch (arg.ToLower())
                {
                case "externalName":
                    tasks.Add(Task.Run(() =>
                    {
                        try
                        {
                            var settings = new ProcessorSettings
                            {
                                InternalHandler = new InternalHandler(),
                                ExternalHandler = new ExternalHandler()
                            };
                            using (var processor = new InternalExternalProcessor(settings))
                            {
                                processor.ProcessAll();
                            }
                        }
                        catch (Exception ex)
                        {
                            exes.Add(ex);
#if DEBUG
                            Debugger.Break();
#endif
                        }
                    }
                                       ));
                    break;

                case "otherOption":
                    tasks.Add(Task.Run(() =>
                    {
                        try
                        {
                            var settings = new ProcessorSettings
                            {
                                InternalHandler = new InternalHandler(),
                                ExternalHandler = new OtherOptionHandler()
                            };
                            using (var processor = new OtherOptionProcessor(settings))
                            {
                                processor.ProcessAll();
                            }
                        }
                        catch (Exception ex)
                        {
                            exes.Add(ex);
#if DEBUG
                            Debugger.Break();
#endif
                        }
                    }
                                       ));
                    break;
                }
            }
            Task.WaitAll(tasks.ToArray());
            if (exes.Any())
            {
                var ex = new AggregateException("Default sync error catcher", exes);
#if DEBUG
                Debugger.Break();
#else
                //handle error;
#endif
            }
#if DEBUG
            Console.WriteLine("Run completed");
            Console.ReadLine();
#endif
        }
Beispiel #14
0
 public OtherOptionProcessor(ProcessorSettings settings)
     : base(settings)
 {
     InternalHandler = settings.InternalHandler as InternalHandler;
     ExternalHandler = settings.InternalHandler as OtherOptionHandler;
 }
        /// <summary>
        /// Generates the scripts
        /// </summary>
        /// <returns>The script generation result</returns>
        public IScriptGenerationResult GenerateScripts()
        {
            if (ConfigurationOptions == null || !ConfigurationOptions.Enabled)
            {
                return(new ScriptGenerationResult(false, $"Script generation is disabled in the configuration options."));
            }

            if (string.IsNullOrEmpty(ConfigurationOptions.ServerObjectsResultFilepath))
            {
                return(new ScriptGenerationResult(false, "ResultFilePath is not specified in the configuration options."));
            }

            Uri projUri = new Uri(ProjectPath);

            Uri resultRelative;

            try
            {
                resultRelative = new Uri(ConfigurationOptions.ServerObjectsResultFilepath, UriKind.RelativeOrAbsolute);
            }
            catch (UriFormatException)
            {
                return(new ScriptGenerationResult(false, "ResultFilePath is not in a valid format."));
            }

            Uri      resultAbsolute = resultRelative.IsAbsoluteUri ? resultRelative : new Uri(projUri, resultRelative);
            FileInfo fi             = new FileInfo(resultAbsolute.LocalPath);

            if (!fi.Directory.Exists)
            {
                return(new ScriptGenerationResult(false, $"The directory in ResultFilePath of the config file ({fi.Directory.FullName}) does not exist."));
            }

            // At this point we are good
            ScriptPackage package = CreatePackage();


            ProcessorSettings processorSettings = new ProcessorSettings()
            {
                TypeNamespace = ConfigurationOptions.ClassNamespace,
                EnumNamespace = ConfigurationOptions.EnumNamespace
            };

            if (!string.IsNullOrEmpty(ConfigurationOptions.MvcActionAttributeName))
            {
                processorSettings.MvcActionFilter = new IsOfTypeFilter(ConfigurationOptions.MvcActionAttributeName);
            }

            ExtractedTypeCollection typeCollection = new ExtractedTypeCollection(package, processorSettings);
            IScriptTemplate         scriptGen      = ScriptTemplateFactory.GetTemplate(ConfigurationOptions.TemplateType);

            // Write the object script text
            string scriptText = scriptGen.CreateTypeTemplate().GetText(typeCollection);

            File.WriteAllText(resultAbsolute.LocalPath, scriptText);

            // Write MVC controllers
            Uri ajaxModuleUri         = string.IsNullOrEmpty(ConfigurationOptions.AjaxFunctionModulePath) ? null : new Uri(projUri, ConfigurationOptions.AjaxFunctionModulePath);
            ControllerContext context = new ControllerContext()
            {
                ServerObjectsResultFilepath = new Uri(resultAbsolute.LocalPath),
                AjaxFunctionName            = ConfigurationOptions.AjaxFunctionName,
                WebMethodNamespace          = ConfigurationOptions.WebMethodNamespace,
                ExtractedTypes         = typeCollection,
                AjaxFunctionModulePath = ajaxModuleUri
            };

            foreach (MvcControllerInfo controller in typeCollection.GetMvcControllers())
            {
                string outputPath       = GetControllerResultPath(controller);
                string controllerScript = scriptGen.CreateControllerTextTemplate().GetText(controller, context, new Uri(outputPath));
                File.WriteAllText(outputPath, controllerScript);
            }

            return(new ScriptGenerationResult(true, null));
        }
Beispiel #16
0
        public PartitionChainingTests()
        {
            processorSettings = new ProcessorSettings
            {
                CollectionSelfLink  = "selfLink",
                MaxItemCount        = 5,
                FeedPollDelay       = TimeSpan.FromMilliseconds(16),
                PartitionKeyRangeId = "keyRangeId",
                RequestContinuation = "initialToken"
            };

            var document = new Document();

            batch1 = new List <Document> {
                document
            };

            document = new Document();
            batch2   = new List <Document> {
                document
            };

            feedResponse1 = Mock.Of <IFeedResponse <Document> >();
            Mock.Get(feedResponse1)
            .Setup(response => response.Count)
            .Returns(batch1.Count);
            Mock.Get(feedResponse1)
            .SetupSequence(response => response.ResponseContinuation)
            .Returns("token1");
            Mock.Get(feedResponse1)
            .SetupSequence(response => response.GetEnumerator())
            .Returns(batch1.GetEnumerator());

            feedResponse2 = Mock.Of <IFeedResponse <Document> >();
            Mock.Get(feedResponse2)
            .Setup(response => response.Count)
            .Returns(batch2.Count);
            Mock.Get(feedResponse2)
            .SetupSequence(response => response.ResponseContinuation)
            .Returns("token2");
            Mock.Get(feedResponse2)
            .SetupSequence(response => response.GetEnumerator())
            .Returns(batch2.GetEnumerator());

            documentQuery = Mock.Of <IChangeFeedDocumentQuery <Document> >();
            Mock.Get(documentQuery)
            .SetupSequence(query => query.HasMoreResults)
            .Returns(true)
            .Returns(false);

            Mock.Get(documentQuery)
            .SetupSequence(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token)))
            .Returns(Task.FromResult(feedResponse1))
            .Returns(Task.FromResult(feedResponse2));

            docClient = Mock.Of <IChangeFeedDocumentClient>();
            Mock.Get(docClient)
            .Setup(ex => ex.CreateDocumentChangeFeedQuery(processorSettings.CollectionSelfLink, It.IsAny <ChangeFeedOptions>()))
            .Returns(documentQuery);

            observer = Mock.Of <IChangeFeedObserver>();
            var checkPointer = new Mock <IPartitionCheckpointer>();

            partitionProcessor = new PartitionProcessor(observer, docClient, processorSettings, checkPointer.Object);

            var i = 0;

            Mock.Get(observer)
            .Setup(feedObserver => feedObserver
                   .ProcessChangesAsync(It.IsAny <ChangeFeedObserverContext>(), It.IsAny <IReadOnlyList <Document> >(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(false))
            .Callback(() =>
            {
                if (++i == 2)
                {
                    cancellationTokenSource.Cancel();
                }
            });
        }
Beispiel #17
0
 public FFMpegWrapper(IOptions <ProcessorSettings> processorSettings,
                      IShellExecutableFactory shellExecutableFactory)
 {
     _options = processorSettings.Value;
     _shellExecutableFactory = shellExecutableFactory;
 }
Beispiel #18
0
 public IndexController(ProcessorSettings settings, BackgroundWorks works, DbHelper dbHelper)
 {
     _works    = works;
     _settings = settings;
     _dbHelper = dbHelper;
 }