Esempio n. 1
0
        private static async Task ListBlobsFlatListingAsync(CloudBlobContainer container, int?segmentSize)
        {
            BlobContinuationToken continuationToken = null;
            CloudBlob             blob;

            try
            {
                // Call the listing operation and enumerate the result segment.
                // When the continuation token is null, the last segment has been returned
                // and execution can exit the loop.
                do
                {
                    BlobResultSegment resultSegment = await container.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.Metadata, segmentSize, continuationToken, null, null);

                    _sensorData = new List <SensorData>();
                    foreach (var blobItem in resultSegment.Results)
                    {
                        // A flat listing operation returns only blobs, not virtual directories.
                        blob = (CloudBlob)blobItem;

                        using (var mStream = new MemoryStream())
                        {
                            if (!blob.Name.Contains("historical") && !blob.Name.Contains("metadata"))
                            {
                                SensorData item = null;
                                if (blob.Name.Contains("humidity"))
                                {
                                    item = new Humidity();
                                }
                                else if (blob.Name.Contains("rainfall"))
                                {
                                    item = new Rainfall();
                                }
                                else if (blob.Name.Contains("temperature"))
                                {
                                    item = new Temperature();
                                }

                                await ParseAndAddDataStream(mStream, item, blob);
                            }
                        }

                        // Write out some blob properties.
                        Console.WriteLine("Blob name: {0}", blob.Name);
                    }

                    foreach (var item in _sensorData)
                    {
                        if (item.GetType().Name.ToLower() == "temperature" && item.MeasurementDay.Date.ToString("yyyy-MM-dd") == "2019-01-10")
                        {
                            Console.WriteLine($"Is temperature on date: {item.MeasurementDay.ToString()}");
                        }
                    }

                    // Get the continuation token and loop until it is null.
                    continuationToken = resultSegment.ContinuationToken;
                } while (continuationToken != null);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
Esempio n. 2
0
        private static async Task ListBlobsFlatListingAsync(CloudBlobContainer container, int?segmentSize)
        {
            BlobContinuationToken continuationToken = null;
            CloudBlob             blob;

            try
            {
                // Call the listing operation and enumerate the result segment.
                // When the continuation token is null, the last segment has been returned
                // and execution can exit the loop.
                do
                {
                    BlobResultSegment resultSegment = await container.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.Metadata, segmentSize, continuationToken, null, null);

                    List <SensorData> sensorData = new List <SensorData>();
                    foreach (var blobItem in resultSegment.Results)
                    {
                        // A flat listing operation returns only blobs, not virtual directories.
                        blob = (CloudBlob)blobItem;

                        using (var mStream = new MemoryStream())
                        {
                            if (!blob.Name.Contains("historical") && !blob.Name.Contains("metadata"))
                            {
                                SensorData item = null;
                                if (blob.Name.Contains("humidity"))
                                {
                                    item = new Humidity();
                                }
                                else if (blob.Name.Contains("rainfall"))
                                {
                                    item = new Rainfall();
                                }
                                else if (blob.Name.Contains("temperature"))
                                {
                                    item = new Temperature();
                                }

                                await blob.DownloadToStreamAsync(mStream);

                                var    result    = mStream.ToArray();
                                string converted = Encoding.UTF8.GetString(result, 0, result.Length);

                                string[] words = converted.Split("\r\n");

                                item.MeasurementData = new List <double>();
                                item.MeasurementDay  = DateTime.Now;
                                item.MeasurementTime = new List <DateTime>();
                                sensorData.Add(item);
                            }
                        }

                        // Write out some blob properties.
                        Console.WriteLine("Blob name: {0}", blob.Name);
                    }

                    foreach (var item in sensorData)
                    {
                        var result = item.GetType();
                    }

                    Console.WriteLine();

                    // Get the continuation token and loop until it is null.
                    continuationToken = resultSegment.ContinuationToken;
                } while (continuationToken != null);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }