Exemple #1
0
#pragma warning restore CS0414

        void Start()
        {
            // -------------------------
            // Creating registry factory
            // -------------------------
            // Reigstry factory constructor takes list of stat installers as parameters.
            // Installer is class converting an input data (eg: json string) to stat data structures.
            // It uses them internally to create stats and install the onto newly created registry,
            // provided with Create() mehtod.
            RegistryFactory registryFactory = new RegistryFactory(new List <IStatInstaller>()
            {
                { new YamlInstaller <Stat, StatData>((Resources.Load("example03/stats") as TextAsset).text) },
                { new YamlInstaller <Resource, ResourceData>((Resources.Load("example03/resources") as TextAsset).text) },
                { new YamlInstaller <Modifier, ModifierData>((Resources.Load("example03/modifiers") as TextAsset).text) },
            });

            // --------------------
            // Creating registry
            // --------------------
            // Using factory Create() method to instantiate registry of stats.
            _registry = registryFactory.Create();

            // --------------------------
            // Accessing stat references
            // --------------------------
            _gold                 = _registry.Get <Resource>("gold");
            _goldCapacity         = _registry.Get <Stat>("gold-capacity");
            _goldCapacityModifier = _registry.Get <Modifier>("broken-storage");
            _goldOutput           = _registry.Get <Stat>("gold-output");
            _goldOutputModifier   = _registry.Get <Modifier>("faster-mining");
        }
Exemple #2
0
        public void TestWork_EmptyJob()
        {
            ObjectJobDefinition d = new ObjectJobDefinition(
                new PipelineDefinition(
                    new AlgorithmDefinition[] { }),
                new JobInput[] { });
            JobRequest r               = new JobRequest(d);
            JobTicket  ticket          = new JobTicket(r, new DudCancellationHandler());
            ProcessPluginRepository re = new ProcessPluginRepository();

            RegistryCache.Cache.Initialize(re);
            RegistryFactory factory = new RegistryFactory(re);
            TicketWorker    w       = new TicketWorker();
            WorkerArgs      args    = new WorkerArgs(new DudPersister(), new BadPipelineFactory());

            args.Ticket = ticket;

            bool       didError  = false;
            bool       didFinish = false;
            TicketSink s         = new TicketSink();

            ticket.Sinks.Add(s);
            s.JobCompleted += (se, e) => didFinish = true;
            w.Work(args);

            // Events are dispatched on a seperate thread, so let it run.
            Thread.Sleep(15);

            Assert.IsTrue(didFinish);

            JobResult result = ticket.Result;

            Assert.AreEqual(JobState.Complete, result.Result);
        }
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            // Code that runs on application startup
            IRegistry registry = RegistryFactory.GetRegistry();

            registry.Register <Module>();
        }
        public void TestManufacture_InvalidDefintion()
        {
            ProcessPluginRepository r = new ProcessPluginRepository();

            RegistryCache.Cache.Initialize(r);
            RegistryFactory factory = new RegistryFactory(r);
            AlgorithmPlugin p       = factory.Manufacture(null);

            Assert.IsNull(p);
        }
        public void TestManufacture_ValidDefinition()
        {
            AlgorithmDefinition     d = new AlgorithmDefinition("gamma", new Property[] {});
            ProcessPluginRepository r = new ProcessPluginRepository();

            RegistryCache.Cache.Initialize(r);
            RegistryFactory factory = new RegistryFactory(r);
            AlgorithmPlugin p       = factory.Manufacture(d);

            Assert.IsNotNull(p);
        }
Exemple #6
0
        public void Start()
        {
            var registry = RegistryFactory.GetRegistry();

            foreach (var reg in registryModels)
            {
                var registryValue = registry.GetValue(reg);
                if (string.IsNullOrEmpty(registryValue))
                {
                    logger.Info($"Unable to get \"{reg.SubKey}\\{reg.Key}\".");
                    continue;
                }
                logger.Info($"Found \"{reg.SubKey}\\{reg.Key}\": \"{registryValue}\"");
                if (registry.SetValue(reg))
                {
                    registryValue = registry.GetValue(reg);
                    logger.Info($"Updated \"{reg.SubKey}\\{reg.Key}\": \"{registryValue}\"");
                }
                else
                {
                    logger.Warn("Unable to update, make sure the registry is available and you are running the process in admin mode.");
                }
            }
        }
 protected BaseWrapper(IEngineShared engineShared)
 {
     Registry     = RegistryFactory.Create(Framework.WindowsRegistryPath, $"{Framework.UnixRegistryFileName}{Framework.UnixRegistryFileExtension}", Logger.Instance);
     EngineShared = engineShared ?? throw new ArgumentNullException(nameof(engineShared));
 }
Exemple #8
0
 protected T Resolve <T>()
 {
     return(RegistryFactory.GetResolver().Resolve <T>());
 }
Exemple #9
0
        public string UploadFiles()
        {
            try
            {
                // DEFINE THE PATH WHERE WE WANT TO SAVE THE FILES.
                string sPath       = System.Web.Hosting.HostingEnvironment.MapPath("~/InputFolder/");
                string outputSPath = System.Web.Hosting.HostingEnvironment.MapPath("~/OutputFolder/");
                string fileName    = "";

                System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;

                for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++)
                {
                    System.Web.HttpPostedFile hpf = hfc[iCnt];
                    fileName = hpf.FileName;
                    if (hpf.ContentLength > 0)
                    {
                        // CHECK IF THE SELECTED FILE(S) ALREADY EXISTS IN FOLDER. (AVOID DUPLICATE)
                        if (!File.Exists(sPath + Path.GetFileName(hpf.FileName)))
                        {
                            // SAVE THE FILE IN THE FOLDER.
                            hpf.SaveAs(sPath + Path.GetFileName(hpf.FileName));
                        }
                    }
                }
                // Read entire text file content in one string
                string text       = File.ReadAllText(sPath + fileName);
                var    cityIdList = text.Split(',');

                foreach (var cityId in cityIdList)
                {
                    var factory = RegistryFactory.GetResolver().Resolve <ICommandFactory>();

                    var weatherDataRequest = new WeatherDataRequest();
                    weatherDataRequest.CityID = Convert.ToInt32(cityId);
                    var command = factory.FetchWeatherDataCommand();
                    WeatherDataResult results = command.Execute(weatherDataRequest);

                    // File name with City Id and Date
                    var outputFileName = "CityId_" + cityId + "_" + DateTime.Now.Date.ToShortDateString();
                    if (File.Exists(outputSPath + outputFileName))
                    {
                        File.Delete(outputSPath + outputFileName);
                    }

                    // Create a Response Weather Data City Wise
                    using (FileStream fs = File.Create(outputSPath + outputFileName))
                    {
                        // Add some text to file
                        Byte[] weatherData = new UTF8Encoding(true).GetBytes(results.WeatherData);
                        fs.Write(weatherData, 0, weatherData.Length);
                    }
                }

                // Delete File in the Input Folder (Request File)
                if (File.Exists(sPath + fileName))
                {
                    File.Delete(sPath + fileName);
                }

                return($"File Processed Successfully, For Weather Data Please browse to path: {outputSPath}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return($"File Processing Failed with error: {ex.Message} and stack trace: {ex.StackTrace}");
            }
        }