// // #endregion//Constructors #region no Properties // ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region no Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // // // // // // #endregion//Private Methods #region Private Form Update Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // /// <summary> /// Check and update list of InstrumentNames. /// Must be called by UI thread. /// </summary> /// <param name="player"></param> private void UpdateInstrumentNames(EventPlayer player) { object o = comboBoxInstrumentNames.SelectedItem; // originally selected item // Add any new names to the combo box - dont check if any are missing... List <InstrumentName> nameList = new List <InstrumentName>(player.SeriesList.Keys); nameList.Sort(new InstrumentNameOrder()); foreach (InstrumentName name in nameList) { if (!comboBoxInstrumentNames.Items.Contains(name)) { comboBoxInstrumentNames.Items.Add(name); } } //else // Console.WriteLine("Error!"); if (o != null) { comboBoxInstrumentNames.SelectedItem = o; // reset the selected item. } // Update the Start and End dates textStartDate.Text = player.StartDate.ToString(Misty.Lib.Utilities.Strings.FormatDateTimeZone); textEndDate.Text = player.EndDate.ToString(Misty.Lib.Utilities.Strings.FormatDateTimeZone); }// UpdateInstrumentNames()
// ***************************************************************** // **** Constructors **** // ***************************************************************** /// <summary> /// To begin, the constructor will load drop file at or just earlier than startDateTime; /// that is, InitialState.LocalTime is earlier/equal to startDateTime! /// Desired file base name like "FillBooks_99990003". /// </summary> /// <param name="basePath">Path where date-directories are located.</param> /// <param name="fileBaseName">Account/user identifier part of the drop files.</param> /* * public EventPlayer(string basePath, string fileBaseName, DateTime startDateTime, double hoursToLoad=0.50) * { * // * // Collect all relevent files * // * m_FileBase = fileBaseName; // Pattern of files to seek. * m_PathBase = basePath; // Seek files (in any directory) beneath this base directory... * m_Files = new SortedList<DateTime, string>(); * EventPlayer.FindAllFiles(m_PathBase,m_FileBase,m_Files);// locate all desired files in all subdirectories * if (m_Files.Count == 0) * return; // quick bypass exit * * * StartDate = startDateTime; * * // Find starting file (near user provided date) and read that file. * int n = 0; * while (n < m_Files.Count && m_Files.Keys[n].CompareTo(StartDate) < 0) // search just past startDate, then load n-1 file. * n++; * m_FileStart = Math.Max(0, n - 1); // inclusive file load ptr (first file that has been loaded) * m_FileEnd = m_FileStart; // inclusize file load (last file that has been loaded). * List<Node> nodeList = new List<Node>(); // a list, into which we load the nodes. * * // Load the initial period of interest * DateTime stopDateTime = StartDate.AddHours(hoursToLoad); // load * this.EndDate = stopDateTime; * int fileIndex = m_FileStart; * while (fileIndex < m_Files.Count && m_Files.Keys[fileIndex].CompareTo(stopDateTime) < 0) * { * nodeList.AddRange(ReadNodesFromFile(fileIndex)); // add these nodes to the end of our list. * m_FileEnd = fileIndex; * fileIndex ++; * } * AddToEventSeries(ref nodeList, false); * }// EventPlayer() */ // private EventPlayer(string basePath, string fileBaseName) { m_FileBase = fileBaseName; // Pattern of files to seek. m_PathBase = basePath; // Seek files (in any directory) beneath this base directory... m_Files = new SortedList <DateTime, string>(); EventPlayer.FindAllFiles(m_PathBase, m_FileBase, m_Files); // locate all desired files in all subdirectories }
/// <summary> /// /// </summary> /// <param name="basePath">Directory with date-named subdirectories; @"\\fileserver\Users\dv_bre\Ambre\Drops\".</param> public EventSeriesView(string basePath, string userAccountFileNamePattern, DateTime startTime) { InitializeComponent(); m_BasePath = basePath; m_FileNamePattern = userAccountFileNamePattern; /// ********************************************* /// *** get settlement time table here *** /// ********************************************* this.textMessageBox.Text = ""; textMessageBox.Visible = false; m_AppInfo = AppInfo.GetInstance("Breconcile", true); string settlementTable = string.Format("{0}ProductSettleTimes.txt", m_AppInfo.UserPath); ProductSettlementTable.TryCreate(settlementTable, out m_ProductSettlementTable, m_SettlementDate); /// settlement table got, stored at m_ProductSettlementTable if (EventPlayer.TryCreate(m_BasePath, m_FileNamePattern, out m_EventPlayer)) { m_EventPlayer.TaskStarted += new EventHandler(EventPlayer_TaskStarted); m_EventPlayer.TaskCompleted += new EventHandler(EventPlayer_TaskCompleted); //progressBar.Visible = true; //progressBar.MarqueeAnimationSpeed = 30; } }
// // #endregion//Constructors #region no Properties // ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region no Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // // // #endregion//Public Methods #region Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // // // // // **** Update InstrumentName List **** /// <summary> /// Whenever new events have been read by EventPlayer, call this /// to update the list of InstrumentNames. /// Called by UI thread. /// </summary> /// <param name="player"></param> private void UpdateInstrumentNameList(EventPlayer player) { object o = comboBoxInstrumentNames.SelectedItem; // originally selected item // Add any new names to the combo box. List <InstrumentName> nameList = new List <InstrumentName>(player.SeriesList.Keys); nameList.Sort(new InstrumentNameOrder()); foreach (InstrumentName name in nameList) { if (!comboBoxInstrumentNames.Items.Contains(name)) { comboBoxInstrumentNames.Items.Add(name); } } // Keep the user's selected instrument selected. if (o != null) { comboBoxInstrumentNames.SelectedItem = o; // reset the selected instrument. } else if (comboBoxInstrumentNames.Items.Count > 0) { comboBoxInstrumentNames.SelectedIndex = 0; // select the first instrument. } // Update the Start and End dates textStartDate.Text = string.Format("{0:ddd dd MMM yyyy}", player.StartDate); textStartTime.Text = string.Format("{0:hh:mm:ss tt}", player.StartDate); textEndDate.Text = string.Format("{0:ddd dd MMM yyyy}", player.EndDate); textEndTime.Text = string.Format("{0:hh:mm:ss tt}", player.EndDate); }// UpdateInstrumentNameList()
/// <summary> /// Must call Load(startTime) after creating the instance. /// </summary> /// <param name="basePath"></param> /// <param name="fileBaseName"></param> /// <param name="createdPlayer"></param> /// <returns></returns> public static bool TryCreate(string basePath, string fileBaseName, out EventPlayer createdPlayer) { createdPlayer = null; EventPlayer newPlayer = new EventPlayer(basePath, fileBaseName); if (newPlayer.m_Files.Count == 0) { return(false); // quick bypass exit } createdPlayer = newPlayer; return(true); }
// ***************************************************************** // **** Constructors **** // ***************************************************************** public FormBookViewer(string[] args) { InitializeComponent(); string basePath = @"\\fileserver\Users\dv_bre\Ambre\Drops\"; string baseFileName = "FillBooks_DVBRE4_82804115"; DateTime startTime = new DateTime(2013, 6, 11, 16, 30, 0); //m_EventPlayer = new EventPlayer(basePath, baseFileName, startTime); if (EventPlayer.TryCreate(basePath, baseFileName, out m_EventPlayer)) { m_EventPlayer.Load(startTime); UpdateInstrumentNames(m_EventPlayer); } }
// // #endregion//Constructors #region no Properties // ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region no Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // // // #endregion//Public Methods #region no Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // // #endregion//Private Methods #region Form Event Handlers // ***************************************************************** // **** Event Handlers **** // ***************************************************************** // // #endregion//Event Handlers #region Form Event Handlers // ***************************************************************** // **** Event Handlers **** // ***************************************************************** // // // // // ************************************************* // **** Button Click() **** // ************************************************* private void Button_Click(object sender, EventArgs e) { if (sender == buttonLoadEventPlayer) { string pathBase = textBoxBasePath.Text; if (comboBoxUserNames.SelectedIndex < 0) { return; } string userAcctName = comboBoxUserNames.SelectedItem.ToString(); int nFilesFound = 1; // EventPlayer.FindAllFiles(pathBase, userAcctName); if (nFilesFound > 0) { /// start time DateTime time1; if (!DateTime.TryParse(textBoxTime.Text, out time1)) { textBoxTime.Text = "16:00:00"; } DateTime startDateTime = dateTimePickerDate.Value.Date; startDateTime = startDateTime.Add(time1.TimeOfDay); /// end time DateTime time2; if (!DateTime.TryParse(textBoxEndTime.Text, out time2)) { textBoxEndTime.Text = "16:00:00"; } DateTime endDateTime = dateTimePicker1.Value.Date; endDateTime = endDateTime.Add(time2.TimeOfDay); TimeSpan t = endDateTime - startDateTime; double hourDiff = t.TotalHours; // Create this async EventSeriesView view = new EventSeriesView(pathBase, userAcctName, startDateTime); // Add to page. TabPage tabPage = new TabPage(userAcctName); tabPage.Name = userAcctName; tabControl.TabPages.Add(tabPage); tabControl.SelectedTab = tabPage; tabPage.Controls.Add(view); view.Location = new Point(0, 0); view.Dock = DockStyle.Fill; view.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; view.Size = new Size(tabPage.ClientSize.Width, tabPage.ClientSize.Height); view.BeginLoad(startDateTime, hourDiff); } } else if (sender == buttonCollectUserNames) { // Search the base directory for a list of all usernames. string basePath = textBoxBasePath.Text; List <string> userNames; if (EventPlayer.TryGetAllUserNames(basePath, out userNames, 2)) { userNames.Sort(); object selectedItem = comboBoxUserNames.SelectedItem; // remember what is selected comboBoxUserNames.SuspendLayout(); comboBoxUserNames.Items.Clear(); comboBoxUserNames.Items.AddRange(userNames.ToArray()); comboBoxUserNames.ResumeLayout(); if (selectedItem != null && comboBoxUserNames.Items.Contains(selectedItem)) { comboBoxUserNames.SelectedItem = selectedItem; } else if (comboBoxUserNames.Items.Count > 0) { comboBoxUserNames.SelectedIndex = 0; } } } }