示例#1
0
        public async Task <QueryResult <Product> > ReadProduct(int[] param1, string param2)
        {
            // var queryInfo = RequestContext.CurrentQueryInfo;
            PerformQueryResult <Product> productsResult = PerformQuery((countQuery) => countQuery.CountAsync());
            int?totalCount = await productsResult.CountAsync();

            List <Product> productsList = new List <Product>();

            if (totalCount > 0)
            {
                productsList = await productsResult.Data.ToListAsync();
            }
            int[] productIDs = productsList.Select(p => p.ProductId).Distinct().ToArray();
            QueryResult <Product> queryResult = new QueryResult <Product>(productsList, totalCount);


            SubResult subResult = new SubResult
            {
                dbSetName = "SalesOrderDetail",
                Result    = await DB.SalesOrderDetail.AsNoTracking().Where(sod => productIDs.Contains(sod.ProductId)).ToListAsync()
            };

            // include related SalesOrderDetails with the products in the same query result
            queryResult.subResults.Add(subResult);

            // example of returning out of band information and use it on the client (of it can be more useful than it)
            queryResult.extraInfo = new { test = "ReadProduct Extra Info: " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss") };
            return(queryResult);
        }
示例#2
0
        public async Task <QueryResult <Product> > ReadProduct(int[] param1, string param2)
        {
            int?totalCount = null;
            var qinf       = RequestContext.CurrentQueryInfo;
            //the async delay is for the demo purposes to make it more  complex
            //await Task.Delay(5000).ConfigureAwait(false);

            //another async part
            var productsArr = await PerformQuery(ref totalCount).ToArrayAsync();

            var productIDs  = productsArr.Select(p => p.ProductID).Distinct().ToArray();
            var queryResult = new QueryResult <Product>(productsArr, totalCount);

            var subResult = new SubResult
            {
                dbSetName = "SalesOrderDetail",
                Result    = DB.SalesOrderDetails.AsNoTracking().Where(sod => productIDs.Contains(sod.ProductID))
            };

            //include related SalesOrderDetails with the products in the same query result
            queryResult.subResults.Add(subResult);
            //example of returning out of band information and use it on the client (of it can be more useful than it)
            queryResult.extraInfo = new { test = "ReadProduct Extra Info: " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss") };
            return(queryResult);
        }
示例#3
0
        public static void Sub(SubRequest numbers, string EviTrackingID)
        {
            var client  = new RestClient(urlBase);
            var request = new RestRequest("Sub", Method.POST);

            if (EviTrackingID != "")
            {
                request.AddHeader("x-evi-tracking-id", EviTrackingID);
            }
            else if (EviTrackingID == "")
            {
                request.AddHeader("x-evi-tracking-id", "0");
            }
            request.AddParameter("application/json", new JavaScriptSerializer().Serialize(numbers), ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            Console.WriteLine();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                SubResult result = (new JavaScriptSerializer()).Deserialize <SubResult>(response.Content);
                Console.WriteLine("Resultado: Diferencia: " + result.Difference + ". " + (EviTrackingID != "" ? "y se guardo en el log." : ""));
            }
            else
            {
                Console.WriteLine("Ha ocurrido un error: " + response.ErrorMessage);
            }
            Console.WriteLine("Fin del programa, va a volver al menu");
            Console.WriteLine();
        }
示例#4
0
        /// <summary>
        /// Refresh Customer's custom ServerCalculated field 'AddressCount' on insert or delete
        /// </summary>
        /// <param name="changeSet"></param>
        /// <param name="refreshResult"></param>
        /// <returns></returns>
        public override async Task AfterChangeSetCommited(ChangeSetRequest changeSet, SubResultList refreshResult)
        {
            DbSetInfo custAddrDbSet = this.GetSetInfosByEntityType(typeof(CustomerAddress)).Single();
            DbSetInfo customerDbSet = this.GetSetInfosByEntityType(typeof(Customer)).Single();

            DbSet dbCustAddr = changeSet.dbSets.FirstOrDefault(d => d.dbSetName == custAddrDbSet.dbSetName);

            if (dbCustAddr != null)
            {
                int[] custIDs = dbCustAddr.rows.Where(r => r.changeType == ChangeType.Deleted || r.changeType == ChangeType.Added).Select(r => r.values.First(v => v.fieldName == "CustomerId").val).Select(id => int.Parse(id)).ToArray();

                System.Collections.Generic.List <Customer> customersList = await DB.Customer.AsNoTracking().Where(c => custIDs.Contains(c.CustomerId)).ToListAsync();

                System.Collections.Generic.List <int> customerAddress = await DB.CustomerAddress.AsNoTracking().Where(ca => custIDs.Contains(ca.CustomerId)).Select(ca => ca.CustomerId).ToListAsync();

                customersList.ForEach(customer =>
                {
                    customer.AddressCount = customerAddress.Count(id => id == customer.CustomerId);
                });

                SubResult subResult = new SubResult
                {
                    dbSetName = customerDbSet.dbSetName,
                    Result    = customersList
                };
                refreshResult.Add(subResult);
            }
        }
示例#5
0
        /// <summary>
        /// Returns a sub-Bits matching the provided <paramref name="slice"/>
        /// <para/>
        /// Because <c>null</c> usually has a special meaning for
        /// <see cref="IBits"/> (e.g. no deleted documents), you must check
        /// <see cref="SubResult.Matches"/> instead to ensure the sub was
        /// actually found.
        /// </summary>
        public SubResult GetMatchingSub(ReaderSlice slice)
        {
            int reader = ReaderUtil.SubIndex(slice.Start, starts);

            Debug.Assert(reader != -1);
            Debug.Assert(reader < subs.Length, "slice=" + slice + " starts[-1]=" + starts[starts.Length - 1]);
            SubResult subResult = new SubResult();

            if (starts[reader] == slice.Start && starts[1 + reader] == slice.Start + slice.Length)
            {
                subResult.Matches = true;
                subResult.Result  = subs[reader];
            }
            else
            {
                subResult.Matches = false;
            }
            return(subResult);
        }
示例#6
0
        public static SubResult Sub(SubRequest subRequest, string trackingID)
        {
            SubResult subResult = new SubResult();

            try
            {
                subResult.Difference = subRequest.Minuend - subRequest.Subtrahend;
                string calculation = subRequest.Minuend.ToString() + "-" + subRequest.Subtrahend.ToString();
                //Si viene el header x-trackingID diferente de 0 se guarda el log
                if (Convert.ToInt32(trackingID) != 0)
                {
                    SaveLog(Convert.ToInt32(trackingID), "Sub", calculation, subResult.Difference);
                }
            }
            catch (Exception ex)
            {
                subResult.Difference = -1;
            }
            return(subResult);
        }
示例#7
0
        public void run()
        {
            testCount = 0;

            foreach (string strDomain in lstSubdomains)
            {
                for (int i = 0; i < strPostfixDomain.Count; i++)
                {
                    if (strPostfixDomain[i].Length < 2)
                    {
                        continue;
                    }

                    string      strTestDomain = $"{strDomain}.{strPostfixDomain[i]}";
                    IPHostEntry ip            = null;

                    try
                    {
                        testCount++;
                        ip = Dns.GetHostEntry(strTestDomain);
                    }
                    catch (Exception ex)
                    {
                        if (ex is System.Net.Sockets.SocketException && bAlwaysDig)
                        {
                            SubResult sr = new SubResult
                            {
                                strDomain = $"{strDomain}.{strPostfixDomain[i]}",
                                strIP     = ip?.AddressList?.ToList().Select(a => a.ToString()).ToList()
                            };

                            DigStatus ds = new DigStatus();
                            ds.strFullDigPath = this.strFullDigPath;
                            ds.bDigResult     = this.bDigResult;


                            Console.WriteLine($"[+] Domain was not resolved executing dig anyway {sr.strDomain}");
                            DigStatus.DigInfo di = ds.getDigResult(sr.strDomain);

                            if (di != null && di.lstRecord != null && (di.lstRecord.Count > 0 || di.strStatus != null))
                            {
                                Console.WriteLine($"[+] Dig successful: {di.strStatus} with {di.lstRecord.Count} records");
                                sr.digInfo = di;
                                lstResult.Add(sr);
                            }
                        }

                        continue;
                    }

                    if (ip?.AddressList?.Length > 0)
                    {
                        bool bAvoid = ip.AddressList.FirstOrDefault(e => this.shouldAvoid(e.ToString())) != null;

                        if (bAvoid)
                        {
                            continue;
                        }

                        SubResult sr = new SubResult
                        {
                            strDomain = $"{strDomain}.{strPostfixDomain[i]}",
                            strIP     = ip?.AddressList?.ToList().Select(a => a.ToString()).ToList()
                        };

                        lstResult.Add(sr);

                        Console.WriteLine($"[+] Found : {sr.strDomain} with ip: {string.Join(", ", sr.strIP)}");

                        if (bFull)
                        {
                            DigStatus ds = new DigStatus();
                            ds.strFullDigPath = strFullDigPath;
                            ds.bDigResult     = bDigResult;

                            Console.WriteLine("[+] Executing dig: " + sr.strDomain);
                            DigStatus.DigInfo di = ds.getDigResult(sr.strDomain);

                            sr.digInfo = di;


                            WebRequest wr = WebRequest.Create($"https://{sr.strDomain}/");


                            if (wr != null)
                            {
                                wr.Timeout = 4000;

                                try
                                {
                                    HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                                    sr.strHttpsResult = response?.StatusCode.ToString();
                                }
                                catch (Exception ex)
                                {
                                    sr.strHttpsResult = ex.Message;
                                }
                            }

                            HttpWebRequest wr2 = (HttpWebRequest)WebRequest.Create($"http://{sr.strDomain}/");


                            if (wr2 != null)
                            {
                                wr2.Timeout = 5000;

                                try
                                {
                                    HttpWebResponse response2 = (HttpWebResponse)wr2.GetResponse();

                                    sr.strHttpResult = response2?.StatusCode.ToString();
                                }
                                catch (Exception ex2)
                                {
                                    sr.strHttpResult = ex2.Message;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#8
0
 /// <summary>
 /// Returns a sub-Bits matching the provided <code>slice</code>
 /// <p>
 /// Because <code>null</code> usually has a special meaning for
 /// Bits (e.g. no deleted documents), you must check
 /// <seealso cref="SubResult#matches"/> instead to ensure the sub was
 /// actually found.
 /// </summary>
 public SubResult GetMatchingSub(ReaderSlice slice)
 {
     int reader = ReaderUtil.SubIndex(slice.Start, Starts);
     Debug.Assert(reader != -1);
     Debug.Assert(reader < Subs.Length, "slice=" + slice + " starts[-1]=" + Starts[Starts.Length - 1]);
     SubResult subResult = new SubResult();
     if (Starts[reader] == slice.Start && Starts[1 + reader] == slice.Start + slice.Length)
     {
         subResult.Matches = true;
         subResult.Result = Subs[reader];
     }
     else
     {
         subResult.Matches = false;
     }
     return subResult;
 }
示例#9
0
        public void run()
        {
            testCount = 0;

            foreach (string strDomain in lstSubdomains)
            {
                for (int i = 0; i < strPostfixDomain.Count; i++)
                {
                    if (strPostfixDomain[i].Length < 2)
                    {
                        continue;
                    }

                    string      strTestDomain = $"{strDomain}.{strPostfixDomain[i]}";
                    IPHostEntry ip            = null;

                    try
                    {
                        testCount++;
                        ip = Dns.GetHostEntry(strTestDomain);
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }

                    if (ip?.AddressList?.Length > 0)
                    {
                        bool bAvoid = ip.AddressList.FirstOrDefault(e => this.shouldAvoid(e.ToString())) != null;

                        if (bAvoid)
                        {
                            continue;
                        }

                        SubResult sr = new SubResult
                        {
                            strDomain = $"{strDomain}.{strPostfixDomain[i]}",
                            strIP     = ip?.AddressList?.ToList().Select(a => a.ToString()).ToList()
                        };

                        lstResult.Add(sr);

                        Console.WriteLine($"[+] Found : {sr.strDomain} with ip: {string.Join(", ", sr.strIP)}");

                        if (bFull)
                        {
                            DigStatus ds = new DigStatus();

                            Console.WriteLine("[+] Executing dig: " + sr.strDomain);
                            DigStatus.DigInfo di = ds.getDigResult(sr.strDomain);

                            sr.digInfo = di;


                            WebRequest wr = WebRequest.Create($"https://{sr.strDomain}/");


                            if (wr != null)
                            {
                                wr.Timeout = 4000;

                                try
                                {
                                    HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                                    sr.strHttpsResult = response?.StatusCode.ToString();
                                }
                                catch (Exception ex)
                                {
                                    sr.strHttpsResult = ex.Message;
                                }
                            }

                            HttpWebRequest wr2 = (HttpWebRequest)WebRequest.Create($"http://{sr.strDomain}/");


                            if (wr2 != null)
                            {
                                wr2.Timeout = 5000;

                                try
                                {
                                    HttpWebResponse response2 = (HttpWebResponse)wr2.GetResponse();

                                    sr.strHttpResult = response2?.StatusCode.ToString();
                                }
                                catch (Exception ex2)
                                {
                                    sr.strHttpResult = ex2.Message;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#10
0
        public async Task <QueryResult <Customer> > ReadCustomer(bool?includeNav)
        {
            IQueryable <Customer> customers = DB.Customers;
            QueryRequest          queryInfo = this.GetCurrentQueryInfo();
            // AddressCount does not exists in Database (we calculate it), so it is needed to sort it manually
            SortItem addressCountSortItem = queryInfo.sortInfo.sortItems.FirstOrDefault(sortItem => sortItem.fieldName == "AddressCount");

            if (addressCountSortItem != null)
            {
                queryInfo.sortInfo.sortItems.Remove(addressCountSortItem);
                if (addressCountSortItem.sortOrder == SortOrder.ASC)
                {
                    customers = customers.OrderBy(c => c.CustomerAddresses.Count());
                }
                else
                {
                    customers = customers.OrderByDescending(c => c.CustomerAddresses.Count());
                }
            }

            // perform query
            PerformQueryResult <Customer> customersResult = this.PerformQuery(customers, (countQuery) => countQuery.CountAsync());
            int?totalCount = await customersResult.CountAsync();

            List <Customer> customersList = await customersResult.Data.ToListAsync();

            QueryResult <Customer> queryRes = new QueryResult <Customer>(customersList, totalCount);

            if (includeNav == true)
            {
                int[] customerIDs = customersList.Select(c => c.CustomerID).ToArray();
                List <CustomerAddress> customerAddress = await DB.CustomerAddresses.Where(ca => customerIDs.Contains(ca.CustomerID)).ToListAsync();

                int[] addressIDs = customerAddress.Select(ca => ca.AddressID).ToArray();

                SubResult subResult1 = new SubResult
                {
                    dbSetName = this.GetSetInfosByEntityType(typeof(CustomerAddress)).Single().dbSetName,
                    Result    = customerAddress
                };

                SubResult subResult2 = new SubResult
                {
                    dbSetName = this.GetSetInfosByEntityType(typeof(Address)).Single().dbSetName,
                    Result    = await DB.Addresses.AsNoTracking().Where(adr => addressIDs.Contains(adr.AddressID)).ToListAsync()
                };

                // since we have preloaded customer addresses then update server side calculated field: AddressCount
                // (which i have introduced for testing purposes as a server calculated field)
                customersList.ForEach(customer =>
                {
                    customer.AddressCount = customer.CustomerAddresses.Count();
                });

                // return two subresults with the query results
                queryRes.subResults.Add(subResult1);
                queryRes.subResults.Add(subResult2);
            }

            return(queryRes);
        }
示例#11
0
 public SubResultWrapper(SubResult subResult)
 {
     SubResult = subResult;
 }
示例#12
0
        public async Task <QueryResult <Customer> > ReadCustomer(bool?includeNav)
        {
            IQueryable <Customer> customers = DB.Customer;
            QueryRequest          queryInfo = this.GetCurrentQueryInfo();
            // AddressCount does not exists in Database (we calculate it), so it is needed to sort it manually
            SortItem addressCountSortItem = queryInfo.sortInfo.sortItems.FirstOrDefault(sortItem => sortItem.fieldName == "AddressCount");

            if (addressCountSortItem != null)
            {
                queryInfo.sortInfo.sortItems.Remove(addressCountSortItem);
                if (addressCountSortItem.sortOrder == SortOrder.ASC)
                {
                    customers = customers.OrderBy(c => c.CustomerAddress.Count());
                }
                else
                {
                    customers = customers.OrderByDescending(c => c.CustomerAddress.Count());
                }
            }

            int?totalCount = queryInfo.pageIndex == 0 ? 0 : (int?)null;
            // perform query
            PerformQueryResult <Customer> customersResult = this.PerformQuery(customers.AsNoTracking(), queryInfo.pageIndex == 0 ? (countQuery) => countQuery.CountAsync() : (Func <IQueryable <Customer>, Task <int> >)null);

            System.Collections.Generic.List <Customer> customersList = await customersResult.Data.ToListAsync();

            // only execute total counting if we got full page size of rows, preventing unneeded database call to count total
            if (queryInfo.pageIndex == 0 && customersList.Any())
            {
                int cnt = customersList.Count;
                if (cnt < queryInfo.pageSize)
                {
                    totalCount = cnt;
                }
                else
                {
                    totalCount = totalCount = await customersResult.CountAsync();
                }
            }

            QueryResult <Customer> queryRes = new QueryResult <Customer>(customersList, totalCount);

            if (includeNav == true)
            {
                int[] customerIDs = customersList.Select(c => c.CustomerId).ToArray();
                System.Collections.Generic.List <CustomerAddress> customerAddress = await DB.CustomerAddress.AsNoTracking().Where(ca => customerIDs.Contains(ca.CustomerId)).ToListAsync();

                int[] addressIDs = customerAddress.Select(ca => ca.AddressId).ToArray();

                SubResult subResult1 = new SubResult
                {
                    dbSetName = "CustomerAddress",
                    Result    = customerAddress
                };

                SubResult subResult2 = new SubResult
                {
                    dbSetName = "Address",
                    Result    = await DB.Address.AsNoTracking().Where(adr => addressIDs.Contains(adr.AddressId)).ToListAsync()
                };

                // since we have loaded customer addresses - update server side calculated field: AddressCount
                // (which i have introduced for testing purposes as a server calculated field)
                ILookup <int, CustomerAddress> addressLookUp = customerAddress.ToLookup(ca => ca.CustomerId);
                customersList.ForEach(customer =>
                {
                    customer.AddressCount = addressLookUp[customer.CustomerId].Count();
                });

                // return two subresults with the query results
                queryRes.subResults.Add(subResult1);
                queryRes.subResults.Add(subResult2);
            }

            return(queryRes);
        }