Ejemplo n.º 1
0
 public void Initialize(WialonApi api, YandexApi yandexApi, SqlRepository sql)
 {
     WialonApi = api;
     Logger    = LogManager.GetCurrentClassLogger();
     YandexApi = yandexApi;
     Sql       = sql;
 }
 public AudioPlayer(YandexApi api, List <YandexTrack> tracks)
 {
     _api         = api;
     _tracks      = tracks;
     _activeTrack = 0;
     _currentTime = new TimeSpan();
 }
Ejemplo n.º 3
0
        public Router Create(YandexApi yandexApi, ITelegramBotClient bot)
        {
            _yandexApi = yandexApi;
            _bot       = bot;

            return(this);
        }
Ejemplo n.º 4
0
        private void BotOnSearchArtist(object sender, MessageEventArgs e)
        {
            Bot.OnMessage -= BotOnSearchArtist;

            Log.Information($"Search track: {e.Message.Text}");

            var message = e.Message;

            try
            {
                var artists     = YandexApi.SearchArtist(message.Text);
                var infoMessage = Bot.SendTextMessageAsync(
                    message.Chat.Id,
                    $"Я пришлю вам 5 артистов по запросу \"{message.Text}\", в ближайшее время");

                for (var i = 0; i < artists.Count; i++)
                {
                    Bot.SendTextMessageAsync(message.Chat.Id, $"Исполнитель: {artists[i].Name}",
                                             replyMarkup: new InlineKeyboardMarkup(new[]
                    {
                        InlineKeyboardButton.WithCallbackData("Подробнее...", "no")
                    }));

                    Log.Information($"[SUCCESS] {artists[i].Name}");
                }

                Bot.SendTextMessageAsync(message.Chat.Id, "Еще что-то поищим?",
                                         replyMarkup: KeyboardBuilder.CreateSearchKeyboardMarkup()).GetAwaiter()
                .GetResult();
            }
            catch (Exception ex)
            {
                Log.Error($"Error message: {ex.Message}\nStackTrace: {ex.StackTrace}");
            }
        }
Ejemplo n.º 5
0
        public void GetTrackTest(string userName, string password, string trackName, string expectedResult)
        {
            var yandexApi = new YandexApi();

            yandexApi.Password = password.ToCharArray();
            yandexApi.UserName = userName.ToCharArray();
            Assert.AreEqual(expectedResult, yandexApi.GetTrack(trackName).Title);
        }
Ejemplo n.º 6
0
        public void GetPlayListOfTheDay(string userName, string password, string expectedResult)
        {
            var yandexApi = new YandexApi();

            yandexApi.Password = password.ToCharArray();
            yandexApi.UserName = userName.ToCharArray();
            Assert.AreEqual(expectedResult, yandexApi.GetPlayOfTheDay().Title);
        }
Ejemplo n.º 7
0
        public void LogInTest(string userName, string password)
        {
            var yandexApi = new YandexApi();

            yandexApi.Password = password.ToCharArray();
            yandexApi.UserName = userName.ToCharArray();
            yandexApi.Authorize();
            Assert.True(true, "Some error");
        }
Ejemplo n.º 8
0
        public override void Execute()
        {
            _dateTimeExecute = DateTime.Now;
            var isFirst = true;

            while (true)
            {
                if (!isFirst)
                {
                    Thread.Sleep(1000);
                }
                else
                {
                    isFirst = false;
                }
                if ((DateTime.Now - _dateTimeExecute).TotalMinutes > 2)
                {
                    Logger.Warn($"Not finded today payment, driver: {_driver}");
                    return;
                }
                var balance = YandexApi.GetLastJobPayForDriver(_driver.YandexId);
                if (balance == null)
                {
                    Logger.Debug($"Not finded today payment, driver: {_driver}");
                    continue;
                }

                if (balance.IsToday &&
                    balance.PaymentType == "Job.Payment" &&
                    balance.Balance < 0)
                {
                    var unit = WialonApi.GetUnit(_car);
                    if (unit == null)
                    {
                        Logger.Warn($"Car for [{_driver}] not finded in wialon!");
                        Sql.Notifications.Add(new Notification
                        {
                            Type        = "WialonCarNotFinded",
                            Message     = $"Не удалось найти машину {_car} для блокировки",
                            InternalId  = _car.Id,
                            DateCreated = DateTime.Now
                        });
                        Sql.SaveChanges();
                        return;
                    }
                    IocKernel.Get <CoreProccessor>().ExecuteCommand(new BlockUnitCommand(_driver, unit));
                    Logger.Info($"Driver [{_driver}] send to block");
                    return;
                }
            }
        }
Ejemplo n.º 9
0
        private void BotOnSearchTrack(object sender, MessageEventArgs e)
        {
            Bot.OnMessage -= BotOnSearchTrack;

            Log.Information($"Search track: {e.Message.Text}");

            var message = e.Message;

            try
            {
                var tracks      = YandexApi.SearchTrack(message.Text);
                var infoMessage = Bot.SendTextMessageAsync(
                    message.Chat.Id,
                    $"Я пришлю вам 5 треков по запросу \"{message.Text}\", в ближайшее время");

                for (var i = 0; i < 5; i++)
                {
                    if (i > tracks.Count)
                    {
                        break;
                    }

                    var track       = YandexApi.GetTrack(tracks[i].Id);
                    var streamTrack = YandexApi.ExtractStreamTrack(track);
                    var artistName  = track.Artists.FirstOrDefault()?.Name;

                    Log.Information($"[SEND] {track.Title}");

                    Task.WaitAll(streamTrack.Task);

                    var inputStream = new InputOnlineFile(streamTrack, $"{artistName} - {track.Title}");

                    Bot.SendAudioAsync(
                        message.Chat.Id,
                        inputStream, disableNotification: true).GetAwaiter().GetResult();

                    Log.Information($"[SUCCESS] {track.Title}");
                }

                Bot.SendTextMessageAsync(message.Chat.Id, "Еще что-то поищим?",
                                         replyMarkup: KeyboardBuilder.CreateSearchKeyboardMarkup()).GetAwaiter()
                .GetResult();
            }
            catch (Exception ex)
            {
                Log.Error($"Error message: {ex.Message}\nStackTrace: {ex.StackTrace}");
            }
        }
Ejemplo n.º 10
0
        public override void Execute()
        {
            var drivers = YandexApi.GetDrivers();

            foreach (var driver in drivers)
            {
                if (!Sql.CreateOrUpdateDriver(driver))
                {
                    Logger.Error($"Update driver data failed: {driver}");
                }

                if (!Sql.CreateOrUpdateCar(driver.Car))
                {
                    Logger.Error($"Update car data failed: {driver.Car}");
                }
            }
        }
Ejemplo n.º 11
0
 public LoginPanel(YandexApi api)
 {
     _api = api;
 }
Ejemplo n.º 12
0
 public Session(TelegramBotClient bot, YandexApi yandexApi)
 {
     Bot       = bot;
     YandexApi = yandexApi;
 }