Skip to content

Commit 8428d27

Browse files
author
ActiveDbSoft
committed
3.2.0
1 parent 3933e93 commit 8428d27

38 files changed

+4239
-183
lines changed

CrossDomain/AdventureWorks.xml

Lines changed: 2922 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Web;
2-
using System.Web.Mvc;
1+
using System.Web.Mvc;
32

43
namespace CrossDomain
54
{
@@ -10,4 +9,4 @@ public static void RegisterGlobalFilters(GlobalFilterCollection filters)
109
filters.Add(new HandleErrorAttribute());
1110
}
1211
}
13-
}
12+
}
Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.IO;
5-
using System.Linq;
6-
using System.Web;
7-
using System.Web.Mvc;
8-
using ActiveQueryBuilder.Core;
9-
using ActiveQueryBuilder.Web.Server;
1+
using System.Web.Mvc;
102

113
namespace CrossDomain.Controllers
124
{
@@ -16,51 +8,14 @@ public ActionResult Index()
168
{
179
return View();
1810
}
11+
}
12+
}
1913

20-
/// <summary>
21-
/// Creates and initializes new instance of the QueryBuilder object for the given identifier if it doesn't exist.
22-
/// </summary>
23-
/// <param name="name">Instance identifier of object in the current session.</param>
24-
/// <returns></returns>
25-
public ActionResult CreateQueryBuilder(string name)
26-
{
27-
// Get an instance of the QueryBuilder object
28-
var qb = QueryBuilderStore.Get(name);
29-
30-
if (qb != null)
31-
return new EmptyResult();
3214

33-
// Create an instance of the QueryBuilder object
34-
var queryBuilder = QueryBuilderStore.Create(name);
3515

36-
// Create an instance of the proper syntax provider for your database server.
37-
queryBuilder.SyntaxProvider = new MSSQLSyntaxProvider();
3816

39-
// Denies metadata loading requests from live database connection
40-
queryBuilder.MetadataLoadingOptions.OfflineMode = true;
4117

42-
// Load MetaData from XML document. File name is stored in the "Web.config" file in [/configuration/appSettings/NorthwindXmlMetaData] key
43-
var path = ConfigurationManager.AppSettings["NorthwindXmlMetaData"];
44-
var xml = Path.Combine(Server.MapPath("~"), path);
4518

46-
queryBuilder.MetadataContainer.ImportFromXML(xml);
4719

48-
//Set default query
49-
queryBuilder.SQL = GetDefaultSql();
5020

51-
return new EmptyResult();
52-
}
5321

54-
private string GetDefaultSql()
55-
{
56-
return @"Select o.OrderID,
57-
c.CustomerID,
58-
s.ShipperID,
59-
o.ShipCity
60-
From Orders o
61-
Inner Join Customers c On o.CustomerID = c.CustomerID
62-
Inner Join Shippers s On s.ShipperID = o.OrderID
63-
Where o.ShipCity = 'A'";
64-
}
65-
}
66-
}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.Caching;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using ActiveQueryBuilder.Core;
7+
using ActiveQueryBuilder.Web.Server;
8+
using ActiveQueryBuilder.Web.Server.Infrastructure.Providers;
9+
10+
namespace CrossDomain.Controllers
11+
{
12+
public class QueryBuilderController : Controller
13+
{
14+
public string CheckToken(string token)
15+
{
16+
// get Token QueryBuilder provider from the store
17+
var provider = (TokenQueryBuilderProvider)QueryBuilderStore.Provider;
18+
19+
// check if the item with specified key exists in the storage.
20+
if (provider.CheckToken(token))
21+
// Return empty string in the case of success
22+
return string.Empty;
23+
24+
// Return the new token to the client if the specified token doesn't exist.
25+
return provider.CreateToken();
26+
}
27+
28+
/// <summary>
29+
/// Creates and initializes new instance of the QueryBuilder object for the given identifier if it doesn't exist.
30+
/// </summary>
31+
/// <param name="name">Instance identifier of object in the current session.</param>
32+
/// <returns></returns>
33+
34+
public ActionResult CreateQueryBuilder(string name)
35+
{
36+
// Get an instance of the QueryBuilder object
37+
var qb = QueryBuilderStore.Get("CrossDomainQueryBuilder");
38+
39+
if (qb != null)
40+
return new HttpStatusCodeResult(200);
41+
42+
try
43+
{
44+
// Create an instance of the QueryBuilder object
45+
QueryBuilderStore.Create(name);
46+
return new HttpStatusCodeResult(200);
47+
}
48+
catch (QueryBuilderException e)
49+
{
50+
return new HttpStatusCodeResult(400, e.Message);
51+
}
52+
}
53+
}
54+
55+
// Token-based QueryBuilder storage provider
56+
// Stores TokenStoreItems using values from HTTP request header as a key.
57+
public class TokenQueryBuilderProvider : IQueryBuilderProvider
58+
{
59+
public bool SaveState { get; }
60+
61+
private readonly MemoryCache _cache;
62+
63+
public TokenQueryBuilderProvider()
64+
{
65+
SaveState = false;
66+
_cache = new MemoryCache("Tokens");
67+
}
68+
69+
public QueryBuilder Get(string id)
70+
{
71+
var token = GetToken();
72+
return ((TokenStoreItem)_cache[token]).Get(id);
73+
}
74+
75+
public void Put(QueryBuilder qb)
76+
{
77+
var token = GetToken();
78+
((TokenStoreItem)_cache[token]).Put(qb);
79+
}
80+
81+
public void Delete(string id)
82+
{
83+
var token = GetToken();
84+
((TokenStoreItem)_cache[token]).Delete(id);
85+
}
86+
87+
private void CreateItem(string token)
88+
{
89+
if (_cache.Contains(token))
90+
((TokenStoreItem)_cache[token]).Dispose();
91+
92+
CacheItem ci = new CacheItem(token, new TokenStoreItem());
93+
CacheItemPolicy cip = new CacheItemPolicy
94+
{
95+
RemovedCallback = args => ((TokenStoreItem)args.CacheItem.Value).Dispose(),
96+
SlidingExpiration = TimeSpan.FromMinutes(20),
97+
Priority = CacheItemPriority.NotRemovable
98+
};
99+
100+
_cache.Set(ci, cip);
101+
}
102+
103+
public bool CheckToken(string token)
104+
{
105+
if (token == null)
106+
return false;
107+
return _cache.Contains(token);
108+
}
109+
110+
public string CreateToken()
111+
{
112+
var token = Guid.NewGuid().ToString();
113+
CreateItem(token);
114+
return token;
115+
}
116+
117+
private string GetToken()
118+
{
119+
var token = HttpContext.Current.Request.Headers["query-builder-token"];
120+
121+
if (string.IsNullOrEmpty(token) || !CheckToken(token))
122+
throw new ApplicationException("Token not found");
123+
124+
return token;
125+
}
126+
}
127+
128+
// Token-based storage item holding an instance of the QueryBuilder object
129+
public class TokenStoreItem : IDisposable
130+
{
131+
private readonly Dictionary<string, QueryBuilder> QueryBuilders = new Dictionary<string, QueryBuilder>();
132+
133+
public QueryBuilder Get(string id)
134+
{
135+
if (!QueryBuilders.ContainsKey(id))
136+
return null;
137+
138+
return QueryBuilders[id];
139+
}
140+
141+
public void Put(QueryBuilder qb)
142+
{
143+
if (QueryBuilders.ContainsKey(qb.Tag) && QueryBuilders[qb.Tag] == qb)
144+
return;
145+
146+
QueryBuilders[qb.Tag] = qb;
147+
}
148+
149+
public void Delete(string id)
150+
{
151+
QueryBuilders[id].Dispose();
152+
QueryBuilders.Remove(id);
153+
}
154+
155+
public void Dispose()
156+
{
157+
foreach (var key in QueryBuilders.Keys)
158+
Delete(key);
159+
}
160+
}
161+
}

CrossDomain/CreateDocker.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
docker build -t crossdomain .
2+
docker run -d --name aqbcrossdomain crossdomain
3+
4+
echo 'Docker is running! Now set ip to AQB.Web.host in your index.html file:'
5+
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" aqbcrossdomain
6+
7+
pause

CrossDomain/CrossDomain.csproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,17 @@
4747
<WarningLevel>4</WarningLevel>
4848
<Prefer32Bit>false</Prefer32Bit>
4949
</PropertyGroup>
50+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
51+
<ExcludeFilesFromDeployment>Dockerfile;CreateDocker.bat</ExcludeFilesFromDeployment>
52+
<ExcludeFoldersFromDeployment>FrontEnd</ExcludeFoldersFromDeployment>
53+
</PropertyGroup>
5054
<ItemGroup>
5155
<Reference Include="Microsoft.CSharp" />
5256
<Reference Include="System" />
5357
<Reference Include="System.Data" />
5458
<Reference Include="System.Data.DataSetExtensions" />
5559
<Reference Include="System.Drawing" />
60+
<Reference Include="System.Runtime.Caching" />
5661
<Reference Include="System.Web.DynamicData" />
5762
<Reference Include="System.Web.Entity" />
5863
<Reference Include="System.Web.ApplicationServices" />
@@ -110,25 +115,32 @@
110115
<Compile Include="App_Start\FilterConfig.cs" />
111116
<Compile Include="App_Start\RouteConfig.cs" />
112117
<Compile Include="Controllers\HomeController.cs" />
118+
<Compile Include="Controllers\QueryBuilderController.cs" />
113119
<Compile Include="Global.asax.cs">
114120
<DependentUpon>Global.asax</DependentUpon>
115121
</Compile>
116122
<Compile Include="Properties\AssemblyInfo.cs" />
117123
</ItemGroup>
118124
<ItemGroup>
125+
<Content Include="AdventureWorks.xml" />
119126
<Content Include="Content\bootstrap-theme.css" />
120127
<Content Include="Content\bootstrap-theme.min.css" />
121128
<Content Include="Content\bootstrap.css" />
122129
<Content Include="Content\bootstrap.min.css" />
123130
<Content Include="favicon.ico" />
124131
<Content Include="fonts\glyphicons-halflings-regular.svg" />
132+
<Content Include="FrontEnd\index.html" />
125133
<Content Include="Global.asax" />
126134
<Content Include="Content\Site.css" />
135+
<Content Include="Northwind.xml" />
136+
<Content Include="Sakila.xml" />
127137
<Content Include="Scripts\bootstrap.js" />
128138
<Content Include="Scripts\bootstrap.min.js" />
139+
<Content Include="Readme.md" />
140+
<Content Include="Dockerfile" />
141+
<Content Include="CreateDocker.bat" />
142+
<None Include="Properties\PublishProfiles\FolderProfile.pubxml" />
129143
<None Include="Scripts\jquery-1.10.2.intellisense.js" />
130-
<Content Include="Scripts\CrossDomain\index.html" />
131-
<Content Include="Scripts\CrossDomain\Readme.txt" />
132144
<Content Include="Scripts\jquery-1.10.2.js" />
133145
<Content Include="Scripts\jquery-1.10.2.min.js" />
134146
<None Include="Scripts\jquery.validate-vsdoc.js" />
@@ -173,10 +185,10 @@
173185
</ItemGroup>
174186
<ItemGroup>
175187
<Reference Include="ActiveQueryBuilder.Core">
176-
<HintPath>..\packages\ActiveQueryBuilder.Core.3.4.7.1084\lib\net\ActiveQueryBuilder.Core.dll</HintPath>
188+
<HintPath>..\packages\ActiveQueryBuilder.Core.3.4.8.1085\lib\net\ActiveQueryBuilder.Core.dll</HintPath>
177189
</Reference>
178190
<Reference Include="ActiveQueryBuilder.Web.Server">
179-
<HintPath>..\packages\ActiveQueryBuilder.Web.MVC.3.1.2.1\lib\net\ActiveQueryBuilder.Web.Server.dll</HintPath>
191+
<HintPath>..\packages\ActiveQueryBuilder.Web.MVC.3.2.0\lib\net\ActiveQueryBuilder.Web.Server.dll</HintPath>
180192
</Reference>
181193
</ItemGroup>
182194
<PropertyGroup>

CrossDomain/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM microsoft/aspnet
2+
COPY ./bin/Release/PublishOutput/ /inetpub/wwwroot

CrossDomain/FrontEnd/aqb.client.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)