示例#1
0
    // Use this for initialization
    void Start()
    {
        JsonSample.PersonToJson();

        object message = ((new TestDemoMessage()).TryXmlDemo());
        //string myString = Newtonsoft.Json.JsonConvert.SerializeXmlNode(message);
        string myString = Newtonsoft.Json.JsonConvert.SerializeObject(message);

        //string myString = UnitySerializer.JSONSerialize(message);
        //Newtonsoft.Json.Linq.JObject test = Newtonsoft.Json.Linq.JObject.Parse(myString);
        //string jsonString = JsonConvert.SerializeObject(test);
        Debug.Log("HH = " + myString);
        //Debug.Log("jsonString = " + jsonString);

//		var s = new SerializationWrapper();
//		string serializedObject;
//		using(var ms = new MemoryStream())
//        {
//            s.Serialize(ms, message);
//			TextReader reader = new StreamReader(ms);
//			serializedObject = reader.ReadToEnd();
//			Debug.Log("serializedObject = " + serializedObject);
//        }

        //LitJson.JsonWriter writer1 = new LitJson.JsonWriter(Console.Out);

        //string LitTest = LitJson.JsonMapper.ToJson(message);
        //Debug.Log("LitTest = " + LitTest);

        //LitJson.JsonMapper.t

        //JsonFx.Json.JsonWriter writer = new JsonFx.Json.JsonWriter();
        //string fxTest = writer.
        //Debug.Log("fxTest = " + fxTest);
    }
示例#2
0
 public JEVisSampleWS(JEVisDataSourceWS ds, JsonSample json, JEVisAttribute att)
 {
     this.attribute = att;
     this.ds        = ds;
     this.json      = json;
     ObjectifyValue();
     ObjectifyTimeStamp();
 }
示例#3
0
    static void btn_onclick()
    {
        var jso = new JsonSample {
            Prop1 = "111", Prop2 = "222"
        };

        alert("New Json was created: {Prop1:\"" + jso.Prop1 + "\", Prop2:\"" + jso.Prop2 + "\"}");
    }
示例#4
0
 public JEVisSampleWS(JEVisDataSourceWS ds, JsonSample json, JEVisAttribute att, JEVisFile file)
 {
     this.attribute = att;
     this.ds        = ds;
     this.json      = json;
     this.file      = file;
     try
     {
         SetValue(file.getFilename());
     }
     catch (Exception ex)
     {
         logger.Error(ex);
     }
 }
        public JEVisSample buildSample(DateTime ts, Object value, String note)
        {
            JsonSample newJson = new JsonSample();

            newJson.setTs(attDTF.print(ts));

            JEVisSample newSample = null;

//TODO: replace this , the getPrimitiveType() is very bad because it will call the Webservice for every sample
//        if (getPrimitiveType() == JEVisConstants.PrimitiveType.FILE) {
            if (value instanceof JEVisFile)// workaround
            {
                JEVisFile file = (JEVisFile)value;
                newSample = new JEVisSampleWS(ds, newJson, this, file);
            }
示例#6
0
        public void Sample()
        {
            var sampleEntry = new JsonSample
            {
                AlleleDepths     = new[] { "92", "21" },
                VariantFrequency = "1",
                TotalDepth       = "10",
                FailedFilter     = true,
                GenotypeQuality  = "790"
            };

            var observedJson = sampleEntry.ToString();

            const string expectedJson =
                "{\"variantFreq\":1,\"totalDepth\":10,\"genotypeQuality\":790,\"alleleDepths\":[92,21],\"failedFilter\":true}";

            Assert.Equal(expectedJson, observedJson);
        }
示例#7
0
        /// <summary>
        /// returns a JsonSample object given the data contained within the sample genotype
        /// field.
        /// </summary>
        private JsonSample ExtractSample(string sampleColumn, bool fixGatkGenomeVcf = false)
        {
            // sanity check: make sure we have a format column
            if (_formatIndices == null || string.IsNullOrEmpty(sampleColumn))
            {
                return(EmptySample());
            }

            var sampleColumns = sampleColumn.Split(':');

            // handle missing sample columns
            if (sampleColumns.Length == 1 && sampleColumns[0] == ".")
            {
                return(EmptySample());
            }

            var tmp = new IntermediateSampleFields(_vcfColumns, _formatIndices, sampleColumns, fixGatkGenomeVcf);

            var sample = new JsonSample
            {
                AlleleDepths           = new AlleleDepths(tmp).GetAlleleDepths(),
                FailedFilter           = new FailedFilter(tmp).GetFailedFilter(),
                Genotype               = new Genotype(tmp).GetGenotype(),
                GenotypeQuality        = new GenotypeQuality(tmp).GetGenotypeQuality(),
                TotalDepth             = new TotalDepth(tmp).GetTotalDepth(_infoDepth),
                VariantFrequency       = new VariantFrequency(tmp).GetVariantFrequency(),
                CopyNumber             = tmp.CopyNumber?.ToString(),
                IsLossOfHeterozygosity = tmp.MajorChromosomeCount != null && tmp.CopyNumber != null &&
                                         tmp.MajorChromosomeCount.Value == tmp.CopyNumber.Value,
                DenovoQuality     = tmp.DenovoQuality?.ToString(),
                SplitReadCounts   = new ReadCounts(tmp).GetSplitReadCounts(),
                PairEndReadCounts = new ReadCounts(tmp).GetPairEndReadCounts()
            };

            // sanity check: handle empty samples
            if (sample.IsNull())
            {
                sample.IsEmpty = true;
            }

            return(sample);
        }
示例#8
0
 static void btn_onclick()
 {
     var jso = new JsonSample { Prop1 = "111", Prop2 = "222"};
     alert("New Json was created: {Prop1:\"" + jso.Prop1 + "\", Prop2:\"" + jso.Prop2 + "\"}");
 }
示例#9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            app.UseStaticFiles();
            // app.UseH1Middleware(new H1MiddlewareOptions { NeverStop = false });
            app.UseSession();

            app.Map("/session", app1 =>
            {
                app1.Run(async(context) =>
                {
                    try
                    {
                        string sessionInfo = context.Session.GetString("MySession");
                        if (string.IsNullOrEmpty(sessionInfo))
                        {
                            context.Session.SetString("MySession", $"session created at {DateTime.Now:T}");
                            await context.Session.CommitAsync();
                            await context.Response.WriteAsync($"session created at {DateTime.Now:T}");
                        }
                        else
                        {
                            await context.Response.WriteAsync($"session exists with this information: {sessionInfo}");
                        }
                    }
                    catch (Exception ex)
                    {
                        await context.Response.WriteAsync(ex.ToString());
                    }
                });
            });


            app.MapWhen(context => context.Request.Path.Value.Contains("one"), app1 =>
            {
                app1.Run(async(context) =>
                {
                    await context.Response.WriteAsync("path contains 'one'");
                });
            });

            app.Map("/mycontroller", app1 =>
            {
                app1.Run(async(context) =>
                {
                    var controller = Container.GetService <HelloController>();
                    string html    = controller.Greeting("Katharina");
                    await context.Response.WriteAsync(html);
                });
            });

            app.Map("/book", app1 =>
            {
                app1.Run(async(context) =>
                {
                    try
                    {
                        var book = new JsonSample().GetABook();

                        string json = JsonConvert.SerializeObject(book);
                        await context.Response.WriteAsync(json);
                    }
                    catch (Exception ex)
                    {
                        await context.Response.WriteAsync(ex.ToString());
                    }
                });
            });

            app.Map("/Cookies", app1 =>
            {
                app1.Run(async(context) =>
                {
                    context.Response.Cookies.Append("Mycookie", "mycookieVal", new CookieOptions {
                        Expires = DateTime.Now.AddDays(3)
                    });
                    await context.Response.WriteAsync(HtmlEncoder.Default.Encode("cookie written"));
                });
            });

            app.Map("/FormSample", app1 =>
            {
                app1.Run(async(context) =>
                {
                    if (context.Request.Method == "POST")
                    {
                        string val1 = context.Request.Form["text1"];
                        await context.Response.WriteAsync($"received from the user: {HtmlEncoder.Default.Encode(val1)}");
                        return;
                    }
                    await MyForm.ReturnFormAsync(context);
                });
            });

            app.Map("/Sample2", app1 =>
            {
                app1.Run(async(context) =>
                {
                    string valx = context.Request.Query["x"].FirstOrDefault();
                    await context.Response.WriteAsync(HtmlEncoder.Default.Encode(valx));
                });
            });

            app.Map("/Sample1", app1 =>
            {
                app1.Run(async(context) =>
                {
                    await context.Response.WriteAsync("<h2>Mapped to Sample1</h2>");
                });
            });


            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("<h2>Hello World!</h2>");
            });
        }
示例#10
0
        public int addSamples(List <JEVisSample> samples)
        {
            List <JsonSample> jsonSamples = new ArrayList <>();
            int imported = 0;

            int primType = getPrimitiveType();

            if (primType != JEVisConstants.PrimitiveType.FILE)
            {
                try {
                    for (JEVisSample s : samples)
                    {
                        JsonSample jsonSample = JsonFactory.buildSample(s, primType);
                        jsonSamples.add(jsonSample);
                    }


//JEWebService/v1/files/8598/attributes/File/samples/files/20180604T141441?filename=nb-configuration.xml
//JEWebService/v1/objects/{id}/attributes/{attribute}/samples
                    String resource = REQUEST.API_PATH_V1
                                      + REQUEST.OBJECTS.PATH
                                      + getObjectID() + "/"
                                      + REQUEST.OBJECTS.ATTRIBUTES.PATH
                                      + getName() + "/"
                                      + REQUEST.OBJECTS.ATTRIBUTES.SAMPLES.PATH;

//                String requestjson = new Gson().toJson(jsonSamples, new TypeToken<List<JsonSample>>() {
//                }.getType());
                    String json = this.ds.getObjectMapper().writeValueAsString(jsonSamples);

//                logger.debug("Payload. {}", requestjson);
/** TODO: implement this function into ws **/
                    StringBuffer response = ds.getHTTPConnection().postRequest(resource, json);

                    logger.debug("Response.payload: {}", response);
                } catch (Exception ex)
                {
                    logger.catching(ex);
                }
            }
            else
            {
                //Also upload die byte file, filename is in json
                for (JEVisSample s : samples)
                {
                    try
                    {
                        String resource = REQUEST.API_PATH_V1
                                          + REQUEST.OBJECTS.PATH
                                          + getObjectID() + "/"
                                          + REQUEST.OBJECTS.ATTRIBUTES.PATH
                                          + getName() + "/"
                                          + REQUEST.OBJECTS.ATTRIBUTES.SAMPLES.PATH
                                          + REQUEST.OBJECTS.ATTRIBUTES.SAMPLES.FILES.PATH
                                          + HTTPConnection.FMT.print(s.getTimestamp())
                                          + "?" + REQUEST.OBJECTS.ATTRIBUTES.SAMPLES.FILES.OPTIONS.FILENAME + s.getValueAsFile().getFilename();

                        HttpURLConnection connection = ds.getHTTPConnection().getPostFileConnection(resource);
                        //                    logger.trace("Upload file-------------: {}", s.getValueAsFile().getBytes().length);
                        try (OutputStream os = connection.getOutputStream()) {
                                os.write(s.getValueAsFile().getBytes());
                                os.flush();
                                os.close();
                            }
                        int responseCode = connection.getResponseCode();
                        imported = 1;/** TODO: fix server side, missing response **/
                    } catch (Exception ex)
                    {
                        logger.catching(ex);
                    }
                }

//
            }
            ds.reloadAttribute(this);

/**
 * cast needs to be removed
 */
            JEVisObjectWS obj = (JEVisObjectWS)getObject();

            obj.notifyListeners(new JEVisEvent(this, JEVisEvent.TYPE.ATTRIBUTE_UPDATE, this));


            return(imported);
        }