Example #1
0
        /// <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>
        /// 
        /// </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;
        }
Example #3
0
        /// <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>
        /// 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;
        }