/// <summary> /// /// </summary> /// <returns></returns> bool DoAddEntry(DataStoreEntry entry) { entry.Initialize(_dataStoreFilesFolder); lock (_entriesAndSessions) { if (_entriesAndSessions.ContainsKey(entry)) { SystemMonitor.OperationWarning("Entry already added."); return(false); } if (entry.Symbol.IsEmpty) { SystemMonitor.Warning("Entry added before initialized."); return(false); } // The sessionInformation reuses the entry Guid, so that it can be easily persisted further. DataSessionInfo entrySessionInfo = new DataSessionInfo(entry.Guid, "Data Store Session [" + entry.Symbol.Name + "]", entry.Symbol, DefaultSessionLotSize, entry.DecimalDigits); RuntimeDataSessionInformation session = new RuntimeDataSessionInformation(entrySessionInfo, entry.Period.Value); _entriesAndSessions.Add(entry, session); } return(true); }
/// <summary> /// Obtain entry based on the sessionInformation orderInfo that corresponds to it. /// </summary> /// <param name="sessionInformation"></param> /// <returns></returns> public DataStoreEntry GetEntryBySessionInfo(DataSessionInfo sessionInfo) { DataStoreEntry entry = null; lock (_entriesAndSessions) { foreach (RuntimeDataSessionInformation information in _entriesAndSessions.Values) { if (information.Info.Equals(sessionInfo)) { if (_entriesAndSessions.GetByValueSafe(information, ref entry)) { return(entry); } } } } return(null); }
/// <summary> /// /// </summary> public bool AddEntry(DataStoreEntry entry) { if (DoAddEntry(entry)) { lock (this) { _persistenceHelper.Insert <DataStoreEntry>(entry); } if (EntryAddedEvent != null) { EntryAddedEvent(this, entry); } return(true); } else { return(false); } }
/// <summary> /// /// </summary> public bool RemoveEntry(DataStoreEntry entry) { lock (_entriesAndSessions) { if (_entriesAndSessions.RemoveByKey(entry) == false) { return(false); } } lock (this) { _persistenceHelper.Delete <DataStoreEntry>(entry); } entry.ClearData(); if (EntryRemovedEvent != null) { EntryRemovedEvent(this, entry); } return(true); }
/// <summary> /// Create an entry and initialize it with dataDelivery from a local file, /// and add it to the currently managed list of entries. /// </summary> /// <returns></returns> public DataStoreEntry AddEntryFromLocalFile(string filePath) { string newFilePath; string filesFolder = _dataStoreFilesFolder; if (string.IsNullOrEmpty(filesFolder)) { SystemMonitor.Error("Files folder for data store manager not initialized."); return(null); } if (File.Exists(filePath) == false) { SystemMonitor.OperationWarning(string.Format("File to create entry from not found [{0}].", filePath)); return(null); } // The "``" symbol is used for separator, since no trading symbol is supposed to have this in its name. newFilePath = Path.Combine(filesFolder, Path.GetFileNameWithoutExtension(filePath) + FileNameGuidSeparator + Guid.NewGuid().ToString() + Path.GetExtension(filePath));; bool sameFile = (Path.GetDirectoryName(filePath) == Path.GetDirectoryName(newFilePath) && Path.GetFileName(filePath) == Path.GetFileName(newFilePath)); if (sameFile == false) { try { File.Copy(filePath, newFilePath); } catch (Exception ex) { SystemMonitor.OperationError(ex.Message); } } DataStoreEntry entry = new DataStoreEntry(); entry.Initialize(_dataStoreFilesFolder); if (entry.LoadFromFile(newFilePath, FileNameGuidSeparator) == false) { if (sameFile == false) { try { File.Delete(newFilePath); } catch (Exception ex) { SystemMonitor.OperationError(ex.Message); } } return(null); } entry.Description = string.Format("Entry generated from file [{0}].", Path.GetFileName(filePath)); this.AddEntry(entry); return(entry); }
/// <summary> /// /// </summary> public bool RemoveEntry(DataStoreEntry entry) { lock (_entriesAndSessions) { if (_entriesAndSessions.RemoveByKey(entry) == false) { return false; } } lock(this) { _persistenceHelper.Delete<DataStoreEntry>(entry); } entry.ClearData(); if (EntryRemovedEvent != null) { EntryRemovedEvent(this, entry); } return true; }
/// <summary> /// /// </summary> /// <returns></returns> bool DoAddEntry(DataStoreEntry entry) { entry.Initialize(_dataStoreFilesFolder); lock(_entriesAndSessions) { if (_entriesAndSessions.ContainsKey(entry)) { SystemMonitor.OperationWarning("Entry already added."); return false; } if (entry.Symbol.IsEmpty) { SystemMonitor.Warning("Entry added before initialized."); return false; } // The sessionInformation reuses the entry Guid, so that it can be easily persisted further. DataSessionInfo entrySessionInfo = new DataSessionInfo(entry.Guid, "Data Store Session [" + entry.Symbol.Name + "]", entry.Symbol, DefaultSessionLotSize, entry.DecimalDigits); RuntimeDataSessionInformation session = new RuntimeDataSessionInformation(entrySessionInfo, entry.Period.Value); _entriesAndSessions.Add(entry, session); } return true; }
/// <summary> /// Create an entry and initialize it with dataDelivery from a local file, /// and add it to the currently managed list of entries. /// </summary> /// <returns></returns> public DataStoreEntry AddEntryFromLocalFile(string filePath) { string newFilePath; string filesFolder = _dataStoreFilesFolder; if (string.IsNullOrEmpty(filesFolder)) { SystemMonitor.Error("Files folder for data store manager not initialized."); return null; } if (File.Exists(filePath) == false) { SystemMonitor.OperationWarning(string.Format("File to create entry from not found [{0}].", filePath)); return null; } // The "``" symbol is used for separator, since no trading symbol is supposed to have this in its name. newFilePath = Path.Combine(filesFolder, Path.GetFileNameWithoutExtension(filePath) + FileNameGuidSeparator + Guid.NewGuid().ToString() + Path.GetExtension(filePath)); ; bool sameFile = (Path.GetDirectoryName(filePath) == Path.GetDirectoryName(newFilePath) && Path.GetFileName(filePath) == Path.GetFileName(newFilePath)); if (sameFile == false) { try { File.Copy(filePath, newFilePath); } catch (Exception ex) { SystemMonitor.OperationError(ex.Message); } } DataStoreEntry entry = new DataStoreEntry(); entry.Initialize(_dataStoreFilesFolder); if (entry.LoadFromFile(newFilePath, FileNameGuidSeparator) == false) { if (sameFile == false) { try { File.Delete(newFilePath); } catch (Exception ex) { SystemMonitor.OperationError(ex.Message); } } return null; } entry.Description = string.Format("Entry generated from file [{0}].", Path.GetFileName(filePath)); this.AddEntry(entry); return entry; }
/// <summary> /// /// </summary> public bool AddEntry(DataStoreEntry entry) { if (DoAddEntry(entry)) { lock (this) { _persistenceHelper.Insert<DataStoreEntry>(entry); } if (EntryAddedEvent != null) { EntryAddedEvent(this, entry); } return true; } else { return false; } }
void Manager_EntryAddedEvent(DataStore manager, DataStoreEntry entry) { WinFormsHelper.BeginFilteredManagedInvoke(this, UpdateUI); }
/// <summary> /// /// </summary> /// <param name="item"></param> /// <param name="entry"></param> void SetItemAsEntryLocal(ListViewItem item, DataStoreEntry entry) { if (listViewProviderEntries.Groups[entry.Symbol.Source] == null) { listViewProviderEntries.Groups.Add(entry.Symbol.Source, entry.Symbol.Source); } listViewProviderEntries.Groups[entry.Symbol.Source].Items.Add(item); while (item.SubItems.Count < 6) { item.SubItems.Add(""); } item.Text = entry.Symbol.Name; item.Tag = entry; if (entry.Period.HasValue) { item.SubItems[1].Text = entry.Period.Value.ToString(); } else { item.SubItems[1].Text = "-"; } item.SubItems[2].Text = entry.StartTime.ToString(); item.SubItems[3].Text = entry.EndTime.ToString(); // Quote count. item.SubItems[4].Text = entry.QuoteCount.ToString(); item.SubItems[5].Text = entry.Description; }
/// <summary> /// Request bar dataDelivery from entry. /// </summary> public bool RequestDataHistoryUpdate(DataSessionInfo sessionInfo, DataHistoryRequest request, bool waitResult) { DataStoreEntry entry = DataStore.Instance.GetEntryBySessionInfo(sessionInfo); if (this.OperationalState != OperationalStateEnum.Operational || entry == null) { SystemMonitor.OperationError("Data history request received while not operational, or invalid session requrested."); return(false); } if (entry.Period != request.Period) { SystemMonitor.OperationError("Data history request received but period not recognized."); return(false); } if (request.MaxValuesRetrieved.HasValue == false) { request.MaxValuesRetrieved = int.MaxValue; } if (request.StartIndex.HasValue == false) { request.StartIndex = -1; } GeneralHelper.GenericReturnDelegate <bool> operationDelegate = delegate() { if (request.IsTickBased) { DataReaderWriter <DataTick> readerWriter = entry.GetDataTickReaderWriter(); List <DataTick> dataTicks; DataHistoryUpdate update = new DataHistoryUpdate(request.Period, new DataTick[] { }); if (readerWriter.Read(request.StartIndex.Value, request.MaxValuesRetrieved.Value, out dataTicks)) { update.DataTicksUnsafe.AddRange(dataTicks); if (DataHistoryUpdateEvent != null) { DataHistoryUpdateEvent(this, sessionInfo, update); } return(true); } } else { DataReaderWriter <DataBar> readerWriter = entry.GetDataBarReaderWriter(); if (readerWriter == null) { SystemMonitor.OperationError("Failed to establish file reader writer for entry."); return(false); } List <DataBar> dataBars; DataHistoryUpdate update = new DataHistoryUpdate(request.Period, new DataBar[] { }); bool readResult = false; if (request.StartIndex.Value < 0) {// Instruction is to read the last count items. readResult = readerWriter.ReadLast( request.MaxValuesRetrieved.Value, out dataBars); } else { readResult = readerWriter.Read(request.StartIndex.Value, request.MaxValuesRetrieved.Value, out dataBars); } if (readResult) { update.DataBarsUnsafe.AddRange(dataBars); if (DataHistoryUpdateEvent != null) { DataHistoryUpdateEvent(this, sessionInfo, update); } return(true); } } return(false); }; if (waitResult) { return(operationDelegate()); } else { GeneralHelper.FireAndForget(operationDelegate); return(true); } }