public List <RecordDto> GetAll()
        {
            List <RecordDto> result = new List <RecordDto>();
            IEnumerable <ConfigurationRecord> cacheRecordDto = GetCachedRecords();

            if (cacheRecordDto != null)
            {
                result = cacheRecordDto.Select(p => new RecordDto()
                {
                    ApplicationName = p.ApplicationName,
                    Guid            = p.GuId,
                    Name            = p.Name,
                    Value           = p.Value,
                    Type            = p.Type
                }
                                               ).ToList();
            }
            else
            {
                var records = _storage.Get(_applicationName).ToList();
                result = records.Select(p => new RecordDto()
                {
                    Name            = p.Name,
                    Type            = p.Type,
                    Value           = p.Value,
                    Guid            = p.GuId,
                    ApplicationName = p.ApplicationName
                }
                                        ).ToList();
            }
            return(result);
        }
 public Task <Result <(Image Image, IReadOnlyCollection <Thumbnail> Thumbnails), Error> > CreateImageWithThumbnails(
     Name galleryName, Id id, uint rowVersion, Option <byte[]> meta, byte[] raw)
 {
     return(_configurationStorage
            .Get(galleryName)
            .AndThenAsync(configuration => _imageFactory.Create(id, rowVersion, meta, raw, configuration)));
 }
示例#3
0
        public void GetValueWithId_StorageExistsCacheNull_Returns()
        {
            var objectId            = new MongoDB.Bson.ObjectId();
            var configurationRecord = new ConfigurationRecord()
            {
                Value = "boyner.com.tr",
                Type  = "String",
                GuId  = objectId,
                Name  = "site"
            };

            _configurationStorage.Get(Arg.Any <string>(), applicationName).Returns(configurationRecord);
            _cacheManager.Get <IEnumerable <ConfigurationRecord> >("site").Returns((IEnumerable <ConfigurationRecord>)null);

            var manager     = new ConfigurationReader(applicationName, "hede", 10, _configurationStorageFactory, _cacheManagerFactory, _configurationStorage);
            var returnValue = manager.GetValueWithId("site");

            Assert.AreEqual(configurationRecord.Value, returnValue.Value);
        }
示例#4
0
        public KeeperEndpoint(IConfigurationStorage storage)
        {
            Storage       = storage;
            ClientVersion = KeeperApiCommand.ClientVersion;
            Locale        = KeeperSettings.DefaultLocale();
            ServerKeyId   = 1;

            var conf = storage.Get();

            Server = conf.LastServer;
            var servConf = conf.GetServerConfiguration(Server);

            if (servConf != null)
            {
                EncryptedDeviceToken = servConf.DeviceId;
                ServerKeyId          = servConf.ServerKeyId;
            }
        }
示例#5
0
        public async Task <PreLoginResponse> GetPreLogin(string username, byte[] twoFactorToken = null)
        {
            var oldDeviceToken = EncryptedDeviceToken;

            if (EncryptedDeviceToken == null)
            {
                EncryptedDeviceToken = await GetDeviceToken();
            }

            var attempt = 0;

            while (attempt < 3)
            {
                attempt++;

                var preLogin = new PreLoginRequest()
                {
                    AuthRequest = new AuthRequest
                    {
                        ClientVersion        = ClientVersion,
                        Username             = username,
                        EncryptedDeviceToken = ByteString.CopyFrom(EncryptedDeviceToken)
                    },
                    LoginType = LoginType.Normal
                };

                if (twoFactorToken != null)
                {
                    preLogin.TwoFactorToken = ByteString.CopyFrom(twoFactorToken);
                }

                byte[] response = null;
                try
                {
                    response = await ExecuteRest("authentication/pre_login", preLogin.ToByteArray());
                }
                catch (KeeperInvalidDeviceToken)
                {
                    EncryptedDeviceToken = await GetDeviceToken();

                    continue;
                }
                catch (KeeperRegionRedirect redirect)
                {
                    var conf       = Storage.Get();
                    var serverConf = conf.GetServerConfiguration(Server);
                    if (serverConf != null)
                    {
                        if (!(EncryptedDeviceToken.SequenceEqual(serverConf.DeviceId) && ServerKeyId == serverConf.ServerKeyId))
                        {
                            var c = new Configuration();
                            c._servers.Add(Server.AdjustServerUrl(), new ServerConfiguration {
                                Server      = Server,
                                DeviceId    = EncryptedDeviceToken,
                                ServerKeyId = ServerKeyId
                            });
                            Storage.Put(c);
                        }
                    }
                    Server               = redirect.RegionHost;
                    serverConf           = conf.GetServerConfiguration(Server);
                    EncryptedDeviceToken = serverConf?.DeviceId;
                    if (EncryptedDeviceToken == null)
                    {
                        EncryptedDeviceToken = await GetDeviceToken();
                    }

                    continue;
                }

                return(PreLoginResponse.Parser.ParseFrom(response));
            }

            throw new KeeperTooManyAttempts();
        }
        public async Task <Result <Contracts.ProcessingConfiguration, Contracts.Error> > GetAsync(string gallery)
        {
            var result = await Name.FromString(gallery).AndThenAsync(name => _storage.Get(name));

            return(result.Map(ToContract, ErrorExtensions.ToContract));
        }