public virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // Dispose any managed, IDisposable resources
                    travelReq     = null;
                    travelRes     = null;
                    flightDetails = null;
                }

                // Dispose of undisposed unmanaged resources
            }
            disposed = true;
        }
 public TableStorage(TripOptionsRequest req, TripsSearchResponse res, FlightDetails fd)
 {
     travelReq     = req;
     travelRes     = res;
     flightDetails = fd;
 }
 public TableStorage()
 {
     travelReq     = null;
     travelRes     = null;
     flightDetails = null;
 }
 // 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)));
 }
示例#5
0
        // Main submethod for processing the results obtained from the QPX Express API
        // It basically loops through the results, determines the best one (price-wise)
        // and creates the output that will be sent to the user
        private static List <string> ProcessResult(bool save, Dictionary <string, Airport> airports, TripOptionsRequest req,
                                                   TripsSearchResponse result, FlightDetails fd, int?totalResults,
                                                   string inb, out string guid)
        {
            int           legs      = 1;
            int           numResult = 0;
            List <string> p         = new List <string>();

            string price   = string.Empty;
            string details = string.Empty;

            guid = string.Empty;

            if (result.Trips.TripOption != null)
            {
                for (int i = 0; i <= totalResults - 1; i++)
                {
                    price   = "Price: " + result.Trips.TripOption[i].SaleTotal;
                    details = GetDetails(airports, result.Trips.Data, result.Trips.TripOption[i], inb, out legs);

                    if (IsResultOk(fd, legs - 1))
                    {
                        numResult++;

                        if (fd.Follow.ToLower() == GatherQuestions.cStrYes)
                        {
                            fd.Posi = i;

                            using (TableStorage ts = new TableStorage(req, result, fd))
                            {
                                if (save)
                                {
                                    guid = ts.Save();
                                }
                            }
                        }

                        if (numResult == Convert.ToInt32(fd.NumResults))
                        {
                            break;
                        }
                    }
                    else
                    {
                        price   = string.Empty;
                        details = string.Empty;
                    }
                }

                if (price != string.Empty && details != string.Empty)
                {
                    SetFooter(ref p, guid, price, details);
                }
            }

            return(p);
        }
示例#6
0
        // Main method for checking if any of the stored flights (being followed by users) have changed their prices
        public async Task <bool> CheckForPriceUpdates(Dictionary <string, Airport> airports, FlightDetails fd,
                                                      Activity activity, ConnectorClient connector, string guid)
        {
            bool changed = false;

            try
            {
                // Connects to Azure Table Storage in order to retrieve th details of
                // flights being watched by users
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                    CloudConfigurationManager.GetSetting(StrConsts.cStrStorageConnectionStr));

                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

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

                TableQuery <TravelEntity> query = new TableQuery <TravelEntity>().
                                                  Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.NotEqual, string.Empty));

                // Gets all the flights being watched
                IEnumerable <TravelEntity> results = table.ExecuteQuery(query);

                // Let's check if any of the flights stored have a change in price
                foreach (TravelEntity entity in results)
                {
                    TripsSearchResponse result = null;
                    TripOptionsRequest  req    = null;

                    // Get the details of a stored flight (being followed)
                    fd = GetStoredFlightData(entity, storageAccount, out req);

                    // If the stored flight was submitted by the user currently
                    // interacting with our bot - very important :)
                    if (fd.UserId.ToLower() == activity.From.Id.ToLower())
                    {
                        // Query the QPX Express API to see if the current price
                        // of the flight stored differs
                        string res = ShowUpdatedResults(airports, fd, out result);

                        // If the flight is still relevant (has not expired)
                        if (res != string.Empty)
                        {
                            // If indeed the current price differs from when it was
                            // originally requested by the user
                            if (PriceHasChanged(entity, result, storageAccount))
                            {
                                changed = true;

                                // Save the new flight price on Azure Storage Table
                                using (TableStorage ts = new TableStorage(req, result, fd))
                                    guid = ts.Save();

                                changed = true;

                                // Create the response with the current flight price that will be
                                // sent back to the user
                                Activity reply = activity.CreateReply(GatherQuestions.cStrPriceChange +
                                                                      StrConsts._NewLine + StrConsts._NewLine + res + StrConsts._NewLine +
                                                                      StrConsts._NewLine + GatherQuestions.cStrGatherRequestProcessed +
                                                                      StrConsts._NewLine + StrConsts._NewLine +
                                                                      GatherQuestions.cStrUnFollow + guid);

                                await connector.Conversations.ReplyToActivityAsync(reply);
                            }
                        }
                        else
                        {
                            // The flight is no longer relevant
                            // so it should be removed from Azure Storage
                            RemoveEntity(GetKey(fd));
                        }
                    }
                }
            }
            catch { }

            // If there has been a price change
            // return true
            return(changed);
        }