Esempio n. 1
0
 private static void EnsureHeaders(this IRestBox box)
 {
     if (box.Headers == null)
     {
         box.Headers = new Dictionary <string, string>();
     }
 }
Esempio n. 2
0
        static async Task DoWork()
        {
            // IDatabaseBox and IRestBox both inherit from IBox.
            IDatabaseBox database = MongoBox();
            IRestBox     remote   = WebApiBox();

            var customer = new Customer {
                Name = "John Doe"
            };
            var invoice = new Invoice {
                Number = "ABC/123"
            };

            // Insert<T> (and other CRUD methods) are all defined by IBox.
            await remote.Insert(customer);

            await database.Insert(invoice);

            // Lookups also work alike, no matter where and how data is stored.
            var brooklynCustomers = await database.Find <Customer>(c => c.Zip == "11201");

            var invoices = await remote.Find <Invoice>(inv => inv.Date >= DateTime.Now.AddDays(-10), new FindOptions <Invoice> {
                IfModifiedSince = DateTime.Now.Date
            });

            Console.WriteLine($"We got back {brooklynCustomers.Count} customers and {invoices.Count} invoices");
        }
Esempio n. 3
0
        public static void IfModifiedSince <T>(this IRestBox box, IFindOptions <T> options)
        {
            if (options == null)
            {
                return;
            }
            if (!options.IfModifiedSince.HasValue)
            {
                return;
            }
            EnsureHeaders(box);

            box.Headers.Add("If-Modified-Since", options.IfModifiedSince.Value.ToString("r"));
        }
Esempio n. 4
0
        public static void IfNoneMatch <T>(this IRestBox box, RestFindOptions <T> options)
        {
            if (options == null)
            {
                return;
            }
            if (options.ETag == null)
            {
                return;
            }
            EnsureHeaders(box);

            box.Headers.Add("If-None-Match", options.ETag);
        }