Ejemplo n.º 1
0
        public static void SerializeDeserializeObjectUsingReflectionStream()
        {
            string          blobName = "aaa/avrotest/test008";
            CloudBlobClient client   = new Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient(
                new Uri("http://hanzstorage.blob.core.windows.net"),
                new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(
                    "hanzstorage",
                    "w9TEpvGTusvFlGAdCoWdDrwqLzy6er0Zm5YKdDD0YTkQdOj3WufeVrgd2c8q8amLR0o6xD0tBChcIIA+DCgxXA=="
                    ));
            CloudBlobContainer container = client.GetContainerReference("hanzhdi");
            CloudBlockBlob     blockBlob = container.GetBlockBlobReference(blobName);

            foreach (var md in blockBlob.Metadata)
            {
                Console.WriteLine("{0}    {1}", md.Key, md.Value);
            }

            Console.WriteLine("Serializing Sample Data Set USING REFLECTION\n");


            AvroBlobAppender.AvroBlobAppenderWriter <MyDataType> writer =
                new AvroBlobAppender.AvroBlobAppenderWriter <MyDataType>(blockBlob, false, AvroSerializer.Create <MyDataType>(), Codec.Null);

            Microsoft.Hadoop.Avro.Container.SequentialWriter <MyDataType> sequentialWriter =
                new SequentialWriter <MyDataType>(writer, 10000);

            List <MyDataType> myDataList = MyDataType.GenerateData(555, 10);

            foreach (var myData in myDataList)
            {
                sequentialWriter.Write(myData);
            }

            sequentialWriter.Flush();
            sequentialWriter.Dispose();

            #region commented code
            //blockBlob.DownloadToFile(blobName, FileMode.Create);
            //using (Stream stream = File.OpenRead(blobName))
            //{
            //    Microsoft.Hadoop.Avro.Container.SequentialReader<MyDataType> reader =
            //        new Microsoft.Hadoop.Avro.Container.SequentialReader<MyDataType>(AvroContainer.CreateReader<MyDataType>(stream));
            //    List<MyDataType> actuals = reader.Objects.ToList();
            //    Console.WriteLine("Number of objects: {0}", actuals.Count);
            //    for (int i = 0; i < actuals.Count; i++)
            //    {
            //        var actual = actuals[i];
            //        MyDataType exp = null;
            //        switch (i)
            //        {
            //            case 0:
            //                exp = expected;
            //                break;
            //            case 1:
            //                exp = expected2;
            //                break;
            //            default:
            //                Console.WriteLine("No expected for object {0}", i);
            //                continue;
            //        }

            //        Console.WriteLine("Result of Data Set Identity Comparison is {0}", Program.Equal(exp, actual));
            //    }
            //}
            #endregion
        }
Ejemplo n.º 2
0
 public static bool Equal(MyDataType left, MyDataType right)
 {
     return(left.SomeNumber.Equals(right.SomeNumber) && left.SomeString.SequenceEqual(right.SomeString));
 }