<%@ Page CodeFileBaseClass="AliCMS.Lib.SystemPageBase" %>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>批量生成</title>
<script language="c#" runat="server">
protected string Condition()
{
	StringBuilder condition = new StringBuilder();
	condition.Append(Alias.Channel.TemplatePath + " IS NOT NULL");
	condition.Append(" AND " + Alias.Channel.Generate + "=true");
	if (Request.QueryString["Type"] == "Channel" || Request.QueryString["Type"] == "Object")
		condition.Append(" AND " + Alias.Channel.InnerID + "=" + Request.QueryString["ChannelID"]);
	
	return condition.ToString();
}

protected string GetNamespace(object record, bool isChannel)
{
	if (isChannel)
	{
		return Manager.Channels.Select(Alias.Channel.ID + "='" + ((DataRow)record)[Alias.Channel.ID] + "'")[0][Alias.Module.Namespace].ToString();
	}
	else
	{
		if (!Guid.Equals(((DataRow)record)[Alias.Channel.ExtraInstance.BindingChannelID], Guid.Empty))
			return Manager.Channels.Select(Alias.Channel.ID + "='" + ((DataRow)record)[Alias.Channel.ExtraInstance.BindingChannelID] + "'")[0][Alias.Module.Namespace].ToString();
		else if (!Guid.Equals(((DataRow)record)[Alias.Channel.ExtraInstance.BindingInstanceID], Guid.Empty))
			return Manager.Channels.Select(Alias.Instance.ID + "='" + ((DataRow)record)[Alias.Channel.ExtraInstance.BindingInstanceID] + "'")[0][Alias.Module.Namespace].ToString();
		else
			return "";
	}
}
</script>
<script>
var _page = 'generate_do',
    _webPath = '<%=WebPath%>',
    _interval = parseInt('<%=Site[GenerateInterval]%>'),
    _type = '<%=Request.QueryString["Type"]%>',
    _objectHeader = '<%=Request.QueryString["Object"]%>',
    _mark,
    _object,
    _pathInChannel, _pathInChannelBackup,
    _caller = new Array(),
    _records = null,
    _recordIndex,
    _recordPageNumber,
    _pageSize = 20,
    _pages = null,
    _pageIndex = 0,
    _pageNumber = -1,
    _pageCount = -1,
    _channelIndex = 0,
    _channels = new Array(),
<ali:List Object="Channel" Condition="Condition()">
	<ali:Record>
		_channels[_channels.length] = new Object(),
		_channels[_channels.length - 1].Namespace = '<%=GetNamespace(Record, true)%>',
		_channels[_channels.length - 1].InstanceID = '<%=InstanceID%>',
		_channels[_channels.length - 1].Lang = '<%=Lang%>',
		_channels[_channels.length - 1].Path = '<%=Path%>',
		_channels[_channels.length - 1].TemplatePath = '<%=TemplatePath%>',
		_channels[_channels.length - 1].Extension = '<%=Extension%>',
	</ali:Record>
</ali:List>
    _extraInstances = new Array(),
<ali:List Object="Channel.ExtraInstance">
	<ali:Record>
		_extraInstances[_extraInstances.length] = new Object(),
		_extraInstances[_extraInstances.length - 1].ChannelID = '<%=ChannelID%>',
		_extraInstances[_extraInstances.length - 1].BindingInstanceID = '<%=BindingInstanceID%>',
		_extraInstances[_extraInstances.length - 1].BindingChannelID = '<%=BindingChannelID%>',
		_extraInstances[_extraInstances.length - 1].Mark ='<%=Mark%>',
		_extraInstances[_extraInstances.length - 1].Namespace = '<%=GetNamespace(Record, false)%>',
	</ali:Record>
</ali:List>
    _modules = new Array(),
<ali:List ID="List" Object="Module">
	<ali:Record>
		_modules[_modules.length] = new Object(),
		_modules[_modules.length - 1].Namespace = '<%=Namespace%>',
		_modules[_modules.length - 1].Name = '<%=Name%>',
	</ali:Record>
</ali:List>
    _lang_nothing = '没有可生成项目！',
    _lang_pages = '获取模板页面失败！',
    _lang_generating = '正在生成：',
    _lang_generate_fail = '生成失败！',
    _lang_generate_success = '生成成功！',
    _lang_generate_complete = '生成完毕！',
    _lang_sleep = '休息{Interval}秒钟';
</script>
</head>
<body>
<script src="<%=CommonPath%>jquery/core.js"></script>
<ali:List Object="Module" Source="List">
	<ali:Record>
		<script src="<%=Manager.GetModulePath(null)%><%=Namespace%>/alias.js"></script>
	</ali:Record>
</ali:List>
<script src="<%=CommonPath%>xmldom.js"></script>
<script src="<%=JsPath%>global.js"></script>
<script src="<%=ModuleJsPath%>module.js"></script>
</body>
</html>
