Beispiel #1
0
 public DistributionCommand(INotifiactionSender notificator, IBotDataStorage storage, IKeyboardsFactory keyboards, SecretKey secret, ILogger <DistributionCommand> logger = null) : base("sendsudo")
 {
     this.notificator = notificator;
     this.storage     = storage;
     this.keyboards   = keyboards;
     this.secret      = secret;
     this.logger      = logger;
 }
        public void SetUp()
        {
            availableGroups = fixt.CreateMany <ScheduleGroup>(10);
            fakeService     = A.Fake <IScheduleService>();
            fakeNotificator = A.Fake <INotifiactionSender>();
            storage         = new InMemoryBotStorage(fakeService, fakeNotificator);
            IScheduleGroup @out;

            A.CallTo(() => fakeService.GroupsMonitor.TryGetCorrectGroup(null, out @out)).WithAnyArguments().Returns(true)
            .AssignsOutAndRefParametersLazily(
                call => new List <object>()
            {
                call.Arguments[0]
            });
        }
 public InMemoryBotStorage(IScheduleService service, INotifiactionSender notifiactionSender,
                           ILogger <InMemoryBotStorage> logger = null)
 {
     this.service            = service;
     this.notifiactionSender = notifiactionSender;
     this.logger             = logger;
     path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/BotServices/" + XmlFileName;
     try
     {
         var doc   = XDocument.Load(path);
         var users = doc.Element("users")?.Elements("user");
         foreach (var user in users)
         {
             var groups = user.Element("groups").Elements("group");
             foreach (var subGroup in groups)
             {
                 if (service.GroupsMonitor.TryFindGroupByName(subGroup.Attribute("name").Value, out var group))
                 {
                     if (long.TryParse(user.Element("chatId").Value, out var chatId))
                     {
                         AddGroupToUserInMemory(chatId, group);
                     }
                 }
                 else
                 {
                     logger?.LogError(
                         $"no group found of user {user.Element("chatId").Value} with name: {subGroup.Attribute("name").Value}");
                 }
             }
         }
     }
     catch (Exception e)
     {
         logger?.LogError(e, "Exc");
         logger?.LogWarning("but i'm alive");
     }
 }