Exemplo n.º 1
0
        public async Task <IEnumerable <TSchema> > GetDataByIdsAsync <TSchema>(DynamicStorageDataConfig config, IEnumerable <string> ids, IParser <TSchema> parser) where TSchema : SchemaBase
        {
            var url = $"{config.Url}&ids={string.Join("&ids=", ids)}";

            var settings = new HttpRequestSettings
            {
                RequestedUri = new Uri(url),
                UserAgent    = "NativeHost"
            };

            settings.Headers["WAS-APPID"]        = config.AppId;
            settings.Headers["WAS-STOREID"]      = config.StoreId;
            settings.Headers["WAS-DEVICETYPE"]   = config.DeviceType;
            settings.Headers["WAS-ISBACKGROUND"] = config.IsBackgroundTask.ToString();

            HttpRequestResult result = await HttpRequest.DownloadAsync(settings);

            if (result.Success)
            {
                var items = await parser.ParseAsync(result.Result);

                return(items);
            }

            throw new RequestFailedException(result.StatusCode, result.Result);
        }
Exemplo n.º 2
0
 protected override void ValidateConfig(DynamicStorageDataConfig config)
 {
     if (config.Url == null)
     {
         throw new ConfigParameterNullException("Url");
     }
 }
Exemplo n.º 3
0
        private async Task <IEnumerable <TSchema> > GetDataFromProvider <TSchema>(DynamicStorageDataConfig config, int pageSize, IParser <TSchema> parser) where TSchema : SchemaBase
        {
            var settings = new HttpRequestSettings
            {
                RequestedUri = GetUrl(config, pageSize),
                UserAgent    = "NativeHost"
            };

            settings.Headers["WAS-APPID"]        = config.AppId;
            settings.Headers["WAS-STOREID"]      = config.StoreId;
            settings.Headers["WAS-DEVICETYPE"]   = config.DeviceType;
            settings.Headers["WAS-ISBACKGROUND"] = config.IsBackgroundTask.ToString();

            HttpRequestResult result = await HttpRequest.DownloadAsync(settings);

            if (result.Success)
            {
                var items = await parser.ParseAsync(result.Result);

                _hasMoreItems     = items.Any();
                ContinuationToken = GetContinuationToken(ContinuationToken);
                return(items);
            }

            throw new RequestFailedException(result.StatusCode, result.Result);
        }
Exemplo n.º 4
0
        private Uri GetUrl(DynamicStorageDataConfig config, int pageSize)
        {
            var sortDirection = config.OrderDirection == SortDirection.Ascending ? "ASC" : "DESC";
            var url           = $"{config.Url}&pageIndex={ContinuationToken}&blockSize={pageSize}";

            if (!string.IsNullOrEmpty(config.OrderBy))
            {
                url += $"&orderby={config.OrderBy}&sortdirection={sortDirection}";
            }
            return(new Uri(url));
        }
 private static void Assertions(DynamicStorageDataConfig config, IParser <T> parser)
 {
     if (config == null)
     {
         throw new ConfigNullException();
     }
     if (parser == null)
     {
         throw new ParserNullException();
     }
     if (config.Url == null)
     {
         throw new ConfigParameterNullException("Url");
     }
 }
Exemplo n.º 6
0
        public async Task LoadDynamicCollection()
        {
            var config = new DynamicStorageDataConfig
            {
                AppId = Guid.Empty.ToString(),
                StoreId = Guid.Empty.ToString(),
                DeviceType = "WINDOWS",
                Url = new Uri("http://appstudio-dev.cloudapp.net/api/data/collection?dataRowListId=6db1e7d0-5216-4519-8978-d51f1452f9f2&appId=7c181582-15d0-42f7-b3eb-ab5d2e7d2c8a")
            };

            var dataProvider = new DynamicStorageDataProvider<CollectionSchema>();
            IEnumerable<CollectionSchema> data = await dataProvider.LoadDataAsync(config);

            Assert.IsNotNull(data);
            Assert.AreNotEqual(data.Count(), 0);
        }
        public override async Task <IEnumerable <T> > LoadDataAsync(DynamicStorageDataConfig config, IParser <T> parser)
        {
            Assertions(config, parser);

            var settings = new HttpRequestSettings
            {
                RequestedUri = new Uri(string.Format("{0}&pageIndex={1}&blockSize={2}", config.Url, config.PageIndex, config.BlockSize)),
                UserAgent    = "NativeHost"
            };

            settings.Headers["WAS-APPID"]        = config.AppId;
            settings.Headers["WAS-STOREID"]      = config.StoreId;
            settings.Headers["WAS-DEVICETYPE"]   = config.DeviceType;
            settings.Headers["WAS-ISBACKGROUND"] = config.IsBackgroundTask.ToString();

            HttpRequestResult result = await HttpRequest.DownloadAsync(settings);

            if (result.Success)
            {
                return(parser.Parse(result.Result));
            }

            throw new RequestFailedException(result.StatusCode, result.Result);
        }
Exemplo n.º 8
0
 protected override async Task <IEnumerable <TSchema> > GetDataAsync <TSchema>(DynamicStorageDataConfig config, int pageSize, IParser <TSchema> parser)
 {
     ContinuationToken = config.PageIndex.ToString();
     return(await GetDataFromProvider(config, pageSize, parser));
 }
 public override async Task <IEnumerable <T> > LoadDataAsync(DynamicStorageDataConfig config)
 {
     return(await LoadDataAsync(config, new GenericParser <T>()));
 }
Exemplo n.º 10
0
 protected override IParser <T> GetDefaultParserInternal(DynamicStorageDataConfig config)
 {
     return(new JsonParser <T>());
 }
Exemplo n.º 11
0
        public async Task LoadMoreDynamicCollection_Sorting()
        {

            var config = new DynamicStorageDataConfig
            {
                AppId = Guid.Empty.ToString(),
                StoreId = Guid.Empty.ToString(),
                DeviceType = "WINDOWS",
                Url = new Uri("http://appstudio-dev.cloudapp.net/api/data/collection?dataRowListId=6389c5e8-788e-42cc-8b74-a16fca5e4bf3&appId=d3fdeca1-ee0e-482c-bc19-82e344d2b78c")
            };

            var dataProvider = new DynamicStorageDataProvider<CollectionSchema2>();

            config.OrderBy = "Title";
            config.OrderDirection = SortDirection.Ascending;
            IEnumerable<CollectionSchema2> dataAsc = await dataProvider.LoadDataAsync(config, 2);
            dataAsc = await dataProvider.LoadMoreDataAsync();
            config.OrderDirection = SortDirection.Descending;
            IEnumerable<CollectionSchema2> dataDesc = await dataProvider.LoadDataAsync(config, 2);
            dataDesc = await dataProvider.LoadMoreDataAsync();

            var dataExpected = dataAsc.OrderBy(x => x.Title).ToList();
            for (int i = 0; i < dataExpected.Count() - 1; i++)
            {
                Assert.AreEqual(dataExpected[i].Title, dataAsc.ToList()[i].Title);
            }

            dataExpected = dataDesc.OrderByDescending(x => x.Title).ToList();
            for (int i = 0; i < dataExpected.Count() - 1; i++)
            {
                Assert.AreEqual(dataExpected[i].Title, dataDesc.ToList()[i].Title);
            }

            config.OrderBy = "Date";
            config.OrderDirection = SortDirection.Ascending;
            dataAsc = await dataProvider.LoadDataAsync(config, 2);
            dataAsc = await dataProvider.LoadMoreDataAsync();
            config.OrderDirection = SortDirection.Descending;
            dataDesc = await dataProvider.LoadDataAsync(config, 2);
            dataDesc = await dataProvider.LoadMoreDataAsync();

            dataExpected = dataAsc.OrderBy(x => x.Date).ToList();
            for (int i = 0; i < dataExpected.Count() - 1; i++)
            {
                Assert.AreEqual(dataExpected[i].Title, dataAsc.ToList()[i].Title);
            }

            dataExpected = dataDesc.OrderByDescending(x => x.Date).ToList();
            for (int i = 0; i < dataExpected.Count() - 1; i++)
            {
                Assert.AreEqual(dataExpected[i].Title, dataDesc.ToList()[i].Title);
            }

            config.OrderBy = "DateTime";
            config.OrderDirection = SortDirection.Ascending;
            dataAsc = await dataProvider.LoadDataAsync(config, 2);
            dataAsc = await dataProvider.LoadMoreDataAsync();
            config.OrderDirection = SortDirection.Descending;
            dataDesc = await dataProvider.LoadDataAsync(config, 2);
            dataDesc = await dataProvider.LoadMoreDataAsync();

            dataExpected = dataAsc.OrderBy(x => x.DateTime).ToList();
            for (int i = 0; i < dataExpected.Count() - 1; i++)
            {
                Assert.AreEqual(dataExpected[i].Title, dataAsc.ToList()[i].Title);
            }

            dataExpected = dataDesc.OrderByDescending(x => x.DateTime).ToList();
            for (int i = 0; i < dataExpected.Count() - 1; i++)
            {
                Assert.AreEqual(dataExpected[i].Title, dataDesc.ToList()[i].Title);
            }
        }
Exemplo n.º 12
0
 public async Task <IEnumerable <TSchema> > GetDataByIdsAsync <TSchema>(DynamicStorageDataConfig config, IEnumerable <string> ids) where TSchema : SchemaBase
 {
     return(await GetDataByIdsAsync(config, ids, new JsonParser <TSchema>()));
 }
Exemplo n.º 13
0
        public async Task LoadDynamicCollection_ByIds()
        {
            var config = new DynamicStorageDataConfig
            {
                AppId = Guid.Empty.ToString(),
                StoreId = Guid.Empty.ToString(),
                DeviceType = "WINDOWS",
                Url = new Uri("http://appstudio-dev.cloudapp.net/api/data/collectionitemsbyid?dataRowListId=6db1e7d0-5216-4519-8978-d51f1452f9f2&appId=7c181582-15d0-42f7-b3eb-ab5d2e7d2c8a")
            };

            var ids = new List<string>();
            ids.Add("565f3175e3ef7f275c35da95");
            ids.Add("565f3175e3ef7f275c35da97");

            var dataProvider = new DynamicStorageDataProvider<CollectionSchema>();
            IEnumerable<CollectionSchema> data = await dataProvider.GetDataByIdsAsync<CollectionSchema>(config, ids);

            Assert.IsNotNull(data);
            Assert.AreEqual(2, data.Count());
        }
Exemplo n.º 14
0
 protected override async Task <IEnumerable <TSchema> > GetMoreDataAsync <TSchema>(DynamicStorageDataConfig config, int pageSize, IParser <TSchema> parser)
 {
     return(await GetDataFromProvider(config, pageSize, parser));
 }
Exemplo n.º 15
0
        public async Task LoadMoreDataInvalidOperationDynamicCollection()
        {
            var config = new DynamicStorageDataConfig
            {
                AppId = Guid.Empty.ToString(),
                StoreId = Guid.Empty.ToString(),
                DeviceType = "WINDOWS",
                Url = new Uri("http://appstudio-dev.cloudapp.net/api/data/collection?dataRowListId=6db1e7d0-5216-4519-8978-d51f1452f9f2&appId=7c181582-15d0-42f7-b3eb-ab5d2e7d2c8a")
            };

            var dataProvider = new LocalStorageDataProvider<CollectionSchema>();
            InvalidOperationException exception = await ExceptionsAssert.ThrowsAsync<InvalidOperationException>(async () => await dataProvider.LoadMoreDataAsync());

        }
Exemplo n.º 16
0
        public async Task TestDynamicNullUrlConfig()
        {
            var config = new DynamicStorageDataConfig
            {
                Url = null
            };

            var dataProvider = new DynamicStorageDataProvider<CollectionSchema>();

            ConfigParameterNullException exception = await ExceptionsAssert.ThrowsAsync<ConfigParameterNullException>(async () => await dataProvider.LoadDataAsync(config));
            Assert.IsTrue(exception.Message.Contains("Url"));
        }
 public DynamicStorageDataProvider(DynamicStorageDataConfig config)
     : base(config, new GenericParser <T>())
 {
 }
 public DynamicStorageDataProvider(DynamicStorageDataConfig config, IParser <T> parser)
     : base(config, parser)
 {
 }