/// <summary> /// Loads user strategy and extracts constructor parameters /// </summary> private void LoadUserStrategy(LoadStrategy loadStrategy) { try { if (_asyncClassLogger.IsInfoEnabled) { _asyncClassLogger.Info("Trying to load user defined strategy from: " + loadStrategy.StrategyAssembly.FullName.Substring(0, loadStrategy.StrategyAssembly.FullName.IndexOf(",", System.StringComparison.Ordinal)), _type.FullName, "LoadUserStrategy"); } var strategyDetails = LoadCustomStrategy.GetConstructorDetails(loadStrategy.StrategyAssembly); if (strategyDetails != null) { if (_asyncClassLogger.IsInfoEnabled) { _asyncClassLogger.Info("Successfully loaded custom strategy: " + strategyDetails.Item1.Name, _type.Name, "LoadUserStrategy"); } // Create new Strategy Constructor Info object StrategyConstructorInfo strategyConstructorInfo = new StrategyConstructorInfo( strategyDetails.Item2, strategyDetails.Item1); // Publish Event to Notify Listener. EventSystem.Publish <StrategyConstructorInfo>(strategyConstructorInfo); } } catch (Exception exception) { _asyncClassLogger.Error(exception, _type.FullName, "LoadUserStrategy"); } }
public void GetCustomAttributesTestCase() { // Load Assembly file from the selected file Assembly assembly = Assembly.LoadFrom(_assemblyName); // Contains custom defined attributes in the given assembly Dictionary <int, Tuple <string, Type> > customAttributes = null; // Get Constructor information for the given assembly var strategyDetails = LoadCustomStrategy.GetConstructorDetails(assembly); if (strategyDetails != null) { // Get Strategy Type var strategyType = strategyDetails.Item1; // Get custom attributes from the given assembly customAttributes = LoadCustomStrategy.GetCustomAttributes(strategyType); } Assert.IsNotNull(strategyDetails, "Constructor Information for the given assembly was not found."); Assert.IsNotNull(customAttributes, "Custom attributes were not found in the given assembly."); Assert.AreEqual(3, customAttributes.Count, "Count of read custom attributes was not equal to expected value."); }
/// <summary> /// Get constructor details /// </summary> /// <param name="assemblyName"></param> /// <returns></returns> public static Tuple <Type, ParameterInfo[]> GetConstructorDetails(string assemblyName) { return(LoadCustomStrategy.GetConstructorDetails(assemblyName)); }
static void Main(string[] args) { //IList<string> namesOfFiles = new List<string>(); //DateTime startTime = new DateTime(2013,8,25); //DateTime endTime = new DateTime(2013,8,30); //string specificFolder = @"C:\aurora\ATS\Saved Data"; //string providerName = "InteractiveBrokers"; //string[] directoryNames = new string[3]; //// Get possible directory path for bars created with BID Price //directoryNames[0] = specificFolder + "\\" + providerName + "\\" + "AAPL" + "\\Bar\\" + // TradeHubConstants.BarFormat.TIME + "\\" + TradeHubConstants.BarPriceType.BID; //// Get possible directory path for bars created with ASK Price //directoryNames[1] = specificFolder + "\\" + providerName + "\\" + "AAPL" + "\\Bar\\" + // TradeHubConstants.BarFormat.TIME + "\\" + TradeHubConstants.BarPriceType.ASK; //// Get possible directory path for bars created with LAST Price //directoryNames[2] = specificFolder + "\\" + providerName + "\\" + "AAPL" + "\\Bar\\" + // TradeHubConstants.BarFormat.TIME + "\\" + TradeHubConstants.BarPriceType.LAST; //// Traverse all possible directories //foreach (string directoryName in directoryNames) //{ // var directory = new DirectoryInfo(directoryName); // // Find required files if the path exists // if (directory.Exists) // { // // Find all possible subfolders in the given directory // IEnumerable<string> subFolders = directory.GetDirectories().Select(subDirectory => subDirectory.Name); // // Use all sub-directories to find files with required info // foreach (string subFolder in subFolders) // { // DateTime tempStartTime = new DateTime(startTime.Ticks); // while (tempStartTime.Date <= endTime.Date) // { // var filename = tempStartTime.ToString("yyyyMMdd") + ".txt"; // // Get the File paths of required date. // string[] path = Directory.GetFiles(directoryName + "\\" + subFolder, // filename, SearchOption.AllDirectories); // if (path.Any()) // { // namesOfFiles.Add(path[0]); // } // tempStartTime = tempStartTime.AddDays(1); // } // } // } //} //foreach (string namesOfFile in namesOfFiles) //{ // System.Console.WriteLine(namesOfFile); //} var strategyDetails = LoadCustomStrategy.GetConstructorDetails("TradeHub.StrategyRunner.SampleStrategy.dll"); if (strategyDetails != null) { var strategyType = strategyDetails.Item1; var ctorDetails = strategyDetails.Item2; object[] ctrArgs = new object[ctorDetails.Length]; foreach (ParameterInfo parameterInfo in ctorDetails) { object value; do { System.Console.WriteLine("Enter " + parameterInfo.ParameterType.Name + " value for: " + parameterInfo.Name); var input = System.Console.ReadLine(); value = LoadCustomStrategy.GetParametereValue(input, parameterInfo.ParameterType.Name); } while (value == null); ctrArgs[parameterInfo.Position] = value; } LoadCustomStrategy.CreateStrategyInstance(strategyType, ctrArgs); } while (true) { } }