Exemplo n.º 1
0
        // Creates or inserts into Azure Storage Tables the flight details the user is interested in watching
        protected void CreateOrInsertTable(string guid, string origenDest, string reqStr, string resStr, string fdStr)
        {
            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                    CloudConfigurationManager.GetSetting(StrConsts.cStrStorageConnectionStr));

                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

                CloudTable table = tableClient.GetTableReference(
                    CloudConfigurationManager.GetSetting(StrConsts.cStrBotId));

                table.CreateIfNotExists();

                TravelEntity entity = new TravelEntity(guid, origenDest);

                entity.FlightDetails = SaveToBlob(guid + StrConsts._FlightDetails, fdStr, storageAccount);
                entity.TravelReq     = SaveToBlob(guid + StrConsts._TravelReq, reqStr, storageAccount);
                entity.TravelRes     = SaveToBlob(guid + StrConsts._TravelRes, resStr, storageAccount);

                TableOperation insertOperation = TableOperation.InsertOrReplace(entity);

                table.Execute(insertOperation);
            }
            catch { }
        }
        // Method that simply compares if the price of the stored flight
        // is different than the current price for that same flight
        protected bool PriceHasChanged(TravelEntity entity, TripsSearchResponse result, CloudStorageAccount storageAccount)
        {
            bool res = false;

            FlightDetails fd = JsonConvert.DeserializeObject <FlightDetails>(GetFromBlob(entity.FlightDetails, storageAccount));

            TripsSearchResponse travelRes = JsonConvert.
                                            DeserializeObject <TripsSearchResponse>(GetFromBlob(entity.TravelRes, storageAccount));

            if (travelRes.Trips.TripOption[fd.Posi].SaleTotal != result.Trips.TripOption[fd.Posi].SaleTotal)
            {
                res = true;
            }

            return(res);
        }
 // Deserializes the JSON strings representing the
 // TripOptionsRequest and FlightDetails objects
 // stored on Azure Blobs
 protected FlightDetails GetStoredFlightData(TravelEntity entity, CloudStorageAccount storageAccount, out TripOptionsRequest to)
 {
     to = JsonConvert.DeserializeObject <TripOptionsRequest>(GetFromBlob(entity.TravelReq, storageAccount));
     return(JsonConvert.DeserializeObject <FlightDetails>(GetFromBlob(entity.FlightDetails, storageAccount)));
 }