public async Task InsertAndGet() { // create tables StorageManager storageManager = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.Download, RunId.GenerateTestRunId()); await storageManager.CreateTables(); // fetch a regionslist file Client obaClient = new Client(TestConstants.OBAApiKey, TestConstants.OBARegionsListUri); RegionsList regionsList = await obaClient.GetAllRegionsAsync(); // stick it into store await storageManager.RegionsListStore.Insert(regionsList); // get it from the store RegionsListEntity regionsListEntity = storageManager.RegionsListStore.Get(); // clean up await storageManager.DeleteDataTables(); // check the retrieved record Assert.IsNotNull(regionsListEntity); Assert.AreEqual(regionsListEntity.RawContent, regionsList.RegionsRawContent); Assert.AreEqual(regionsListEntity.RegionsServiceUri, TestConstants.OBARegionsListUri); Assert.AreEqual(regionsListEntity.RecordType, Enum.GetName(typeof(RecordType), RecordType.RegionsList)); Assert.AreEqual(TestConstants.OBARegionsListUri, regionsList.Uri); }
public void GetRegions() { Device.BeginInvokeOnMainThread(async() => { UserDialogs.Instance.ShowLoading(null, MaskType.Clear); if (CrossConnectivity.Current.IsConnected) { if (RegionsList != null && RegionsList.Count > 0) { RegionsList.Clear(); } var values = await _apiService.GetAsync <RegionRequest>(Constants.Regions); if (values != null) { RegionsList = new ObservableCollection <Models.Regions.Region>(values.results); IsEmpty = false; } else { IsEmpty = true; } UserDialogs.Instance.HideLoading(); } else { UserDialogs.Instance.HideLoading(); ErrorAlert(); IsEmpty = true; } }); }
private void DeleteButton_Click(object sender, EventArgs e) { if (RegionsList.SelectedItem != null) { deleteRegion(RegionsList.GetItemText(RegionsList.SelectedItem)); RegionsList.Items.Remove(RegionsList.SelectedItem); } }
internal override void AfterLoad(World world) { base.AfterLoad(world); _regionSearch = new RegionsList(World); _uRegionSearch = new UndergroundRegionsList(World); _landmassSearch = new LandmassesList(World); _mountainPeaksSearch = new MountainPeaksList(World); _riverSearch = new RiverList(World); var regions = from region in World.Regions orderby region.Type group region by region.Type into regiontype select regiontype; var uregions = from uregion in World.UndergroundRegions orderby uregion.Type group uregion by uregion.Type into uregiontype select uregiontype; cmbRegionType.Items.Add("All"); cmbRegionType.SelectedIndex = 0; foreach (var region in regions) { cmbRegionType.Items.Add(region.Key); } cmbURegionType.Items.Add("All"); cmbURegionType.SelectedIndex = 0; foreach (var uregion in uregions) { cmbURegionType.Items.Add(uregion.Key); } var regionEvents = from eventType in World.Regions.SelectMany(region => region.Events) group eventType by eventType.Type into type select type.Key; var undergroundRegionEvents = from eventType in World.UndergroundRegions.SelectMany(uRegion => uRegion.Events) group eventType by eventType.Type into type select type.Key; var landmassEvents = from eventType in World.Landmasses.SelectMany(element => element.Events) group eventType by eventType.Type into type select type.Key; var mountainPeakEvents = from eventType in World.MountainPeaks.SelectMany(element => element.Events) group eventType by eventType.Type into type select type.Key; var riverEvents = from eventType in World.Rivers.SelectMany(element => element.Events) group eventType by eventType.Type into type select type.Key; TabEvents.Clear(); TabEvents.Add(regionEvents.ToList()); TabEvents.Add(undergroundRegionEvents.ToList()); TabEvents.Add(landmassEvents.ToList()); TabEvents.Add(mountainPeakEvents.ToList()); TabEvents.Add(riverEvents.ToList()); }
/// <summary> /// Downloads all OBA data and stores it /// </summary> /// <returns>task that fetches all OBA data and stores it</returns> public async Task DownloadAndStore() { RegionsList regionsList = await DownloadRegionsList.DownloadAndStore(this.obaClient, this.downloadStorage, this.downloadMetadataStorage, this.runId); IEnumerable <Region> regions = await ProcessRegions.Store(regionsList, this.downloadStorage, this.downloadMetadataStorage, this.runId); IEnumerable <Tuple <Region, Agency> > agencies = await DownloadAgencies.DownloadAndStore(regions, this.obaClient, this.downloadStorage, this.downloadMetadataStorage, this.runId); IEnumerable <Tuple <Region, Agency, IEnumerable <Route> > > routes = await DownloadRoutes.DownloadAndStore(agencies, this.obaClient, this.downloadStorage, this.downloadMetadataStorage, this.runId); await DownloadStops.DownloadAndStore(routes, this.obaClient, this.downloadStorage, this.downloadMetadataStorage, this.runId); }
/// <summary> /// Stores a OBA Source model in Azure Tables /// </summary> /// <param name="regionsList">OBA Source model from the OBA client</param> /// <returns>task that stores the entity</returns> public async Task Insert(RegionsList regionsList) { // create a new storage entity RegionsListEntity regionsListEntity = new RegionsListEntity { RawContent = regionsList.RegionsRawContent, RecordType = RecordType.RegionsList.ToString(), RegionsServiceUri = regionsList.Uri }; // insert it await this.Insert(regionsListEntity); }
/// <summary> /// Fetches OBA regions list and stores it /// </summary> /// <param name="obaClient">interface to the OBA servers</param> /// <param name="downloadStorage">interface to storage for downloaded data</param> /// <param name="downloadMetadataStorage">interface to storage for download metadata</param> /// <param name="runId">uniquely identifies a run of the OBA service</param> /// <returns>downloaded regions list</returns> public static async Task <RegionsList> DownloadAndStore(Client obaClient, StorageManager downloadStorage, StorageManager downloadMetadataStorage, string runId) { // check inputs if (obaClient == null) { throw new ArgumentNullException("obaClient"); } else if (downloadStorage == null) { throw new ArgumentNullException("downloadStorage"); } else if (downloadMetadataStorage == null) { throw new ArgumentNullException("downloadMetadataStorage"); } else if (string.IsNullOrWhiteSpace(runId)) { throw new ArgumentNullException("runId"); } // fetch the regions list RegionsList regionsList = await obaClient.GetAllRegionsAsync(); // check the regions list if (regionsList == null) { throw new Exception("regions list is null"); } else if (regionsList.Regions == null) { throw new Exception("regions in regions list is null"); } else if (regionsList.Regions.Count <= 0) { throw new Exception("regions in regions list is empty"); } else if (string.IsNullOrWhiteSpace(regionsList.RegionsRawContent)) { throw new Exception("raw content in regions list is empty"); } // store it await downloadStorage.RegionsListStore.Insert(regionsList); // add a metadata entry await downloadMetadataStorage.DownloadMetadataStore.Insert(runId, string.Empty, string.Empty, RecordType.RegionsList, 1); return(regionsList); }
//------------------------------------------------------------------------------------------------------------ public void FetchRegionList() { System.Data.SqlClient.SqlCommand cmdSelect = new System.Data.SqlClient.SqlCommand(); gClass.MakeStoreProcedureName(ref cmdSelect, "sp_Regions_LoadData", true); cmdSelect.Parameters.Add("@OrganizationCode", System.Data.SqlDbType.Int).Value = Convert.ToInt32(gClass.OrganizationCode); RegionsList.DataSource = gClass.FetchData(cmdSelect, "tblRegion"); RegionsList.DataMember = "tblRegion"; RegionsList.DataValueField = "Region Id"; RegionsList.DataTextField = "Region Name"; try { RegionsList.DataBind(); } catch { } RegionsList.Items.Insert(0, new ListItem("Select ...", "")); }
/// <summary> /// Stores downloaded OBA regions /// </summary> /// <param name="regionsList">regions list from DownloadRegionsList class</param> /// <param name="downloadStorage">interface to storage for downloaded data</param> /// <param name="downloadMetadataStorage">interface to storage for download metadata</param> /// <param name="runId">uniquely identifies a run of the OBA service</param> /// <returns>list of regions</returns> public static async Task <IEnumerable <Region> > Store(RegionsList regionsList, StorageManager downloadStorage, StorageManager downloadMetadataStorage, string runId) { // check inputs if (downloadStorage == null) { throw new ArgumentNullException("downloadStorage"); } else if (downloadMetadataStorage == null) { throw new ArgumentNullException("downloadMetadataStorage"); } else if (string.IsNullOrWhiteSpace(runId)) { throw new ArgumentNullException("runId"); } // check the regions list if (regionsList == null) { throw new ArgumentNullException("regionsList"); } else if (regionsList.Regions == null) { throw new Exception("regions in regions list is null"); } else if (regionsList.Regions.Count <= 0) { throw new Exception("regions in regions list is empty"); } else if (string.IsNullOrWhiteSpace(regionsList.RegionsRawContent)) { throw new Exception("raw content in regions list is empty"); } // filter them IEnumerable <Region> regions = FilterRegionsForEmbeddedSocial(regionsList.Regions); // store them await downloadStorage.RegionStore.Insert(regions); // add a metadata entry await downloadMetadataStorage.DownloadMetadataStore.Insert(runId, string.Empty, string.Empty, RecordType.Region, regions.Count()); return(regions); }
public async Task DownloadAndStore() { string runId = RunId.GenerateTestRunId(); // create storage managers StorageManager downloadStorage = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.Download, runId); StorageManager downloadMetadataStorage = new StorageManager(TestConstants.AzureStorageConnectionString, TableNames.TableType.DownloadMetadata, runId); // create OBA client Client obaClient = new Client(TestConstants.OBAApiKey, TestConstants.OBARegionsListUri); // create tables await downloadStorage.CreateTables(); await downloadMetadataStorage.CreateTables(); // download and store RegionsList regionsList = await DownloadRegionsList.DownloadAndStore(obaClient, downloadStorage, downloadMetadataStorage, runId); // get it from store RegionsListEntity regionsListEntity = downloadStorage.RegionsListStore.Get(); IEnumerable <DownloadMetadataEntity> downloadMetadataEntities = downloadMetadataStorage.DownloadMetadataStore.Get(runId); // clean up await downloadStorage.DeleteDataTables(); await downloadMetadataStorage.DownloadMetadataStore.Delete(runId); // check Assert.IsNotNull(regionsList); Assert.IsNotNull(regionsListEntity); Assert.IsNotNull(downloadMetadataEntities); Assert.AreEqual(regionsList.RegionsRawContent, regionsListEntity.RawContent); Assert.AreEqual(regionsList.Uri, TestConstants.OBARegionsListUri); Assert.AreEqual(regionsListEntity.RecordType, Enum.GetName(typeof(RecordType), RecordType.RegionsList)); Assert.AreEqual(TestConstants.OBARegionsListUri, regionsListEntity.RegionsServiceUri); Assert.AreEqual(downloadMetadataEntities.Count(), 1); Assert.AreEqual(downloadMetadataEntities.First().RecordType, RecordType.RegionsList.ToString()); Assert.AreEqual(downloadMetadataEntities.First().Count, 1); Assert.AreEqual(downloadMetadataEntities.First().AgencyId, string.Empty); Assert.AreEqual(downloadMetadataEntities.First().RegionId, string.Empty); Assert.AreEqual(downloadMetadataEntities.First().RunId, runId); }
private void RegionItemRemove_OnClick(object sender, RoutedEventArgs e) { var containerFromElement = (ListBoxItem)RegionsList.ContainerFromElement((Button)sender); if (containerFromElement != null) { var curItem = containerFromElement.Content; if (((ImageItem)ThumbnailList.Items[_thumbIndex]).RemoveRegion(curItem)) { _regIndex = -1; _thumbIndex = ThumbnailList.SelectedIndex; if (_thumbIndex != -1) { ((ImageItemsViewModel)DataContext).RefreshRegions(_thumbIndex); RedrawRects(); } } } }