Skip to content

Commit

Permalink
api
Browse files Browse the repository at this point in the history
  • Loading branch information
starlying committed Oct 17, 2018
1 parent b6b8b47 commit 4002507
Show file tree
Hide file tree
Showing 28 changed files with 465 additions and 311 deletions.
32 changes: 26 additions & 6 deletions SiteServer.BackgroundPages/Cms/PageTemplateMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,18 @@ private void Process(List<int> channelIdList, int templateId, bool isChannelTemp
{
foreach (var channelId in channelIdList)
{
TemplateManager.UpdateChannelTemplateId(SiteId, channelId, templateId);
var channelInfo = ChannelManager.GetChannelInfo(SiteId, channelId);
channelInfo.ChannelTemplateId = templateId;
DataProvider.ChannelDao.UpdateChannelTemplateId(channelInfo);
}
}
else
{
foreach (var channelId in channelIdList)
{
TemplateManager.UpdateContentTemplateId(SiteId, channelId, templateId);
var channelInfo = ChannelManager.GetChannelInfo(SiteId, channelId);
channelInfo.ContentTemplateId = templateId;
DataProvider.ChannelDao.UpdateContentTemplateId(channelInfo);
}
}
}
Expand Down Expand Up @@ -340,7 +344,10 @@ public void CreateChannelTemplate_Click(object sender, EventArgs e)
var insertedTemplateId = DataProvider.TemplateDao.Insert(templateInfo, string.Empty, AuthRequest.AdminName);
if (nodeInfo.ParentId > 0)
{
TemplateManager.UpdateChannelTemplateId(SiteId, channelId, insertedTemplateId);
nodeInfo.ChannelTemplateId = insertedTemplateId;
DataProvider.ChannelDao.UpdateChannelTemplateId(nodeInfo);

//TemplateManager.UpdateChannelTemplateId(SiteId, channelId, insertedTemplateId);
//DataProvider.BackgroundNodeDAO.UpdateChannelTemplateID(channelId, insertedTemplateID);
}

Expand Down Expand Up @@ -381,7 +388,11 @@ public void CreateSubChannelTemplate_Click(object sender, EventArgs e)
var childChannelIdList = ChannelManager.GetChannelIdList(ChannelManager.GetChannelInfo(SiteId, channelId), EScopeType.Descendant, string.Empty, string.Empty, string.Empty);
foreach (var childChannelId in childChannelIdList)
{
TemplateManager.UpdateChannelTemplateId(SiteId, childChannelId, insertedTemplateId);
var childChannelInfo = ChannelManager.GetChannelInfo(SiteId, childChannelId);
childChannelInfo.ChannelTemplateId = insertedTemplateId;
DataProvider.ChannelDao.UpdateChannelTemplateId(childChannelInfo);

//TemplateManager.UpdateChannelTemplateId(SiteId, childChannelId, insertedTemplateId);
//DataProvider.BackgroundNodeDAO.UpdateChannelTemplateID(childChannelId, insertedTemplateID);
}
}
Expand Down Expand Up @@ -430,7 +441,12 @@ public void CreateContentTemplate_Click(object sender, EventArgs e)
continue;
}
var insertedTemplateId = DataProvider.TemplateDao.Insert(templateInfo, string.Empty, AuthRequest.AdminName);
TemplateManager.UpdateContentTemplateId(SiteId, channelId, insertedTemplateId);

var channelInfo = ChannelManager.GetChannelInfo(SiteId, channelId);
channelInfo.ContentTemplateId = insertedTemplateId;
DataProvider.ChannelDao.UpdateContentTemplateId(channelInfo);

//TemplateManager.UpdateContentTemplateId(SiteId, channelId, insertedTemplateId);
//DataProvider.BackgroundNodeDAO.UpdateContentTemplateID(channelId, insertedTemplateID);
}
}
Expand Down Expand Up @@ -469,7 +485,11 @@ public void CreateSubContentTemplate_Click(object sender, EventArgs e)
var childChannelIdList = ChannelManager.GetChannelIdList(ChannelManager.GetChannelInfo(SiteId, channelId), EScopeType.Descendant, string.Empty, string.Empty, string.Empty);
foreach (var childChannelId in childChannelIdList)
{
TemplateManager.UpdateContentTemplateId(SiteId, childChannelId, insertedTemplateId);
var childChannelInfo = ChannelManager.GetChannelInfo(SiteId, childChannelId);
childChannelInfo.ContentTemplateId = insertedTemplateId;
DataProvider.ChannelDao.UpdateContentTemplateId(childChannelInfo);

//TemplateManager.UpdateContentTemplateId(SiteId, childChannelId, insertedTemplateId);
//DataProvider.BackgroundNodeDAO.UpdateContentTemplateID(childChannelId, insertedTemplateID);
}
}
Expand Down
4 changes: 2 additions & 2 deletions SiteServer.BackgroundPages/SiteServer.BackgroundPages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SiteServer.Plugin, Version=2.0.16.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SiteServer.Plugin.2.0.16\lib\net45\SiteServer.Plugin.dll</HintPath>
<Reference Include="SiteServer.Plugin, Version=2.0.17.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SiteServer.Plugin.2.0.17\lib\net45\SiteServer.Plugin.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion SiteServer.BackgroundPages/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<package id="Microsoft.Net.Compilers" version="2.7.0" targetFramework="net452" developmentDependency="true" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="SiteServer.Plugin" version="2.0.16" targetFramework="net452" />
<package id="SiteServer.Plugin" version="2.0.17" targetFramework="net452" />
</packages>
42 changes: 0 additions & 42 deletions SiteServer.CMS/Api/V1/ORequest.cs

This file was deleted.

43 changes: 20 additions & 23 deletions SiteServer.CMS/Api/V1/OResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ namespace SiteServer.CMS.Api.V1
{
public class OResponse
{
private ORequest _request;
private int? _count;
private int? _top;
private int? _skip;
private string _rowUrl;

public OResponse(object value)
public OResponse(object value, int top, int skip, string rowUrl)
{
Value = value;
}

public OResponse(ORequest request, object value)
{
_request = request;
Value = value;
_top = top;
_skip = skip;
_rowUrl = rowUrl;
}

[JsonProperty(PropertyName = "value")]
Expand All @@ -37,54 +36,52 @@ public OResponse(ORequest request, object value)
[JsonProperty(PropertyName = "last", NullValueHandling = NullValueHandling.Ignore)]
public string Last { get; private set; }



[JsonProperty(PropertyName = "count", NullValueHandling = NullValueHandling.Ignore)]
public int? Count
{
get { return _count; }
set
{
_count = value;
if (_request != null && _count != null)
if (_count != null && _top != null && _skip != null && _rowUrl != null)
{
var url = PageUtils.RemoveQueryString(_request.RawUrl, new List<string> {"top", "skip"});
var pages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((int)_count / _request.Top)));
var pageIndex = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(_request.Skip / _request.Top)));
var url = PageUtils.RemoveQueryString(_rowUrl, new List<string> {"top", "skip"});
var pages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble((int)_count / _top)));
var pageIndex = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(_skip / _top)));

if (_request.Skip > 0)
if (_skip > 0)
{
First = PageUtils.AddQueryString(url,
new NameValueCollection
{
{"top", _request.Top.ToString()},
{"top", _top.ToString()},
{"skip", "0"}
});

Prev = PageUtils.AddQueryString(url,
new NameValueCollection
{
{"top", _request.Top.ToString()},
{"skip", ((pageIndex - 1) * _request.Top).ToString()}
{"top", _top.ToString()},
{"skip", ((pageIndex - 1) * _top).ToString()}
});
}

if (_request.Top + _request.Skip < _count)
if (_top + _skip < _count)
{
Next =
PageUtils.AddQueryString(url,
new NameValueCollection
{
{"top", _request.Top.ToString()},
{"skip", ((pageIndex + 1) * _request.Top).ToString()}
{"top", _top.ToString()},
{"skip", ((pageIndex + 1) * _top).ToString()}
});

Last =
PageUtils.AddQueryString(url,
new NameValueCollection
{
{"top", _request.Top.ToString()},
{"skip", ((pages - 1) * _request.Top).ToString()}
{"top", _top.ToString()},
{"skip", ((pages - 1) * _top).ToString()}
});
}
}
Expand Down
6 changes: 2 additions & 4 deletions SiteServer.CMS/Api/V1/StlRequest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using SiteServer.CMS.Core;
using SiteServer.CMS.DataCache;
using SiteServer.CMS.Model;
using SiteServer.CMS.Plugin;
using SiteServer.CMS.Plugin.Impl;
using SiteServer.CMS.StlParser.Model;
using SiteServer.Plugin;
Expand All @@ -25,8 +23,8 @@ public class StlRequest

public StlRequest()
{
Request = new RequestImpl(AccessTokenManager.ScopeStl);
IsApiAuthorized = Request.IsApiAuthorized;
Request = new RequestImpl();
IsApiAuthorized = Request.IsApiAuthenticated && AccessTokenManager.IsScope(Request.ApiToken, AccessTokenManager.ScopeStl);

if (!IsApiAuthorized) return;

Expand Down
30 changes: 16 additions & 14 deletions SiteServer.CMS/DataCache/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ private static class ChannelManagerCache
{
private static readonly object LockObject = new object();
private static readonly string CacheKey = DataCacheManager.GetCacheKey(nameof(ChannelManager));
//private static readonly FileWatcherClass FileWatcher;

//static ChannelManagerCache()
//{
// FileWatcher = new FileWatcherClass(FileWatcherClass.Channel);
// FileWatcher.OnFileChange += FileWatcher_OnFileChange;
//}

//private static void FileWatcher_OnFileChange(object sender, EventArgs e)
//{
// CacheManager.Remove(CacheKey);
//}

private static void Update(Dictionary<int, Dictionary<int, ChannelInfo>> allDict, Dictionary<int, ChannelInfo> dic, int siteId)
{
Expand Down Expand Up @@ -60,8 +48,16 @@ public static void Remove(int siteId)
{
allDict.Remove(siteId);
}
}

//FileWatcher.UpdateCacheFile();
public static void Update(int siteId, ChannelInfo channelInfo)
{
var dict = GetChannelInfoDictionaryBySiteId(siteId);

lock (LockObject)
{
dict[channelInfo.Id] = channelInfo;
}
}

public static Dictionary<int, ChannelInfo> GetChannelInfoDictionaryBySiteId(int siteId)
Expand All @@ -79,12 +75,18 @@ public static Dictionary<int, ChannelInfo> GetChannelInfoDictionaryBySiteId(int
}
}

public static void RemoveCache(int siteId)
public static void RemoveCacheBySiteId(int siteId)
{
ChannelManagerCache.Remove(siteId);
StlChannelCache.ClearCache();
}

public static void UpdateCache(int siteId, ChannelInfo channelInfo)
{
ChannelManagerCache.Update(siteId, channelInfo);
StlChannelCache.ClearCache();
}

public static ChannelInfo GetChannelInfo(int siteId, int channelId)
{
ChannelInfo channelInfo = null;
Expand Down
10 changes: 0 additions & 10 deletions SiteServer.CMS/DataCache/TemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,6 @@ public static void WriteContentToTemplateFile(SiteInfo siteInfo, TemplateInfo te
}
}

public static void UpdateChannelTemplateId(int siteId, int channelId, int channelTemplateId)
{
DataProvider.ChannelDao.UpdateChannelTemplateId(channelId, channelTemplateId);
}

public static void UpdateContentTemplateId(int siteId, int channelId, int contentTemplateId)
{
DataProvider.ChannelDao.UpdateContentTemplateId(channelId, contentTemplateId);
}

public static int GetIndexTempalteId(int siteId)
{
return GetDefaultTemplateId(siteId, TemplateType.IndexPageTemplate);
Expand Down
3 changes: 2 additions & 1 deletion SiteServer.CMS/Plugin/Apis/ChannelApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public string GetChannelName(int siteId, int channelId)

public void Update(int siteId, IChannelInfo channelInfo)
{
DataProvider.ChannelDao.Update(channelInfo);
if (channelInfo == null) return;
DataProvider.ChannelDao.Update((ChannelInfo)channelInfo);
}

public void Delete(int siteId, int channelId)
Expand Down
Loading

0 comments on commit 4002507

Please sign in to comment.