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("}");
            }
        }
Beispiel #2
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("}");
		}
Beispiel #3
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("}");
		}
        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("}");
            }
        }