PageRenderTime 27ms CodeModel.GetById 2ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 1ms

/Default.aspx.cs

https://bitbucket.org/Offroadcode/usitebuilderimporter
C# | 735 lines | 448 code | 107 blank | 180 comment | 27 complexity | 9268ee0b60d9760a25ff9781437d7d35 MD5 | raw file
  1// --------------------------------------------------------------------------------------------------------------------
  2// <copyright file="Default.aspx.cs" company="">
  3//   
  4// </copyright>
  5// <summary>
  6//   Defines the _Default type.
  7// </summary>
  8// --------------------------------------------------------------------------------------------------------------------
  9
 10using System;
 11using System.Configuration;
 12using System.Data;
 13using System.Data.SqlClient;
 14using System.IO;
 15using System.Text;
 16using System.Web.UI;
 17
 18using Microsoft.ApplicationBlocks.Data;
 19
 20/// <summary>
 21/// Default class
 22/// </summary>
 23public partial class Default : Page
 24{
 25    #region Public Methods
 26
 27    /// <summary>
 28    /// Get Templates Default Doc Type
 29    /// </summary>
 30    /// <param name="nodeid">
 31    /// The nodeid.
 32    /// </param>
 33    /// <returns>
 34    /// Node ID
 35    /// </returns>
 36    public static string GetTemplatesDefaultDocType(string nodeid)
 37    {
 38        string rtnText = string.Empty;
 39        string strSql =
 40            "SELECT cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsContentType.alias FROM  cmsDocumentType INNER JOIN cmsContentType ON cmsDocumentType.contentTypeNodeId = cmsContentType.nodeId where isDefault=1 and templateNodeId="
 41            + nodeid;
 42
 43        SqlDataReader dr = SqlHelper.ExecuteReader(
 44            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
 45
 46        while (dr.Read())
 47        {
 48            rtnText = ": Vega.USiteBuilder.TemplateBase<uSiteBuilderImport.Web.DocumentTypes." + dr["alias"] + ">";
 49        }
 50
 51        dr.Close();
 52
 53        return rtnText != string.Empty ? rtnText : ": Vega.USiteBuilder.TemplateBase";
 54
 55        // return ": System.Web.UI.MasterPage";
 56        // return string.Empty;
 57    }
 58
 59    /// <summary>
 60    /// The create child doc type.
 61    /// </summary>
 62    /// <param name="nodeid">
 63    /// The nodeid.
 64    /// </param>
 65    /// <param name="alias">
 66    /// The alias.
 67    /// </param>
 68    /// <param name="path">
 69    /// The path.
 70    /// </param>
 71    public void CreateChildDocType(string nodeid, string alias, string path)
 72    {
 73        // string strSQL = "SELECT [pk],[nodeId],[alias],[icon],[thumbnail],[description],[masterContentType] FROM [cmsContentType] where masterContentType=" + nodeid + " order by Alias";
 74        string strSql =
 75            "SELECT     cmsContentType.pk, cmsContentType.nodeId, cmsContentType.alias, cmsContentType.icon, cmsContentType.thumbnail, cmsContentType.description,  "
 76            + "cmsContentType.masterContentType, umbracoNode.text " + "FROM         cmsContentType INNER JOIN "
 77            + "umbracoNode ON cmsContentType.nodeId = umbracoNode.id " + "WHERE     cmsContentType.masterContentType = "
 78            + nodeid + "  ORDER BY alias";
 79
 80        SqlDataReader dr = SqlHelper.ExecuteReader(
 81            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
 82
 83        while (dr.Read())
 84        {
 85            // Start file
 86            var sb = new StringBuilder();
 87
 88            this.Response.Write("Create Doc Type for child " + dr["alias"] + " (" + dr["nodeid"] + ")<br/>");
 89
 90            sb.AppendLine("using System;");
 91            sb.AppendLine("using System.Collections.Generic;");
 92            sb.AppendLine("using System.Linq;");
 93            sb.AppendLine("using System.Web;");
 94
 95            sb.AppendLine("using Vega.USiteBuilder;");
 96
 97            sb.AppendLine("namespace uSiteBuilderImport.Web.DocumentTypes");
 98            sb.AppendLine("{");
 99            sb.AppendLine();
100            sb.Append(
101                "[DocumentType(Name=\"" + dr["text"] + "\",IconUrl=\"" + dr["icon"] + "\""
102                + this.GetAllowedTemplates(dr["nodeid"].ToString()));
103            sb.Append(GetAllowedContentType(dr["nodeid"].ToString()));
104            sb.Append(")]");
105            sb.AppendLine();
106            sb.AppendLine("public class " + dr["alias"] + " : uSiteBuilderImport.Web.DocumentTypes." + alias);
107
108            sb.AppendLine("{");
109
110            sb.AppendLine(this.CreateProperties(dr["nodeid"].ToString()));
111
112            sb.AppendLine("}");
113            sb.AppendLine("}");
114
115            if (!Directory.Exists(this.Server.MapPath("DocTypes/")))
116            {
117                Directory.CreateDirectory(this.Server.MapPath("DocumentTypes/"));
118            }
119
120            using (var writer = new StreamWriter(path + dr["alias"] + ".cs"))
121            {
122                writer.Write(sb.ToString());
123            }
124
125            // Make recursive call
126            this.CreateChildDocType(dr["nodeid"].ToString(), dr["alias"].ToString(), path);
127        }
128
129        dr.Close();
130    }
131
132    /// <summary>
133    /// Create Child Master Pages
134    /// </summary>
135    /// <param name="nodeid">
136    /// The nodeid.
137    /// </param>
138    /// <param name="parentAlias">
139    /// The parent alias.
140    /// </param>
141    public void CreateChildMasterPages(string nodeid, string parentAlias)
142    {
143        string strSql = "SELECT pk, nodeId, master, alias, design FROM cmsTemplate WHERE master =" + nodeid;
144
145        SqlDataReader dr = SqlHelper.ExecuteReader(
146            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
147
148        while (dr.Read())
149        {
150            string alias = dr["alias"].ToString().Replace(" ", string.Empty);
151
152            this.Response.Write("Creating Child MasterPage: " + alias + " (" + dr["nodeId"] + ")</br>");
153
154            var sb = new StringBuilder();
155
156            // Create Master Page
157            sb.AppendLine(
158                "<%@ Master Language=\"C#\" MasterPageFile=\"~/MasterPages/" + parentAlias
159                + ".master\" AutoEventWireup=\"true\" CodeBehind=\"" + alias
160                + ".master.cs\" Inherits=\"uSiteBuilderImport.Web.MasterPages." + alias + "\" %>");
161
162            // Get Markup
163            sb.AppendLine(GetMarkUp(dr["nodeid"].ToString()));
164            using (var writer = new StreamWriter(this.Server.MapPath("MasterPages/" + alias + ".Master")))
165            {
166                writer.Write(sb.ToString());
167            }
168
169            sb.Length = 0;
170
171            // Create Code behind file
172            sb.AppendLine("using System;");
173            sb.AppendLine("using System.Collections.Generic;");
174            sb.AppendLine("using System.Linq;");
175            sb.AppendLine("using System.Web;");
176            sb.AppendLine("using System.Web.UI;");
177            sb.AppendLine("using System.Web.UI.WebControls;");
178            sb.AppendLine("namespace uSiteBuilderImport.Web.MasterPages");
179            sb.AppendLine("{");
180            sb.AppendLine("public partial class " + alias + GetTemplatesDefaultDocType(dr["nodeId"].ToString()));
181            sb.AppendLine("{");
182            sb.AppendLine(" protected void Page_Load(object sender, EventArgs e)");
183            sb.AppendLine("{");
184            sb.AppendLine("}");
185            sb.AppendLine("}");
186            sb.AppendLine("}");
187            string path = this.Server.MapPath("MasterPages/");
188
189            using (var writer = new StreamWriter(path + alias + ".Master.cs"))
190            {
191                writer.Write(sb.ToString());
192            }
193
194            this.CreateChildMasterPages(dr["nodeId"].ToString(), alias);
195
196            // Response.Write(getTemplatesDefaultDocType(dr["nodeId"].ToString()));
197        }
198
199        dr.Close();
200    }
201
202    /// <summary>
203    /// Create Master Pages
204    /// </summary>
205    public void CreateMasterPages()
206    {
207        const string StrSQL =
208            "SELECT pk, nodeId, master, alias, design FROM cmsTemplate WHERE (master IS NULL) order by alias";
209
210        SqlDataReader dr = SqlHelper.ExecuteReader(
211            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, StrSQL);
212
213        while (dr.Read())
214        {
215            // string alias = dr["alias"].ToString().Replace(" ", "");
216            string alias = dr["alias"].ToString();
217
218            this.Response.Write(alias + " (" + dr["nodeId"] + ")</br>");
219
220            var sb = new StringBuilder();
221
222            // Create Master Page
223            sb.AppendLine(
224                "<%@ Master Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"" + alias
225                + ".master.cs\" Inherits=\"uSiteBuilderImport.Web.MasterPages." + dr["alias"] + "\" %>");
226
227            // Get Markup
228            sb.AppendLine(GetMarkUp(dr["nodeid"].ToString()));
229
230            // Clean MarkUp
231            if (!Directory.Exists(this.Server.MapPath("MasterPages/")))
232            {
233                Directory.CreateDirectory(this.Server.MapPath("MasterPages/"));
234            }
235
236            using (var writer = new StreamWriter(this.Server.MapPath("MasterPages/") + alias + ".Master"))
237            {
238                writer.Write(sb.ToString());
239            }
240
241            sb.Length = 0;
242
243            // Create Code behind file
244            sb.AppendLine("using System;");
245            sb.AppendLine("using System.Collections.Generic;");
246            sb.AppendLine("using System.Linq;");
247            sb.AppendLine("using System.Web;");
248            sb.AppendLine("using System.Web.UI;");
249            sb.AppendLine("using System.Web.UI.WebControls;");
250            sb.AppendLine("namespace uSiteBuilderImport.Web.MasterPages");
251            sb.AppendLine("{");
252            sb.AppendLine("public partial class " + alias + GetTemplatesDefaultDocType(dr["nodeId"].ToString()));
253            sb.AppendLine("{");
254            sb.AppendLine(" protected void Page_Load(object sender, EventArgs e)");
255            sb.AppendLine("{");
256            sb.AppendLine("}");
257            sb.AppendLine("}");
258            sb.AppendLine("}");
259
260            using (var writer = new StreamWriter(this.Server.MapPath("MasterPages/" + alias + ".Master.cs")))
261            {
262                writer.Write(sb.ToString());
263            }
264
265            this.CreateChildMasterPages(dr["nodeId"].ToString(), alias);
266        }
267
268        dr.Close();
269    }
270
271    #endregion
272
273    #region Methods
274
275    /// <summary>
276    /// Page Load event
277    /// </summary>
278    /// <param name="sender">
279    /// The sender.
280    /// </param>
281    /// <param name="e">
282    /// The event arguments
283    /// </param>
284    protected void Page_Load(object sender, EventArgs e)
285    {
286        // Clear and create Directories
287        string path = this.Server.MapPath("MasterPages/");
288
289        if (Directory.Exists(path))
290        {
291            Directory.Delete(path, true);
292        }
293
294        Directory.CreateDirectory(path);
295
296        path = this.Server.MapPath("DocumentTypes");
297
298        if (Directory.Exists(path))
299        {
300            Directory.Delete(path, true);
301        }
302
303        Directory.CreateDirectory(path);
304
305        this.Response.Write("<br/>-------------------------------------------------------------<br/>");
306        this.Response.Write("Creating MasterPages");
307        this.Response.Write("<br/>-------------------------------------------------------------<br/><br/>");
308
309        this.CreateMasterPages();
310
311        this.Response.Write("<br/>-------------------------------------------------------------<br/>");
312        this.Response.Write("Creating DocTypes");
313        this.Response.Write("<br/>-------------------------------------------------------------<br/><br/>");
314        this.CreateDocTypes();
315
316        this.Response.Write("<br/>-------------------------------------------------------------<br/>");
317        this.Response.Write("End");
318        this.Response.Write("<br/>-------------------------------------------------------------<br/><br/>");
319    }
320
321    /// <summary>
322    /// The get allowed content type.
323    /// </summary>
324    /// <param name="nodeid">
325    /// The nodeid.
326    /// </param>
327    /// <returns>
328    /// The allowed content type.
329    /// </returns>
330    private static string GetAllowedContentType(string nodeid)
331    {
332        // string strSQL = "SELECT cmsContentTypeAllowedContentType.Id, cmsContentTypeAllowedContentType.AllowedId, umbracoNode.text FROM cmsContentTypeAllowedContentType INNER JOIN umbracoNode ON cmsContentTypeAllowedContentType.AllowedId = umbracoNode.id  where cmsContentTypeAllowedContentType.id =" + nodeid;
333        string strSql =
334            "SELECT  cmsContentTypeAllowedContentType.Id, cmsContentTypeAllowedContentType.AllowedId, cmsContentType.alias "
335            + "FROM cmsContentTypeAllowedContentType INNER JOIN "
336            +
337            "cmsContentType ON cmsContentTypeAllowedContentType.AllowedId = cmsContentType.nodeId where cmsContentTypeAllowedContentType.id ="
338            + nodeid;
339
340        SqlDataReader dr = SqlHelper.ExecuteReader(
341            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
342
343        var sb = new StringBuilder();
344
345        while (dr.Read())
346        {
347            sb.Append("typeof(" + dr["alias"] + "),");
348
349            // Response.Write("Here's an allowed type " + dr["text"].ToString() + "<br/>");
350        }
351
352        dr.Close();
353
354        if (sb.ToString() != string.Empty)
355        {
356            return ",AllowedChildNodeTypes = new Type[] {" + sb.ToString().Remove(sb.Length - 1, 1) + "}";
357        }
358
359        return string.Empty;
360    }
361
362    /*
363    /// <summary>
364    /// The get allowed templates old code.
365    /// </summary>
366    /// <param name="nodeid">
367    /// The nodeid.
368    /// </param>
369    /// <returns>
370    /// The allowed templates old code.
371    /// </returns>
372    private string GetAllowedTemplatesOldCode(string nodeid)
373    {
374        var strSql =
375            "SELECT     cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsTemplate.alias "
376            + "FROM         cmsDocumentType INNER JOIN "
377            + "cmsTemplate ON cmsDocumentType.templateNodeId = cmsTemplate.nodeId "
378            + "WHERE     (cmsDocumentType.IsDefault = 0) AND cmsDocumentType.contentTypeNodeId =" + nodeid;
379
380        var dr = SqlHelper.ExecuteReader(
381            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
382
383        var sb = new StringBuilder();
384
385        while (dr.Read())
386        {
387            sb.Append("\"" + dr["alias"] + "\",");
388        }
389
390        dr.Close();
391
392        if (sb.ToString() != string.Empty)
393        {
394            return ", AllowedTemplates = new string[] {" + sb.ToString().Remove(sb.Length - 1, 1) + "}";
395        }
396        else
397        {
398            return string.Empty;
399        }
400    }
401*/
402
403    /// <summary>
404    /// The get data type.
405    /// </summary>
406    /// <param name="dataTypeId">
407    /// The data type id.
408    /// </param>
409    /// <returns>
410    /// The data type.
411    /// </returns>
412    private static string GetDataType(int dataTypeId)
413    {
414        var dt = (Enums.UmbracoPropertyType)dataTypeId;
415
416        if (dt.ToString() != dataTypeId.ToString())
417        {
418            return "UmbracoPropertyType." + dt;
419        }
420
421        // Custom DataType
422        string strSql = "SELECT [text] FROM [umbracoNode] where id=" + dataTypeId;
423
424        SqlDataReader dr = SqlHelper.ExecuteReader(
425            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
426
427        string rtnText = string.Empty;
428
429        while (dr.Read())
430        {
431            rtnText = dr["text"].ToString();
432        }
433
434        dr.Close();
435
436        return "UmbracoPropertyType.Other, OtherTypeName=\"" + rtnText + "\"";
437    }
438
439    /// <summary>
440    /// The get default template doc type.
441    /// </summary>
442    /// <param name="nodeid">
443    /// The nodeid.
444    /// </param>
445    /// <returns>
446    /// The default template doc type.
447    /// </returns>
448    private static string GetDefaultTemplateDocType(string nodeid)
449    {
450        // At the moment this is switched off as default Doc Types is set via the allowed templates.
451
452        // string strSQL = "SELECT    cmsContentType.nodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsContentType.alias  " +
453        // "FROM         cmsDocumentType INNER JOIN " +
454        // "cmsContentType ON cmsDocumentType.contentTypeNodeId = cmsContentType.nodeId " +
455        // "WHERE     (cmsDocumentType.IsDefault = 1)  and nodeid=" + nodeid;
456
457        // string strSQL = "SELECT     cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsTemplate.alias " +
458        // "FROM         cmsDocumentType INNER JOIN " +
459        // "cmsTemplate ON cmsDocumentType.templateNodeId = cmsTemplate.nodeId " +
460        // "WHERE     (cmsDocumentType.IsDefault = 1) and contentTypeNodeID=" + nodeid;
461        string strSql =
462            "SELECT     cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsContentType.alias "
463            + "FROM         cmsDocumentType INNER JOIN "
464            + "cmsContentType ON cmsDocumentType.contentTypeNodeId = cmsContentType.nodeId "
465            + "WHERE     (cmsDocumentType.IsDefault = 1) and contentTypeNodeId=" + nodeid;
466
467        SqlDataReader dr = SqlHelper.ExecuteReader(
468            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
469
470        var sb = new StringBuilder();
471
472        while (dr.Read())
473        {
474            sb.Append(dr["alias"].ToString());
475        }
476
477        dr.Close();
478
479        return string.Empty;
480    }
481
482    /// <summary>
483    /// The get mark up.
484    /// </summary>
485    /// <param name="nodeid">
486    /// The nodeid.
487    /// </param>
488    /// <returns>
489    /// The get mark up.
490    /// </returns>
491    private static string GetMarkUp(string nodeid)
492    {
493        string rtnText = string.Empty;
494        string strSql = "SELECT pk, nodeId, master, alias, design FROM cmsTemplate where nodeid=" + nodeid;
495
496        SqlDataReader dr = SqlHelper.ExecuteReader(
497            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
498
499        while (dr.Read())
500        {
501            rtnText = dr["design"].ToString();
502        }
503
504        dr.Close();
505
506        int startPos = rtnText.IndexOf(">");
507
508        return rtnText.Substring(startPos + 1);
509    }
510
511    /// <summary>
512    /// The get tab.
513    /// </summary>
514    /// <param name="tabid">
515    /// The tabid.
516    /// </param>
517    /// <returns>
518    /// The tab.
519    /// </returns>
520    private static string GetTab(string tabid)
521    {
522        if (tabid != string.Empty)
523        {
524            string strSql = "SELECT [id],[text],[sortorder] FROM [cmsTab] where id=" + tabid;
525
526            SqlDataReader dr = SqlHelper.ExecuteReader(
527                ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
528
529            string tab = string.Empty;
530
531            while (dr.Read())
532            {
533                tab = dr["text"].ToString();
534            }
535
536            dr.Close();
537
538            if (tab != string.Empty)
539            {
540                return ", Tab=\"" + tab + "\"";
541            }
542
543            return string.Empty;
544        }
545
546        return string.Empty;
547    }
548
549    /// <summary>
550    /// The get validation.
551    /// </summary>
552    /// <param name="isMandatory">
553    /// The is mandatory.
554    /// </param>
555    /// <param name="rgx">
556    /// The rgx.
557    /// </param>
558    /// <returns>
559    /// The  validation.
560    /// </returns>
561    private static string GetValidation(string isMandatory, string rgx)
562    {
563        var sb = new StringBuilder();
564
565        sb.Append(isMandatory == "True" ? ",Mandatory=true" : ",Mandatory=false");
566
567        if (rgx != string.Empty)
568        {
569            sb.Append(",ValidationRegExp=\"" + rgx.Replace("\\", "\\\\") + "\"");
570        }
571
572        return sb.ToString();
573    }
574
575    /// <summary>
576    /// The create doc types.
577    /// </summary>
578    private void CreateDocTypes()
579    {
580        string path = this.Server.MapPath("DocumentTypes");
581
582        path = path + "\\";
583
584        const string StrSql =
585            "SELECT     cmsContentType.pk, cmsContentType.nodeId, cmsContentType.alias, cmsContentType.icon, cmsContentType.thumbnail, cmsContentType.description, "
586            + "cmsContentType.masterContentType, umbracoNode.text FROM cmsContentType INNER JOIN "
587            + "umbracoNode ON cmsContentType.nodeId = umbracoNode.id "
588            + "WHERE     (cmsContentType.masterContentType = 0) " + "ORDER BY cmsContentType.alias";
589
590        SqlDataReader dr = SqlHelper.ExecuteReader(
591            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, StrSql);
592
593        while (dr.Read())
594        {
595            var sb = new StringBuilder();
596            this.Response.Write("Create Doc Type for " + dr["text"] + " (" + dr["nodeid"] + ")<br/>");
597
598            sb.AppendLine("using System;");
599            sb.AppendLine("using System.Collections.Generic;");
600            sb.AppendLine("using System.Linq;");
601            sb.AppendLine("using System.Web;");
602
603            sb.AppendLine("using Vega.USiteBuilder;");
604
605            sb.AppendLine("namespace uSiteBuilderImport.Web.DocumentTypes");
606            sb.AppendLine("{");
607
608            // AllowedTemplates = new string[] { "Property" }
609            sb.Append(
610                "[DocumentType(Name=\"" + dr["text"] + "\",IconUrl=\"" + dr["icon"] + "\""
611                + this.GetAllowedTemplates(dr["nodeid"].ToString()));
612            sb.Append(GetAllowedContentType(dr["nodeid"].ToString()));
613                
614            sb.AppendLine( ")]");
615            sb.AppendLine("public class " + dr["alias"] + " : Vega.USiteBuilder.DocumentTypeBase");
616            sb.AppendLine("{");
617
618            sb.AppendLine(this.CreateProperties(dr["nodeid"].ToString()));
619
620            // Response.Write("Check if any child docs types of " + dr["nodeid"] + "<br/>");
621            this.CreateChildDocType(dr["nodeid"].ToString(), dr["alias"].ToString(), path);
622
623            sb.AppendLine("}");
624            sb.AppendLine("}");
625
626            using (var writer = new StreamWriter(path + dr["alias"] + ".cs"))
627            {
628                writer.Write(sb.ToString());
629            }
630        }
631
632        dr.Close();
633    }
634
635    /// <summary>
636    /// The create properties.
637    /// </summary>
638    /// <param name="nodeid">
639    /// The nodeid.
640    /// </param>
641    /// <returns>
642    /// The create properties.
643    /// </returns>
644    private string CreateProperties(string nodeid)
645    {
646        string strSql =
647            "SELECT [id],[dataTypeId],[contentTypeId],[tabId],[Alias],[Name],[helpText],[sortOrder],[mandatory],[validationRegExp],[Description] FROM [cmsPropertyType] where contentTypeId="
648            + nodeid + " order by sortOrder";
649
650        var sb = new StringBuilder();
651
652        SqlDataReader dr = SqlHelper.ExecuteReader(
653            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
654
655        while (dr.Read())
656        {
657            sb.AppendLine(
658                "[DocumentTypeProperty(" + GetDataType(Convert.ToInt32(dr["dataTypeId"])) + ",Name=\"" + dr["Name"]
659                + "\",Description=\""
660                + dr["Description"].ToString().Replace(Environment.NewLine, string.Empty).Replace("\"", "\\\"") + "\""
661                + GetTab(dr["tabId"].ToString())
662                + GetValidation(dr["mandatory"].ToString(), dr["validationRegExp"].ToString()) + ")]");
663
664            sb.AppendLine("public string " + dr["alias"] + " { get; set; }");
665
666            // Response.Write("Alias: " + dr["alias"] + " Name: " + dr["name"] + " Description: " + dr["Description"] + " Tab: " + getTab(dr["tabId"].ToString()) + " DataType: " + getDataType(Convert.ToInt32(dr["dataTypeId"])) + "<br/>");
667        }
668
669        dr.Close();
670
671        return sb.ToString();
672    }
673
674    /// <summary>
675    /// The get allowed templates.
676    /// </summary>
677    /// <param name="nodeid">
678    /// The nodeid.
679    /// </param>
680    /// <returns>
681    /// The allowed templates.
682    /// </returns>
683    private string GetAllowedTemplates(string nodeid)
684    {
685        // This code is correct from when we were only getting non default Templates, however now we want them all and we'll deal with the default one later
686        // string strSQL = "SELECT     cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsTemplate.alias " +
687        // "FROM         cmsDocumentType INNER JOIN " +
688        // "cmsTemplate ON cmsDocumentType.templateNodeId = cmsTemplate.nodeId " +
689        // "WHERE     (cmsDocumentType.IsDefault = 0) AND cmsDocumentType.contentTypeNodeId =" + nodeid;
690        string strSql =
691            "SELECT     cmsDocumentType.contentTypeNodeId, cmsDocumentType.templateNodeId, cmsDocumentType.IsDefault, cmsTemplate.alias "
692            + "FROM         cmsDocumentType INNER JOIN "
693            + "cmsTemplate ON cmsDocumentType.templateNodeId = cmsTemplate.nodeId "
694            + "WHERE  cmsDocumentType.contentTypeNodeId =" + nodeid + " order by isDefault desc";
695
696        SqlDataReader dr = SqlHelper.ExecuteReader(
697            ConfigurationManager.AppSettings["ImportDB"], CommandType.Text, strSql);
698
699        var sb = new StringBuilder();
700
701        // int x = 0;
702        while (dr.Read())
703        {
704            // x++;
705            // if (x == 1)
706            // {
707            // //Check if this is default if so we mark it as such in the string and deal with it later
708            // if (dr["isDefault"].ToString() == "True")
709            // { sb.Append("\"xxxxxxxxxx" + dr["templateNodeId3"].ToString() + "\","); }
710
711            // else { sb.Append("\"" + dr["alias"].ToString() + "\","); }
712            // }
713            // else
714            // {
715            sb.Append("\"" + dr["alias"] + "\",");
716
717            // }
718        }
719
720        dr.Close();
721
722        if (sb.ToString() != string.Empty)
723        {
724            // If there are more than one templates we have to specify default template
725            return ", AllowedTemplates = new string[] {" + sb.ToString().Remove(sb.Length - 1, 1) + "}"
726                   + GetDefaultTemplateDocType(nodeid);
727
728            // return string.Empty;
729        }
730
731        return string.Empty;
732    }
733
734    #endregion
735}