예제 #1
0
        static void Main(string[] args)
        {
            var catalogMetaDataCollection    = HyperCatDataHelper.GetCatalogueMetaDataCollection();
            var itemMetaDataCollectionLondon = HyperCatDataHelper.GetItemMetaDataCollectionLondon();
            var itemMetaDataCollectionSuva   = HyperCatDataHelper.GetMetaDataCollectionSuva();

            var items = new ItemCollection
            {
                new Item
                {
                    ItemMetadata = itemMetaDataCollectionLondon,
                    Href         = "/london"
                },
                new Item
                {
                    ItemMetadata = itemMetaDataCollectionSuva,
                    Href         = "/suva"
                }
            };

            var catelouge = new Catalogue
            {
                CatalogueMetaData = catalogMetaDataCollection,
                Items             = items
            };

            var catalougeDataConvetor = new CatalogueDataJsonConvertor {
                Formatting = Formatting.Indented
            };

            // Serialize the Catalouge object to HyperCat Catelouge
            var hyperCatalougeJsonData = JsonConvert.SerializeObject(catelouge,
                                                                     Formatting.Indented, catalougeDataConvetor);

            Console.WriteLine(hyperCatalougeJsonData);

            // Using HyperCat Builder
            var hyperCatBuilder = new HyperCatBuilder();

            hyperCatBuilder.AddCatalogueMetaData(catalogMetaDataCollection);
            hyperCatBuilder.AddCatalogueItem(items);
            hyperCatalougeJsonData = hyperCatBuilder.ToString();
            Console.WriteLine(hyperCatalougeJsonData);

            // Deserialize the Hypercat Catalouge to strongly typed object
            var hyperCatalouge = JsonConvert.DeserializeObject <Catalogue>(hyperCatalougeJsonData);

            Console.ReadLine();
        }
예제 #2
0
        private static string BuildHypercatCatalouge(string cityName, WeatherEntity weatherEntity)
        {
            var items = new ItemCollection
            {
                new Item
                {
                    ItemMetadata = HypercatWeatherDataHelper.GetItemMetaDataCollection(cityName, weatherEntity),
                    Href         = "/" + cityName
                }
            };

            var catelouge = new Catalogue
            {
                CatalogueMetaData = HypercatWeatherDataHelper.GetCatalogueMetaDataCollection(),
                Items             = items
            };

            var hyperCatBuilder = new HyperCatBuilder();

            hyperCatBuilder.AddCatalogueMetaData(catelouge.CatalogueMetaData);
            hyperCatBuilder.AddCatalogueItem(items);
            return(hyperCatBuilder.ToString());
        }