示例#1
0
        public JsonResult GetGeoDetails(string PinCode)
        {
            GEO       obj   = new GEO();
            BALCommon CScmn = new BALCommon(ConStr);

            try
            {
                obj = CScmn.GetGeoDetails(PinCode);
            }
            catch (Exception ex)
            {
                ExecptionLogger.FileHandling("Fee(GetGeoDetails)", "Error_014", ex, "Fee");
            }
            finally
            {
            }
            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        //SaveJSON  - Сохраняем настройки в файл JSON (Сереализация)
        public static void SaveJSON(string url1, string user1, string dev1)
        // public async Task SaveJSON(string url1, string user1, string dev1)
        {
            GEO initgeo = new GEO();

            initgeo.url0          = url1;
            initgeo.NameUser      = user1;
            initgeo.geonamedevice = dev1;

            string initjson = JsonConvert.SerializeObject(initgeo);

            //string path = @"settings.conf";
            // тут происходит неведомая хрень по выделению места под файл geosetting.conf
            var geogenmobpath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "geosettings.conf");

            using (var conf = File.CreateText(geogenmobpath))
            {
                conf.WriteLine(initjson);
            }
        }
示例#3
0
        private static void initURL()
        {
            GEO initgeo = new GEO();

            Console.Write("Адрес сервера: ");
            initgeo.url0 = Console.ReadLine();
            Console.Write("Пользователь: ");
            initgeo.nameID = Console.ReadLine();
            Console.Write("Устройство: ");
            initgeo.geonamedevice = Console.ReadLine();

            string initjson = JsonConvert.SerializeObject(initgeo);

            Console.WriteLine("initJSON: {0}", initjson);

            string path = @"settings.conf";

            using (StreamWriter conf = File.CreateText(path))
            {
                //conf.WriteLine("url0*" + url);
                //conf.WriteLine("user0*" + user+"*dev0*"+dev);
                conf.WriteLine(initjson);
            }
        }
示例#4
0
        //Десериализуем полученную строку из файла JSON и
        // отправляем на сервер

        // public static void SendGEO(object n)
        public static async Task SendGEO(object n)
        {
            try
            {
                DateTime localDate = DateTime.Now;  //получаем время
                // Random rnd = new Random();
                //string url = "https://localhost:44359/home/inputgeoJSON";
                //string url = "http://random-red.ddns.net:62424/home/inputgeoJSON";
                string jsonstr = printJSON();
                GEO    testgeo = JsonConvert.DeserializeObject <GEO>(jsonstr);

                GeoCoordinates GCcore = new GeoCoordinates();
                await GCcore.InitGeoCoordinates();

                int n1 = int.Parse(n.ToString()); //перобразовываем из n - object в n1 int
                                                  //try
                                                  //{
                                                  //GeoCoordinates GCcore = new GeoCoordinates();
                for (int i = 0; i < n1; i++)
                {
                    //Thread.Sleep(2000);
                    Thread.Sleep(1000); //ждём одну секунду

                    await GCcore.InitGeoCoordinates();

                    testgeo.LatitudeX  = GCcore.printXGeoCoordinates();
                    testgeo.LongitudeY = GCcore.printYGeoCoordinates();
                    testgeo.geoDT      = localDate.ToString("dd.MM.yyyy");
                    testgeo.geoTM      = localDate.ToString("HH:mm:ss");

                    string json = JsonConvert.SerializeObject(testgeo);

                    var httpRequest = (HttpWebRequest)WebRequest.Create(testgeo.url0);
                    httpRequest.Method      = "POST";
                    httpRequest.ContentType = "application/json";
                    using (var requestStream = httpRequest.GetRequestStream())
                        using (var writer = new StreamWriter(requestStream))
                        {
                            writer.Write(json);
                        }
                    using (var httpResponse = httpRequest.GetResponse())
                        using (var responseStream = httpResponse.GetResponseStream())
                            using (var reader = new StreamReader(responseStream))
                            {
                                string response = reader.ReadToEnd();
                            }
                    //await GCcore.InitGeoCoordinates();
                }
            }
            catch (WebException e)
            {
                var geogenlogpath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "geogen.log");
                using (var log = File.CreateText(geogenlogpath))
                {
                    log.WriteLine(e);
                }

                //using (StreamWriter log = File.CreateText(pathlog))
                //{
                //    log.WriteLine(e);
                //    log.WriteLine("-----");
                //}
                // Console.WriteLine(e); //показываем ошибку
                //Console.WriteLine("");
            }
            //Console.WriteLine("===>OK<===");
        }
示例#5
0
        public static void SendGEO(object n)
        {
            Random rnd = new Random();
            //GEO testgeo = new GEO();

            //string url = "https://localhost:44359/home/inputgeoJSON";
            //string url = "http://random-red.ddns.net:62424/home/inputgeoJSON";
            //string url = printURL();
            string jsonstr = printJSON();
            GEO    testgeo = JsonConvert.DeserializeObject <GEO>(jsonstr);

            //Console.WriteLine("url : {0}", url);
            Console.WriteLine("url: {0}", testgeo.url0);
            Console.WriteLine("name: {0}", testgeo.nameID);
            Console.WriteLine("dev: {0}", testgeo.geonamedevice);



            // testgeo.nameID = "GeoGenTest";
            // testgeo.geonamedevice = "devGGT";

            int n1 = int.Parse(n.ToString()); //перобразовываем из n - object в n1 int

            try
            {
                for (int i = 0; i < n1; i++)
                {
                    //testgeo.nameID = "GeoGenTest";
                    //testgeo.nameID = "GeoGenTest";
                    //testgeo.geonamedevice = "devGGT";
                    //testgeo.X=78.12;
                    testgeo.X = rnd.Next(99) /*+rnd.NextDouble()*/;
                    //testgeo.Y = 980.12;
                    testgeo.Y = rnd.Next(99) /*+rnd.NextDouble()*/;

                    string json = JsonConvert.SerializeObject(testgeo);
                    Console.WriteLine("JSON: {0}", json);

                    var httpRequest = (HttpWebRequest)WebRequest.Create(testgeo.url0);
                    httpRequest.Method      = "POST";
                    httpRequest.ContentType = "application/json";
                    using (var requestStream = httpRequest.GetRequestStream())
                        using (var writer = new StreamWriter(requestStream))
                        {
                            writer.Write(json);
                        }
                    using (var httpResponse = httpRequest.GetResponse())
                        using (var responseStream = httpResponse.GetResponseStream())
                            using (var reader = new StreamReader(responseStream))
                            {
                                string response = reader.ReadToEnd();
                            }
                }
            }
            catch (WebException e)
            {
                Console.WriteLine(e); //показываем ошибку
                Console.WriteLine("");
            }
            Console.WriteLine("===>OK<===");
        }
示例#6
0
        /// <summary>
        /// Method used to add a property to the instance. Will be placed in the correct class Property.
        /// </summary>
        /// <param name="input">The vCard.Property to add.</param>
        public void AddProperty(Props.IProperty input)
        {
            if (input == null || input.IsValueNull)
            {
                return;
            }

            switch (input.Property)
            {
            case KnownProperties.ADR:
                ADR.AddIfNotNull(input as Props.ADR);
                break;

            case KnownProperties.ANNIVERSARY:
                ANNIVERSARY = input as Props.ANNIVERSARY;
                break;

            case KnownProperties.BDAY:
                BDAY = input as Props.BDAY;
                break;

            case KnownProperties.CALADRURI:
                CALADRURI.AddIfNotNull(input as Props.CALADRURI);
                break;

            case KnownProperties.CALURI:
                CALURI.AddIfNotNull(input as Props.CALURI);
                break;

            case KnownProperties.CATEGORIES:
                CATEGORIES.AddIfNotNull(input as Props.CATEGORIES);
                break;

            case KnownProperties.CLIENTPIDMAP:
                CLIENTPIDMAP.AddIfNotNull(input as Props.CLIENTPIDMAP);
                break;

            case KnownProperties.EMAIL:
                EMAIL.AddIfNotNull(input as Props.EMAIL);
                break;

            case KnownProperties.FBURL:
                FBURL.AddIfNotNull(input as Props.FBURL);
                break;

            case KnownProperties.FN:
                FN.AddIfNotNull(input as Props.FN);
                break;

            case KnownProperties.GENDER:
                GENDER = input as Props.GENDER;
                break;

            case KnownProperties.GEO:
                GEO.AddIfNotNull(input as Props.GEO);
                break;

            case KnownProperties.IMPP:
                IMPP.AddIfNotNull(input as Props.IMPP);
                break;

            case KnownProperties.KEY:
                KEY.AddIfNotNull(input as Props.KEY);
                break;

            case KnownProperties.KIND: {
                char k = (input as Props.KIND).Value.ToLower()[0];
                if (k == 'i')
                {
                    KIND = Kinds.Individual;
                }
                else if (k == 'g')
                {
                    KIND = Kinds.Group;
                }
                else if (k == 'o')
                {
                    KIND = Kinds.Org;
                }
                else if (k == 'l')
                {
                    KIND = Kinds.Location;
                }
                else
                {
                    KIND = Kinds.Individual;
                }
                break;
            }

            case KnownProperties.LANG:
                LANG.AddIfNotNull(input as Props.LANG);
                break;

            case KnownProperties.LOGO:
                LOGO.AddIfNotNull(input as Props.LOGO);
                break;

            case KnownProperties.MEMBER:
                MEMBER.AddIfNotNull(input as Props.MEMBER);
                break;

            case KnownProperties.N:
                N = input as Props.N;
                break;

            case KnownProperties.NICKNAME:
                NICKNAME.AddIfNotNull(input as Props.NICKNAME);
                break;

            case KnownProperties.NOTE:
                NOTE.AddIfNotNull(input as Props.NOTE);
                break;

            case KnownProperties.ORG:
                ORG.AddIfNotNull(input as Props.ORG);
                break;

            case KnownProperties.PHOTO:
                PHOTO.AddIfNotNull(input as Props.PHOTO);
                break;

            case KnownProperties.PRODID:
                PRODID = input as Props.PRODID;
                break;

            case KnownProperties.RELATED:
                RELATED.AddIfNotNull(input as Props.RELATED);
                break;

            case KnownProperties.REV:
                REV = input as Props.REV;
                break;

            case KnownProperties.ROLE:
                ROLE.AddIfNotNull(input as Props.ROLE);
                break;

            case KnownProperties.SOUND:
                SOUND.AddIfNotNull(input as Props.SOUND);
                break;

            case KnownProperties.SOURCE:
                SOURCE.AddIfNotNull(input as Props.SOURCE);
                break;

            case KnownProperties.TEL:
                TEL.AddIfNotNull(input as Props.TEL);
                break;

            case KnownProperties.TITLE:
                TITLE.AddIfNotNull(input as Props.TITLE);
                break;

            case KnownProperties.TZ:
                TZ.AddIfNotNull(input as Props.TZ);
                break;

            case KnownProperties.UID:
                UID = input as Props.UID;
                break;

            case KnownProperties.URL:
                URL.AddIfNotNull(input as Props.URL);
                break;

            case KnownProperties.VERSION:
                VERSION = input as Props.VERSION;
                break;

            case KnownProperties.XML:
                XML.AddIfNotNull(input as Props.XML);
                break;

            default:
                return;
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start HTTP request");

            string url = "https://localhost:44359/home/inputgeoJSON";

            Console.WriteLine("url : {0}", url);

            Console.Write("Количество отправлений ===> ");
            int n = int.Parse(Console.ReadLine());

            Random rnd = new Random();

            for (int i = 0; i <= n; i++)
            {
                GEO testgeo = new GEO();


                testgeo.nameID        = "test00";
                testgeo.geonamedevice = "dev00";
                //testgeo.X=78.12;
                testgeo.X = rnd.Next(99);
                //testgeo.Y = 980.12;
                testgeo.Y = rnd.Next(99);

                //MemoryStream stream1 = new MemoryStream();
                //DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(GEO));
                //ser.WriteObject(stream1, testgeo);

                string json = "{"
                              + "\""
                              + "nameID"
                              + "\""
                              + ": "
                              + "\""
                              + testgeo.nameID
                              + "\""
                              + ","
                              + "\""
                              + "geonamedevice"
                              + "\""
                              + ": "
                              + "\""
                              + testgeo.geonamedevice
                              + "\""
                              + ","
                              + "\""
                              + "X"
                              + "\""
                              + ": "
                              + "\""
                              + Convert.ToString(testgeo.X)
                              + "\""
                              + ","
                              + "\""
                              + "Y"
                              + "\""
                              + ": "
                              + "\""
                              + Convert.ToString(testgeo.Y)
                              + "\""
                              + "}";

                Console.WriteLine("JSON: {0}", json);

                var httpRequest = (HttpWebRequest)WebRequest.Create(url);
                httpRequest.Method      = "POST";
                httpRequest.ContentType = "application/json";
                using (var requestStream = httpRequest.GetRequestStream())
                    using (var writer = new StreamWriter(requestStream))
                    {
                        writer.Write(json);
                    }
                using (var httpResponse = httpRequest.GetResponse())
                    using (var responseStream = httpResponse.GetResponseStream())
                        using (var reader = new StreamReader(responseStream))
                        {
                            string response = reader.ReadToEnd();
                        }
            }
            Console.WriteLine("===>OK<===");
            Console.ReadLine();
        }