예제 #1
0
    // Use this for initialization
    void Start()
    {
        TextAsset asset = Resources.Load(Path.Combine("", filePathName)) as TextAsset;
        RootJson  json  = JsonUtility.FromJson <RootJson>(asset.text);


        size = json.x.Length;
        GameObject[] points = new GameObject[size];
        GameObject   tmpObj = new GameObject();

        GameObject wayPointsBall = new GameObject("wayPoints" + transform.name);

        for (int i = 0; i < json.x.Length; i++)
        {
            Vector3 tempPos = new Vector3((float)json.x[i], (float)json.y[i], (float)json.z[i]);

            GameObject go = Instantiate(tmpObj, tempPos, Quaternion.identity) as GameObject;
            go.name   = "Point" + i;
            go.tag    = "Point" + transform.name;
            points[i] = go;
            points[i].transform.parent = wayPointsBall.transform;
            //print(points[i].transform.position);
        }

        GameObject.Destroy(tmpObj);
    }
예제 #2
0
        /// <summary>
        /// 设置扩展
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetExtraField(string key, string value)
        {
            JObject payloadJson = null;
            JObject extraJson   = null;

            if (RootJson.ContainsKey("payload"))
            {
                payloadJson = RootJson.Value <JObject>("payload");
            }
            else
            {
                payloadJson = new JObject();
                RootJson.Add("payload", payloadJson);
            }

            if (payloadJson.ContainsKey("extra"))
            {
                extraJson = payloadJson.Value <JObject>("extra");
            }
            else
            {
                extraJson = new JObject();
                payloadJson.Add("extra", extraJson);
            }
            extraJson.Add(key, value);
            return(true);
        }
    static void Main(string[] args)
    {
        List <RootJson> eList    = new List <RootJson>();
        RootJson        rootjson = new RootJson();

        Libs.B.Get(rootjson);
    }
예제 #4
0
        /// <summary>
        /// Set extra key/value for Android notification
        /// 设置附加的参数 key value列表 可选 用户自定义key-value。只对"通知"
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetExtraField(string key, string value)
        {
            JObject payloadJson = null;
            JObject extraJson   = null;

            if (RootJson.Properties().Any(p => p.Name == "payload"))
            {
                payloadJson = RootJson.Property("payload").Value.ToObject <JObject>();
            }
            else
            {
                payloadJson = new JObject();
                RootJson.Add("payload", payloadJson);
            }

            if (payloadJson.Properties().Any(p => p.Name == "extra"))
            {
                extraJson = payloadJson.Property("extra").Value.ToObject <JObject>();
            }
            else
            {
                extraJson = new JObject();
                payloadJson.Add("extra", extraJson);
            }
            extraJson.Add(key, value);
            //需要重新赋值,否则值设置不上
            payloadJson.Property("extra").Value = extraJson;
            RootJson.Property("payload").Value  = payloadJson;
            return(true);
        }
예제 #5
0
        /// <summary>
        /// 设置预定义的值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool SetPredefinedKeyValue(string key, object value)
        {
            var val = JToken.FromObject(value);

            if (ROOT_KEYS.Contains(key))
            {
                RootJson.Add(key, val);
            }
            else if (APS_KEYS.Contains(key))
            {
                JObject apsJson     = null;
                JObject payloadJson = null;
                if (RootJson.ContainsKey("payload"))
                {
                    payloadJson = RootJson.Value <JObject>("payload");
                }
                else
                {
                    payloadJson = new JObject();
                    RootJson.Add("payload", payloadJson);
                }
                if (payloadJson.ContainsKey("aps"))
                {
                    apsJson = payloadJson.Value <JObject>("aps");
                }
                else
                {
                    apsJson = new JObject();
                    payloadJson.Add("aps", apsJson);
                }
                apsJson.Add(key, val);
            }
            else if (POLICY_KEYS.Contains(key))
            {
                JObject policyJson = null;
                if (RootJson.ContainsKey("policy"))
                {
                    policyJson = RootJson.Value <JObject>("policy");
                }
                else
                {
                    policyJson = new JObject();
                    RootJson.Add("policy", policyJson);
                }
                policyJson.Add(key, val);
            }
            else
            {
                if (key == "payload" || key == "aps" || key == "policy")
                {
                    throw new Exception(" 未找到 " + key + "在集合中");
                }
                else
                {
                    throw new Exception("未知 key: " + key);
                }
            }
            return(true);
        }
예제 #6
0
 private static IEnumerable <NewUniEvent> ToUniEvent(this RootJson json)
 {
     return(json.Events.Select(x => new NewUniEvent
     {
         StartTime = x.StartTime,
         EndTime = x.EndTime,
         EventType = x.ModuleTypeName.ToUniEventType(),
         Unit = x.ModuleName.ToUniUnit(),
         EventLeader = x.LecturerNames
     }));
 }
    public static void Get(RootJson rootJson)
    {
        // Do something if rootJson is null
        if (rootJson == null)
        {
            rootJson = new RootJson();
        }
        rootJson.Hub = new List <Hub>();
        Hub hub = new Hub();

        hub.OS = "1.1";
        rootJson.Hub.Add(hub);
    }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetCustomizedField(string key, string value)
        {
            JObject payloadJson = null;

            if (RootJson.ContainsKey("payload"))
            {
                payloadJson = RootJson.Value <JObject>("payload");
            }
            else
            {
                payloadJson = new JObject();
                RootJson.Add("payload", payloadJson);
            }
            payloadJson.Add(key, value);
            return(true);
        }
예제 #9
0
        /// <summary>
        /// Set customized key/value for IOS notification
        /// 设置自定义的key/value参数到提交的json字符串中
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetCustomizedField(string key, string value)
        {
            //RootJson.put(key, value);
            JObject payloadJson = null;

            if (RootJson.Properties().Any(p => p.Name == "payload"))
            {
                payloadJson = RootJson.Property("payload").Value.ToObject <JObject>();
            }
            else
            {
                payloadJson = new JObject();
                RootJson.Add("payload", payloadJson);
            }
            payloadJson.Add(key, value);
            //需要重新赋值,否则值设置不上
            RootJson.Property("payload").Value = payloadJson;
            return(true);
        }
예제 #10
0
        public async Task <RootJson> GetData()
        {
            var url = $@"http://api.openweathermap.org/data/2.5/forecast?q={CityName}&mode=json&units=metric&lang=pt&appid={APPID}";
            var obj = new RootJson();

            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage res = await client.GetAsync(url))
                {
                    using (HttpContent content = res.Content)
                    {
                        var data = await content.ReadAsStringAsync();

                        if (data != null)
                        {
                            obj = JsonConvert.DeserializeObject <RootJson>(data);
                        }
                        return(obj);
                    }
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Upload file with device_tokens or alias to Umeng
        /// </summary>
        /// <param name="contents"></param>
        /// <returns></returns>
        public string UploadContents(string contents)
        {
            if (RootJson.Properties().All(p => p.Name != "appkey") || RootJson.Properties().All(p => p.Name != "timestamp") || RootJson.Properties().All(p => p.Name != "validation_token"))
            {
                throw new Exception("appkey, timestamp and validation_token needs to be set.");
            }
            // Construct the json string
            JObject uploadJson = new JObject
            {
                {"appkey", RootJson.GetValue("appkey")},
                {"timestamp", RootJson.GetValue("timestamp")},
                {"validation_token", RootJson.GetValue("validation_token")},
                {"content", contents}
            };
            // Construct the request
            string url = Host + UploadPath;
            string postBody = uploadJson.ToString();

            var request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "POST";
            request.UserAgent = UserAgent;
            request.Timeout = 2 * 60 * 1000; //超时时间设置为两分钟
            //request.ContentType = "application/json";
            //request.Headers.Set("Pragma", "no-cache");

            byte[] postData = Encoding.UTF8.GetBytes(postBody);
            string retString;
            using (var requestStream = request.GetRequestStream())
            {
                requestStream.Write(postData, 0, postData.Length);
                using (var response = request.GetResponse())
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
                        {
                            retString = myStreamReader.ReadToEnd();
                            //ret = responseStream.ReadBytes();
                        }
                    }
                }
            }

            try
            {

                JObject jObject = JObject.Parse(retString);
                string result = jObject.Property("ret").Value.ToString();
                if (result.Equals("SUCCESS", StringComparison.OrdinalIgnoreCase))
                {
                    string fileId = jObject.GetValue("data").ToObject<JObject>().GetValue("file_id").ToString();
                    SetPredefinedKeyValue("file_id", fileId);
                    return fileId;
                }
                else
                {
                    LogHelper.WriteLog("调用友盟发送失败");
                    LogHelper.WriteLog(retString);
                    throw new Exception("Failed to upload file");
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex.ToString());
                throw ex;
            }
        }
예제 #12
0
        /// <summary>
        /// 设置参数到提交json中去
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public sealed override bool SetPredefinedKeyValue(string key, object value)
        {
            if (RootKeys.Contains(key))
            {
                // This key should be in the root level
                RootJson.Add(key, JToken.FromObject(value));
            }
            else if (ApsKeys.Contains(key))
            {
                // This key should be in the aps level
                JObject apsJson     = null;
                JObject payloadJson = null;
                if (RootJson.Properties().Any(p => p.Name == "payload"))
                {
                    payloadJson = RootJson.Property("payload").Value.ToObject <JObject>();
                }
                else
                {
                    payloadJson = new JObject();
                    RootJson.Add("payload", payloadJson);
                }
                if (payloadJson.Properties().Any(p => p.Name == "aps"))
                {
                    apsJson = payloadJson.Property("aps").Value.ToObject <JObject>();
                }
                else
                {
                    apsJson = new JObject();
                    payloadJson.Add("aps", apsJson);
                }
                apsJson.Add(key, JToken.FromObject(value));
                //需要重新赋值,否则值设置不上
                payloadJson.Property("aps").Value  = apsJson;
                RootJson.Property("payload").Value = payloadJson;
            }
            else if (PolicyKeys.Contains(key))
            {
                // This key should be in the body level
                JObject policyJson = null;
                if (RootJson.Properties().Any(p => p.Name == "policy"))
                {
                    policyJson = RootJson.Property("policy").Value.ToObject <JObject>();
                }
                else
                {
                    policyJson = new JObject();
                    RootJson.Add("policy", policyJson);
                }
                policyJson.Add(key, JToken.FromObject(value));
                //需要重新赋值,否则值设置不上
                RootJson.Property("policy").Value = policyJson;
            }
            else
            {
                if (key == "payload" || key == "aps" || key == "policy")
                {
                    throw new Exception("You don't need to set value for " + key + " , just set values for the sub keys in it.");
                }
                else
                {
                    throw new Exception("Unknownd key: " + key);
                }
            }

            return(true);
        }
예제 #13
0
        /// <summary>
        /// 设置预定义的值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool SetPredefinedKeyValue(string key, object value)
        {
            var val = JToken.FromObject(value);

            if (ROOT_KEYS.Contains(key))
            {
                RootJson.Add(key, val);
            }
            else if (PAYLOAD_KEYS.Contains(key))
            {
                JObject payloadJson = null;
                if (RootJson.ContainsKey("payload"))
                {
                    payloadJson = RootJson.Value <JObject>("payload");
                }
                else
                {
                    payloadJson = new JObject();
                    RootJson.Add("payload", payloadJson);
                }
                payloadJson.Add(key, val);
            }
            else if (BODY_KEYS.Contains(key))
            {
                JObject bodyJson    = null;
                JObject payloadJson = null;
                //
                if (RootJson.ContainsKey("payload"))
                {
                    payloadJson = RootJson.Value <JObject>("payload");
                }
                else
                {
                    payloadJson = new JObject();
                    RootJson.Add("payload", payloadJson);
                }
                if (payloadJson.ContainsKey("body"))
                {
                    bodyJson = payloadJson.Value <JObject>("body");
                }
                else
                {
                    bodyJson = new JObject();
                    payloadJson.Add("body", bodyJson);
                }
                bodyJson.Add(key, val);
            }
            else if (POLICY_KEYS.Contains(key))
            {
                JObject policyJson = null;
                if (RootJson.ContainsKey("policy"))
                {
                    policyJson = RootJson.Value <JObject>("policy");
                }
                else
                {
                    policyJson = new JObject();
                    RootJson.Add("policy", policyJson);
                }
                policyJson.Add(key, val);
            }
            else
            {
                if (key == "payload" || key == "body" || key == "policy" || key == "extra")
                {
                    throw new Exception("没有添加 " + key + " , 到HashSet集合");
                }
                else
                {
                    throw new Exception("未知的 key: " + key);
                }
            }
            return(true);
        }
예제 #14
0
        /// <summary>
        /// Set key/value in the RootJson, for the keys can be set please see RootKeys, PayloadKeys,
        /// BodyKeys and PolicyKeys.
        /// 设置预定义的key/value
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public sealed override bool SetPredefinedKeyValue(string key, object value)
        {
            if (RootKeys.Contains(key))
            {
                // This key should be in the root level
                RootJson.Add(key, JToken.FromObject(value));
            }
            else if (PayloadKeys.Contains(key))
            {
                // This key should be in the payload level
                JObject payloadJson = null;

                if (RootJson.Properties().Any(p => p.Name == "payload"))
                {
                    payloadJson = RootJson.GetValue("payload").ToObject <JObject>();
                }
                else
                {
                    payloadJson = new JObject();
                    RootJson.Add("payload", payloadJson);
                }
                payloadJson.Add(key, JToken.FromObject(value));
                //需要重新赋值,否则值设置不上
                RootJson.Property("payload").Value = payloadJson;
            }
            else if (BodyKeys.Contains(key))
            {
                // This key should be in the body level
                JObject bodyJson    = null;
                JObject payloadJson = null;
                // 'body' is under 'payload', so build a payload if it doesn't exist
                if (RootJson.Properties().Any(p => p.Name == "payload"))
                {
                    payloadJson = RootJson.Property("payload").Value.ToObject <JObject>();
                }
                else
                {
                    payloadJson = new JObject();
                    RootJson.Add("payload", payloadJson);
                }
                // Get body JSONObject, generate one if not existed
                if (payloadJson.Properties().Any(p => p.Name == "body"))
                {
                    bodyJson = payloadJson.GetValue("body").ToObject <JObject>();
                }
                else
                {
                    bodyJson = new JObject();
                    payloadJson.Add("body", bodyJson);
                }
                bodyJson.Add(key, JToken.FromObject(value));
                //需要重新赋值,否则值设置不上
                payloadJson.Property("body").Value = bodyJson;
                RootJson.Property("payload").Value = payloadJson;
            }
            else if (PolicyKeys.Contains(key))
            {
                // This key should be in the body level
                JObject policyJson = null;
                if (RootJson.Properties().Any(p => p.Name == "policy"))
                {
                    policyJson = RootJson.Property("policy").Value.ToObject <JObject>();
                }
                else
                {
                    policyJson = new JObject();
                    RootJson.Add("policy", policyJson);
                }
                policyJson.Add(key, JToken.FromObject(value));
                //需要重新赋值,否则值设置不上
                RootJson.Property("policy").Value = policyJson;
            }
            else
            {
                if (key == "payload" || key == "body" || key == "policy" || key == "extra")
                {
                    throw new Exception("You don't need to set value for " + key + " , just set values for the sub keys in it.");
                }
                else
                {
                    throw new Exception("Unknown key: " + key);
                }
            }
            return(true);
        }
예제 #15
0
        public async Task IntencaoFilmeSerie(IDialogContext context, LuisResult result)
        {
            var    filme_serie = result.Entities?.Select(e => e.Entity);
            string filtro      = String.Join(" ", filme_serie.ToArray());
            string retorno     = "";

            if (filtro.Equals(""))
            {
                if (result.Query.Contains("filmes") || result.Query.Contains("series") || result.Query.Contains("séries"))
                {
                    retorno = "Entendi que você quer saber sobre filmes ou séries, mas qual seria o filme ou série ?";
                }
                else if (result.Query.Contains("filme") || result.Query.Contains("serie") || result.Query.Contains("série"))
                {
                    retorno = "Não encontrei esse filme ou série na nossa base dados ...";
                }
                else
                {
                    retorno = "Fale mais um pouco sobre o filme ou série que procura ...";
                }

                await context.PostAsync(retorno);

                context.Done <string>(null);
                return;
            }

            string parameters = $"api_key={ConfigurationManager.AppSettings["ApiKeyTMDB"]}&query={filtro}";

            string urlEndpoint = ConfigurationManager.AppSettings["EndpointTheMovieDB"] + $"{parameters}";

            await context.PostAsync("Aguarde um momento, estou consultando sobre filmes e séries ...");

            using (var client = new HttpClient())
            {
                var response = await client.GetAsync(urlEndpoint);

                if (!response.IsSuccessStatusCode)
                {
                    await context.PostAsync("Ocorreu algum erro... tente novamente mais tarde");

                    return;
                }
                else
                {
                    var json = await response.Content.ReadAsStringAsync();

                    RootJson resultado = JsonConvert.DeserializeObject <RootJson>(json);

                    if (resultado.TotalResults == 0)
                    {
                        await context.PostAsync("Não encontrei esse filme ou série na nossa base dados ...");
                    }
                    else
                    {
                        var filmes_series = resultado.Results;

                        var activity = (Activity)context.Activity;
                        var message  = activity.CreateReply();

                        foreach (Results element in filmes_series)
                        {
                            string urlImage = ConfigurationManager.AppSettings["EndpointImagemTMDB"] + element.PosterPath;
                            var    heroCard = CreateHeroCard(element.Title, element.ReleaseDate, urlImage);
                            message.Attachments.Add(heroCard.ToAttachment());
                        }

                        await context.PostAsync(message);
                    }
                }

                return;
            }
        }
예제 #16
0
        private void Form1_Load(object sender, EventArgs e)
        {
            FactoryPaciente _FactoryPaciente = new FactoryPaciente();

            CulturaInfo();
            Text = Application.ProductName;
            this.toolStripStatusFecha.Text = DateTime.Now.ToString();

            String   datos      = File.ReadAllText("../../JSON/datos.json");
            RootJson oDatosJSON = JSONGenericObject <RootJson> .JSonToObject(datos);

            foreach (var item in oDatosJSON.Lista)
            {
                Paciente oPaciente = null;

                if (item.Sexo.Equals("h", StringComparison.InvariantCultureIgnoreCase))
                {
                    //creo un hombre
                    oPaciente      = _FactoryPaciente.CreatePaciente(Sexo.Hombre);
                    oPaciente.Sexo = "Hombre";
                    //precion alta
                    if (item.Sexo.Equals("s", StringComparison.InvariantCultureIgnoreCase))
                    {
                        (oPaciente as IPresionAlta).PrecionAlta = true;
                    }
                    else
                    {
                        (oPaciente as IPresionAlta).PrecionAlta = false;
                    }
                }

                if (item.Sexo.Equals("m", StringComparison.InvariantCultureIgnoreCase))
                {
                    //creo a una mujer
                    oPaciente      = _FactoryPaciente.CreatePaciente(Sexo.Mujer);
                    oPaciente.Sexo = "Mujer";
                    //Embarazo
                    if (item.Sexo.Equals("s", StringComparison.InvariantCultureIgnoreCase))
                    {
                        (oPaciente as IEmbarazada).IsEmbrazada = true;
                    }
                    else
                    {
                        (oPaciente as IEmbarazada).IsEmbrazada = false;
                    }
                }

                oPaciente.Nombre          = item.Nombre;
                oPaciente.Apellidos       = item.Apellidos;
                oPaciente.FechaNacimiento = DateTime.Parse(item.FechaNacimiento);

                Muestra muestra = new Muestra();
                muestra.ARN            = item.ARN;
                muestra.MatrixProteina = Array.ConvertAll(item.MatrixProteina.Split(','), s => int.Parse(s));
                oPaciente._Muestra     = muestra;

                _Gestor.AddPaciente(oPaciente);
            }
            this.dataGridView1.AutoGenerateColumns = true;
            this.dataGridView1.DataSource          = oDatosJSON.Lista;
        }