コード例 #1
0
        public List <order> GetOrdersByDateRange(DateTime beginTime, DateTime endTime)
        {
            HttpClientHandler handler = new HttpClientHandler();

            handler.Credentials = new NetworkCredential(username, api_key);

            HttpClient client = new HttpClient(handler)
            {
                BaseAddress = new Uri(baseUrl),
            };

            string bt = Rfc822DateTime.ToString(beginTime.ToUniversalTime()).Replace("Z", "-0700").Trim();
            string et = Rfc822DateTime.ToString(endTime.ToUniversalTime()).Replace("Z", "-0700").Trim();

            string url = String.Format("orders.json?min_date_created={0}&max_date_created={1}", bt, et);

            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                List <order> result = response.Content.ReadAsAsync <List <order> >().Result;
                return(result);
            }

            return(null);
        }
コード例 #2
0
ファイル: RFC.cs プロジェクト: smehmoodf3/bigcommercerestapi
        /// <summary>
        /// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent.
        /// </summary>
        /// <param name="s">A string containing a date and time to convert.</param>
        /// <param name="result">
        /// When this method returns, contains the <see cref="DateTime"/> value equivalent to the date and time
        /// contained in <paramref name="s"/>, expressed as <i>Coordinated Universal Time (UTC)</i>,
        /// if the conversion succeeded, or <see cref="DateTime.MinValue">MinValue</see> if the conversion failed.
        /// The conversion fails if the s parameter is a <b>null</b> reference (Nothing in Visual Basic),
        /// or does not contain a valid string representation of a date and time.
        /// This parameter is passed uninitialized.
        /// </param>
        /// <returns><b>true</b> if the <paramref name="s"/> parameter was converted successfully; otherwise, <b>false</b>.</returns>
        /// <remarks>
        /// The string <paramref name="s"/> is parsed using formatting information in the <see cref="DateTimeFormatInfo.InvariantInfo"/> object.
        /// </remarks>
        public static bool TryParse(string s, out DateTime result)
        {
            //------------------------------------------------------------
            //  Attempt to convert string representation
            //------------------------------------------------------------
            bool wasConverted = false;

            result = DateTime.MinValue;

            if (!String.IsNullOrEmpty(s))
            {
                DateTime parseResult;
                if (DateTime.TryParseExact(Rfc822DateTime.ConvertZoneToLocalDifferential(s), Rfc822DateTime.Rfc822DateTimePatterns, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AdjustToUniversal, out parseResult))
                {
                    result       = DateTime.SpecifyKind(parseResult, DateTimeKind.Utc);
                    wasConverted = true;
                }
            }

            return(wasConverted);
        }
コード例 #3
0
ファイル: RFC.cs プロジェクト: smehmoodf3/bigcommercerestapi
        //============================================================
        //  Public Methods
        //============================================================
        #region Parse(string s)
        /// <summary>
        /// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent.
        /// </summary>
        /// <param name="s">A string containing a date and time to convert.</param>
        /// <returns>
        /// A <see cref="DateTime"/> equivalent to the date and time contained in <paramref name="s"/>,
        /// expressed as <i>Coordinated Universal Time (UTC)</i>.
        /// </returns>
        /// <remarks>
        /// The string <paramref name="s"/> is parsed using formatting information in the <see cref="DateTimeFormatInfo.InvariantInfo"/> object.
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="s"/> is a <b>null</b> reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException"><paramref name="s"/> is an empty string.</exception>
        /// <exception cref="FormatException"><paramref name="s"/> does not contain a valid RFC 822 string representation of a date and time.</exception>
        public static DateTime Parse(string s)
        {
            //------------------------------------------------------------
            //  Validate parameter
            //------------------------------------------------------------
            if (String.IsNullOrEmpty(s))
            {
                throw new ArgumentNullException("s");
            }

            DateTime result;

            if (Rfc822DateTime.TryParse(s, out result))
            {
                return(result);
            }
            else
            {
                throw new FormatException(String.Format(null, "{0} is not a valid RFC 822 string representation of a date and time.", s));
            }
        }