示例#1
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     svc = new service(
             "Server=DESKTOP-2B4NB4K\\SQLDEV;Database=JSSQLTEST;User Id=sa;Password=1q2w3e4r5t;Max Pool Size=1000;Min Pool Size=10;", 
             Server.MapPath("~/configuration.json"),
             ErrorLevels.debug,
             null,
             256,
             true
         );
 }
示例#2
0
 public errorResponse(service s) {
     service = s;
 }
示例#3
0
        static void Main(string[] args) {
            service s = new CRUDbind.service("Server=DESKTOP-2B4NB4K\\SQLDEV;Database=JSSQLTEST;User Id=sa;Password=1q2w3e4r5t;");

            // Create Requests

            // perfectly legitimate query with no foreign key relations
            var tmp = s.processRequest(@"
                            {
                                ""CRUDauth"":""auth01"",
                                ""requestType"":""create"",
                                ""table"":""DoubleForeignDef"",
                                ""record"": {
                                    ""DateField"":""2016-02-02"",
                                    ""TextField"":""some text added programmatically"",
                                    ""WriteOnlyField"":""write only text added programmatically""
                                }
                            }
                        ");

            // query with legitimate foreign relation set
            tmp = s.processRequest(@"
                            {
                                ""CRUDauth"":""auth01"",
                                ""requestType"":""create"",
                                ""table"":""DoubleForeignDef"",
                                ""record"": {
                                    ""DateField"":""2016-02-02"",
                                    ""TextField"":""some text added programmatically"",
                                    ""LinkToUserDef"":1
                                }
                            }
                        ");

            // query with two foreign relations set, both legitimate
            tmp = s.processRequest(@"
                            {
                                ""CRUDauth"":""auth01"",
                                ""requestType"":""create"",
                                ""table"":""DoubleForeignDef"",
                                ""record"": {
                                    ""DateField"":""2016-02-02"",
                                    ""TextField"":""some text added programmatically"",
                                    ""LinkToUserDef"":1,
                                    ""LinkToSingleDef"":1
                                }
                            }
                        ");


            tmp = s.processRequest(@"
                            {
                                ""CRUDauth"":""auth01"",
                                ""requestType"":""create"",
                                ""table"":""DoubleForeignDef"",
                                ""record"": {
                                    ""DateField"":""2016-02-02"",
                                    ""TextField"":""some text added programmatically"",
                                    ""IntField"":1,
                                    ""DoubleField"":1
                                }
                            }
                        ");

            // query with a link to a foreign record that exists but is outside of the users access
            tmp = s.processRequest(@"
                            {
                                ""CRUDauth"":""auth01"",
                                ""requestType"":""create"",
                                ""table"":""DoubleForeignDef"",
                                ""record"": {
                                    ""DateField"":""2016-02-02"",
                                    ""TextField"":""some text added programmatically"",
                                    ""WriteOnlyField"":""write only text added programmatically"",
                                    ""LinkToUserDef"":3,
                                    ""LinkToSingleDef"":1
                                }
                            }
                        ");

            // query with a link to a foreign record that does not exist
            tmp = s.processRequest(@"
                            {
                                ""CRUDauth"":""auth01"",
                                ""requestType"":""create"",
                                ""table"":""DoubleForeignDef"",
                                ""record"": {
                                    ""DateField"":""2016-02-02"",
                                    ""TextField"":""some text added programmatically"",
                                    ""LinkToSingleDef"":4
                                }
                            }
                        ");

            // query with an attempt to write to a read only field
            tmp = s.processRequest(@"
                            {
                                ""CRUDauth"":""auth01"",
                                ""requestType"":""create"",
                                ""table"":""DoubleForeignDef"",
                                ""record"": {
                                    ""DateField"":""2016-02-02"",
                                    ""TextField"":""some text added programmatically"",
                                    ""ReadOnlyField"":""this should not show up in the database because this is a read only field""
                                }
                            }
                        ");
#if profiling
            // create request profiling
            List<double> cpuTimes = new List<double>();
            List<double> ioTimes = new List<double>();

            for (int i = 0; i < 1000; i++) {
                // query with two foreign relations set, both legitimate
                s.resetProfiler();

                tmp = s.processRequest(@"
                                {
                                    ""CRUDauth"":""auth01"",
                                    ""requestType"":""create"",
                                    ""table"":""DoubleForeignDef"",
                                    ""record"": {
                                        ""DateField"":""2016-02-02"",
                                        ""TextField"":""some text added programmatically"",
                                        ""LinkToUserDef"":1,
                                        ""LinkToSingleDef"":1,
                                        ""IntField"":1,
                                        ""DoubleField"":1.2
                                    }
                                }
                            ");

                cpuTimes.Add(s.cpu);
                ioTimes.Add(s.io);
            }

            Console.WriteLine("1000 Create Requests");
            Console.WriteLine("CPU time:");
            Console.WriteLine("\tAverage: " + cpuTimes.Average() + " ms");
            Console.WriteLine("\tMin: " + cpuTimes.Min() + " ms");
            Console.WriteLine("\tMax: " + cpuTimes.Max() + " ms");
            Console.WriteLine("\tTotal: " + cpuTimes.Sum() + " ms");
            Console.WriteLine("");
            Console.WriteLine("IO time:");
            Console.WriteLine("\tAverage: " + ioTimes.Average() + " ms");
            Console.WriteLine("\tMin: " + ioTimes.Min() + " ms");
            Console.WriteLine("\tMax: " + ioTimes.Max() + " ms");
            Console.WriteLine("\tTotal: " + ioTimes.Sum() + " ms");
            Console.WriteLine("");
            Console.WriteLine("Summary:");
            Console.WriteLine("\tCPU: " + (cpuTimes.Average() / (ioTimes.Average() + cpuTimes.Average())) * 100 + "%");
            Console.WriteLine("\tIO : " + (ioTimes.Average() / (ioTimes.Average() + cpuTimes.Average())) * 100 + "%");
#endif
            // read requests

            // Full request with legitimate information
            tmp = s.processRequest(
@"
{
    ""CRUDauth"": ""auth01"",
    ""requestType"":""read"",
    ""table"":""DoubleForeignDef"",
    ""Fields"": [
        ""DateField"",
        ""ReadOnlyField"",
        ""LinkToUserDef"",
        ""IntField"",
        ""DoubleField""
    ],
    ""filters"": [
        {
            ""field"": ""ReadOnlyField"",
            ""type"":""contains"",
            ""operand"":""a""
        },
        {
            ""field"": ""IntField"",
            ""type"":"">"",
            ""operand"":0
        },
        {
            ""field"": ""DoubleField"",
            ""type"":"">"",
            ""operand"":0.0
        }
    ],
    ""filterAnd"": false,
    ""order"":[
        {
            ""field"": ""IntField"",
            ""type"":""asc""
        },
        {
            ""field"": ""DoubleField"",
            ""type"":""asc""
        }
    ],
    ""count"":30,
    ""skip"":5
}
"
            );

            // invalid filter type specified
            tmp = s.processRequest(
@"
{
    ""CRUDauth"": ""auth01"",
    ""requestType"":""read"",
    ""table"":""DoubleForeignDef"",
    ""Fields"": [
        ""DateField"",
        ""ReadOnlyField"",
        ""LinkToUserDef"",
        ""IntField"",
        ""DoubleField""
    ],
    ""filters"": [
        {
            ""field"": ""ReadOnlyField"",
            ""type"":""contains"",
            ""operand"":""a""
        },
        {
            ""field"": ""IntField"",
            ""type"":""q"",
            ""operand"":0
        },
        {
            ""field"": ""DoubleField"",
            ""type"":"">"",
            ""operand"":0.0
        }
    ],
    ""filterAnd"": false,
    ""order"":[
        {
            ""field"": ""IntField"",
            ""type"":""asc""
        },
        {
            ""field"": ""DoubleField"",
            ""type"":""asc""
        }
    ],
    ""count"":30,
    ""skip"":5
}
"
            );

            // no filters
            tmp = s.processRequest(
@"
{
    ""CRUDauth"": ""auth01"",
    ""requestType"":""read"",
    ""table"":""DoubleForeignDef"",
    ""Fields"": [
        ""DateField"",
        ""ReadOnlyField"",
        ""LinkToUserDef"",
        ""IntField"",
        ""DoubleField""
    ],
    ""filterAnd"": false,
    ""order"":[
        {
            ""field"": ""IntField"",
            ""type"":""asc""
        },
        {
            ""field"": ""DoubleField"",
            ""type"":""asc""
        }
    ],
    ""count"":30,
    ""skip"":5
}
"
            );

            // Invalid filter operator
            tmp = s.processRequest(
@"
{
    ""CRUDauth"": ""auth01"",
    ""requestType"":""read"",
    ""table"":""DoubleForeignDef"",
    ""Fields"": [
        ""DateField"",
        ""ReadOnlyField"",
        ""LinkToUserDef"",
        ""IntField"",
        ""DoubleField""
    ],
    ""filters"": [
        {
            ""field"": ""ReadOnlyField"",
            ""type"":""contains"",
            ""operand"":""a""
        },
        {
            ""field"": ""IntField"",
            ""type"":""q"",
            ""operand"":0
        },
        {
            ""field"": ""DoubleField"",
            ""type"":"">"",
            ""operand"":0.0
        }
    ],
    ""filterAnd"": false,
    ""count"":30,
    ""skip"":5
}
"
            );

            // No ordering statements
            tmp = s.processRequest(
@"
{
    ""CRUDauth"": ""auth01"",
    ""requestType"":""read"",
    ""table"":""DoubleForeignDef"",
    ""Fields"": [
        ""DateField"",
        ""ReadOnlyField"",
        ""LinkToUserDef"",
        ""IntField"",
        ""DoubleField""
    ],
    ""filters"": [
        {
            ""field"": ""ReadOnlyField"",
            ""type"":""contains"",
            ""operand"":""a""
        },
        {
            ""field"": ""DoubleField"",
            ""type"":"">"",
            ""operand"":0.0
        }
    ],
    ""filterAnd"": false,
    ""count"":30,
    ""skip"":5
}
"
            );

            // Filters without a filterAnd declaration
            tmp = s.processRequest(
@"
{
    ""CRUDauth"": ""auth01"",
    ""requestType"":""read"",
    ""table"":""DoubleForeignDef"",
    ""Fields"": [
        ""DateField"",
        ""ReadOnlyField"",
        ""LinkToUserDef"",
        ""IntField"",
        ""DoubleField""
    ],
    ""filters"": [
        {
            ""field"": ""ReadOnlyField"",
            ""type"":""contains"",
            ""operand"":""a""
        },
        {
            ""field"": ""DoubleField"",
            ""type"":"">"",
            ""operand"":0.0
        }
    ],
    ""order"":[
        {
            ""field"": ""IntField"",
            ""type"":""asc""
        },
        {
            ""field"": ""DoubleField"",
            ""type"":""asc""
        }
    ],
    ""count"":30,
    ""skip"":5
}
"
            );

            // Filters without a filterAnd declaration and skip without count
            tmp = s.processRequest(
@"
{
    ""CRUDauth"": ""auth01"",
    ""requestType"":""read"",
    ""table"":""DoubleForeignDef"",
    ""Fields"": [
        ""DateField"",
        ""ReadOnlyField"",
        ""LinkToUserDef"",
        ""IntField"",
        ""DoubleField""
    ],
    ""filters"": [
        {
            ""field"": ""ReadOnlyField"",
            ""type"":""contains"",
            ""operand"":""a""
        },
        {
            ""field"": ""IntField"",
            ""type"":"">"",
            ""operand"":0
        },
        {
            ""field"": ""DoubleField"",
            ""type"":"">"",
            ""operand"":0.0
        }
    ],
    ""order"":[
        {
            ""field"": ""IntField"",
            ""type"":""asc""
        },
        {
            ""field"": ""DoubleField"",
            ""type"":""asc""
        }
    ],
    ""skip"":5
}
"
            );

            // Filters without a filterAnd declaration and count withou skip and withou fields
            tmp = s.processRequest(
@"
{
    ""CRUDauth"": ""auth01"",
    ""requestType"":""read"",
    ""table"":""DoubleForeignDef"",
    ""filters"": [
        {
            ""field"": ""ReadOnlyField"",
            ""type"":""contains"",
            ""operand"":""a""
        },
        {
            ""field"": ""DoubleField"",
            ""type"":"">"",
            ""operand"":0.0
        }
    ],
    ""order"":[
        {
            ""field"": ""IntField"",
            ""type"":""asc""
        },
        {
            ""field"": ""DoubleField"",
            ""type"":""asc""
        }
    ],
    ""count"":30
}
"
            );

            // test delete request
            tmp = s.processRequest(
@"
{
    ""CRUDauth"": ""auth01"",
    ""requestType"":""delete"",
    ""table"":""DoubleForeignDef"",
    ""identifier"":1
}
"
            );

            // test update request
            tmp = s.processRequest(@"
                                {
                                    ""CRUDauth"":""auth01"",
                                    ""requestType"":""update"",
                                    ""table"":""DoubleForeignDef"",
                                    ""identifier"":3,
                                    ""record"": {
                                        ""DateField"":""2016-02-02"",
                                        ""TextField"":""some text added programmatically"",
                                        ""LinkToUserDef"":1,
                                        ""LinkToSingleDef"":1,
                                        ""IntField"":1,
                                        ""DoubleField"":1.2
                                    }
                                }
                            ");

        }