Exemplo n.º 1
0
 public ConfigureCommandRequest(HandshakeResponse response, shareAction1 s1, shareAction2 s2) : base(response, s1, s2)
 {
     this.dataBelong = 0;
     this.number     = FrequencyAction.GetNuRenewAction();
     this.dotPwoer   = ChannelAction.GetNuRenewAction();
     this.request    = DateAction.GetNuRenewAction();
 }
Exemplo n.º 2
0
        public override void ConfigureServices(IServiceCollection services, IPlatform platform)
        {
            services.UseSqliteStore();
            //services.UseSqliteStorage();
            services.AddSingleton <AppNotifications>();
            services.AddSingleton <IDialogs, Dialogs>();

            // your infrastructure
            services.AddSingleton <SampleSqliteConnection>();
            services.AddSingleton <CoreDelegateServices>();
            services.AddSingleton <IAppSettings, AppSettings>();

            // startup tasks
            services.AddSingleton <GlobalExceptionHandler>();
            services.AddSingleton <JobLoggerTask>();

            // register all of the shiny stuff you want to use
            //services.UseJobForegroundService(TimeSpan.FromSeconds(30));
            services.UseHttpTransfers <HttpTransferDelegate>();
            services.UseBeaconRanging();
            services.UseBeaconMonitoring <BeaconDelegate>();
            services.UseBleClient <BleClientDelegate>();
            services.UseBleHosting();
            services.UseSpeechRecognition();
            services.UseAllSensors();
            services.UseNfc();

            services.UseTestMotionActivity();
            //services.UseMotionActivity();

            services.UseGeofencing <GeofenceDelegate>();
            //services.UseGpsDirectGeofencing<LocationDelegates>();
            services.UseGps <GpsDelegate>();

            services.UseNotifications <NotificationDelegate>(null, new[] {
                Channel.Create(
                    "Test",
                    ChannelAction.Create("Reply", ChannelActionType.TextReply),
                    ChannelAction.Create("Yes"),
                    ChannelAction.Create("No", ChannelActionType.Destructive)
                    ),
                Channel.Create(
                    "ChatName",
                    ChannelAction.Create("Answer", ChannelActionType.TextReply)
                    ),
                Channel.Create(
                    "ChatAnswer",
                    ChannelAction.Create("Yes"),
                    ChannelAction.Create("No", ChannelActionType.Destructive)
                    )
            });

            //services.UsePush<PushDelegate>();
            //services.UseFirebaseMessaging<PushDelegate>();
            services.UsePushAzureNotificationHubs <PushDelegate>(
                Secrets.Values.AzureNotificationHubListenerConnectionString,
                Secrets.Values.AzureNotificationHubName
                );
        }
Exemplo n.º 3
0
        public static string ChannelMode(string channel, ChannelMode mode, ChannelAction action)
        {
            string actionName = $"{(char)action}";
            string modeName   = $"{(char)mode}";
            string command    = $"MODE {channel} {actionName}{modeName}";

            return(command);
        }
Exemplo n.º 4
0
        public static string ChannelMode(string channel, ChannelMode mode, ChannelAction action, List <string> modeParams)
        {
            string param      = $" {string.Join(" ", modeParams)}";
            string actionName = $"{(char)action}";
            string modeName   = $"{(char)mode}";
            string command    = $"MODE {channel} {actionName}{modeName}{param}";

            return(command);
        }
        protected override void Work(MainViewModel input)
        {
            _vm = input;

            // Initial delay before outputting starts
            Thread.Sleep(1000);

            while (IsStopPending == false)
            {
                // Create random channel message
                int           index             = _random.Next(0, 6);
                ChannelAction action            = (ChannelAction)_random.Next(0, 2);
                int           messageBufferSize = _random.Next(0, 64);
                string        messageBuffer     = GenerateRandomString(messageBufferSize, false);

                ChannelMessage channelMessage = new ChannelMessage(index, action, messageBuffer);
                _vm.OnNewChannelMessage(channelMessage);

                Thread.Sleep(_random.Next(100, 500));
            }
        }
Exemplo n.º 6
0
        public async Task Run()
        {
            var nickName = configuration["NickName"];
            var userName = configuration["UserName"];
            var realName = configuration["RealName"];
            var channels = configuration["Channels"].Split(',').Select(x => x.Trim()).ToList();

            ircLayer = new IrcLayer(configuration);

            var server = configuration["Server"];

            if (string.IsNullOrWhiteSpace(server))
            {
                throw new Exception("No server given");
            }

            var hasPort = int.TryParse(configuration["Port"], out var port);

            bool.TryParse(configuration["UseSsl"], out var useSsl);

            if (!hasPort)
            {
                port = useSsl ? 6697 : 6667;
            }

            nexmo = new NexmoClient(configuration);
            noticeActions.AddRange(NoticeAction.GetAll(ircLayer, nexmo, configuration));
            channelActions.AddRange(ChannelAction.GetAll(ircLayer, nexmo, configuration));
            channelCommands.AddRange(Command.GetAll(ircLayer, nexmo, configuration));

            ircLayer.OnMessageReceived += IrcLayerOnOnMessageReceived;
            ircLayer.OnNoticeReceived  += IrcLayerOnOnNoticeReceived;
            ircLayer.OnQueryReceived   += IrcLayerOnOnQueryReceived;
            ircLayer.Disconnected      += IrcLayerDisconnected;
            await ircLayer.Connect(server, port, useSsl, nickName, userName, realName, channels);

            IsConnected = true;
        }
Exemplo n.º 7
0
        public async Task StartSetChannelAction(IClient client, long channelId, ChannelAction action)
        {
            if (client.FocusedChannelId != default && client.FocusedChannelId != channelId)
            {
                var packet = packets.New <P2CChannelAction>();
                packet.ChannelId = client.FocusedChannelId;
                packet.AccountId = client.AccountId;
                packet.Action    = ChannelAction.None;
                await delivery.StartSendToChannel(packet, client.FocusedChannelId, client).ConfigureAwait(false);
            }

            if (channelId != default && (channelId != client.FocusedChannelId || action != client.ChannelAction))
            {
                var packet = packets.New <P2CChannelAction>();
                packet.ChannelId = channelId;
                packet.AccountId = client.AccountId;
                packet.Action    = action;
                await delivery.StartSendToChannel(packet, channelId, client).ConfigureAwait(false);
            }

            client.FocusedChannelId = channelId;
            client.ChannelAction    = action;
        }
        protected override IWebSocket OnGetOrderBookDeltasWebSocket(Action <ExchangeOrderBook> callback, int maxCount = 20, params string[] symbols)
        {
            return(ConnectWebSocket(string.Empty, (_socket, msg) =>
            {
                string message = msg.ToStringFromUTF8();
                var book = new ExchangeOrderBook();

                // string comparison on the json text for faster deserialization
                // More likely to be an l2update so check for that first
                if (message.Contains(@"""l2update"""))
                {
                    // parse delta update
                    var delta = JsonConvert.DeserializeObject <Level2>(message);
                    book.Symbol = delta.ProductId;
                    book.SequenceId = delta.Time.Ticks;
                    foreach (string[] change in delta.Changes)
                    {
                        decimal price = change[1].ConvertInvariant <decimal>();
                        decimal amount = change[2].ConvertInvariant <decimal>();
                        if (change[0] == "buy")
                        {
                            book.Bids[price] = new ExchangeOrderPrice {
                                Amount = amount, Price = price
                            };
                        }
                        else
                        {
                            book.Asks[price] = new ExchangeOrderPrice {
                                Amount = amount, Price = price
                            };
                        }
                    }
                }
                else if (message.Contains(@"""snapshot"""))
                {
                    // parse snapshot
                    var snapshot = JsonConvert.DeserializeObject <Snapshot>(message);
                    book.Symbol = snapshot.ProductId;
                    foreach (decimal[] ask in snapshot.Asks)
                    {
                        decimal price = ask[0];
                        decimal amount = ask[1];
                        book.Asks[price] = new ExchangeOrderPrice {
                            Amount = amount, Price = price
                        };
                    }

                    foreach (decimal[] bid in snapshot.Bids)
                    {
                        decimal price = bid[0];
                        decimal amount = bid[1];
                        book.Bids[price] = new ExchangeOrderPrice {
                            Amount = amount, Price = price
                        };
                    }
                }
                else
                {
                    // no other message type handled
                    return Task.CompletedTask;
                }

                callback(book);
                return Task.CompletedTask;
            }, async(_socket) =>
            {
                // subscribe to order book channel for each symbol
                if (symbols == null || symbols.Length == 0)
                {
                    symbols = (await GetSymbolsAsync()).ToArray();
                }
                var chan = new Channel {
                    Name = ChannelType.Level2, ProductIds = symbols.ToList()
                };
                var channelAction = new ChannelAction {
                    Type = ActionType.Subscribe, Channels = new List <Channel> {
                        chan
                    }
                };
                await _socket.SendMessageAsync(JsonConvert.SerializeObject(channelAction));
            }));
        }
Exemplo n.º 9
0
        protected override IWebSocket OnGetOrderBookDeltasWebSocket(Action <ExchangeOrderBook> callback, int maxCount = 20, params string[] symbols)
        {
            if (callback == null || symbols == null || symbols.Length == 0)
            {
                return(null);
            }

            return(ConnectWebSocket(string.Empty, (msg, _socket) =>
            {
                try
                {
                    string message = msg.UTF8String();
                    var book = new ExchangeOrderBook();

                    // string comparison on the json text for faster deserialization
                    // More likely to be an l2update so check for that first
                    if (message.Contains(@"""l2update"""))
                    {
                        // parse delta update
                        var delta = JsonConvert.DeserializeObject <Level2>(message);
                        book.Symbol = delta.ProductId;
                        book.SequenceId = delta.Time.Ticks;
                        foreach (string[] change in delta.Changes)
                        {
                            decimal price = change[1].ConvertInvariant <decimal>();
                            decimal amount = change[2].ConvertInvariant <decimal>();
                            if (change[0] == "buy")
                            {
                                book.Bids[price] = new ExchangeOrderPrice {
                                    Amount = amount, Price = price
                                };
                            }
                            else
                            {
                                book.Asks[price] = new ExchangeOrderPrice {
                                    Amount = amount, Price = price
                                };
                            }
                        }
                    }
                    else if (message.Contains(@"""snapshot"""))
                    {
                        // parse snapshot
                        var snapshot = JsonConvert.DeserializeObject <Snapshot>(message);
                        book.Symbol = snapshot.ProductId;
                        foreach (decimal[] ask in snapshot.Asks)
                        {
                            decimal price = ask[0];
                            decimal amount = ask[1];
                            book.Asks[price] = new ExchangeOrderPrice {
                                Amount = amount, Price = price
                            };
                        }

                        foreach (decimal[] bid in snapshot.Bids)
                        {
                            decimal price = bid[0];
                            decimal amount = bid[1];
                            book.Bids[price] = new ExchangeOrderPrice {
                                Amount = amount, Price = price
                            };
                        }
                    }
                    else
                    {
                        // no other message type handled
                        return;
                    }

                    callback(book);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine($"ExchangeCoinbaseAPI.OnGetOrderBookDeltasWebSocket: {ex.Message}");
                }
            }, _socket =>
            {
                // subscribe to order book channel for each symbol
                var chan = new Channel {
                    Name = ChannelType.Level2, ProductIds = symbols.ToList()
                };
                var channelAction = new ChannelAction {
                    Type = ActionType.Subscribe, Channels = new List <Channel> {
                        chan
                    }
                };
                _socket.SendMessage(JsonConvert.SerializeObject(channelAction));
            }));
        }
Exemplo n.º 10
0
 protected override void ReadPacketInternal(PacketBuffer buffer, PacketRole role)
 {
     ChannelId = buffer.ReadInt64();
     AccountId = buffer.ReadInt64();
     Action    = (ChannelAction)buffer.ReadByte();
 }
Exemplo n.º 11
0
 public void SetChannel(int channelNum)
 {
     this.dotPwoer = ChannelAction.GetRenewAction(channelNum);
 }
        protected override PendingIntent CreateActionIntent(Notification notification, ChannelAction action)
        {
            var intent = this.Services.Android.CreateIntent <ShinyPushNotificationBroadcastReceiver>(ShinyPushNotificationBroadcastReceiver.EntryIntentAction);

            this.PopulateIntent(intent, notification);
            intent.PutExtra(INTENT_KEY, action.Identifier);

            counter++;
            var pendingIntent = PendingIntent.GetBroadcast(
                this.Services.Android.AppContext,
                counter,
                intent,
                PendingIntentFlags.UpdateCurrent
                ) !;

            return(pendingIntent);
        }
Exemplo n.º 13
0
 public ChannelMessage(int index, ChannelAction action, string messageBuffer)
 {
     Index         = index;
     Action        = action;
     MessageBuffer = messageBuffer;
 }
Exemplo n.º 14
0
 /// <summary>
 /// 更换频道
 /// </summary>
 /// <param name="action"></param>
 /// <param name="num"></param>
 public void ChangeChannel(ChannelAction action, int num = 0)
 {
     var msg = BuildActionSignal(ActionType.CHANGE_CHANNEL, string.Format("{{action:{0}, num: {1}}}", (int)action, num) );
     SendMessage(msg);  
 }