// ***************************************************************** // **** Constructors **** // ***************************************************************** // // // public HedgeOptionsDatabaseWriterTest() { m_Log = new LogHub("BRELibLog", string.Format("{0}{1}", UV.Lib.Application.AppInfo.GetInstance().BasePath, UV.Lib.Application.AppInfo.GetInstance().LogDirectory), true, LogLevel.ShowAllMessages); InitializeComponent(); m_UIDispatcher = Dispatcher.CurrentDispatcher; DatabaseInfo dbInfo = DatabaseInfo.Create(DatabaseInfo.DatabaseLocation.bredev); dbInfo.UserName = "******"; dbInfo.UserPW = "test"; m_DatabaseReaderWriter = new DatabaseReaderWriter(dbInfo); m_DatabaseReaderWriter.QueryResponse += new EventHandler(DatabaseReaderWriter_QueryResponse); this.textBoxExchangeName.Text = "CME"; this.textBoxProductName.Text = "GE"; this.textBoxProductType.Text = "Spread"; m_TTAPIService = TTApiService.GetInstance(); m_TTAPIService.ServiceStateChanged += new EventHandler(TTApiService_ServiceStateChanged); m_TTAPIService.Start(true); m_Market = new MarketTTAPI(); m_Market.MarketStatusChanged += new EventHandler(MarketTTAPI_MarketStatusChanged); m_Market.FoundResource += new EventHandler(MarketTTAPI_MarketFoundServiceResource); m_Market.Start(); m_Market.Connect(); // initialize connection to API. }
// ***************************************************************** // **** Constructors **** // ***************************************************************** // // /// <summary> /// Caller would like to create a new Instrument matrix for a given list of /// instruments. This class will use the provided DatabaseReaderWriter to submit /// queries and create the need matrix of quote and hedge legs as well as there hedge /// ratios. /// </summary> /// <param name="instruments"></param> /// <param name="dbReaderWriter"></param> public InstrumentMatrix(List <InstrumentName> instruments, DatabaseReaderWriter dbReaderWriter) { m_Instruments = instruments; m_DatabaseReaderWriter = dbReaderWriter; m_Log = dbReaderWriter.Log; //m_DatabaseReaderWriter.QueryResponse += new EventHandler(); // Need to think about threading issues here...who is going to own // this object and how the collections will be accessed }
// // private void InstrumentMatrixTest_FormClosed(object sender, FormClosedEventArgs e) { if (m_DatabaseReaderWriter != null) { m_DatabaseReaderWriter.RequestStop(); m_DatabaseReaderWriter = null; } if (m_Log != null) { m_Log.RequestStop(); m_Log = null; } }
// ***************************************************************** // **** Constructors **** // ***************************************************************** public Test1() { InitializeComponent(); // Create the database connection. DatabaseInfo dbInfo = DatabaseInfo.Create(DatabaseInfo.DatabaseLocation.apastor); m_DBReaderWriter = new DatabaseReaderWriter(dbInfo); m_DBReaderWriter.QueryResponse += new EventHandler(DatabaseReaderWriter_QueryResponse); // Request info //Queries.Instruments instrQ = new Queries.Instruments(); //instrQ.InstrumentName = new InstrumentName(new Product("CME", "ZT", ProductTypes.Future), "H4"); //m_DBReaderWriter.SubmitAsync(instrQ); }
// ***************************************************************** // **** Constructors **** // ***************************************************************** // // // public InstrumentMatrixTest() { //BRELibLog.Log.NewEntry(LogLevel.Minor, ""); m_Log = new LogHub("BRELibLog", string.Format("{0}{1}", UV.Lib.Application.AppInfo.GetInstance().BasePath, UV.Lib.Application.AppInfo.GetInstance().LogDirectory), true, LogLevel.ShowAllMessages); InitializeComponent(); DatabaseInfo dbInfo = DatabaseInfo.Create(DatabaseInfo.DatabaseLocation.bredev); dbInfo.UserName = "******"; dbInfo.UserPW = "test"; m_DatabaseReaderWriter = new DatabaseReaderWriter(dbInfo); m_DatabaseReaderWriter.QueryResponse += new EventHandler(DatabaseReaderWriter_QueryResponse); this.textBoxInstrument1.Text = "CME.GE (Spread) Calendar: 1xGE Sep14:-1xJun15"; this.textBoxInstrument2.Text = "CME.GE (Spread) Calendar: 1xGE Dec14:-1xMar15"; }
}// TryCreateFromFile() // // // // ******************************************************** // **** TryCreateFromDatabase **** // ******************************************************** /// <summary> /// Called by the strategy hub thread to create strategies for a given group id. /// </summary> /// <param name="groupId">List of groups from which strategies are to be created. If null, no groups are loaded.</param> /// <param name="strategyIds">List of strategy ids to be created. If null, no strategyIds added.</param> /// <param name="aLog"></param> /// <param name="dataBaseReader"></param> /// <param name="strategyList"></param> /// <returns></returns> public static bool TryCreateFromDatabase(List <int> groupId, List <int> strategyIds, LogHub aLog, DatabaseReaderWriter dataBaseReader, out List <Strategy> strategyList) { strategyList = new List <Strategy>(); // place to put new strategies List <int> strategyIdList = new List <int>(); // List of strategy ids we are going to create. try { // // Request strategy Ids from groupIds provided by user. // StrategiesQuery strategyQuery = new StrategiesQuery(groupId, strategyIds); if (!dataBaseReader.SubmitSync(strategyQuery)) { aLog.NewEntry(LogLevel.Error, "TryCreateFromDatabase: StrategiesQuery failed, cannot create strategies."); return(false); } foreach (StrategyQueryItem aStrategyResult in strategyQuery.Results) { strategyIdList.Add(aStrategyResult.StrategyId); // create list of all id's we care about. } // // Request all engines for those strategy ids. // StrategyEnginesQuery engineQuery = new StrategyEnginesQuery(strategyIdList); if (!dataBaseReader.SubmitSync(engineQuery)) { aLog.NewEntry(LogLevel.Error, "TryCreateFromDatabase: query failed try to find engines for {0} strategies, cannot create strategy", strategyIdList.Count); return(false); } // Workspace Dictionary <int, IStringifiable> enginesWithIds = new Dictionary <int, IStringifiable>(); List <IStringifiable> enginesWithOutIds = new List <IStringifiable>(); Dictionary <IStringifiable, StrategyEnginesQueryItem> itemList = new Dictionary <IStringifiable, StrategyEnginesQueryItem>(); Dictionary <string, string> attributes = new Dictionary <string, string>(); // // Now create each strategy // foreach (StrategyQueryItem strategyItem in strategyQuery.Results) { int strategyId = strategyItem.StrategyId; // // Search for its engines, create them. // foreach (StrategyEnginesQueryItem item in engineQuery.Results)// Now create all its engines. { if (item.StrategyId == strategyId) { // This is an engine for this strategy. // Validate that we can create this object. Type type; if (!Stringifiable.TryGetType(item.EngineType, out type)) { aLog.NewEntry(LogLevel.Error, "TryCreateFromDatabase: {0} unknown type in strategy {1}.", item.EngineType, strategyId); return(false); } if (!typeof(IStringifiable).IsAssignableFrom(type)) { aLog.NewEntry(LogLevel.Error, "TryCreateFromDatabase: Type {0} does not implement IStringifiable!", type.FullName); return(false); } // Create the new engine now. IStringifiable newObj = (IStringifiable)Activator.CreateInstance(type); attributes.Clear(); // empty this for next use. StringifiableReader.TryAddAllAttributes(item.AttributeString, ref attributes); newObj.SetAttributes(attributes); // load its attributes. // Store this engine in appropriate list. if (item.EngineId >= 0) { // This engine has Id# if (enginesWithIds.ContainsKey(item.EngineId)) { aLog.NewEntry(LogLevel.Error, "TryCreateFromDatabase: EngineIds must be unique. Found dupe engineIds in strategy #{0}.", strategyId); return(false); } else { enginesWithIds.Add(item.EngineId, newObj); itemList.Add(newObj, item); // store the info about this new object } } else { // This engine has NO Id#. (Which only means it can't be someone's parent.) enginesWithOutIds.Add(newObj); itemList.Add(newObj, item); // store the info about this new object } }// strategyId }// next engine in list // // Now create the strategy. // Strategy newStrategy = new Strategy(); attributes.Clear(); // empty this now StringifiableReader.TryAddAllAttributes(strategyItem.AttributeString, ref attributes); // extract attributes from string. ((IStringifiable)newStrategy).SetAttributes(attributes); // load its attributes. newStrategy.QueryItem = strategyItem; // give the strategy his database row, rather than giving him its contents. //newStrategy.SqlId = strategyItem.StrategyId; //newStrategy.StartTime = strategyItem.StartTime; //newStrategy.EndTime = strategyItem.EndTime; newStrategy.Name = strategyItem.Name; // // Add engines to their parents. // // Now that we have the strategy AND collected all of its engines, // add engines to their parents, and then finally add engines without parents to the strategy. // Notes: // 1) Engines without a parent, have strategy as its parent. // 2) Parent engines NEED to have an id, otherwise we couldn't know who their children are! // 3) Children can have Id numbers or not... who knows. // Search both lists for children. foreach (IStringifiable engine in enginesWithOutIds) { StrategyEnginesQueryItem item; IStringifiable parentEngine; if (itemList.TryGetValue(engine, out item) && item.ParentEngineId >= 0) { // This engine has a parent. if (enginesWithIds.TryGetValue(item.ParentEngineId, out parentEngine)) { parentEngine.AddSubElement(engine); // added child to parent! } } else { // This engine has NO parent! It's parent is therefore the strategy! ((IStringifiable)newStrategy).AddSubElement(engine); } }// next engine foreach (IStringifiable engine in enginesWithIds.Values) { StrategyEnginesQueryItem item; IStringifiable parentEngine; if (itemList.TryGetValue(engine, out item) && item.ParentEngineId >= 0) { // This engine has a parent. if (enginesWithIds.TryGetValue(item.ParentEngineId, out parentEngine)) { parentEngine.AddSubElement(engine); // added child to parent! } } else { ((IStringifiable)newStrategy).AddSubElement(engine); } }// next engine strategyList.Add(newStrategy); // Store new strategy for output. // Clean up enginesWithIds.Clear(); enginesWithOutIds.Clear(); itemList.Clear(); }//next strategyId } catch (Exception e) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("Exception: {0}\r\nContinue?", e.Message); System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(msg.ToString(), "StrategyMaker.TryCreateFromFile", System.Windows.Forms.MessageBoxButtons.OKCancel); if (aLog != null) { aLog.NewEntry(LogLevel.Major, "StrategyMaker: Exception {0}", e.Message); } return(result == System.Windows.Forms.DialogResult.OK); } return(true); }
/// <summary> /// /// </summary> /// <param name="_selectedSetupViewModel"></param> /// <param name="_dialogs"></param> public MifareUltralightSetupViewModel(object _selectedSetupViewModel, ObservableCollection <IDialogViewModel> _dialogs) { try { MefHelper.Instance.Container.ComposeParts(this); //Load Plugins databaseReaderWriter = new DatabaseReaderWriter(); chipModel = new MifareUltralightChipModel(string.Format("Task Description: {0}", SelectedTaskDescription), CARD_TYPE.MifareUltralight); pageModel = new MifareUltralightPageModel(new byte[4], 0); pageModel.PageNumber = selectedUltralightPageCurrentAsInt; childNodeViewModelFromChip = new RFiDChipChildLayerViewModel(pageModel, null, CARD_TYPE.MifareUltralight, null, true); childNodeViewModelTemp = new RFiDChipChildLayerViewModel(pageModel, null, CARD_TYPE.MifareUltralight, null, true); if (_selectedSetupViewModel is MifareUltralightSetupViewModel) { PropertyInfo[] properties = typeof(MifareUltralightSetupViewModel).GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo p in properties) { // If not writable then cannot null it; if not readable then cannot check it's value if (!p.CanWrite || !p.CanRead) { continue; } MethodInfo mget = p.GetGetMethod(false); MethodInfo mset = p.GetSetMethod(false); // Get and set methods have to be public if (mget == null) { continue; } if (mset == null) { continue; } p.SetValue(this, p.GetValue(_selectedSetupViewModel)); } } else { SelectedTaskIndex = "0"; SelectedTaskDescription = "Enter a Description"; } MifareUltralightPages = CustomConverter.GenerateStringSequence(0, 15).ToArray(); SelectedUltralightPageCurrent = "0"; HasPlugins = items != null?items.Any() : false; if (HasPlugins) { SelectedPlugin = Items.FirstOrDefault(); } } catch (Exception e) { LogWriter.CreateLogEntry(string.Format("{0}: {1}; {2}", DateTime.Now, e.Message, e.InnerException != null ? e.InnerException.Message : "")); } }
/// <summary> /// init main /// </summary> public MainWindowViewModel() { RunMutex(this, null); try{ dialogs = new ObservableCollection <IDialogViewModel>(); updater = new Updater(); updater.isUserNotified = Environment.GetCommandLineArgs().Contains <string>("IAmNotified_DoUpdate"); runSilent = Environment.GetCommandLineArgs().Contains <string>("runSilent"); } catch (Exception e) { LogWriter.CreateLogEntry(string.Format("{0}\n{1}", e.Message, e.InnerException != null ? e.InnerException.Message : "")); return; } if (!updater.isUserNotified) { settingsReaderWriter = new SettingsReaderWriter(); dbReaderWriter = new DatabaseReaderWriter(); } else { updater.allowUpdate = true; firstRun = false; updater.StartMonitoring(); } try{ resLoader = new ResourceLoader(); pipeServer = new PipeServer(); eventObjectHandler = new EventObjectHandler(); tb = (TaskbarIcon)Application.Current.FindResource("TrayNotifyIcon"); } catch (Exception e) { LogWriter.CreateLogEntry(string.Format("{0}\n{1}", e.Message, e.InnerException != null ? e.InnerException.Message : "")); } mainWindowIcon = new BitmapImage(); mainWindowIcon.BeginInit(); mainWindowIcon.UriSource = new Uri("pack://application:,,,/EventMessenger;component/Resources/logo.ico"); mainWindowIcon.EndInit(); tb.IconSource = mainWindowIcon; //logReader = new LogFileReaderWriter(10000, true); // just for testing purposes _cmdDeleteEntry = new RelayCommand(DeleteRow); _cmdAddNewEvent = new RelayCommand(AddNewEvent); _cmdAddNewResponse = new RelayCommand(AddNewResponse); rowContextMenuItems = new ObservableCollection <MenuItem>(); emptySpaceContextMenuItems = new ObservableCollection <MenuItem>(); emptySpaceContextMenuItems.Add(new MenuItem() { Header = resLoader.getResource("contextMenuItemAddNewEvent"), Command = _cmdAddNewEvent }); rowContextMenuItems.Add(new MenuItem() { Header = resLoader.getResource("contextMenuItemAddOrEditResponse"), Command = _cmdAddNewResponse }); rowContextMenuItems.Add(new MenuItem() { Header = resLoader.getResource("contextMenuItemEditEvent"), //ToolTip = "this will be the helptext", Command = _cmdAddNewEvent }); rowContextMenuItems.Add(new MenuItem() { Header = resLoader.getResource("contextMenuItemDeleteSelectedItem"), Command = _cmdDeleteEntry }); //dataGridSource = new ObservableCollection<EventObjectModel>(); Application.Current.MainWindow.Closing += new CancelEventHandler(CloseThreads); Application.Current.MainWindow.Activated += new EventHandler(LoadCompleted); updater.newVersionAvailable += new EventHandler(AskForUpdateNow); tb.TrayLeftMouseDown += new RoutedEventHandler(RestoreMainWindow); tb.MouseDown += new MouseButtonEventHandler(RestoreMainWindow); //any dialog boxes added in the constructor won't appear until DialogBehavior.DialogViewModels gets bound to the Dialogs collection. }