示例#1
0
        private void ProbeUntilConsumed(Func <bool> reading, IChannelPublisher reader, Func <int> write, int maxSeconds)
        {
            var sw = new Stopwatch();

            sw.Start();
            do
            {
                write();
                reader.ProcessChannel();
            } while (reading() || sw.Elapsed.TotalSeconds >= maxSeconds);
            sw.Stop();
        }
示例#2
0
        public WsIQClientRx()
        {
            // TODO INJECT
            _ws            = new WebSocketWrapper();
            _epoch         = new Epoch();
            _randomNumbers = new RandomNumbers();

            MessagesFeed = Observable
                           .FromEventPattern <OnMessageEventHandler, WsRecievemessageEventArgs>(
                h => _ws.OnMessage += h,
                h => _ws.OnMessage -= h)
                           //.ObserveOn(NewThreadScheduler.Default)
                           .Map((e) =>
            {
                var serializedMessage = e.EventArgs.Message;
                var iQmessage         = JsonConvert.DeserializeObject <IQOptionMessage>(serializedMessage);
                return(iQmessage);
            });

            _onConnection = Observable
                            .FromEventPattern <OnConnectedEventHandler, EventArgs>(
                h => _ws.OnConnected += h,
                h => _ws.OnConnected -= h)
                            .Map(e => e.EventArgs)
                            .Replay();

            _onConnectionConnection = _onConnection.Connect();

            //TODO DO THIS IN THE IQCLient
            _ssidDualChannel = new SsidPublisherChannel(this);

            _heartBeatDualChannel = new HeartBeatDualChannel(this);

            _wsMessagesSubscription = _heartBeatDualChannel.ChannelFeed
                                      .Map(heartbeat => _heartBeatDualChannel.SendMessage(new HeartBeatOutputMessage(_epoch.EpochMilliSeconds, heartbeat.HeartbeatTime)))
                                      .Subscribe();

            _candleGeneratedDualChannel = new CandleGeneratedDualChannel(this);

            _serverTimeSync = new TimeSyncListenerChannel(this);

            _profileChannel = new ProfileListenerChannel(this);

            _listInfoDataChannelListener = new ListInfoDataListenerChannel(this);

            _buyV2ChannelPublisher = new BuyV2Channel(this, _epoch);
        }
示例#3
0
            /// <summary>
            /// Initiates a channel publishing process.
            /// </summary>
            /// <param name="channelPublisher">Instance of the object which implements IChannelPublisher.</param>
            /// <returns>Return publishing parameters.</returns>
            /// <remarks>Retrieves the channel info from the CRT, then executes callbacks for the supplied IChannelPublisher and finally updates the channel publishing status in CRT/AX.</remarks>
            public PublishingParameters PublishChannel(IChannelPublisher channelPublisher)
            {
                if (channelPublisher == null)
                {
                    throw new ArgumentNullException(nameof(channelPublisher));
                }

                if (this.onlineChannel.PublishStatus != OnlineChannelPublishStatusType.Published &&
                    this.onlineChannel.PublishStatus != OnlineChannelPublishStatusType.InProgress)
                {
                    throw new ChannelNotPublishedException(Resources.ErrorChannelNotInPublishedState, this.onlineChannel.PublishStatus, this.onlineChannel.PublishStatusMessage);
                }

                IEnumerable <Category> categories;
                Dictionary <long, IEnumerable <AttributeCategory> > categoriesAttributes;

                // always load the categories but process them only if the channel is not published yet.
                try
                {
                    this.LoadCategories(out categories, out categoriesAttributes);
                    int categoriesCount = categories.Count();
                    NetTracer.Information(Resources.NumberOfReadCategoriesAndTheirAttributes, categoriesCount, categoriesAttributes.Count());
                    if (categoriesCount == 0)
                    {
                        throw new InvalidDataException(string.Format(
                                                           "Navigation categories count returned is '{0}'. Error details {1}",
                                                           categoriesCount,
                                                           Resources.ErrorNoNavigationCategories));
                    }

                    // Loading product attributes schema from CRT
                    IEnumerable <AttributeProduct> productAttributes = this.LoadProductAttributes();
                    channelPublisher.OnValidateProductAttributes(productAttributes);

                    int listingAttributesCount = productAttributes.Count();
                    NetTracer.Information(Resources.NumberOfReadAttributes, listingAttributesCount);
                    if (listingAttributesCount == 0)
                    {
                        throw new InvalidDataException(string.Format(
                                                           "Listing Attributes Count returned is '{0}'. Error details '{1}'",
                                                           listingAttributesCount,
                                                           Resources.ErrorNoSchemaAttributes));
                    }

                    ChannelLanguage language = this.onlineChannel.ChannelLanguages.Single(l => l.IsDefault);
                    CultureInfo     culture  = new CultureInfo(language.LanguageId);

                    PublishingParameters parameters = new PublishingParameters
                    {
                        Categories            = categories,
                        CategoriesAttributes  = categoriesAttributes,
                        ProductsAttributes    = productAttributes,
                        ChannelDefaultCulture = culture,
                        GiftCartItemId        = this.channelManager.GetChannelConfiguration().GiftCardItemId
                    };

                    if (this.onlineChannel.PublishStatus == OnlineChannelPublishStatusType.InProgress)
                    {
                        channelPublisher.OnChannelInformationAvailable(parameters, true);
                        this.channelManager.UpdateOnlineChannelPublishStatus(OnlineChannelPublishStatusType.Published, null);
                    }
                    else
                    {
                        channelPublisher.OnChannelInformationAvailable(parameters, false);
                    }

                    return(parameters);
                }
                catch (Exception ex)
                {
                    RetailLogger.Log.EcommercePlatformChannelPublishFailure(ex);
                    string error = string.Format(CultureInfo.InvariantCulture, Resources.ErrorChannelPublishingFailed, ex.Message, DateTime.Now);
                    this.channelManager.UpdateOnlineChannelPublishStatus(OnlineChannelPublishStatusType.Failed, error);
                    throw;
                }
            }
示例#4
0
 protected IqOptionGenericDualChannel(IChannelListener <TInMessage> channelListener, IChannelPublisher <TOutMessage, IQOptionMessage> channelPublisher)
 {
     _channelPublisher = channelPublisher;
     _channelListener  = channelListener;
 }
示例#5
0
 public CandleGeneratedDualChannel(IWsIQClient wsIqClient)
 {
     _channelListener  = new IqOptionGenericChannelListener <Candle>(wsIqClient, ListenerChannelName);
     _channelPublisher = new IqOptionGenericChannelPublisher <dynamic>(wsIqClient, PublisherChannelName);
 }