Example #1
0
        private static void WriteTerm(JsonWriter writer, Spec.Term term)
        {
            if (term.type == Term.TermType.DATUM)
            {
                WriteDatum(writer, term.datum);
                return;
            }

            writer.BeginArray();
            writer.WriteNumber((int)term.type);
            if (term.args.Count > 0 || term.optargs.Count > 0)
            {
                writer.BeginArray();
                foreach (var arg in term.args)
                {
                    WriteTerm(writer, arg);
                }
                writer.EndArray();
                writer.BeginObject();
                foreach (var opt in term.optargs)
                {
                    writer.WriteMember(opt.key);
                    WriteTerm(writer, opt.val);
                }
                writer.EndObject();
            }
            writer.EndArray();
        }
Example #2
0
 public static void NewConfigure()
 {
     try
     {
         CheckConfigureFile();
         FileStream ConfigureStream = File.Open(FileName, FileMode.OpenOrCreate);
         JsonWriter jWriter         = new JsonWriter(new Java.IO.OutputStreamWriter(ConfigureStream));
         jWriter.BeginObject();
         jWriter.Name("CSIWebServerName").Value(string.Empty);
         jWriter.Name("Theme").Value(string.Empty);
         jWriter.Name("Configuration").Value(string.Empty);
         jWriter.Name("EnableHTTPS").Value(false);
         jWriter.Name("UseRESTForRequest").Value(false);
         jWriter.Name("SaveUser").Value(false);
         jWriter.Name("SavePassword").Value(false);
         jWriter.Name("SavedUser").Value(string.Empty);
         jWriter.Name("SavedPassword").Value(string.Empty);
         jWriter.Name("LoadPicture").Value(false);
         jWriter.Name("RecordCap").Value(10);
         jWriter.Name("ConfigurationList");
         jWriter.BeginArray();
         jWriter.Value(string.Empty);
         jWriter.EndArray();
         jWriter.EndObject();
         jWriter.Close();
         ConfigureStream.Close();
     }
     catch (Exception Ex)
     {
         WriteErrorLog(Ex);
     }
 }
 /// <summary>Writes an array.</summary>
 /// <param name="writer">The writer.</param>
 /// <param name="name">The name of the array.</param>
 /// <param name="field">The field properties.</param>
 /// <param name="values">The values.</param>
 public static void Array(this JsonWriter writer, string name, FieldProperties field, IEnumerable values)
 {
     writer.BeginArray(name);
     foreach (object val in values)
     {
         string value = field.GetString(val, "\"", true);
         writer.ArrayValue(value, false, false);
     }
     writer.EndArray();
 }
Example #4
0
 private static void WriteQuery(JsonWriter writer, Spec.Query query)
 {
     writer.BeginArray();
     writer.WriteNumber((int)query.type);
     if (query.type == Spec.Query.QueryType.START)
     {
         WriteTerm(writer, query.query);
         writer.BeginObject();
         foreach (var opt in query.global_optargs)
         {
             writer.WriteMember(opt.key);
             WriteTerm(writer, opt.val);
         }
         writer.EndObject();
     }
     writer.EndArray();
 }
Example #5
0
        void FilterList(WebData webData, ITable table, string nameField, string guidField, string text)
        {
            var ids = new Set <long>();

            if (text == null)
            {
                ids.IncludeRange(table.FindRows(Search.None, ResultOption.Limit(20)));
            }
            else
            {
                ids.AddRange(table.FindRows(Search.FieldLike(nameField, MDBSearch.Text(text + "%")) & Search.FieldNotEquals(guidField, null), ResultOption.SortAscending(nameField) + ResultOption.Group(nameField) + ResultOption.Group(guidField) + ResultOption.Limit(20)));
                if (ids.Count < 20)
                {
                    ids.IncludeRange(table.FindRows(Search.FieldLike(nameField, MDBSearch.Text("% " + text + "%")) & Search.FieldNotEquals(guidField, null), ResultOption.SortAscending(nameField) + ResultOption.Group(nameField) + ResultOption.Group(guidField) + ResultOption.Limit(20)));
                }
                if (ids.Count < 20)
                {
                    ids.IncludeRange(table.FindRows(Search.FieldLike(nameField, MDBSearch.Text(text + "%")) & Search.FieldEquals(guidField, null), ResultOption.SortAscending(nameField) + ResultOption.Group(nameField) + ResultOption.Limit(20 - ids.Count)));
                }
                if (ids.Count < 20)
                {
                    ids.IncludeRange(table.FindRows(Search.FieldLike(nameField, MDBSearch.Text("% " + text + "%")) & Search.FieldEquals(guidField, null), ResultOption.SortAscending(nameField) + ResultOption.Group(nameField) + ResultOption.Limit(20 - ids.Count)));
                }
            }
            var json = new JsonWriter();

            json.BeginArray("results");
            if (ids.Count > 0)
            {
                //get items
                var values = table.GetValues <string>(nameField, false, ids.SubRange(0, Math.Min(20, ids.Count)));
                foreach (var value in values)
                {
                    json.BeginObject();
                    json.String("id", value);
                    json.String("text", value);
                    json.EndObject();
                }
            }
            json.EndArray();
            var message = WebMessage.Create(webData.Method, $"Filter {nameField} {text}");

            webData.Answer = WebAnswer.Json(webData.Request, message, json.ToString());
        }
Example #6
0
 public static void WriteConfigure(CSIContext c)
 {
     try
     {
         File.Delete(FileName);
         FileStream ConfigureStream = File.Open(FileName, FileMode.OpenOrCreate);
         JsonWriter jWriter         = new JsonWriter(new Java.IO.OutputStreamWriter(ConfigureStream));
         jWriter.BeginObject();
         jWriter.Name("CSIWebServerName").Value(c.CSIWebServerName ?? string.Empty);
         jWriter.Name("Configuration").Value(c.Configuration ?? string.Empty);
         jWriter.Name("ConfigurationList");
         jWriter.BeginArray();
         foreach (string config in c.ConfigurationList)
         {
             jWriter.Value(config ?? string.Empty);
         }
         jWriter.EndArray();
         jWriter.Name("Theme").Value(c.Theme);
         jWriter.Name("EnableHTTPS").Value(c.EnableHTTPS);
         jWriter.Name("UseRESTForRequest").Value(c.UseRESTForRequest);
         jWriter.Name("SaveUser").Value(c.SaveUser);
         jWriter.Name("SavePassword").Value(c.SavePassword);
         jWriter.Name("SavedUser").Value(c.SaveUser ? c.SavedUser : string.Empty);
         jWriter.Name("SavedPassword").Value(c.SaveUser && c.SavePassword ? c.SavedPassword : string.Empty);
         jWriter.Name("LoadPicture").Value(c.LoadPicture);
         jWriter.Name("RecordCap").Value(c.RecordCap ?? "10");
         jWriter.Name("ForceAutoPost").Value(c.ForceAutoPost);
         jWriter.Name("ShowSuccessMessage").Value(c.ShowSuccessMessage);
         jWriter.Name("LicenseString").Value(c.LicenseString);
         jWriter.Name("ExpDate").Value(c.ExpDate);
         jWriter.EndObject();
         jWriter.Close();
         ConfigureStream.Close();
     }
     catch (Exception Ex)
     {
         WriteErrorLog(Ex);
     }
 }
Example #7
0
        public string ToJson()
        {
            StringBuilder sb = new StringBuilder();
            JsonWriter    jw = new JsonWriter(new StringWriter(sb));

            jw.StartObject();
            jw.WriteProperty("taskEndPoint", TaskEndPoint.ToString());
            jw.Writer.Write(",");
            if (!string.IsNullOrEmpty(Title))
            {
                jw.WriteProperty("title", Title.ToString());
                jw.Writer.Write(",");
            }
            if (!string.IsNullOrEmpty(TaskName))
            {
                jw.WriteProperty("taskName", TaskName.ToString());
                jw.Writer.Write(",");
            }
            if (HelpUrl != null)
            {
                jw.WriteProperty("helpUrl", HelpUrl.ToString());
                jw.Writer.Write(",");
            }

            jw.WriteProperty("useProxy", UseProxy.ToString());
            jw.Writer.Write(",");

            jw.StartProperty("inputParameters");
            jw.StartArray();
            bool wroteFirst = false;

            foreach (ParameterSupport.ParameterConfig config in InputParameters)
            {
                if (config == null)
                {
                    continue;
                }
                if (wroteFirst)
                {
                    jw.Writer.Write(",");
                }
                else
                {
                    wroteFirst = true;
                }
                config.ToJson(jw);
            }
            jw.EndArray();
            jw.Writer.Write(",");
            jw.StartProperty("outputParameters");
            jw.StartArray();
            wroteFirst = false;
            foreach (ParameterSupport.ParameterConfig config in OutputParameters)
            {
                if (config == null)
                {
                    continue;
                }
                if (wroteFirst)
                {
                    jw.Writer.Write(",");
                }
                else
                {
                    wroteFirst = true;
                }
                config.ToJson(jw);
            }
            jw.EndArray();

            if (LayerOrder != null)
            {
                jw.Writer.Write(",");
                jw.StartProperty("layerOrder");
                jw.StartArray();
                wroteFirst = false;
                foreach (string layer in LayerOrder)
                {
                    if (string.IsNullOrEmpty(layer))
                    {
                        continue;
                    }
                    if (wroteFirst)
                    {
                        jw.Writer.Write(",");
                    }
                    else
                    {
                        wroteFirst = true;
                    }
                    jw.Writer.Write(string.Format("\"{0}\"", layer));
                }
                jw.EndArray();
            }
            jw.EndObject();
            return(sb.ToString());
        }
        /// <inheritdoc />
        public override void GenerateSolution(Solution solution)
        {
            // Setup directory for Visual Studio Code files
            var vsCodeFolder = Path.Combine(solution.WorkspaceRootPath, ".vscode");

            if (!Directory.Exists(vsCodeFolder))
            {
                Directory.CreateDirectory(vsCodeFolder);
            }

            // Prepare
            var buildToolWorkspace = Environment.CurrentDirectory;
            var buildToolPath      = Utilities.MakePathRelativeTo(typeof(Builder).Assembly.Location, solution.WorkspaceRootPath);
            var rules = Builder.GenerateRulesAssembly();

            // Create tasks file
            using (var json = new JsonWriter())
            {
                json.BeginRootObject();
                {
                    json.AddField("version", "2.0.0");

                    json.BeginArray("tasks");
                    {
                        foreach (var project in solution.Projects)
                        {
                            // C++ project
                            if (project.Type == TargetType.NativeCpp)
                            {
                                bool defaultTask = project == solution.MainProject;
                                foreach (var configuration in project.Configurations)
                                {
                                    var target = configuration.Target;
                                    var name   = project.Name + '|' + configuration.Name;

                                    json.BeginObject();

                                    json.AddField("label", name);

                                    if (defaultTask && configuration.Configuration == TargetConfiguration.Development && configuration.Platform == Platform.BuildPlatform.Target)
                                    {
                                        defaultTask = false;
                                        json.BeginObject("group");
                                        {
                                            json.AddField("kind", "build");
                                            json.AddField("isDefault", true);
                                        }
                                        json.EndObject();
                                    }
                                    else
                                    {
                                        json.AddField("group", "build");
                                    }

                                    switch (Platform.BuildPlatform.Target)
                                    {
                                    case TargetPlatform.Windows:
                                    {
                                        json.AddField("command", buildToolPath);
                                        json.BeginArray("args");
                                        {
                                            json.AddUnnamedField("-build");
                                            json.AddUnnamedField("-log");
                                            json.AddUnnamedField("-mutex");
                                            json.AddUnnamedField(string.Format("\\\"-workspace={0}\\\"", buildToolWorkspace));
                                            json.AddUnnamedField(string.Format("-arch={0}", configuration.ArchitectureName));
                                            json.AddUnnamedField(string.Format("-configuration={0}", configuration.ConfigurationName));
                                            json.AddUnnamedField(string.Format("-platform={0}", configuration.PlatformName));
                                            json.AddUnnamedField(string.Format("-buildTargets={0}", target.Name));
                                            if (!string.IsNullOrEmpty(Configuration.Compiler))
                                            {
                                                json.AddUnnamedField(string.Format("-compiler={0}", Configuration.Compiler));
                                            }
                                        }
                                        json.EndArray();

                                        json.AddField("type", "shell");

                                        json.BeginObject("options");
                                        {
                                            json.AddField("cwd", buildToolWorkspace);
                                        }
                                        json.EndObject();
                                        break;
                                    }

                                    case TargetPlatform.Linux:
                                    {
                                        json.AddField("command", Path.Combine(Globals.EngineRoot, "Source/Platforms/Editor/Linux/Mono/bin/mono"));
                                        json.BeginArray("args");
                                        {
                                            json.AddUnnamedField(buildToolPath);
                                            json.AddUnnamedField("--build");
                                            json.AddUnnamedField("--log");
                                            json.AddUnnamedField("--mutex");
                                            json.AddUnnamedField(string.Format("--workspace=\\\"{0}\\\"", buildToolWorkspace));
                                            json.AddUnnamedField(string.Format("--arch={0}", configuration.Architecture));
                                            json.AddUnnamedField(string.Format("--configuration={0}", configuration.ConfigurationName));
                                            json.AddUnnamedField(string.Format("--platform={0}", configuration.PlatformName));
                                            json.AddUnnamedField(string.Format("--buildTargets={0}", target.Name));
                                            if (!string.IsNullOrEmpty(Configuration.Compiler))
                                            {
                                                json.AddUnnamedField(string.Format("--compiler={0}", Configuration.Compiler));
                                            }
                                        }
                                        json.EndArray();

                                        json.AddField("type", "shell");

                                        json.BeginObject("options");
                                        {
                                            json.AddField("cwd", buildToolWorkspace);
                                        }
                                        json.EndObject();
                                        break;
                                    }

                                    default: throw new Exception("Visual Code project generator does not support current platform.");
                                    }

                                    json.EndObject();
                                }
                            }
                        }
                    }
                    json.EndArray();
                }
                json.EndRootObject();

                json.Save(Path.Combine(vsCodeFolder, "tasks.json"));
            }

            // Create launch file
            using (var json = new JsonWriter())
            {
                json.BeginRootObject();
                {
                    json.AddField("version", "0.2.0");

                    json.BeginArray("configurations");
                    {
                        foreach (var project in solution.Projects)
                        {
                            // C++ project
                            if (project.Type == TargetType.NativeCpp)
                            {
                                foreach (var configuration in project.Configurations)
                                {
                                    var name   = project.Name + '|' + configuration.Name;
                                    var target = configuration.Target;

                                    var outputType           = project.OutputType ?? target.OutputType;
                                    var outputTargetFilePath = target.GetOutputFilePath(configuration.TargetBuildOptions, project.OutputType);

                                    json.BeginObject();
                                    {
                                        if (configuration.Platform == TargetPlatform.Windows)
                                        {
                                            json.AddField("type", "cppvsdbg");
                                        }
                                        else
                                        {
                                            json.AddField("type", "cppdbg");
                                        }
                                        json.AddField("name", name);
                                        json.AddField("request", "launch");
                                        json.AddField("preLaunchTask", name);
                                        json.AddField("cwd", buildToolWorkspace);

                                        switch (Platform.BuildPlatform.Target)
                                        {
                                        case TargetPlatform.Windows:
                                            if (configuration.Platform == TargetPlatform.Windows && outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor."))
                                            {
                                                var editorFolder = configuration.Architecture == TargetArchitecture.x64 ? "Win64" : "Win32";
                                                json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", editorFolder, configuration.ConfigurationName, "FlaxEditor.exe"));
                                                json.BeginArray("args");
                                                {
                                                    json.AddUnnamedField("-project");
                                                    json.AddUnnamedField(buildToolWorkspace);
                                                    json.AddUnnamedField("-skipCompile");
                                                    json.AddUnnamedField("-debug");
                                                    json.AddUnnamedField("127.0.0.1:55555");
                                                }
                                                json.EndArray();
                                            }
                                            else
                                            {
                                                json.AddField("program", outputTargetFilePath);
                                            }
                                            break;

                                        case TargetPlatform.Linux:
                                            if (configuration.Platform == TargetPlatform.Linux && (outputType != TargetOutputType.Executable || project.Name == "Flax") && configuration.Name.StartsWith("Editor."))
                                            {
                                                json.AddField("program", Path.Combine(Globals.EngineRoot, "Binaries", "Editor", "Linux", configuration.ConfigurationName, "FlaxEditor"));
                                            }
                                            else
                                            {
                                                json.AddField("program", outputTargetFilePath);
                                            }
                                            if (configuration.Platform == TargetPlatform.Linux)
                                            {
                                                json.AddField("MIMode", "gdb");
                                                json.BeginArray("setupCommands");
                                                {
                                                    json.BeginObject();
                                                    json.AddField("description", "Enable pretty-printing for gdb");
                                                    json.AddField("text", "-enable-pretty-printing");
                                                    json.AddField("ignoreFailures", true);
                                                    json.EndObject();

                                                    // Ignore signals used by Mono
                                                    json.BeginObject();
                                                    json.AddField("description", "ignore SIG35 signal");
                                                    json.AddField("text", "handle SIG35 nostop noprint pass");
                                                    json.EndObject();
                                                    json.BeginObject();
                                                    json.AddField("description", "ignore SIG36 signal");
                                                    json.AddField("text", "handle SIG36 nostop noprint pass");
                                                    json.EndObject();
                                                    json.BeginObject();
                                                    json.AddField("description", "ignore SIG357 signal");
                                                    json.AddField("text", "handle SIG37 nostop noprint pass");
                                                    json.EndObject();
                                                }
                                                json.EndArray();
                                                json.BeginArray("args");
                                                {
                                                    json.AddUnnamedField("--std");
                                                    if (outputType != TargetOutputType.Executable && configuration.Name.StartsWith("Editor."))
                                                    {
                                                        json.AddUnnamedField("--project");
                                                        json.AddUnnamedField(buildToolWorkspace);
                                                        json.AddUnnamedField("--skipCompile");
                                                    }
                                                }
                                                json.EndArray();
                                            }
                                            break;
                                        }
                                        switch (configuration.Platform)
                                        {
                                        case TargetPlatform.Windows:
                                            json.AddField("stopAtEntry", false);
                                            json.AddField("externalConsole", true);
                                            break;

                                        case TargetPlatform.Linux:
                                            break;
                                        }
                                        json.AddField("visualizerFile", Path.Combine(Globals.EngineRoot, "Source", "flax.natvis"));
                                    }
                                    json.EndObject();
                                }
                            }
                            // C# project
                            else if (project.Type == TargetType.DotNet)
                            {
                                foreach (var configuration in project.Configurations)
                                {
                                    json.BeginObject();
                                    {
                                        json.AddField("type", "mono");
                                        json.AddField("name", project.Name + " (C# attach)" + '|' + configuration.Name);
                                        json.AddField("request", "attach");
                                        json.AddField("address", "localhost");
                                        json.AddField("port", 55555);
                                    }
                                    json.EndObject();
                                }
                            }
                        }
                    }
                    json.EndArray();
                }
                json.EndRootObject();

                json.Save(Path.Combine(vsCodeFolder, "launch.json"));
            }

            // Create C++ properties file
            using (var json = new JsonWriter())
            {
                json.BeginRootObject();
                json.BeginArray("configurations");
                json.BeginObject();
                var project = solution.MainProject ?? solution.Projects.FirstOrDefault(x => x.Name == Globals.Project.Name);
                if (project != null)
                {
                    json.AddField("name", project.Name);

                    var targetPlatform = Platform.BuildPlatform.Target;
                    var configuration  = TargetConfiguration.Development;
                    var architecture   = TargetArchitecture.x64;

                    var includePaths            = new HashSet <string>();
                    var preprocessorDefinitions = new HashSet <string>();
                    foreach (var e in project.Defines)
                    {
                        preprocessorDefinitions.Add(e);
                    }

                    foreach (var target in project.Targets)
                    {
                        var platform = Platform.GetPlatform(targetPlatform);
                        if (platform.HasRequiredSDKsInstalled && target.Platforms.Contains(targetPlatform))
                        {
                            var toolchain          = platform.GetToolchain(architecture);
                            var targetBuildOptions = Builder.GetBuildOptions(target, platform, toolchain, architecture, configuration, Globals.Root);
                            var modules            = Builder.CollectModules(rules, platform, target, targetBuildOptions, toolchain, architecture, configuration);
                            foreach (var module in modules)
                            {
                                // This merges private module build options into global target - not the best option but helps with syntax highlighting and references collecting
                                module.Key.Setup(targetBuildOptions);
                                module.Key.SetupEnvironment(targetBuildOptions);
                            }

                            foreach (var e in targetBuildOptions.CompileEnv.PreprocessorDefinitions)
                            {
                                preprocessorDefinitions.Add(e);
                            }
                            foreach (var e in targetBuildOptions.CompileEnv.IncludePaths)
                            {
                                includePaths.Add(e);
                            }
                        }
                    }

                    json.BeginArray("includePath");
                    {
                        foreach (var path in includePaths)
                        {
                            json.AddUnnamedField(path.Replace('\\', '/'));
                        }
                    }
                    json.EndArray();

                    if (targetPlatform == TargetPlatform.Windows)
                    {
                        json.AddField("intelliSenseMode", "msvc-x64");
                    }
                    else
                    {
                        json.AddField("intelliSenseMode", "clang-x64");
                    }

                    json.BeginArray("defines");
                    {
                        foreach (string definition in preprocessorDefinitions)
                        {
                            json.AddUnnamedField(definition);
                        }
                    }
                    json.EndArray();
                }
                json.EndObject();
                json.EndArray();
                json.EndRootObject();

                json.Save(Path.Combine(vsCodeFolder, "c_cpp_properties.json"));
            }

            // Create settings file
            using (var json = new JsonWriter())
            {
                json.BeginRootObject();

                // File and folders excludes
                json.BeginObject("files.exclude");
                json.AddField("**/.git", true);
                json.AddField("**/.svn", true);
                json.AddField("**/.hg", true);
                json.AddField("**/.vs", true);
                json.AddField("**/Binaries", true);
                json.AddField("**/Cache", true);
                json.AddField("**/packages", true);
                json.AddField("**/Logs", true);
                json.AddField("**/Screenshots", true);
                json.AddField("**/Output", true);
                json.AddField("**/*.flax", true);
                json.EndObject();

                json.EndRootObject();
                json.Save(Path.Combine(vsCodeFolder, "settings.json"));
            }

            // Create workspace file
            using (var json = new JsonWriter())
            {
                json.BeginRootObject();

                // Settings
                json.BeginObject("settings");
                json.AddField("typescript.tsc.autoDetect", "off");
                json.AddField("npm.autoDetect", "off");
                json.AddField("gulp.autoDetect", "off");
                json.AddField("jake.autoDetect", "off");
                json.AddField("grunt.autoDetect", "off");
                json.AddField("omnisharp.defaultLaunchSolution", solution.Name + ".sln");
                json.EndObject();

                // Folders
                json.BeginArray("folders");
                {
                    // This project
                    json.BeginObject();
                    json.AddField("name", solution.Name);
                    json.AddField("path", ".");
                    json.EndObject();

                    // Referenced projects outside the current project (including engine too)
                    foreach (var project in Globals.Project.GetAllProjects())
                    {
                        if (!project.ProjectFolderPath.Contains(Globals.Project.ProjectFolderPath))
                        {
                            json.BeginObject();
                            {
                                json.AddField("name", project.Name);
                                json.AddField("path", project.ProjectFolderPath);
                            }
                            json.EndObject();
                        }
                    }
                }
                json.EndArray();

                json.EndRootObject();
                json.Save(Path.Combine(solution.WorkspaceRootPath, solution.Name + ".code-workspace"));
            }

            // Create extensions recommendations file
            using (var json = new JsonWriter())
            {
                json.BeginRootObject();

                json.BeginArray("recommendations");
                {
                    json.AddUnnamedField("ms-dotnettools.csharp");
                    json.AddUnnamedField("ms-vscode.mono-debug");

                    if (!Globals.Project.IsCSharpOnlyProject)
                    {
                        json.AddUnnamedField("ms-vscode.cpptools");
                    }
                }
                json.EndArray();

                json.EndRootObject();
                json.Save(Path.Combine(vsCodeFolder, "extensions.json"));
            }
        }
Example #9
0
        public override string BuildJson(int indicator = 0)
        {
            /* {
             *      "IDOName": "UserNames",
             *      "Items": [{
             *                      "EditStatus": 0,
             *                      "ID": "PBT=[UserNames] UserNames.DT=[20171223 20:19:13.103] UserNames.ID=[4c0a3eb1-5492-4785-bb2b-db0522a92a6e]",
             *                      "Properties": [{
             *                                      "Property": "2",
             *                                      "Updated": false
             *                              }, {
             *                                      "Property": "sa",
             *                                      "Updated": false
             *                              }, {
             *                                      "Property": "",
             *                                      "Updated": false
             *                              }
             *                      ]
             *              }
             *      ],
             *      "PropertyList": ["UserId", "Username", "UserDesc"]
             *  }
             */
            string       output     = "";
            StringWriter writer     = new StringWriter();
            JsonWriter   jsonWriter = new JsonWriter(writer);

            if (string.IsNullOrEmpty(iResult.IDOName))
            {
                return("");
            }

            jsonWriter.BeginObject();
            jsonWriter.Name("IDOName").Value(iResult.IDOName);
            jsonWriter.Name("Items");
            jsonWriter.BeginArray();
            foreach (BaseIDOObject obj in iResult.Objects)
            {
                jsonWriter.BeginObject();
                if (obj.Inserted)
                {
                    jsonWriter.Name("EditStatus").Value(1);
                }
                else if (obj.Updated)
                {
                    jsonWriter.Name("EditStatus").Value(2);
                }
                else if (obj.Deleted)
                {
                    jsonWriter.Name("EditStatus").Value(4);
                }
                else
                {
                    jsonWriter.Name("EditStatus").Value(0);
                }
                jsonWriter.Name("ID").Value(string.Format("PBT=[{0}] {0}.DT=[{1}] {0}.ID=[{2}]", iResult.IDOName, "", ""));
                jsonWriter.Name("Properties");
                jsonWriter.BeginArray();
                foreach (BaseIDOObjectItem objitem in obj.ObjectItems)
                {
                    jsonWriter.BeginObject();
                    jsonWriter.Name("Property").Value(objitem.ItemValue);
                    jsonWriter.Name("Updated").Value(objitem.Updated);
                    jsonWriter.EndObject();
                }
                jsonWriter.EndArray();
                jsonWriter.EndObject();
            }
            jsonWriter.EndArray();
            jsonWriter.Name("PropertyList");
            jsonWriter.BeginArray();
            foreach (string propertyName in iResult.ObjectNames)
            {
                jsonWriter.Value(propertyName);
            }
            jsonWriter.EndArray();
            jsonWriter.EndObject();
            jsonWriter.Flush();
            jsonWriter.Close();
            output = writer.ToString();
            return(output);
        }
Example #10
0
        internal virtual void ToJson(JsonWriter jw)
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            AddToJsonDictionary(ref dictionary);
            jw.StartObject();
            bool wroteFirst = false;

            #region serialize dictionary
            foreach (KeyValuePair <string, object> item in dictionary)
            {
                if (wroteFirst)
                {
                    jw.Writer.Write(",");
                }
                else
                {
                    wroteFirst = true;
                }
                if (item.Key == "defaultValue")
                {
                    if (item.Value is ESRI.ArcGIS.Client.Tasks.GPLinearUnit)
                    {
                        ESRI.ArcGIS.Client.Tasks.GPLinearUnit linearUnit = item.Value as ESRI.ArcGIS.Client.Tasks.GPLinearUnit;
                        jw.StartProperty("defaultValue");
                        jw.StartObject();
                        jw.WriteProperty("distance", linearUnit.Distance);
                        jw.Writer.Write(",");
                        jw.WriteProperty("units", linearUnit.Unit);
                        jw.EndObject();
                    }
                    else if (item.Value is ESRI.ArcGIS.Client.Tasks.GPRasterData)
                    {
                        ESRI.ArcGIS.Client.Tasks.GPRasterData raster = item.Value as ESRI.ArcGIS.Client.Tasks.GPRasterData;
                        jw.StartProperty("defaultValue");
                        jw.StartObject();
                        jw.WriteProperty("url", raster.Url);
                        jw.Writer.Write(",");
                        jw.WriteProperty("format", raster.Format);
                        jw.EndObject();
                    }
                    else
                    {
                        jw.WriteProperty(item.Key, item.Value, false);
                    }
                }
                else
                {
                    jw.WriteProperty(item.Key, item.Value, false);
                }
            }
            #endregion

            #region Choice List
            if (ChoiceList != null && ChoiceList.Count > 0)
            {
                jw.Writer.Write(",");
                jw.StartProperty("choiceList");
                jw.StartArray();
                wroteFirst = false;
                foreach (Choice item in ChoiceList)
                {
                    if (item != null)
                    {
                        if (!wroteFirst)
                        {
                            wroteFirst = true;
                        }
                        else
                        {
                            jw.Writer.Write(",");
                        }
                        item.ToJson(jw);
                    }
                }
                jw.EndArray();
            }
            #endregion
            jw.EndObject();
        }
Example #11
0
		/// <summary>
		/// Stops exporting a timestamp. This call must be made for every call made to <see cref="StartExportTimestamp"/>.
		/// </summary>
		/// <param name="Json">JSON Output</param>
		public static void EndExportTimestamp (JsonWriter Json)
		{
			Json.EndArray ();
			Json.EndObject ();
		}
Example #12
0
		/// <summary>
		/// Stops exporting a node. This call must be made for every call made to <see cref="StartExportNode"/>.
		/// </summary>
		/// <param name="Json">JSON Output</param>
		public static void EndExportNode (JsonWriter Json)
		{
			Json.EndArray ();
			Json.EndObject ();
		}
Example #13
0
		/// <summary>
		/// Stops exporting Sensor Data JSON. This call must be made for every call made to <see cref="StartExportJson"/>.
		/// </summary>
		/// <param name="Json">JSON Output</param>
		public static void EndExportJson (JsonWriter Json)
		{
			Json.EndArray ();
		}
Example #14
0
            public Visitor(JsonWriter writer,
                           bool includeLineColumn, bool includeRange,
                           LocationMembersPlacement locationMembersPlacement)
            {
                _writer = writer ?? ThrowArgumentNullException <JsonWriter>(nameof(writer));
                _stack  = new ObservableStack <Node>();

                _stack.Pushed += node =>
                {
                    _writer.StartObject();

                    if ((includeLineColumn || includeRange) &&
                        locationMembersPlacement == LocationMembersPlacement.Start)
                    {
                        WriteLocationInfo(node);
                    }

                    Member("type", node.Type.ToString());
                };

                _stack.Popped += node =>
                {
                    if ((includeLineColumn || includeRange) &&
                        locationMembersPlacement == LocationMembersPlacement.End)
                    {
                        WriteLocationInfo(node);
                    }

                    _writer.EndObject();
                };

                void WriteLocationInfo(Node node)
                {
                    if (node is ChainExpression)
                    {
                        return;
                    }

                    if (includeRange)
                    {
                        _writer.Member("range");
                        _writer.StartArray();
                        _writer.Number(node.Range.Start);
                        _writer.Number(node.Range.End);
                        _writer.EndArray();
                    }

                    if (includeLineColumn)
                    {
                        _writer.Member("loc");
                        _writer.StartObject();
                        _writer.Member("start");
                        Write(node.Location.Start);
                        _writer.Member("end");
                        Write(node.Location.End);
                        _writer.EndObject();
                    }

                    void Write(Position position)
                    {
                        _writer.StartObject();
                        Member("line", position.Line);
                        Member("column", position.Column);
                        _writer.EndObject();
                    }
                }
            }
Example #15
0
        public override string BuildJson(int indicator = 0)
        {
            /* {
             *  "Action":1/2/4,
             *  "ItemId":"PBT=[Usernames]", "ItemId": "PBT=[MCBCustomers] mcb.ID=[70c0b27f-8151-4f3a-8fcf-a8a8381823b4] mcb.DT=[2015-01-07 13:13:04.660]",
             *  "Properties":
             *  [
             *  {"IsNull":false,"Modified":true/false,"Name":"Username","Value":"newuser54"},
             *  {"IsNull":false,"Modified":true/false,"Name":"EditLevel","Value":"2"},
             *  {"IsNull":false,"Modified":true/false,"Name":"UserDesc","Value":"user description"},
             *  {"IsNull":false,"Modified":true/false,"Name":"SuperUserFlag","Value":"1"}
             *  ]
             *  }
             */
            string       output     = "";
            StringWriter writer     = new StringWriter();
            JsonWriter   jsonWriter = new JsonWriter(writer);

            if (string.IsNullOrEmpty(iResult.IDOName))
            {
                return("");
            }

            jsonWriter.BeginObject();
            jsonWriter.Name("Action").Value(indicator);
            switch (indicator)
            {
            case 1:
                jsonWriter.Name("ItemId").Value(string.Format("PBT=[{0}]", iResult.IDOName));
                break;

            case 2:
            case 4:
                string.Format("PBT=[{0}] {0}.DT=[{1}] {0}.ID=[{2}]", iResult.IDOName, "", "");
                break;

            default:
                break;
            }
            jsonWriter.Name("Properties");
            jsonWriter.BeginArray();
            foreach (BaseIDOObject obj in iResult.Objects)
            {
                if (((indicator == 1) && (!obj.Inserted)) || ((indicator == 2) && (obj.Inserted || obj.Deleted)) || ((indicator == 4) && (!obj.Deleted)))
                {
                    continue;
                }
                foreach (BaseIDOObjectItem objitem in obj.ObjectItems)
                {
                    jsonWriter.BeginObject();
                    jsonWriter.Name("IsNull").Value((string.IsNullOrEmpty(objitem.ItemValue) ? true : false));
                    jsonWriter.Name("Modified").Value(objitem.Updated);
                    jsonWriter.Name("Name").Value(objitem.ItemName);
                    jsonWriter.Name("Value").Value(objitem.ItemValue);
                    jsonWriter.EndObject();
                }
            }
            jsonWriter.EndObject();
            jsonWriter.EndArray();
            jsonWriter.EndObject();
            jsonWriter.Flush();
            jsonWriter.Close();
            output = writer.ToString();
            return(output);
        }
Example #16
0
		/// <summary>
		/// Exports common Field attributes, similar to XEP-0323 Sensor data, but using JSON.
		/// </summary>
		/// <param name="w">JSON Output</param>
		protected void ExportAsJsonSensorDataCommonAttributes (JsonWriter w)
		{
			w.WriteName ("name");
			w.WriteValue (this.fieldName);

			if ((this.type & ReadoutType.MomentaryValues) != 0)
			{
				w.WriteName ("momentary");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.PeakValues) != 0)
			{
				w.WriteName ("peak");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.StatusValues) != 0)
			{
				w.WriteName ("status");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.Computed) != 0)
			{
				w.WriteName ("computed");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.Identity) != 0)
			{
				w.WriteName ("identity");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesSecond) != 0)
			{
				w.WriteName ("historicalSecond");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesMinute) != 0)
			{
				w.WriteName ("historicalMinute");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesHour) != 0)
			{
				w.WriteName ("historicalHour");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesDay) != 0)
			{
				w.WriteName ("historicalDay");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesWeek) != 0)
			{
				w.WriteName ("historicalWeek");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesMonth) != 0)
			{
				w.WriteName ("historicalMonth");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesQuarter) != 0)
			{
				w.WriteName ("historicalQuarter");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesYear) != 0)
			{
				w.WriteName ("historicalYear");
				w.WriteValue (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesOther) != 0)
			{
				w.WriteName ("historicalOther");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.Missing) != 0)
			{
				w.WriteName ("missing");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.AutomaticEstimate) != 0)
			{
				w.WriteName ("automaticEstimate");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.ManualEstimate) != 0)
			{
				w.WriteName ("manualEstimate");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.ManualReadout) != 0)
			{
				w.WriteName ("manualReadout");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.AutomaticReadout) != 0)
			{
				w.WriteName ("automaticReadout");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.TimeOffset) != 0)
			{
				w.WriteName ("timeOffset");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.Warning) != 0)
			{
				w.WriteName ("warning");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.Error) != 0)
			{
				w.WriteName ("error");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.Signed) != 0)
			{
				w.WriteName ("signed");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.Invoiced) != 0)
			{
				w.WriteName ("invoiced");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.EndOfSeries) != 0)
			{
				w.WriteName ("endOfSeries");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.PowerFailure) != 0)
			{
				w.WriteName ("powerFailure");
				w.WriteValue (true);
			}

			if ((this.status & FieldStatus.InvoicedConfirmed) != 0)
			{
				w.WriteName ("invoiceConfirmed");
				w.WriteValue (true);
			}

			if (this.stringIds != null && this.stringIds.Length > 0)
			{
				if (!string.IsNullOrEmpty (this.languageModule))
				{
					w.WriteName ("module");
					w.WriteValue (this.languageModule);
				}

				w.WriteName ("stringIds");
				w.BeginArray ();

				foreach (FieldLanguageStep Step in this.stringIds)
				{
					w.BeginObject ();

					w.WriteName ("stringId");
					w.WriteValue (Step.StringId);

					if (Step.Seed != null)
					{
						w.WriteName ("seed");
						w.WriteValue (Step.Seed);
					}

					if (!string.IsNullOrEmpty (Step.LanguageModule))
					{
						w.WriteName ("module");
						w.WriteValue (Step.LanguageModule);
					}

					w.EndObject ();
				}

				w.EndArray ();
			}
		}