public WeatherStationDetailViewModel(WeatherStation item = null)
        {
            Title     = "Weather Details: " + item?.StationName;
            dateRange = WeatherSet.WeatherSetDateRanges.Today;
            Item      = item;

            RgSets             = new RangeObservableCollection <WeatherSet>();
            _rgSets            = new ObservableCollection <WeatherSet>();
            RefreshWeatherSets = new Command(async() => await LoadObservableCollection());
        }
Пример #2
0
        //Generates all the prefixes needed for the specific range
        private List <string> GeneratePrefixStrings(WeatherSet.WeatherSetDateRanges range)
        {
            List <string> prefixes = new List <string>();
            //Blobs are stroed under utc time
            DateTime currentUtcDay = DateTime.UtcNow;
            string   sLogPrefix;
            string   testmode = ConfigurationManager.AppSettings["TestMode"];

            if (testmode == "true")
            {
                sLogPrefix = @"test/";
            }
            else
            {
                sLogPrefix = @"logs/post/";
            }

            switch (range)
            {
            case WeatherSet.WeatherSetDateRanges.Today:
                prefixes.Add(sLogPrefix + currentUtcDay.Year + "//" + currentUtcDay.Month + "//" + currentUtcDay.Date);
                return(prefixes);

            case WeatherSet.WeatherSetDateRanges.PastThreeDays:
                for (int i = 0; i < 3; i++)
                {
                    prefixes.Add(sLogPrefix + currentUtcDay.Year + "//" + currentUtcDay.Month + "//" + currentUtcDay.Date);
                    currentUtcDay.AddDays(-1);
                }
                return(prefixes);

            case WeatherSet.WeatherSetDateRanges.PastWeek:
                for (int i = 0; i < 7; i++)
                {
                    prefixes.Add(sLogPrefix + currentUtcDay.Year + "//" + currentUtcDay.Month + "//" + currentUtcDay.Date);
                    currentUtcDay.AddDays(-1);
                }
                return(prefixes);

            case WeatherSet.WeatherSetDateRanges.ThisMonth:
                prefixes.Add(sLogPrefix + currentUtcDay.Year + "//" + currentUtcDay.Month);
                return(prefixes);

            case WeatherSet.WeatherSetDateRanges.ThisYear:
                prefixes.Add(sLogPrefix + currentUtcDay.Year);
                return(prefixes);

            default:
                prefixes.Add(sLogPrefix);
                return(prefixes);
            }
        }
Пример #3
0
        public async Task <bool> RefreshWeatherSets(WeatherSet.WeatherSetDateRanges range)
        {
            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container.
            CloudBlobContainer container = blobClient.GetContainerReference("sensor-hub");

            BlobResultSegment seg = await ListBlobsAsync(container, range);

            bool succ = await CreateWeatherStationsFromBlob(seg);

            // Retrieve reference to a blob named "myblob".
            return(await Task.FromResult(true));
        }
Пример #4
0
        //Generates all the prefixes needed for the specific range
        private List <string> GeneratePrefixStrings(WeatherSet.WeatherSetDateRanges range)
        {
            List <string> prefixes = new List <string>();
            //Blobs are stroed under utc time
            DateTime currentUtcDay = DateTime.UtcNow;
            string   sLogPrefix    = @"logs/post/";

            switch (range)
            {
            case WeatherSet.WeatherSetDateRanges.Today:
                prefixes.Append(sLogPrefix + currentUtcDay.Year + "//" + currentUtcDay.Month + "//" + currentUtcDay.Date);
                return(prefixes);

            case WeatherSet.WeatherSetDateRanges.PastThreeDays:
                for (int i = 0; i < 3; i++)
                {
                    prefixes.Append(sLogPrefix + currentUtcDay.Year + "//" + currentUtcDay.Month + "//" + currentUtcDay.Date);
                    currentUtcDay.AddDays(-1);
                }
                return(prefixes);

            case WeatherSet.WeatherSetDateRanges.PastWeek:
                for (int i = 0; i < 7; i++)
                {
                    prefixes.Append(sLogPrefix + currentUtcDay.Year + "//" + currentUtcDay.Month + "//" + currentUtcDay.Date);
                    currentUtcDay.AddDays(-1);
                }
                return(prefixes);

            case WeatherSet.WeatherSetDateRanges.ThisMonth:
                prefixes.Append(sLogPrefix + currentUtcDay.Year + "//" + currentUtcDay.Month);
                return(prefixes);

            case WeatherSet.WeatherSetDateRanges.ThisYear:
                prefixes.Append(sLogPrefix + currentUtcDay.Year);
                return(prefixes);

            default:
                prefixes.Add(sLogPrefix);
                return(prefixes);
            }
        }
Пример #5
0
        public async Task <BlobResultSegment> ListBlobsAsync(CloudBlobContainer con, WeatherSet.WeatherSetDateRanges range)
        {
            BlobContinuationToken continuationToken = null;
            BlobResultSegment     resultSegment     = null;

            try
            {
                //Call ListBlobsSegmentedAsync and enumerate the result segment returned, while the continuation token is non-null.
                //When the continuation token is null, the last page has been returned and execution can exit the loop.
                do
                {
                    //This overload allows control of the page size. You can return all remaining results by passing null for the maxResults parameter,
                    //or by calling a different overload.
                    // from: https://hahoangv.wordpress.com/2016/05/16/azure-storage-step-4-blobs-storage-in-action/
                    List <string> prefixForBlob = GeneratePrefixStrings(WeatherSet.WeatherSetDateRanges.AllTime);
                    foreach (string prefix in prefixForBlob)
                    {
                        if (resultSegment == null)
                        {
                            resultSegment = await con.ListBlobsSegmentedAsync(prefix, true, BlobListingDetails.All, 1000, continuationToken, null, null);
                        }
                        else
                        {
                            BlobResultSegment temp = await con.ListBlobsSegmentedAsync(prefix, true, BlobListingDetails.All, 1000, continuationToken, null, null);

                            resultSegment.Results.Union(temp.Results);
                        }
                    }

                    Console.WriteLine();

                    //Get the continuation token.
                    continuationToken = resultSegment.ContinuationToken;
                }while (continuationToken != null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(resultSegment);
        }
Пример #6
0
 public async Task <IEnumerable <WeatherStation> > GetAllWeatherSets(bool forceRefresh = false, WeatherSet.WeatherSetDateRanges range = WeatherSet.WeatherSetDateRanges.Today)
 {
     return(await Task.FromResult(weatherStations));
 }