예제 #1
0
        public RavenFileSystem(InMemoryRavenConfiguration config, string name, TransportState receivedTransportState = null)
        {
            ExtensionsState = new AtomicDictionary <object>();

            Name          = name;
            ResourceName  = string.Concat(Constants.FileSystem.UrlPrefix, "/", name);
            configuration = config;

            try
            {
                ValidateStorage();

                configuration.Container.SatisfyImportsOnce(this);

                transportState = receivedTransportState ?? new TransportState();

                storage = CreateTransactionalStorage(configuration);

                sigGenerator    = new SigGenerator();
                fileLockManager = new FileLockManager();

                BufferPool       = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
                conflictDetector = new ConflictDetector();
                conflictResolver = new ConflictResolver(storage, new CompositionContainer(configuration.Catalog));

                notificationPublisher = new NotificationPublisher(transportState);
                synchronizationTask   = new SynchronizationTask(storage, sigGenerator, notificationPublisher, configuration);

                metricsCounters = new MetricsCountersManager();

                search = new IndexStorage(name, configuration);

                conflictArtifactManager = new ConflictArtifactManager(storage, search);

                TimerManager = new ResourceTimerManager();

                Tasks            = new TaskActions(this, Log);
                Files            = new FileActions(this, Log);
                Synchronizations = new SynchronizationActions(this, Log);

                AppDomain.CurrentDomain.ProcessExit  += ShouldDispose;
                AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
            }
            catch (Exception e)
            {
                Log.ErrorException(string.Format("Could not create file system '{0}'", Name ?? "unknown name"), e);
                try
                {
                    Dispose();
                }
                catch (Exception ex)
                {
                    Log.FatalException("Failed to dispose when already getting an error in file system ctor", ex);
                }
                throw;
            }
        }
예제 #2
0
 public static EditorTaskInfo DoEditorTask( String title, TaskActions _taskList, bool breakIfException = false ) {
     if ( _taskList == null || _taskList.Count == 0 ) {
         return null;
     }
     title = title ?? "unknown editor task";
     var taskInfo = new EditorTaskInfo( title );
     EditorApplication.CallbackFunction tick = null;
     // we handle task item from the end of list
     _taskList.Reverse();
     int totalTaskCount = _taskList.Count;
     taskInfo._breakIfException = breakIfException;
     taskInfo._totalTaskCount = totalTaskCount;
     if ( totalTaskCount > 0 ) {
         taskInfo._taskList = _taskList;
         EditorTaskInfo._allTasks.Add( taskInfo );
         tick = () => {
             if ( _taskList.Count > 0 ) {
                 var item = _taskList[ _taskList.Count - 1 ];
                 _taskList.RemoveAt( _taskList.Count - 1 );
                 taskInfo._curTaskCount = _taskList.Count;
                 taskInfo._curTask = item.name;
                 Debug.LogFormat( "DoEditorTask: {0}", item.name );
                 if ( EditorUtility.DisplayCancelableProgressBar( title, item.name, ( totalTaskCount - _taskList.Count ) / ( float )totalTaskCount ) ) {
                     _taskList.RemoveAll( _e => _e.breakAble );
                     return;
                 }
                 try {
                     if ( item.action != null ) {
                         item.action();
                     }
                 } catch ( Exception e ) {
                     if ( taskInfo._breakIfException ) {
                         _taskList.RemoveAll( _e => _e.breakAble );
                     }
                     Debug.LogErrorFormat( "Process {0} failed: {1}", item.name, e.ToString() );
                 }
             } else {
                 EditorApplication.update -= tick;
                 taskInfo._isWorking = false;
                 taskInfo._totalTaskCount = 0;
                 taskInfo._curTask = String.Empty;
                 EditorUtility.ClearProgressBar();
                 if ( taskInfo._curTaskCount == 0 ) {
                     Debug.LogFormat( title + " done. total: {0}", totalTaskCount );
                 } else {
                     Debug.LogFormat( title + " canceled. total: {0}, done:{1}, remain: {2}", totalTaskCount, ( totalTaskCount - taskInfo._curTaskCount ), taskInfo._curTaskCount );
                 }
                 taskInfo._done = true;
                 taskInfo._curTaskCount = 0;
                 EditorTaskInfo._allTasks.Remove( taskInfo );
             }
         };
         EditorApplication.update += tick;
     }
     return taskInfo;
 }
        public static int Run()
        {
            var mainTask = Task.Run(TaskActions.MainTaskAction);

            var child = mainTask
                        .ContinueWith(_ => TaskActions.ContinuationTaskAction());

            child.GetAwaiter().GetResult();

            return(0);
        }
        public static int Run()
        {
            var cts = new CancellationTokenSource();

            var token    = cts.Token;
            var mainTask = Task.Run(() => TaskActions.MainTaskAction(token), token);

            Thread.Sleep(700);
            cts.Cancel();

            mainTask
            .ContinueWith(
                _ => TaskActions.ContinuationTaskAction(),
                TaskContinuationOptions.NotOnRanToCompletion);

            mainTask.GetAwaiter().GetResult();

            return(0);
        }
예제 #5
0
        public static int Run()
        {
            var cts = new CancellationTokenSource();

            var token    = cts.Token;
            var mainTask = Task.Run(() => TaskActions.MainTaskAction(token), token);

            Thread.Sleep(500);
            cts.Cancel();

            mainTask
            .ContinueWith(
                _ => TaskActions.ContinuationTaskAction(),
                TaskContinuationOptions.OnlyOnCanceled |
                TaskContinuationOptions.RunContinuationsAsynchronously);

            mainTask.GetAwaiter().GetResult();

            return(0);
        }
예제 #6
0
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)
                   .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.AddJsonFile("appsettings.json", optional: true, true);
                config.AddEnvironmentVariables();

                if (args != null)
                {
                    config.AddCommandLine(args);
                }
            })
                   .ConfigureServices((hostContext, services) =>
            {
                services.AddOptions();
                var nLogConfig = hostContext.Configuration.GetSection("NLog");
                LogManager.Configuration = new NLogLoggingConfiguration(nLogConfig);
                ILogger logger = LogManager.GetCurrentClassLogger();
                services.AddSingleton(logger);
                services.Configure <AlgorithmServiceConfige>(hostContext.Configuration.GetSection("AlgorithmServiceConfige"));
                var dataProvider = hostContext.Configuration.GetSection("DataProvider").Get <DataProvider>();
                IMapper mapper = DownloaderProvider.AutoMapperConfiguration.Configure().CreateMapper();
                IServiceActions serviceActions = new ServiceActions(dataProvider.KarmaDownloader, mapper);
                ITaskActions taskActions = new TaskActions(dataProvider.KarmaDownloader, mapper);
                IMapper cbrDownloaderMapper = CbrDownloader.AutoMapperConfiguration.Configure().CreateMapper();
                ICbrDownloader cbrDownloader = new CbrProvider(logger, cbrDownloaderMapper);
                IMapper moexMapper = MoexProvider.AutoMapperConfiguration.Configure().CreateMapper();
                IMoexDownloader moexDownloader = new MoexDownloader(moexMapper, logger);
                IXmlSaver xmlSaver = new XmlSaver.XmlSaver();
                ICsvSaver csvSaver = new CsvSaver.CsvSaver();
                IConverterFactory converterFactory = new ConverterFactory();
                IMapper saverMurrMapper = SaverMurrData.AutoMapperConfiguration.Configure().CreateMapper();
                ISaverMurrData saverMurrData = new SaverMurrProvider(logger, saverMurrMapper, dataProvider.KarmaSaver);
                ICalculationFactory calculationFactory = new CalculationFactory(logger, taskActions, cbrDownloader, moexDownloader, xmlSaver, csvSaver, converterFactory, saverMurrData);
                services.AddSingleton <IAlgorithmServiceProvider>(new AlgorithmServiceProvider(taskActions, serviceActions, logger, calculationFactory));
                var schedulerMapper = DownloaderProvider.AutoMapperConfiguration.Configure().CreateMapper();
                services.AddSingleton <IServiceActions>(new ServiceActions(dataProvider.KarmaDownloader, schedulerMapper));
                services.AddHostedService <Worker>();
            }).UseWindowsService());
        }
예제 #7
0
        public DocumentDatabase(InMemoryRavenConfiguration configuration, TransportState transportState = null)
        {
            DocumentLock        = new PutSerialLock();
            Name                = configuration.DatabaseName;
            Configuration       = configuration;
            this.transportState = transportState ?? new TransportState();
            ExtensionsState     = new AtomicDictionary <object>();

            using (LogManager.OpenMappedContext("database", Name ?? Constants.SystemDatabase))
            {
                Log.Debug("Start loading the following database: {0}", Name ?? Constants.SystemDatabase);

                initializer = new DocumentDatabaseInitializer(this, configuration);

                initializer.InitializeEncryption();
                initializer.ValidateLicense();

                initializer.SubscribeToDomainUnloadOrProcessExit();
                initializer.ExecuteAlterConfiguration();
                initializer.SatisfyImportsOnce();

                backgroundTaskScheduler = configuration.CustomTaskScheduler ?? TaskScheduler.Default;


                recentTouches = new SizeLimitedConcurrentDictionary <string, TouchedDocumentInfo>(configuration.MaxRecentTouchesToRemember, StringComparer.OrdinalIgnoreCase);

                configuration.Container.SatisfyImportsOnce(this);

                workContext = new WorkContext
                {
                    Database            = this,
                    DatabaseName        = Name,
                    IndexUpdateTriggers = IndexUpdateTriggers,
                    ReadTriggers        = ReadTriggers,
                    TaskScheduler       = backgroundTaskScheduler,
                    Configuration       = configuration,
                    IndexReaderWarmers  = IndexReaderWarmers
                };

                try
                {
                    uuidGenerator = new SequentialUuidGenerator();
                    initializer.InitializeTransactionalStorage(uuidGenerator);
                    lastCollectionEtags = new LastCollectionEtags(TransactionalStorage, WorkContext);
                }
                catch (Exception)
                {
                    if (TransactionalStorage != null)
                    {
                        TransactionalStorage.Dispose();
                    }
                    throw;
                }

                try
                {
                    TransactionalStorage.Batch(actions => uuidGenerator.EtagBase = actions.General.GetNextIdentityValue("Raven/Etag"));

                    // Index codecs must be initialized before we try to read an index
                    InitializeIndexCodecTriggers();
                    initializer.InitializeIndexStorage();

                    Attachments   = new AttachmentActions(this, recentTouches, uuidGenerator, Log);
                    Documents     = new DocumentActions(this, recentTouches, uuidGenerator, Log);
                    Indexes       = new IndexActions(this, recentTouches, uuidGenerator, Log);
                    Maintenance   = new MaintenanceActions(this, recentTouches, uuidGenerator, Log);
                    Notifications = new NotificationActions(this, recentTouches, uuidGenerator, Log);
                    Patches       = new PatchActions(this, recentTouches, uuidGenerator, Log);
                    Queries       = new QueryActions(this, recentTouches, uuidGenerator, Log);
                    Tasks         = new TaskActions(this, recentTouches, uuidGenerator, Log);
                    Transformers  = new TransformerActions(this, recentTouches, uuidGenerator, Log);

                    inFlightTransactionalState = TransactionalStorage.GetInFlightTransactionalState(Documents.Put, Documents.Delete);

                    CompleteWorkContextSetup();

                    prefetcher       = new Prefetcher(workContext);
                    indexingExecuter = new IndexingExecuter(workContext, prefetcher);

                    RaiseIndexingWiringComplete();

                    InitializeTriggersExceptIndexCodecs();
                    SecondStageInitialization();
                    ExecuteStartupTasks();
                    lastCollectionEtags.Initialize();

                    Log.Debug("Finish loading the following database: {0}", configuration.DatabaseName ?? Constants.SystemDatabase);
                }
                catch (Exception)
                {
                    Dispose();
                    throw;
                }
            }
        }