Пример #1
0
		public void WriteCode(ITemplate tpl, MemberCodePoint point, CodeBuilder cb) {
			switch (point) {
				case MemberCodePoint.ServerDefinition:
				case MemberCodePoint.ClientDefinition:
					cb.AppendLine("private int copyrightYear;")
					  .AppendLine("public int CopyrightYear {").Indent()
					  .AppendLine("get { return copyrightYear; }")
					  .AppendLine("set { copyrightYear = value; }").Outdent()
					  .AppendLine("}").AppendLine();
					break;
				case MemberCodePoint.ServerConstructor:
					cb.AppendLine("copyrightYear = DateTime.Now.Year;");
					break;
				case MemberCodePoint.ClientConstructor:
					cb.AppendLine("copyrightYear = (new DateTime()).GetFullYear();");
					break;
				case MemberCodePoint.TransferConstructor:
					cb.AppendLine("copyrightYear = (int)" + ParserUtils.ConfigObjectName + "[\"copyrightYear\"];");
					break;
				case MemberCodePoint.ConfigObjectInit:
					cb.AppendLine(ParserUtils.ConfigObjectName + "[\"copyrightYear\"] = this.copyrightYear;");
					break;
			}
		}
Пример #2
0
		    private string GetTemplateCodeFileContents(ISaltarelleParser parser, XmlDocument doc, string className, string nmspace) {
			    ITemplate template = parser.ParseTemplate(doc);
			    template.ClassName = className;
			    template.Nmspace   = nmspace;

			    CodeBuilder cb = new CodeBuilder();
			    cb.AppendLine("#pragma warning disable 1591")
			      .AppendLine("#if SERVER");
			    template.WriteServerCode(cb);
			    cb.AppendLine("#endif")
			      .AppendLine("#if CLIENT");
			    template.WriteClientCode(cb);
			    cb.AppendLine("#endif");
			
			    return cb.ToString();
		    }
Пример #3
0
		public void WriteCode(ITemplate tpl, FragmentCodePoint point, CodeBuilder cb) {
			cb.AppendLine(ParserUtils.RenderFunctionStringBuilderName + ".Append(\"Copyright © \" + Utils.ToStringInvariantInt(this.copyrightYear) + @\" " + text.Replace("\"", "\"\"") + "\");");
		}
Пример #4
0
		public void WriteClientCode(CodeBuilder cb) {
			var orderedMembers = TopologicalSort(members);

			foreach (var us in clientUsings)
				cb.AppendLine("using " + us.Key + ";");
			cb.AppendLine();
			
			if (!string.IsNullOrEmpty(nmspace))
				cb.AppendFormat("namespace {0} {{", nmspace).Indent().AppendLine();
				
			cb.AppendFormat("public partial class " + className)
			  .Append(" : ")
			  .Append(ClientInheritanceList)
			  .Append(" {").AppendLine().Indent()
			  .AppendLine("partial void Constructed();")
			  .AppendLine("partial void Attached();").AppendLine()
			  .AppendLine("private Dictionary<string, IControl> controls = new Dictionary<string, IControl>();")
			  .AppendLine("private JsDictionary " + ParserUtils.ConfigObjectName + ";")
			  .AppendLine()
			  .AppendLine("private Position position;")
			  .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Position Position {").Indent()
			  .AppendLine("get { return isAttached ? PositionHelper.GetPosition(GetElement()) : position; }")
			  .AppendLine("set {").Indent()
			  .AppendLine("position = value;")
			  .AppendLine("if (isAttached)").Indent()
			  .AppendLine("PositionHelper.ApplyPosition(GetElement(), value);").Outdent()
			  .Outdent().AppendLine("}")
			  .Outdent().AppendLine("}").AppendLine()
			  .AppendLine("private bool isAttached = false;")
			  .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Element GetElement() { return isAttached ? Document.GetElementById(id) : null; }").AppendLine();

			WriteIdProperty(cb, false, this, orderedMembers);
			cb.AppendLine();
			
			foreach (var m in orderedMembers)
				m.WriteCode(this, MemberCodePoint.ClientDefinition, cb);

			WriteAttachSelf(cb, this, orderedMembers);
			cb.AppendLine();

			if (enableClientCreate) {
				WriteAttach(cb, this, orderedMembers);

				cb.AppendLine()
				  .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "string Html {").Indent()
				  .AppendLine("get {").Indent()
				  .AppendLine("if (string.IsNullOrEmpty(id))").Indent()
				  .AppendLine("throw new InvalidOperationException(\"Must assign Id before rendering.\");").Outdent()
				  .AppendLine("return " + MainRenderFunctionName + "();").Outdent()
				  .AppendLine("}").Outdent()
				  .AppendLine("}").AppendLine()
				  .AppendLine("[AlternateSignature]")
				  .AppendLine("public " + className + "() {}");
			}
			WriteClientConstructor(cb, this);
			cb.AppendLine();
			WriteClientDependenciesAvailable(cb, this, orderedMembers);
			
			cb.Outdent().AppendLine("}");
			if (!string.IsNullOrEmpty(nmspace))
				cb.Outdent().AppendLine("}");
		}
Пример #5
0
		public void WriteServerCode(CodeBuilder cb) {
			var orderedMembers = TopologicalSort(members);

			foreach (var us in serverUsings)
				cb.AppendLine("using " + us.Key + ";");
			cb.AppendLine();

			if (!string.IsNullOrEmpty(nmspace))
				cb.AppendFormat("namespace {0} {{", nmspace).Indent().AppendLine();
				
			cb.AppendFormat("public partial class " + className)
			  .Append(" : ")
			  .Append(ServerInheritanceList)
			  .Append(" {").AppendLine().Indent()
			  .AppendLine("partial void Constructed();").AppendLine()
			  .AppendLine("private Dictionary<string, IControl> controls = new Dictionary<string, IControl>();").AppendLine()
			  .AppendLine("private Position position = PositionHelper.NotPositioned;")
			  .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Position Position { get { return position; } set { position = value; } }").AppendLine();

			WriteIdProperty(cb, true, this, orderedMembers);
			cb.AppendLine();
			WriteGetConfig(cb, this, orderedMembers);
			cb.AppendLine();
			
			foreach (var m in orderedMembers)
				m.WriteCode(this, MemberCodePoint.ServerDefinition, cb);

			cb.AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "string Html {").Indent()
			  .AppendLine("get {").Indent()
			  .AppendLine("if (string.IsNullOrEmpty(id))").Indent()
			  .AppendLine("throw new InvalidOperationException(\"Must assign Id before rendering.\");").Outdent()
			  .AppendLine("return " + MainRenderFunctionName + "();").Outdent()
			  .AppendLine("}").Outdent()
			  .AppendLine("}").AppendLine();

			WriteServerConstructor(cb, this);
			cb.AppendLine();
			WriteServerDependenciesAvailable(cb, this, orderedMembers);
			
			cb.Outdent().AppendLine("}");
			if (!string.IsNullOrEmpty(nmspace))
				cb.Outdent().AppendLine("}");
		}
Пример #6
0
		internal static void WriteAttachSelf(CodeBuilder cb, ITemplate tpl, IList<IMember> orderedMembers) {
			cb.AppendLine("private void AttachSelf() {").Indent();
			foreach (var m in orderedMembers)
				m.WriteCode(tpl, MemberCodePoint.AttachSelf, cb);
			cb.AppendLine("this.isAttached = true;")
			  .AppendLine("Attached();").Outdent()
			  .AppendLine("}");
		}
Пример #7
0
		internal static void WriteAttach(CodeBuilder cb, ITemplate tpl, IList<IMember> orderedMembers) {
			cb.AppendLine("public void Attach() {").Indent()
			  .AppendLine("if (Script.IsNullOrEmpty(id) || isAttached) throw new Exception(\"Must set id before attach and can only attach once.\");");
			foreach (var m in orderedMembers)
				m.WriteCode(tpl, MemberCodePoint.Attach, cb);
			cb.AppendLine("AttachSelf();").Outdent()
			  .AppendLine("}");
		}
Пример #8
0
		private void WriteIdProperty(CodeBuilder cb, bool server, ITemplate tpl, IList<IMember> orderedMembers) {
			cb.AppendLine("private string id;")
			  .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "string Id {").Indent()
			  .AppendLine("get { return id; }")
			  .AppendLine("set {").Indent();

			cb.AppendLine("foreach (var kvp in controls)").Indent()
			  .AppendLine("kvp.Value.Id = value + \"_\" + kvp.Key;").Outdent();

			foreach (var m in orderedMembers)
				m.WriteCode(tpl, server ? MemberCodePoint.ServerIdChanging : MemberCodePoint.ClientIdChanging, cb);
				
			if (!server) {
				cb.AppendLine("if (isAttached)").Indent()
				  .AppendLine("GetElement().ID = value;").Outdent();
			}

			cb.AppendLine("this.id = value;")
			  .Outdent().AppendLine("}")
			  .Outdent().AppendLine("}");
		}
Пример #9
0
		internal void WriteGetConfig(CodeBuilder cb, ITemplate tpl, IList<IMember> orderedMembers) {
			cb.AppendLine("public " + (GenerateImplementationsAsOverrides ? "override " : "") + "object ConfigObject {").Indent()
			  .AppendLine("get {").Indent()
			  .AppendLine("Dictionary<string, object> " + ParserUtils.ConfigObjectName + " = new Dictionary<string, object>();")
			  .AppendLine(ParserUtils.ConfigObjectName + "[\"id\"] = id;");
			
			foreach (IMember m in orderedMembers)
				m.WriteCode(tpl, MemberCodePoint.ConfigObjectInit, cb);

			cb.AppendLine("return " + ParserUtils.ConfigObjectName + ";")
			  .Outdent().AppendLine("}")
			  .Outdent().AppendLine("}");
		}
Пример #10
0
		internal static void WriteClientDependenciesAvailable(CodeBuilder cb, ITemplate tpl, IList<IMember> orderedMembers) {
			cb.AppendLine("public void DependenciesAvailable() {").Indent()
			  .AppendLine("if (" + ParserUtils.ConfigObjectName + " != null) {").Indent()
			  .AppendLine("this.id = (string)" + ParserUtils.ConfigObjectName + "[\"id\"];");

			foreach (var m in orderedMembers)
				m.WriteCode(tpl, MemberCodePoint.TransferConstructor, cb);

			cb.AppendLine("Constructed();")
			  .AppendLine("AttachSelf();")
			  .Outdent().AppendLine("}")
			  .AppendLine("else {").Indent();

			if (tpl.EnableClientCreate) {
				cb.AppendLine("this.position = PositionHelper.NotPositioned;");
				foreach (var m in orderedMembers)
					m.WriteCode(tpl, MemberCodePoint.ClientConstructor, cb);
				cb.AppendLine("Constructed();");
			}
			else {
				cb.AppendLine("throw new Exception(\"This control must be created server-side\");");
			}

			cb.Outdent().AppendLine("}")
			  .Outdent().AppendLine("}");
		}
Пример #11
0
		internal static void WriteClientConstructor(CodeBuilder cb, ITemplate tpl) {
			cb.AppendLine("[Obsolete(@\"" + DoNotCallConstructorMessage.Replace("\"", "\"\"") + "\")]")
			  .AppendLine("public " + tpl.ClassName + "(object config) {").Indent()
			  .AppendLine(ParserUtils.ConfigObjectName + " = (!Script.IsUndefined(config) ? JsDictionary.GetDictionary(config) : null);")
			  .Outdent().AppendLine("}");
		}
Пример #12
0
		internal static void WriteServerDependenciesAvailable(CodeBuilder cb, ITemplate tpl, IList<IMember> orderedMembers) {
			cb.AppendLine("public void DependenciesAvailable() {").Indent();
			foreach (var m in orderedMembers)
				m.WriteCode(tpl, MemberCodePoint.ServerConstructor, cb);
			cb.AppendLine("Constructed();").Outdent()
			  .AppendLine("}");
		}
Пример #13
0
		internal static void WriteServerConstructor(CodeBuilder cb, ITemplate tpl) {
			cb.AppendLine("[Obsolete(@\"" + DoNotCallConstructorMessage.Replace("\"", "\"\"") + "\")]")
			  .AppendLine("public " + tpl.ClassName + "() {")
			  .AppendLine("}");
		}
Пример #14
0
        public void WriteClientCode(CodeBuilder cb)
        {
            var orderedMembers = TopologicalSort(members);

            foreach (var us in clientUsings)
            {
                cb.AppendLine("using " + us.Key + ";");
            }
            cb.AppendLine();

            if (!string.IsNullOrEmpty(nmspace))
            {
                cb.AppendFormat("namespace {0} {{", nmspace).Indent().AppendLine();
            }

            cb.AppendFormat("public partial class " + className)
            .Append(" : ")
            .Append(ClientInheritanceList)
            .Append(" {").AppendLine().Indent()
            .AppendLine("partial void Constructed();")
            .AppendLine("partial void Attached();").AppendLine()
            .AppendLine("private Dictionary<string, IControl> controls = new Dictionary<string, IControl>();")
            .AppendLine("private JsDictionary " + ParserUtils.ConfigObjectName + ";")
            .AppendLine()
            .AppendLine("private Position position;")
            .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Position Position {").Indent()
            .AppendLine("get { return isAttached ? PositionHelper.GetPosition(GetElement()) : position; }")
            .AppendLine("set {").Indent()
            .AppendLine("position = value;")
            .AppendLine("if (isAttached)").Indent()
            .AppendLine("PositionHelper.ApplyPosition(GetElement(), value);").Outdent()
            .Outdent().AppendLine("}")
            .Outdent().AppendLine("}").AppendLine()
            .AppendLine("private bool isAttached = false;")
            .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Element GetElement() { return isAttached ? Document.GetElementById(id) : null; }").AppendLine();

            WriteIdProperty(cb, false, this, orderedMembers);
            cb.AppendLine();

            foreach (var m in orderedMembers)
            {
                m.WriteCode(this, MemberCodePoint.ClientDefinition, cb);
            }

            WriteAttachSelf(cb, this, orderedMembers);
            cb.AppendLine();

            if (enableClientCreate)
            {
                WriteAttach(cb, this, orderedMembers);

                cb.AppendLine()
                .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "string Html {").Indent()
                .AppendLine("get {").Indent()
                .AppendLine("if (string.IsNullOrEmpty(id))").Indent()
                .AppendLine("throw new InvalidOperationException(\"Must assign Id before rendering.\");").Outdent()
                .AppendLine("return " + MainRenderFunctionName + "();").Outdent()
                .AppendLine("}").Outdent()
                .AppendLine("}").AppendLine()
                .AppendLine("[AlternateSignature]")
                .AppendLine("public " + className + "() {}");
            }
            WriteClientConstructor(cb, this);
            cb.AppendLine();
            WriteClientDependenciesAvailable(cb, this, orderedMembers);

            cb.Outdent().AppendLine("}");
            if (!string.IsNullOrEmpty(nmspace))
            {
                cb.Outdent().AppendLine("}");
            }
        }
Пример #15
0
 internal static void WriteServerConstructor(CodeBuilder cb, ITemplate tpl)
 {
     cb.AppendLine("[Obsolete(@\"" + DoNotCallConstructorMessage.Replace("\"", "\"\"") + "\")]")
     .AppendLine("public " + tpl.ClassName + "() {")
     .AppendLine("}");
 }