Exemplo n.º 1
0
        /// <summary>
        /// Assisted by code from https://dev.socrata.com/foundry/data.cityofnewyork.us/fhrw-4uyv
        /// queried DB - https://data.cityofnewyork.us
        /// API KEY - PVGjhHLj8Svy7Ryz0uJgW9IBh
        /// loadDB connects to the database, sends the query and then returns the data
        /// </summary>
        /// <returns>Returns the da taset of the query to main</returns>
        public IEnumerable <Dictionary <string, object> > LoadDB()
        {
            /// <remarks>
            /// This requires the SODA library
            /// It can be installed from NuGet in Visual studio using
            /// Install-Package CSM.SodaDotNet
            /// </remarks>>
            SODA.SodaClient client = new SodaClient("https://data.cityofnewyork.us", "PVGjhHLj8Svy7Ryz0uJgW9IBh");

            /// <remarks>
            /// The documentation on the web is outdated.
            /// The .NET library has been updated to no longer allow generic typing.
            /// You must use either Dictionary(String,Object) - use <> but not allowed in XML comments
            /// OR a user-defined json serializable class - their documentation does not explain how to do this
            /// well enough, however so we are sticking with the Generic Collection specified
            /// </remarks>>
            SODA.Resource <Dictionary <string, object> > dataset = client.GetResource <Dictionary <string, object> >("fhrw-4uyv");

            /// <summary>
            /// instantiate our object and get our query from GetQueryDate()
            /// </summary>
            ManageDB test = new ManageDB();

            SODA.SoqlQuery soql = test.GetQueryDate();

            /// <summary>
            /// Query sends our query to our pre-defined location and returns an IEnumerable which we assign to results
            /// results now contains the results of our query
            /// </summary>
            IEnumerable <Dictionary <string, object> > results = dataset.Query <Dictionary <string, object> >(soql);

            /// <summary>
            /// Testing to make sure that our query returned results
            /// Will be changed to throw an error instead of printing a value
            /// </summary>
            int SizeOfList;

            test.TestIEnum(ref results, out SizeOfList);
            Console.WriteLine(SizeOfList);
            return(results);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Query this Resource using the specified <see cref="SoqlQuery"/>.
 /// </summary>
 /// <typeparam name="T">The .NET class that represents the type of the underlying rows in this resultset of this query.</typeparam>
 /// <param name="soqlQuery">A <see cref="SoqlQuery"/> to execute against this Resource.</param>
 /// <returns>A collection of entities of type <typeparamref name="T"/>.</returns>
 /// <remarks>
 /// By default, Socrata will only return the first 1000 rows unless otherwise specified in SoQL using the Limit and Offset parameters.
 /// This method checks the specified SoqlQuery object for either the Limit or Offset parameter, and honors those parameters if present.
 /// If both Limit and Offset are not part of the SoqlQuery, this method attempts to retrieve all rows in the dataset across all pages.
 /// In other words, this method hides the fact that Socrata will only return 1000 rows at a time, unless explicity told not to via the SoqlQuery argument.
 /// </remarks>
 public IEnumerable <T> Query <T>(SoqlQuery soqlQuery) where T : class
 {
     return(Client.Query <T>(soqlQuery, Identifier));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Get a subset of the rows contained in this Resource, with maximum size equal to the specified limit, starting at the specified offset into the total row count.
        /// </summary>
        /// <param name="limit">The maximum number of rows to return in the resulting collection.</param>
        /// <param name="offset">The index into this Resource's total rows from which to start.</param>
        /// <returns>A collection of type <typeparamref name="TRow"/>, of maximum size equal to the specified <paramref name="limit"/>.</returns>
        public IEnumerable <TRow> GetRows(int limit, int offset)
        {
            var soqlQuery = new SoqlQuery().Limit(limit).Offset(offset);

            return(Query <TRow>(soqlQuery));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Query this Resource using the specified <see cref="SoqlQuery"/>.
 /// </summary>
 /// <param name="soqlQuery">A <see cref="SoqlQuery"/> to execute against this Resource.</param>
 /// <returns>A collection of entities of type <typeparamref name="TRow"/>.</returns>
 /// <remarks>
 /// This is a convenience method for the generic <see cref="Query{T}"/>, and is useful if you want the result of a query
 /// to be typed to <typeparamref name="TRow"/> (this Resource's underlying record type).
 /// </remarks>
 public IEnumerable <TRow> Query(SoqlQuery soqlQuery)
 {
     return(Query <TRow>(soqlQuery));
 }