Beispiel #1
0
		public RithmicClient(ILogReceiver receiver, string adminConnectionPoint, string certFile, string domainServerAddress, string domainName, string licenseServerAddress, string localBrokerAddress, string loggerAddress, string logFileName)
		{
			if (receiver == null)
				throw new ArgumentNullException(nameof(receiver));

			if (!File.Exists(certFile))
				throw new FileNotFoundException(LocalizedStrings.Str3457Params.Put(certFile));

			Callbacks = new RCallbacksImpl(this, receiver);

			var eParams = new REngineParams
			{
				AdmCnnctPt = adminConnectionPoint,
				AdmCallbacks = new AdmCallbacksImpl(this, receiver),
				AppName = "StockSharp",
				AppVersion = GetType().Assembly.GetName().Version.ToString(),
				CertFile = certFile,
				DmnSrvrAddr = domainServerAddress,
				DomainName = domainName,
				LicSrvrAddr = licenseServerAddress,
				LocBrokAddr = localBrokerAddress,
				LoggerAddr = loggerAddress,
				LogFilePath = logFileName,
			};

			Session = new REngine(eParams);
		}
			public RCallbacksImpl(RithmicClient client, ILogReceiver receiver)
			{
				if (client == null)
					throw new ArgumentNullException(nameof(client));

				if (receiver == null)
					throw new ArgumentNullException(nameof(receiver));

				_client = client;
				_receiver = receiver;
			}
        /// <summary>
        /// Initializes a new instance of the <see cref="QueueReader"/> class.
        /// </summary>
        /// <param name="queueName">Name of the message queue.</param>
        /// <param name="receiver">The implementation of this interface will be invoked for each received log entry.</param>
        public QueueReader(string queueName, ILogReceiver receiver)
        {
            if (queueName == null) throw new ArgumentNullException("queueName");
            if (receiver == null) throw new ArgumentNullException("receiver");
            _queueName = queueName;
            _receiver = receiver;

            if (!MessageQueue.Exists(queueName))
                throw new ArgumentOutOfRangeException("queueName", queueName, "Queue do not exist.");

            _queue = new MessageQueue(_queueName);
            _queue.ReceiveCompleted += OnReceived;
            _queue.Formatter = new XmlMessageFormatter(new[] {typeof (LogEntryDTO)});
            _queue.BeginReceive();
        }
Beispiel #4
0
		public IQFeedWrapper(ILogReceiver logReceiver, string name, EndPoint address)
		{
			if (logReceiver == null)
				throw new ArgumentNullException("logReceiver");

			if (name.IsEmpty())
				throw new ArgumentNullException("name");

			if (address == null)
				throw new ArgumentNullException("address");

			Address = address;
			_logReceiver = logReceiver;
			Name = name;
		}
Beispiel #5
0
        public static LogWriter LogWriter_NewRegion(IRegionManager regionmgr, ILogReceiver receiver, out int system_reserved_space)
        {
            LogWriter lw = new LogWriter(regionmgr);
            lw.receiver = receiver;
            lw._InitNewRegion(regionmgr, out system_reserved_space);
            lw._InitResume(regionmgr);

            lw.log_handler.prepareLog();

            return lw;
        }
Beispiel #6
0
 public LookupInfo(ILogReceiver logReceiver, MessageTypes resultType)
 {
     ResultType    = resultType;
     LookupTimeOut = new LookupTimeOutTimer(logReceiver);
     _createResult = id => resultType.CreateLookupResult(id);
 }
Beispiel #7
0
 public void SetLogger(ILogReceiver logger) => m_Logger = logger;
Beispiel #8
0
 /// <summary>
 /// To record a warning to the log.
 /// </summary>
 /// <param name="receiver">Logs receiver.</param>
 /// <param name="getMessage">The function returns the text for <see cref="LogMessage.Message"/>.</param>
 public static void AddWarningLog(this ILogReceiver receiver, Func <string> getMessage)
 {
     receiver.AddLog(LogLevels.Warning, getMessage);
 }
Beispiel #9
0
 /// <summary>
 /// To record an error to the log.
 /// </summary>
 /// <param name="receiver">Logs receiver.</param>
 /// <param name="getMessage">The function returns the text for <see cref="LogMessage.Message"/>.</param>
 public static void AddErrorLog(this ILogReceiver receiver, Func <string> getMessage)
 {
     receiver.AddLog(LogLevels.Error, getMessage);
 }
Beispiel #10
0
 /// <summary>
 /// To record an error to the log.
 /// </summary>
 /// <param name="receiver">Logs receiver.</param>
 /// <param name="message">Text message.</param>
 /// <param name="args">Text message settings. Used if a message is the format string. For details, see <see cref="string.Format(string,object[])"/>.</param>
 public static void AddErrorLog(this ILogReceiver receiver, string message, params object[] args)
 {
     receiver.AddMessage(LogLevels.Error, message, args);
 }
Beispiel #11
0
 /// <summary>
 /// To record a message to the log.
 /// </summary>
 /// <param name="receiver">Logs receiver.</param>
 /// <param name="getMessage">The function returns the text for <see cref="LogMessage.Message"/>.</param>
 public static void AddInfoLog(this ILogReceiver receiver, Func <string> getMessage)
 {
     receiver.AddLog(LogLevels.Info, getMessage);
 }
Beispiel #12
0
 public BookInfo(SecurityId securityId, ILogReceiver logs)
 => Builder = new OrderBookIncrementBuilder(securityId, logs);
Beispiel #13
0
 /// <summary>
 /// To record an error to the log.
 /// </summary>
 /// <param name="receiver">Logs receiver.</param>
 /// <param name="exception">Error detais.</param>
 public static void AddErrorLog(this ILogReceiver receiver, Exception exception)
 {
     receiver.AddErrorLog(exception, null);
 }
Beispiel #14
0
        /// <summary>
        /// Clear dates cache for storages.
        /// </summary>
        /// <param name="drives">Storage drives.</param>
        /// <param name="updateProgress">The handler through which a progress change will be passed.</param>
        /// <param name="isCancelled">The handler which returns an attribute of search cancel.</param>
        /// <param name="logsReceiver">Logs receiver.</param>
        public static void ClearDatesCache(this IEnumerable <IMarketDataDrive> drives, Action <int, int> updateProgress,
                                           Func <bool> isCancelled, ILogReceiver logsReceiver)
        {
            if (drives == null)
            {
                throw new ArgumentNullException(nameof(drives));
            }

            if (updateProgress == null)
            {
                throw new ArgumentNullException(nameof(updateProgress));
            }

            if (isCancelled == null)
            {
                throw new ArgumentNullException(nameof(isCancelled));
            }

            if (logsReceiver == null)
            {
                throw new ArgumentNullException(nameof(logsReceiver));
            }

            //var dataTypes = new[]
            //{
            //	Tuple.Create(typeof(ExecutionMessage), (object)ExecutionTypes.Tick),
            //	Tuple.Create(typeof(ExecutionMessage), (object)ExecutionTypes.OrderLog),
            //	Tuple.Create(typeof(ExecutionMessage), (object)ExecutionTypes.Order),
            //	Tuple.Create(typeof(ExecutionMessage), (object)ExecutionTypes.Trade),
            //	Tuple.Create(typeof(QuoteChangeMessage), (object)null),
            //	Tuple.Create(typeof(Level1ChangeMessage), (object)null),
            //	Tuple.Create(typeof(NewsMessage), (object)null)
            //};

            var formats  = Enumerator.GetValues <StorageFormats>().ToArray();
            var progress = 0;

            var marketDataDrives = drives as IMarketDataDrive[] ?? drives.ToArray();
            var iterCount        = marketDataDrives.Sum(d => d.AvailableSecurities.Count());      // кол-во сбросов кэша дат

            updateProgress(progress, iterCount);

            foreach (var drive in marketDataDrives)
            {
                foreach (var secId in drive.AvailableSecurities)
                {
                    foreach (var format in formats)
                    {
                        foreach (var dataType in drive.GetAvailableDataTypes(secId, format))
                        {
                            if (isCancelled())
                            {
                                break;
                            }

                            drive
                            .GetStorageDrive(secId, dataType.MessageType, dataType.Arg, format)
                            .ClearDatesCache();
                        }
                    }

                    if (isCancelled())
                    {
                        break;
                    }

                    updateProgress(progress++, iterCount);

                    logsReceiver.AddInfoLog(LocalizedStrings.Str2931Params, secId, drive.Path);
                }

                if (isCancelled())
                {
                    break;
                }
            }
        }
Beispiel #15
0
        // standard open/resume
        public static LogWriter LogWriter_Resume(IRegionManager regionmgr, ILogReceiver receiver)
        {
            LogWriter lw = new LogWriter(regionmgr);
            lw.receiver = receiver;
            lw._InitResume(regionmgr);

            lw.log_handler.prepareLog();
            return lw;
        }
Beispiel #16
0
        /// <summary>
        /// Synchronize securities with storage.
        /// </summary>
        /// <param name="drives">Storage drives.</param>
        /// <param name="securityStorage">Securities meta info storage.</param>
        /// <param name="exchangeInfoProvider">Exchanges and trading boards provider.</param>
        /// <param name="newSecurity">The handler through which a new instrument will be passed.</param>
        /// <param name="updateProgress">The handler through which a progress change will be passed.</param>
        /// <param name="logsReceiver">Logs receiver.</param>
        /// <param name="isCancelled">The handler which returns an attribute of search cancel.</param>
        public static void SynchronizeSecurities(this IEnumerable <IMarketDataDrive> drives,
                                                 ISecurityStorage securityStorage, IExchangeInfoProvider exchangeInfoProvider,
                                                 Action <Security> newSecurity, Action <int, int> updateProgress,
                                                 Func <bool> isCancelled, ILogReceiver logsReceiver)
        {
            if (drives == null)
            {
                throw new ArgumentNullException(nameof(drives));
            }

            if (securityStorage == null)
            {
                throw new ArgumentNullException(nameof(securityStorage));
            }

            if (exchangeInfoProvider == null)
            {
                throw new ArgumentNullException(nameof(exchangeInfoProvider));
            }

            if (newSecurity == null)
            {
                throw new ArgumentNullException(nameof(newSecurity));
            }

            if (updateProgress == null)
            {
                throw new ArgumentNullException(nameof(updateProgress));
            }

            if (isCancelled == null)
            {
                throw new ArgumentNullException(nameof(isCancelled));
            }

            if (logsReceiver == null)
            {
                throw new ArgumentNullException(nameof(logsReceiver));
            }

            var securityPaths = new List <string>();
            var progress      = 0;

            foreach (var dir in drives.Select(drive => drive.Path).Distinct())
            {
                foreach (var letterDir in InteropHelper.GetDirectories(dir))
                {
                    if (isCancelled())
                    {
                        break;
                    }

                    var name = Path.GetFileName(letterDir);

                    if (name == null || name.Length != 1)
                    {
                        continue;
                    }

                    securityPaths.AddRange(InteropHelper.GetDirectories(letterDir));
                }

                if (isCancelled())
                {
                    break;
                }
            }

            if (isCancelled())
            {
                return;
            }

            // кол-во проходов по директории для создания инструмента
            var iterCount = securityPaths.Count;

            updateProgress(0, iterCount);

            var securities = securityStorage.LookupAll().ToDictionary(s => s.Id, s => s, StringComparer.InvariantCultureIgnoreCase);

            foreach (var securityPath in securityPaths)
            {
                if (isCancelled())
                {
                    break;
                }

                var securityId = Path.GetFileName(securityPath).FolderNameToSecurityId();

                var isNew = false;

                var security = securities.TryGetValue(securityId);

                if (security == null)
                {
                    var firstDataFile =
                        Directory.EnumerateDirectories(securityPath)
                        .SelectMany(d => Directory.EnumerateFiles(d, "*.bin")
                                    .Concat(Directory.EnumerateFiles(d, "*.csv"))
                                    .OrderBy(f => Path.GetExtension(f).CompareIgnoreCase(".bin") ? 0 : 1))
                        .FirstOrDefault();

                    if (firstDataFile != null)
                    {
                        var id = securityId.ToSecurityId();

                        decimal priceStep;

                        if (Path.GetExtension(firstDataFile).CompareIgnoreCase(".bin"))
                        {
                            try
                            {
                                priceStep = File.ReadAllBytes(firstDataFile).Range(6, 16).To <decimal>();
                            }
                            catch (Exception ex)
                            {
                                throw new InvalidOperationException(LocalizedStrings.Str2929Params.Put(firstDataFile), ex);
                            }
                        }
                        else
                        {
                            priceStep = 0.01m;
                        }

                        security = new Security
                        {
                            Id        = securityId,
                            PriceStep = priceStep,
                            Name      = id.SecurityCode,
                            Code      = id.SecurityCode,
                            Board     = exchangeInfoProvider.GetOrCreateBoard(id.BoardCode),
                        };

                        securities.Add(securityId, security);

                        securityStorage.Save(security);
                        newSecurity(security);

                        isNew = true;
                    }
                }

                updateProgress(progress++, iterCount);

                if (isNew)
                {
                    logsReceiver.AddInfoLog(LocalizedStrings.Str2930Params, security);
                }
            }
        }
Beispiel #17
0
 /// <summary>
 /// To record a verbose message to the log.
 /// </summary>
 /// <param name="receiver">Logs receiver.</param>
 /// <param name="message">Text message.</param>
 /// <param name="args">Text message settings. Used if a message is the format string. For details, see <see cref="string.Format(string,object[])"/>.</param>
 public static void AddVerboseLog(this ILogReceiver receiver, string message, params object[] args)
 {
     receiver.AddMessage(LogLevels.Verbose, message, args);
 }
Beispiel #18
0
 public void Register(ILogReceiver receiver)
 {
     this.receivers.Add(receiver);
 }
Beispiel #19
0
 public static void Unsubscribe(ILogReceiver receiver)
 {
     Subscriptions.RemoveAll(subscription => (subscription.Receiver == receiver));
 }
Beispiel #20
0
 public LookupTimeOutTimer(ILogReceiver logReceiver)
 {
     _logReceiver = logReceiver ?? throw new ArgumentNullException(nameof(logReceiver));
 }