예제 #1
0
        public void ArrayByIndexTest()
        {
            dynamic uobj = new UObj();

            uobj.x[3] = 1;
            Console.WriteLine(uobj.ToJson());
            Assert.AreEqual(@"{""x"":[null,null,null,1]}", uobj.ToJson());
        }
예제 #2
0
        public void ArrayByPushTest()
        {
            dynamic uobj = new UObj();

            uobj.x.push(1);
            uobj.x.push(2);
            uobj.x.push(3);
            Console.WriteLine(uobj.ToJson());
            Assert.AreEqual(@"{""x"":[1,2,3]}", uobj.ToJson());
        }
예제 #3
0
        public void ArrayDefaults()
        {
            dynamic uobj  = new UObj();
            dynamic uobj2 = new UObj();

            uobj.push(null, 1, null, 2, null, 3);
            uobj2.push(-1, 2, -2, null, -3, 4);
            uobj.defaults(uobj2);
            Console.WriteLine(uobj.ToJson());
            Assert.AreEqual(@"[-1,1,-2,2,-3,3]", uobj.ToJson());
        }
예제 #4
0
        public void Defaults()
        {
            dynamic uobj  = new UObj();
            dynamic uobj2 = new UObj();

            uobj.a  = 1;
            uobj.b  = 2;
            uobj2.a = 3;
            uobj2.c = 4;
            uobj.defaults(uobj2);
            Console.WriteLine(uobj.ToJson());
            Assert.AreEqual(@"{""a"":1,""b"":2,""c"":4}", uobj.ToJson());
        }
예제 #5
0
        public void CanCreateAndUse()
        {
            dynamic uobj = new UObj();

            //one field
            uobj.a.b.c = 1;
            // second field (not alphabetic order)
            uobj.a.b.a = "tren\nd";
            //only GET will be treated as garbage
            var a = uobj.a.b.u.c.d.f;

            Assert.AreEqual(1, uobj.a.b.c);
            Console.WriteLine(uobj.ToJson());
            //test valid JSON in alphabet mode
            Assert.AreEqual(@"{""a"":{""b"":{""a"":""tren\nd"",""c"":1}}}", uobj.ToJson());
            uobj.a = new test {
                A = 3, B = 4
            };
            Console.WriteLine(uobj.ToJson());
            Assert.AreEqual(@"{""a"":{""A"":3,""B"":4}}", uobj.ToJson());
            Console.WriteLine(uobj.ToJson(UObjSerializeMode.KeepType));
            Assert.AreEqual(@"{""a"":{""_srctype"":""Qorpent.Serialization.Tests.Uson.UsonMainTest+test, Qorpent.Serialization.Tests"",""A"":3,""B"":4}}", uobj.ToJson(UObjSerializeMode.KeepType));
            uobj.a = new object[] { "x", 1, true, new DateTime(2002, 5, 2) };
            Console.WriteLine(uobj.ToJson());
            Assert.AreEqual(@"{""a"":[""x"",1,true,""2002-05-02T00:00:00""]}", uobj.ToJson());
            Assert.AreEqual(1, uobj.a[1]);
            Assert.AreEqual(null, uobj.a[10]);
        }
예제 #6
0
        public void DeepDefaults()
        {
            dynamic uobj  = new UObj();
            dynamic uobj2 = new UObj();

            uobj.a  = new { x = 1, y = 2 };
            uobj.b  = new { a = 3, b = 4 };
            uobj2.a = new { x = 2, z = 3 };
            uobj2.c = new { a = 4, c = 5 };
            uobj.deepdefaults(uobj2);
            Console.WriteLine(uobj.ToJson());
            Assert.AreEqual(@"{""a"":{""x"":1,""y"":2,""z"":3},""b"":{""a"":3,""b"":4},""c"":{""a"":4,""c"":5}}", uobj.ToJson());
        }
예제 #7
0
        private string GetErrorChartContent(IMvcContext context, IChartConfig config)
        {
            if (context.Get("format", context.Get("__format")) == "json")
            {
                dynamic result = new UObj();
                result.config       = config;
                result.error        = config.State.Message;
                context.ContentType = MimeHelper.JSON;
                return(result.ToJson());
            }
            var id     = "g" + Guid.NewGuid().ToString().Replace("-", "");
            var script = @"<div class='chart_Error chart_Error_'" + config.State.Level + "'>";

            if (!string.IsNullOrWhiteSpace(config.State.Title))
            {
                script += "<h3>" + config.State.Title + "</h3>";
            }
            else if (null != config.State.Exception)
            {
                script += "<p>Произошла ошибка " + config.State.Exception.GetType().Name + "</p>";
            }
            if (!string.IsNullOrWhiteSpace(config.State.Message))
            {
                script += "<p>" + config.State.Message.Replace("\r\n", "<br/>") + "</p>";
            }
            else if (null != config.State.Exception)
            {
                script += "<p>" + config.State.Exception.Message.Replace("\r\n", "<br/>") + "</p>";
            }
            if (null != config.State.Exception)
            {
                script += "<button onclick='$(\"#" + id + "\").toggle()'>Показать подробности ошибки</button>";
                script += "<BR /><textarea rows='30' cols='120' id='" + id + "' style='display:none'>" + config.State.Exception + "</textarea>";
            }
            script += "</div>";
            if (!string.IsNullOrWhiteSpace(context.Get("standalone")))
            {
                script = @"
<html>
<header>
</header>
<body>
<script type=""text/javascript"" src=""../scripts/jquery.min.js""></script>
" + script + @"
</body>
</html>";
            }
            return(script);
        }
예제 #8
0
	    private string GetErrorChartContent(IMvcContext context, IChartConfig config) {
			if (context.Get("format", context.Get("__format")) == "json")
			{
				dynamic result = new UObj();
				result.config = config;			
				result.error = config.State.Message;
				context.ContentType = MimeHelper.JSON;
				return result.ToJson();
			}
		    var id = "g"+Guid.NewGuid().ToString().Replace("-", "");
		    var script = @"<div class='chart_Error chart_Error_'"+config.State.Level+"'>";
			if (!string.IsNullOrWhiteSpace(config.State.Title)){
				script += "<h3>" + config.State.Title + "</h3>";
			} else if (null != config.State.Exception) {
				script += "<p>Произошла ошибка " + config.State.Exception.GetType().Name + "</p>"; 
			}
			if (!string.IsNullOrWhiteSpace(config.State.Message)) {
				script += "<p>" + config.State.Message.Replace("\r\n", "<br/>") + "</p>";
			} else if (null != config.State.Exception) {
				script += "<p>" + config.State.Exception.Message.Replace("\r\n", "<br/>") + "</p>";
			}
			if (null != config.State.Exception){
				script += "<button onclick='$(\"#" + id + "\").toggle()'>Показать подробности ошибки</button>";
				script += "<BR /><textarea rows='30' cols='120' id='" + id + "' style='display:none'>" + config.State.Exception + "</textarea>";
			}
		    script += "</div>";
			if (!string.IsNullOrWhiteSpace(context.Get("standalone")))
			{
				script = @"
<html>
<header>
</header>
<body>
<script type=""text/javascript"" src=""../scripts/jquery.min.js""></script>
" + script + @"
</body>
</html>";
			}
		    return script;
	    }
        private string GenerateSingleController(IBSharpClass targetclass)
        {
            var xml      = targetclass.Compiled;
            var code     = xml.Attr("fullcode").Split('.').Last();
            var sb       = new StringBuilder();
            var deps     = new Dictionary <string, XElement>();
            var advanced = new StringBuilder();

            if (xml.Elements().Any(_ => _.GetSmartValue("persistent", "persistentCode").ToBool()) && deps.All(_ => _.Value.Attr("type") != "settings"))
            {
                deps["settings"] = new XElement("service", new XAttribute("type", "settings"), new XAttribute("before", "true"));
            }
            foreach (var s in xml.Elements("service"))
            {
                var scode = s.Attr("code");
                deps[scode] = s;
            }
            var deplist = string.Join("','", deps.Values.Select(_ => _.ChooseAttr("type", "code")).Distinct().OrderBy(_ => _));

            if (!string.IsNullOrWhiteSpace(deplist))
            {
                deplist = ", '" + deplist + "'";
            }
            var calllist = string.Join(",", deps.Values.Select(_ => _.ChooseAttr("type", "code")).Distinct().OrderBy(_ => _));

            if (!string.IsNullOrWhiteSpace(calllist))
            {
                calllist = ", " + calllist;
            }
            sb.Append(string.Format(@"
        .controller('{3}_{0}', ['$scope','$http','$rootScope'{1},'$element', function ($scope, $http, $rootScope{2},$element) {{ 
                $scope.api = Api($http, $rootScope);
				$scope.$services = {{}};
				$scope.$services.$element = $element;
				$scope.$services.$http = $http;
				$scope.$services.$rootScope = $rootScope;
", code, deplist, calllist, Project.ProjectName));
            foreach (var dep in deps)
            {
                sb.Append("\t\t\t\t$scope.$services." + dep.Key + "=" + dep.Key + ";");
                sb.AppendLine();
            }
            sb.AppendFormat(
                @"				$scope.{2} = '{0}.html';
				$scope.title= '{1}';
",
                targetclass.Compiled.ChooseAttr("view", "code"),
                targetclass.Compiled.ChooseAttr("name", "code"),
                (targetclass.Compiled.Element("menu") == null)?"view":"_view"
                );



            var items = xml.Elements("item");

            foreach (var e in deps.Where(_ => _.Value.Attr("before").ToBool()).OrderBy(_ => _.Key))
            {
                var type = e.Value.ChooseAttr("type", "code");
                UnifyPersistentCode(targetclass, e);
                if (type == "refresh")
                {
                    SetupRefresh(targetclass, e, advanced);
                }
                sb.AppendLine("\t\t\t\t" + type + "($scope," + e.Value.ToJson() + ");");
            }
            foreach (var item in items.OrderBy(_ => _.Attr("code")))
            {
                var type    = item.Attr("type");
                var typestr = "{}";
                var watcher = "";
                if (!string.IsNullOrWhiteSpace(type))
                {
                    var persistent = item.GetSmartValue("persistent", "persistentCode");
                    if (persistent == "1")
                    {
                        persistent = Project.ProjectName + "-" + xml.Attr("code") + "-" + item.Attr("code");
                    }

                    dynamic ext        = new UObj();
                    var     parameters = item.Element("parameters");
                    if (null != parameters)
                    {
                        foreach (var a in parameters.Attributes())
                        {
                            ext[a.Name.LocalName] = a.Value;
                        }
                    }
                    string ctor = ext.ToJson(UObjSerializeMode.Javascript);
                    if (!string.IsNullOrWhiteSpace(persistent))
                    {
                        ctor = "$.extend(" + ctor + ",$scope.settings.get('" + persistent + "'))";
                    }
                    typestr = "new Types." + type.Split('.').Last() + "(" + ctor + ")";
                    watcher = "\t\t\t\t$scope.$watch('" + item.Attr("code") + "',function(n,o){$scope.settings.set('" + persistent +
                              "',n)},true);";
                }
                else if (item.HasElements)
                {
                    var uson = new UObj();
                    foreach (var e in item.Elements())
                    {
                        var u = e.XmlToUson();
                        u.Properties["itemtype"] = e.Name.LocalName;
                        uson.push(u);
                    }

                    typestr = uson.ToJson(UObjSerializeMode.Javascript);
                }


                sb.AppendLine("\t\t\t\t$scope." + item.Attr("code") + " = " + typestr + ";");
                if (!string.IsNullOrWhiteSpace(watcher))
                {
                    sb.AppendLine(watcher);
                }
            }

            foreach (var e in deps.Where(_ => !_.Value.Attr("before").ToBool()).OrderBy(_ => _.Key))
            {
                var type = e.Value.ChooseAttr("type", "code");
                UnifyPersistentCode(targetclass, e);
                if (type == "refresh")
                {
                    SetupRefresh(targetclass, e, advanced);
                }
                sb.AppendLine("\t\t\t\t" + type + "($scope," + e.Value.ToJson() + ");");
            }
            sb.AppendLine(advanced.ToString());

            sb.AppendLine("\t\t}])");


            //sb.AppendLine();
            return(sb.ToString());
        }
예제 #10
0
	    private string GetNormalChartContent(IMvcContext context, IChartConfig config) {
		    var comments = GetComments(context).Aggregate(string.Empty, (_, __) => _ + __);
		    var datascript = RenderDataScript(context, config);
			if (string.IsNullOrWhiteSpace(datascript)) {
				return GetErrorChartContent(context, config);
			}
		    var script = "";
		    var error = string.Empty;

		    if (string.IsNullOrWhiteSpace(datascript)) {
			    error = "Нет данных для отображения";
		    }

		    if (context.Get("format", context.Get("__format")) == "json") {
			    dynamic result = new UObj();
			    result.config = config;
			    result.data = datascript;
			    result.error = error;
			    context.ContentType = MimeHelper.JSON;
				return result.ToJson().Replace("\\\'", "'");
		    }

		    var id = config.Id;
		    var container = config.Container;

		    if (string.IsNullOrWhiteSpace(container)) {
			    container = "fc-container-" + id;
			    script += string.Format(@"
<div class=""assoiGraphContainer""><div class=""fusinchart-container{0}"" id=""{1}"">{2}</div>{3}</div>", string.IsNullOrEmpty(error) ? " fusionchart-error" : "", container, error, comments);
		    }


		    if (string.IsNullOrWhiteSpace(error)) {
			    script += string.Format(@"
<div style=""display:none"" id=""fc-data-{1}"">{5}</div>
<script type=""text/javascript""><!--
    FusionCharts.setCurrentRenderer('javascript');
    var myChart = new FusionCharts('../charts/{0}.swf', 'fc-chart-{1}', '{2}', '{3}', '{4}');
    myChart.set{7}Data($('#fc-data-{1}').text());
    myChart.render('{6}');
// -->
</script>", config.Type, id, config.Width, config.Height, config.Debug, datascript.Replace("<", "&lt;").Replace("&quot;","&amp;quot;"), container, config.DataType);
			    context.ContentType = "text/html";
		    }

		    if (!string.IsNullOrWhiteSpace(context.Get("standalone"))) {
			    script = @"
<html>
<header>
	<style type=""text/css"">
		.assoiGraphContainer { position: relative;}
		.assoiGraphComment {
			position: absolute;
			background: #FFFED6;
			border: 1px #006699 dotted;
			color: #000;
			padding: 5px 8px 5px 8px;
		}
	</style>
	<title>График АССОИ</title>
</header>
<body>
<script type=""text/javascript"" src=""../scripts/jquery.min.js""></script>
<script type=""text/javascript"" src=""../scripts/FusionCharts.js""></script>
<script type=""text/javascript"" src=""../scripts/FusionCharts.HC.js""></script>
<script type=""text/javascript"" src=""../scripts/FusionCharts.HC.PowerCharts.js""></script>
<script type=""text/javascript"" src=""../scripts/FusionCharts.HC.Widgets.js""></script>
" + script + @"
</body>
</html>";
		    }
		    return script;
	    }
예제 #11
0
        private string GetNormalChartContent(IMvcContext context, IChartConfig config)
        {
            var comments   = GetComments(context).Aggregate(string.Empty, (_, __) => _ + __);
            var datascript = RenderDataScript(context, config);

            if (string.IsNullOrWhiteSpace(datascript))
            {
                return(GetErrorChartContent(context, config));
            }
            var script = "";
            var error  = string.Empty;

            if (string.IsNullOrWhiteSpace(datascript))
            {
                error = "Нет данных для отображения";
            }

            if (context.Get("format", context.Get("__format")) == "json")
            {
                dynamic result = new UObj();
                result.config       = config;
                result.data         = datascript;
                result.error        = error;
                context.ContentType = MimeHelper.JSON;
                return(result.ToJson().Replace("\\\'", "'"));
            }

            var id        = config.Id;
            var container = config.Container;

            if (string.IsNullOrWhiteSpace(container))
            {
                container = "fc-container-" + id;
                script   += string.Format(@"
<div class=""assoiGraphContainer""><div class=""fusinchart-container{0}"" id=""{1}"">{2}</div>{3}</div>", string.IsNullOrEmpty(error) ? " fusionchart-error" : "", container, error, comments);
            }


            if (string.IsNullOrWhiteSpace(error))
            {
                script += string.Format(@"
<div style=""display:none"" id=""fc-data-{1}"">{5}</div>
<script type=""text/javascript""><!--
    FusionCharts.setCurrentRenderer('javascript');
    var myChart = new FusionCharts('../charts/{0}.swf', 'fc-chart-{1}', '{2}', '{3}', '{4}');
    myChart.set{7}Data($('#fc-data-{1}').text());
    myChart.render('{6}');
// -->
</script>", config.Type, id, config.Width, config.Height, config.Debug, datascript.Replace("<", "&lt;").Replace("&quot;", "&amp;quot;"), container, config.DataType);
                context.ContentType = "text/html";
            }

            if (!string.IsNullOrWhiteSpace(context.Get("standalone")))
            {
                script = @"
<html>
<header>
	<style type=""text/css"">
		.assoiGraphContainer { position: relative;}
		.assoiGraphComment {
			position: absolute;
			background: #FFFED6;
			border: 1px #006699 dotted;
			color: #000;
			padding: 5px 8px 5px 8px;
		}
	</style>
	<title>График АССОИ</title>
</header>
<body>
<script type=""text/javascript"" src=""../scripts/jquery.min.js""></script>
<script type=""text/javascript"" src=""../scripts/FusionCharts.js""></script>
<script type=""text/javascript"" src=""../scripts/FusionCharts.HC.js""></script>
<script type=""text/javascript"" src=""../scripts/FusionCharts.HC.PowerCharts.js""></script>
<script type=""text/javascript"" src=""../scripts/FusionCharts.HC.Widgets.js""></script>
" + script + @"
</body>
</html>";
            }
            return(script);
        }