/// <summary>
        /// Create Host for MA environment when MA has been installed
        /// </summary>
        /// <returns></returns>
        private IHost CreateHostForMAInstalled()
        {
            var compilationCachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "MessageAnalyzer", "CompilationCache");
            var codecCachePath       = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "MessageAnalyzer", "CodecCache");

            //Create and register a host
            SimpleHost         host         = new SimpleHost();
            SimpleModelManager modelManager = new SimpleModelManager(compilationCachePath);

            host.SetModelManager(modelManager);

            new CoreTechnology(StandardStages.Runtime).Register(host);
            new RuntimeTechnology().Register(host);
            new OPNTechnology().Register(host);
            new CompilerTechnology().Register(host);

            var ext = new ExtensionContainer(PlatformManager.ExtensionsDirectory);

            foreach (var tech in ext.technologies)
            {
                tech.Register(host);
            }

            var runtimeProps = host.GetService <RuntimeProperties>();

            runtimeProps.AssemblyCachePath = compilationCachePath;

            var compilerProps = host.GetService <CompilerProperties>();

            compilerProps.CodecCacheFolder = codecCachePath;

            host.EndRegistration();
            return(host);
        }
Esempio n. 2
0
        public async Task RefreshWrapperExtension()
        {
            var cacheStackMock     = new Mock <ICacheStack>();
            var refreshWrapperMock = new Mock <IRefreshWrapperExtension>();
            var container          = new ExtensionContainer(new[] { refreshWrapperMock.Object });

            container.Register(cacheStackMock.Object);

            var cacheEntry = new CacheEntry <int>(1, TimeSpan.FromDays(1));

            var refreshedValue = await container.RefreshValueAsync("WrapperTestCacheKey", () =>
            {
                return(new ValueTask <CacheEntry <int> >(cacheEntry));
            }, new CacheSettings(TimeSpan.FromDays(1)));

            refreshWrapperMock.Verify(e => e.Register(cacheStackMock.Object), Times.Once);
            refreshWrapperMock.Verify(e => e.RefreshValueAsync(
                                          "WrapperTestCacheKey",
                                          It.IsAny <Func <ValueTask <CacheEntry <int> > > >(), new CacheSettings(TimeSpan.FromDays(1))
                                          ),
                                      Times.Once
                                      );

            await DisposeOf(container);
        }
        /// <summary>
        /// Create Host for MA environment
        /// </summary>
        /// <returns></returns>
        private IHost CreateHost()
        {
            string modelCachePath = PlatformManager.DefaultModelCompilationCacheDirectory;
            string codecCachePath = Path.Combine(PlatformManager.BaseDirectory, "CodecCache");
            //Create and register a host
            var host = new SimpleHost();
            SimpleModelManager modelManager = new SimpleModelManager(modelCachePath);

            host.SetModelManager(modelManager);
            new RuntimeTechnology().Register(host);
            new CoreTechnology().Register(host);
            new OPNTechnology().Register(host);
            new CompilerTechnology().Register(host);
            // host.RegisterService(new CertificateStore());

            var ext = new ExtensionContainer(PlatformManager.ExtensionsDirectory);

            foreach (var tech in ext.technologies)
            {
                tech.Register(host);
            }

            var runtimeProps = host.GetService <RuntimeProperties>();

            runtimeProps.AssemblyCachePath = modelCachePath;
            var compilerProps = host.GetService <CompilerProperties>();

            compilerProps.CodecCacheFolder = codecCachePath;

            host.EndRegistration();
            return(host);
        }
Esempio n. 4
0
        public CacheStack(ICacheLayer[] cacheLayers, ICacheExtension[] extensions)
        {
            if (cacheLayers == null || cacheLayers.Length == 0)
            {
                throw new ArgumentException("There must be at least one cache layer", nameof(cacheLayers));
            }

            CacheLayers = cacheLayers;

            Extensions = new ExtensionContainer(extensions);
            Extensions.Register(this);

            WaitingKeyRefresh = new Dictionary <string, IEnumerable <TaskCompletionSource <object> > >(StringComparer.Ordinal);
        }
Esempio n. 5
0
        public void IndexDirectory(string path, HashSet <string> ignoredDirectories, ExtensionContainer extensionContainer)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return;
            }

            try
            {
                var traverseDirectoriesWatch = Stopwatch.StartNew();

                var allFiles = SafeWalk.EnumerateFiles(path, ignoredDirectories);

                var paths = allFiles
                            .Where(x => extensionContainer.IsKnownExtension(Path.GetExtension(x)))
                            .Distinct()
                            .ToArray();

                traverseDirectoriesWatch.Stop();

                var indexWatch = Stopwatch.StartNew();

                try
                {
                    _lock.EnterWriteLock();
                    _indexData.Update(path, paths);
                    SaveIndex();
                }
                finally
                {
                    _lock.ExitWriteLock();
                }

                indexWatch.Stop();

                var traverseMs = traverseDirectoriesWatch.ElapsedMilliseconds;
                var indexMs    = indexWatch.ElapsedMilliseconds;
                var totalMs    = indexWatch.ElapsedMilliseconds + traverseDirectoriesWatch.ElapsedMilliseconds;

                Log.Information($"Index {path} - {paths.Length} items. [ {totalMs} ms, tra: {traverseMs} ms, idx: {indexMs} ms ]");
            }
            catch (Exception e)
            {
                Log.Error(e, "Failed to index path: {path}, message: {message}", path, e.Message);
            }
        }
Esempio n. 6
0
        public async Task ValueRefreshExtension()
        {
            var cacheStackMock   = new Mock <ICacheStack>();
            var valueRefreshMock = new Mock <IValueRefreshExtension>();
            var container        = new ExtensionContainer(new[] { valueRefreshMock.Object });

            container.Register(cacheStackMock.Object);

            await container.OnValueRefreshAsync("ValueRefreshTestCacheKey", TimeSpan.FromDays(1));

            valueRefreshMock.Verify(e => e.Register(cacheStackMock.Object), Times.Once);
            valueRefreshMock.Verify(e =>
                                    e.OnValueRefreshAsync("ValueRefreshTestCacheKey", TimeSpan.FromDays(1)),
                                    Times.Once
                                    );

            await DisposeOf(container);
        }
Esempio n. 7
0
        public async Task CacheChangeExtension_Flush()
        {
            var cacheStackMock   = new Mock <ICacheStack>();
            var valueRefreshMock = new Mock <ICacheChangeExtension>();

            await using var container = new ExtensionContainer(new[] { valueRefreshMock.Object });

            container.Register(cacheStackMock.Object);

            var expiry = DateTime.UtcNow.AddDays(1);

            await container.OnCacheFlushAsync();

            valueRefreshMock.Verify(e => e.Register(cacheStackMock.Object), Times.Once);
            valueRefreshMock.Verify(e =>
                                    e.OnCacheFlushAsync(),
                                    Times.Once
                                    );
        }
Esempio n. 8
0
File: k.cs Progetto: webrot/Kooboo
 public object this[string key] {
     get { return(ExtensionContainer.Get(key, RenderContext)); } set { ExtensionContainer.Set(value); }
 }
Esempio n. 9
0
 public IkScript this[string key] {
     get { return(ExtensionContainer.Get(key, RenderContext) as IkScript); } set { ExtensionContainer.Set(value); }
 }
Esempio n. 10
0
 public async Task AcceptsEmptyExtensions()
 {
     await using var container = new ExtensionContainer(Array.Empty <ICacheExtension>());
 }
Esempio n. 11
0
 public async Task AcceptsNullExtensions()
 {
     await using var container = new ExtensionContainer(null);
 }
Esempio n. 12
0
        /// <summary>
        /// Constructor. Spawn a new bot instance
        /// </summary>
        /// <param name="config">Configuration object</param>
        public Bot(Config config, string host, int port)
        {
            // Initialize the wait handler
            //wait_event = new ManualResetEvent(false);

            // Assign the config to our class variable
            this.Config = config;

            // Check if the authtoken stored is empty
            if (String.IsNullOrWhiteSpace(Config.Authtoken))
            {
                ConIO.Write("We don't have an authtoken. Grabbing one...");
                Config.Authtoken = AuthToken.Grab(Config.Username, Config.Password);

                if (String.IsNullOrWhiteSpace(Config.Authtoken))
                {
                    ConIO.Write("Invalid username or password! Deleting config...");
                    System.IO.File.Delete(@"./Config.dat");
                    Program.Running = false;
                    Program.wait_event.Set();
                    return;
                }
                else
                {
                    ConIO.Write("Got an authtoken!");
                    Config.Save("Config.dat");
                }
            }

            // Make sure events are clear.
            Events.ClearEvents();

            // Initialize the Core extensions
            Core        = new Core();
            BDS         = new BDS();
            Logger      = new Logger();
            Extensions  = new ExtensionContainer();
            Users       = new Users(this.Config.Owner);
            Colors      = new Colors();
            AI          = new AI();

            // Now, let's initialize the socket.
            Socket      = new SocketWrapper();
            Socket.Connect(host, port);

            can_loop = true;

            // Start a new thread for our MainLoop method
            _loop_thread = new Thread(new ThreadStart(MainLoop));
            _loop_thread.IsBackground = false;
            _loop_thread.Start();
        }
Esempio n. 13
0
        public async Task AcceptsEmptyExtensions()
        {
            var container = new ExtensionContainer(Array.Empty <ICacheExtension>());

            await DisposeOf(container);
        }
Esempio n. 14
0
        public async Task AcceptsNullExtensions()
        {
            var container = new ExtensionContainer(null);

            await DisposeOf(container);
        }
Esempio n. 15
0
 public static void SetConfig(JsonUserConfiguration config)
 {
     _paths = config.Paths;
     _ignoredDirectories = new HashSet <string>(config.IgnoredDirectories);
     _extensionContainer = new ExtensionContainer(config.Extensions.Select(x => new ExtensionInfo(x)));
 }
Esempio n. 16
0
 public DirectoryTraverser()
 {
     //_extensionContainer = new ExtensionReader().ReadRegistry();
     _extensionContainer = new ExtensionContainer(new ExtensionInfo[0]);
 }