Ejemplo n.º 1
0
        public string RegisterStorage(string type, string name)
        {
            var storage = storageFactory.CreateStorage(type, name);

            this.storageRegistry.Add(storage);
            return($"Registered {name}");
        }
Ejemplo n.º 2
0
        public string RegisterStorage(string type, string name)
        {
            Storage storage = storageFactory.CreateStorage(type, name);

            storages.Add(storage);
            return($"Registered {name}");
        }
Ejemplo n.º 3
0
        public string RegisterStorage(string type, string name)
        {
            Storage storage = storageFactory.CreateStorage(type, name);

            this.storages[storage.Name] = storage;
            return($"Registered {storage.Name}");
        }
Ejemplo n.º 4
0
        public void StorageFactory_ShouldThrowException()
        {
            StorageFactory storageFactory = new StorageFactory();

            Assert.Throws <InvalidOperationException>(
                () => storageFactory.CreateStorage("NotExisting", "Name"));
        }
Ejemplo n.º 5
0
        public void TestStorageFactory()
        {
            var fac = new StorageFactory();

            var store = fac.CreateStorage("Warehouse", "Kurax");

            Assert.AreEqual(10, store.Capacity);
        }
Ejemplo n.º 6
0
        public string RegisterStorage(string type, string name)
        {
            Storage storage = storageFactory.CreateStorage(type, name);

            this.storages.Add(storage);

            return(string.Format(Messages.successfulAddedStorageToRegistry, name));
        }
Ejemplo n.º 7
0
        public void CreateStorage_NoParameter_ValidStorage()
        {
            IStorageFactory storageFactory = new StorageFactory();

            IStorage <UnitTestComponent> result = storageFactory.CreateStorage <UnitTestComponent>();

            Assert.NotNull(result);
        }
Ejemplo n.º 8
0
        public void StorageFactory_ShouldWorkCorrectly()
        {
            StorageFactory storageFactory = new StorageFactory();

            Storage storage = storageFactory.CreateStorage("Warehouse", "WHouse");

            Assert.That(typeof(Storage).IsAssignableFrom(storage.GetType()));
        }
        public void ValidStorageFactory()
        {
            StorageFactory storageFactory = new StorageFactory();

            var storage = storageFactory.CreateStorage("Warehouse", "Gosho");

            Assert.AreEqual("Gosho", storage.Name);
        }
Ejemplo n.º 10
0
        public string RegisterStorage(string type, string name)
        {
            Storage storage = storageFactory.CreateStorage(type, name);

            storageRegistry.Add(storage);

            string output = $"Registered {name}";

            return(output);
        }
Ejemplo n.º 11
0
        public string RegisterStorage(string type, string name)
        {
            Storage storage = storageFactory.CreateStorage(type, name);

            this.storages.Add(name, storage);

            string result = $"Registered {name}";

            return(result);
        }
Ejemplo n.º 12
0
        public string RegisterStorage(string type, string name)
        {
            IStorage storage = storageFactory.CreateStorage(type, name);

            //if (storage == null)
            //{
            //    throw new InvalidOperationException("Invalid storage type!");
            //}
            this.storagesRegister.Add(name, storage);
            return($"Registered {storage.Name}");
        }
Ejemplo n.º 13
0
        public void TestIfStorageFactortThrows()
        {
            var fac = new StorageFactory();

            Assert.Throws <InvalidOperationException>(() => fac.CreateStorage("Metro", "Billa"));
        }
        public void TestWarehouseFactoryReturnsTheCorrectNameOfTheWarehouse()
        {
            var storageFactory = new StorageFactory();

            Assert.AreEqual(storageFactory.CreateStorage("Warehouse", "SmartSolutions").Name, "SmartSolutions", "Doesnt return the correct name of the storage place.");
        }
        public void TestWarehouseFactoryReturnsTheCorrectTypeOfVehicle()
        {
            var storageFactory = new StorageFactory();

            Assert.AreEqual(storageFactory.CreateStorage("Warehouse", "SmartSolutions").GetType().Name, typeof(Warehouse).Name, "Doesnt return the correct storage place.");
        }
        public void TestStorageFactoryThrowsExceptionWhenTypeIsNull()
        {
            var storageFactory = new StorageFactory();

            Assert.Throws <InvalidOperationException>(() => storageFactory.CreateStorage(null, "SmartTech"), "Doesnt throw exception when the type is null.");
        }
        public void InvalidStorageFactory()
        {
            StorageFactory storageFactory = new StorageFactory();

            Assert.Throws <InvalidOperationException>(() => storageFactory.CreateStorage("NotARealStorage", "Pesho"));
        }
 public void CreateStorageMethodShouldThrowExceptionIfStorageDoesNotExist(string type, string name)
 {
     Assert.Throws <InvalidOperationException>(() => storageFactory.CreateStorage(type, name));
 }
Ejemplo n.º 19
0
        private static void Main(string[] args)
        {
            IConfigFileClient <JObject, JToken> configFileLocal = new JSONConfigFileClient();

            try
            {
                configFileLocal.Load(MagicStringEnumerator.DefaultLocalConfigPath);
                Log.Instance?.Info($"Configuration file {MagicStringEnumerator.DefaultLocalConfigPath} loaded.");
            }
            catch (Exception ex)
            {
                Log.Instance?.Error($"{MagicStringEnumerator.DefaultLocalConfigPath}: {ex.Message}");
                CleanExit();
            }

            var ip   = configFileLocal.GetAddress();
            var port = configFileLocal.GetPort();

            Log.Instance?.Info($"Server ip: {ip}");
            Log.Instance?.Info($"Server port: {port}");

            AppDomain.CurrentDomain.ProcessExit += (o, e) => { CleanExit(); };

            client = new HalClient(ip, port);
            new Thread(async() => { await client.StartAsync(); }).Start();

            IPluginMaster pluginMaster = new PluginMasterBasePlugin();

            /*
             * The plugin manager will manage and schedule plugins
             *
             * when a plugin need to be executed, PluginManager will launch what the plugin needs and output the result
             * where desired above.
             */
            APluginManager pluginManager = new ScheduledPluginManager(pluginMaster);

            // We only want to configure all the plugins when the client has received all the informations and plugins
            client.OnReceiveDone += async(o, e) =>
            {
                /*
                 * Here we instanciate the configuration file
                 * Its a JSON format file.
                 *
                 * All HAL's client configuration is here.
                 */
                IConfigFileClient <JObject, JToken> configFile = new JSONConfigFileClient();

                try
                {
                    configFile.Load(MagicStringEnumerator.DefaultConfigPath);
                    Log.Instance?.Info($"Configuration file {MagicStringEnumerator.DefaultConfigPath} loaded.");
                }
                catch (Exception ex)
                {
                    Log.Instance?.Error($"{MagicStringEnumerator.DefaultConfigPath}: {ex.Message}");
                    receiveError = true;
                    CleanExit();
                }

                foreach (var storageName in configFile.GetStorageNames())
                {
                    var storage = StorageFactory.CreateStorage(storageName);

                    if (storage is StorageServerFile)
                    {
                        (storage as StorageServerFile).StreamWriter = client.StreamWriter;
                    }
                    else if (storage is StorageLocalFile)
                    {
                        (storage as StorageLocalFile).SavePath = configFile.GetSavePath();
                    }

                    storages.Add(storage);
                    Log.Instance?.Info($"Storage \"{storageName}\" added.");
                }

                await pluginManager.UnscheduleAllPluginsAsync(pluginMaster.Plugins);

                pluginMaster.RemoveAllPlugins();

                /*
                 * A connection string is needed if you want to access a database
                 *
                 * if none is specified, then it will do nothing and return null.
                 */

                var connectionStrings = configFile.GetDataBaseConnectionStrings();
                var databases         = storages.Where(s => s is IDatabaseStorage).ToArray();

                for (var i = 0; i < connectionStrings?.Length; ++i)
                {
                    var db = databases[i];
                    var connectionString = connectionStrings[i];

                    db.Init(connectionString);
                    Log.Instance?.Info($"Database \"{db}\" with connection string \"{connectionString}\"");
                }

                /*
                 * Here pluginMaster will receive some customs user specifications,
                 * like new extensions or intepreter.
                 */
                configFile.SetScriptExtensionsConfiguration(pluginMaster);
                configFile.SetInterpreterNameConfiguration(pluginMaster);

                /*
                 * All the plugins in the directory "plugins" will be loaded and added to the plugin master
                 */
                foreach (var file in Directory.GetFiles(MagicStringEnumerator.DefaultPluginPath))
                {
                    pluginMaster.AddPlugin(file);
                }

                /*
                 * Then the configuration of all of the plugins is set.
                 */
                configFile.SetPluginsConfiguration(pluginMaster.Plugins);
                configFileLocal.SetPluginsConfiguration(pluginMaster.Plugins);
                configFileLocal.SetInterpreterNameConfiguration(pluginMaster);

                /*
                 * An event is added when the plugin's execution is finished to save it where the user specified above.
                 */
                var savePath = configFile.GetSavePath();
                foreach (var plugin in pluginMaster.Plugins)
                {
                    plugin.OnExecutionFinished += async(o, e) =>
                    {
                        foreach (var storage in storages)
                        {
                            try
                            {
                                var code = await storage.Save(e.Plugin, e.Result);

                                if (code == StorageCode.Failed)
                                {
                                    Log.Instance?.Error("Storage failed.");
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Instance?.Error($"Storage failed: {ex.Message}");
                            }
                        }
                    }
                }
                ;

                /*
                 * All the plugins are then schelduled to be launched when needed.
                 */
                pluginManager.SchedulePlugins(pluginMaster.Plugins);

                Log.Instance?.Info("Configuration reloaded.");
            };

            while (!receiveError)
            {
                Thread.Sleep(100);
            }

            CleanExit();
        }
    }