public Dictionary <string, decimal> Run(Dictionary <string, object> items, IOptimizerConfiguration config) { Dictionary <string, Dictionary <string, decimal> > results = OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain); _config = config; _id = (items.ContainsKey("Id") ? items["Id"] : Guid.NewGuid()).ToString(); if (_config.StartDate.HasValue && _config.EndDate.HasValue) { if (!items.ContainsKey("startDate")) { items.Add("startDate", _config.StartDate); } if (!items.ContainsKey("endDate")) { items.Add("endDate", _config.EndDate); } } string jsonKey = JsonConvert.SerializeObject(items); if (results.ContainsKey(jsonKey)) { return(results[jsonKey]); } //just ignore id gene foreach (var pair in items.Where(i => i.Key != "Id")) { if (pair.Value is DateTime?) { var cast = ((DateTime?)pair.Value); if (cast.HasValue) { Config.Set(pair.Key, cast.Value.ToString("O")); } } else { Config.Set(pair.Key, pair.Value.ToString()); } } if (EngineContext.SystemHandlers == null || EngineContext.Engine == null) { LaunchLean(); } RunJob(); if (_resultsHandler.FullResults != null && _resultsHandler.FullResults.Any()) { results.Add(jsonKey, _resultsHandler.FullResults); OptimizerAppDomainManager.SetResults(AppDomain.CurrentDomain, results); } return(_resultsHandler.FullResults); }
public Dictionary <string, decimal> Run(Dictionary <string, object> items) { Dictionary <string, Dictionary <string, decimal> > results = OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain); _config = OptimizerAppDomainManager.GetConfig(AppDomain.CurrentDomain); _id = (items.ContainsKey("Id") ? items["Id"] : Guid.NewGuid()).ToString(); items.Remove("Id"); if (_config.StartDate.HasValue && _config.EndDate.HasValue) { if (!items.ContainsKey("startDate")) { items.Add("startDate", _config.StartDate); } if (!items.ContainsKey("endDate")) { items.Add("endDate", _config.EndDate); } } string plain = string.Join(",", items.Select(s => s.Value)); if (results.ContainsKey(plain)) { return(results[plain]); } foreach (var pair in items) { if (pair.Value is DateTime?) { var cast = ((DateTime?)pair.Value); if (cast.HasValue) { Config.Set(pair.Key, cast.Value.ToString("O")); } } else { Config.Set(pair.Key, pair.Value.ToString()); } } LaunchLean(); results.Add(plain, _resultsHandler.FullResults); OptimizerAppDomainManager.SetResults(AppDomain.CurrentDomain, results); return(_resultsHandler.FullResults); }
public Dictionary <string, decimal> Run(Dictionary <string, object> items, IOptimizerConfiguration config) { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); Dictionary <string, Dictionary <string, decimal> > results = OptimizerAppDomainManager.GetResults(AppDomain.CurrentDomain); _config = config; _id = (items.ContainsKey("Id") ? items["Id"] : Guid.NewGuid().ToString("N")).ToString(); if (_config.StartDate.HasValue && _config.EndDate.HasValue) { if (!items.ContainsKey("startDate")) { items.Add("startDate", _config.StartDate); } if (!items.ContainsKey("endDate")) { items.Add("endDate", _config.EndDate); } } string jsonKey = JsonConvert.SerializeObject(items.Where(i => i.Key != "Id")); if (!config.EnableRunningDuplicateParameters && results.ContainsKey(jsonKey)) { return(results[jsonKey]); } //just ignore id gene foreach (var pair in items.Where(i => i.Key != "Id")) { if (pair.Value is DateTime?) { var cast = ((DateTime?)pair.Value); if (cast.HasValue) { Config.Set(pair.Key, cast.Value.ToString("O")); } } else { Config.Set(pair.Key, pair.Value.ToString()); } } LogProvider.TraceLogger.Trace($"id: {_id} started."); LaunchLean(); LogProvider.TraceLogger.Trace($"id: {_id} finished."); if (_resultsHandler.FullResults != null && _resultsHandler.FullResults.Any()) { if (config.EnableRunningDuplicateParameters && results.ContainsKey(jsonKey)) { results.Remove(jsonKey); } results.Add(jsonKey, _resultsHandler.FullResults); OptimizerAppDomainManager.SetResults(AppDomain.CurrentDomain, results); } return(_resultsHandler.FullResults); }