예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var user = "******";
            var pwd  = "7c222fb2927d828af22f592134e8932480637c0d";
            //NameValueCollection nv = new NameValueCollection();
            //nv.Add("guia", "WYB6146112");
            //nv.Add("docref", "0");
            //nv.Add("vp_linea", "3");
            //var qry = ToQueryString(nv);
            //var client = new RestClient("https://app.urbano.com.ec/ws/ue/tracking/");
            //client.BaseUrl = new Uri("https://app.urbano.com.ec/ws/ue/tracking/?");
            ////client.Authenticator= new SimpleAuthenticator("user", user, "pass", pwd);
            //var request = new RestRequest(Method.GET);
            //request.AddHeader("content-type","application/x-www-form-urlencoded");
            //request.AddHeader("user",user);
            //request.AddHeader("pass",pwd);
            //request.RequestFormat = DataFormat.Json;

            var obj = new Lad
            {
                guia     = "WYB6146112",
                docref   = "0",
                vp_linea = "3"
            };
            var json = new JavaScriptSerializer().Serialize(obj);
            //request.AddBody(json);
            //IRestResponse response = client.Execute(request);
            var content = response.Content; // raw content as string
        }
예제 #2
0
    static void Main()
    {
        var obj = new Lad
        {
            EndPoint  = "Hardship",
            TestCase  = "Employment",
            SampleArr = new List <TestMethods>()
            {
                new TestMethods
                {
                    id   = "1",
                    Name = "Test Method Name"
                },
                new TestMethods
                {
                    id   = "2",
                    Name = "Test Method Sample 2"
                }
            }
        };

        var json = new JavaScriptSerializer().Serialize(obj);

        using (var sw = new StreamWriter())
        {
        }


        Console.WriteLine(json);
        Console.ReadLine();
    }
 static void Main()
 {
     var lad = new Lad
     {
         FirstName = "Markoff",
         LastName = "Chaney",
         DateOfBirth = new MyDate
         {
             year = 1901,
             month = 4,
             day = 30
         }
     };
     var json = JsonSerializer.Serialize(lad);
     Console.WriteLine(json);
 }
예제 #4
0
 private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         Range[] arr  = S.Get();
         int     size = arr.Length;
         if (size == 0)
         {
             MessageBox.Show("Nothing to save.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         toolStripStatusLabel1.Text = "Saving file...";
         saveFileDialog1.Filter     = "JSON File|*.json";
         saveFileDialog1.Title      = "Save File";
         saveFileDialog1.FileName   = "file1.json";
         DialogResult result = saveFileDialog1.ShowDialog();
         if (result == DialogResult.OK)
         {
             fileStream   = new FileStream(saveFileDialog1.FileName, FileMode.Create);
             streamWriter = new StreamWriter(fileStream);
             try
             {
                 Lad[] product = new Lad[size];
                 for (int i = 0; i < size; i++)
                 {
                     product[i]   = new Lad();
                     product[i].A = arr[i].ToString().Split(':')[0].ToString();
                     product[i].B = arr[i].ToString().Split(':')[1].ToString();
                 }
                 string output = JsonConvert.SerializeObject(product);
                 streamWriter.Write(output);
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             streamWriter.Close();
             fileStream.Close();
             toolStripStatusLabel1.Text = "Save file: " + saveFileDialog1.FileName;
         }
         else
         {
             toolStripStatusLabel1.Text = "Saving canceled";
         }
     }
     catch (Exception) { }
 }
    static void Main()
    {
        var obj = new Lad
        {
            firstName   = "Markoff",
            lastName    = "Chaney",
            dateOfBirth = new MyDate
            {
                year  = 1901,
                month = 4,
                day   = 30
            }
        };
        var json = new JavaScriptSerializer().Serialize(obj);

        Console.WriteLine(json);
    }
예제 #6
0
    static void Main()
    {
        var obj = new Lad
        {
            firstName   = "RICHARAAAADDDAAAAAXBRUCE",
            lastName    = "GAZEY",
            dateOfBirth = new MyDate
            {
                year  = 1911,
                month = 5,
                day   = 30
            }
        };
        //var json = new JsonSerializer.JsonSerializer(


        // Console.WriteLine(json);



        const string  MyPassword           = "******";
        const string  MyConnectioNTiemout  = "connection timeout=15";
        const string  MyTruestedConnection = "Trusted_Connection=yes;";
        const string  MyUSerid             = "user id=sa;";
        const string  MyDatabase           = "database=TestCSharp; ";
        SqlConnection myConnection         = new SqlConnection(MyUSerid +
                                                               MyPassword +
                                                               MyTruestedConnection +
                                                               MyDatabase +
                                                               MyConnectioNTiemout);



        try
        {
            myConnection.Open();

            SqlCommand myCommand = new SqlCommand("INSERT INTO Person (FirstName, LastName) " +
                                                  "Values ('Bob', 'Bobby')", myConnection);

            myCommand.ExecuteNonQuery();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }


        try
        {
            SqlDataReader myReader  = null;
            SqlCommand    myCommand = new SqlCommand("select * from Person",
                                                     myConnection);
            myReader = myCommand.ExecuteReader();
            int v_loop = 0;
            System.IO.File.WriteAllText(@"C:\Ab Initio\WriteLines.txt", "FirstName1,LastName" + "\r\n");
            while (myReader.Read())
            {
                //      Console.WriteLine(myReader["FirstName"].ToString());
                //      Console.WriteLine(myReader["LastName"].ToString());

                string TrimString = myReader["FirstName"].ToString().Trim();
                System.Threading.Thread.Sleep(300);
                v_loop += 1;
                string LoopString = v_loop.ToString();

                System.IO.File.AppendAllText(@"C:\Ab Initio\WriteLines.txt",
                                             myReader["FirstName"].ToString().Trim() + "," + LoopString + "," + myReader["LastName"].ToString().Trim() + "\r\n");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
    }
예제 #7
0
        public ActionResult Monitoring(int id)
        {
            string cpu, ram;
            string con = @"Server=tcp:diplom.database.windows.net,1433;Database=diploma;User ID=ivan@diplom;Password=Balonka1;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
            using (SqlConnection myConnection = new SqlConnection(con))
            {
                myConnection.Open();
                string oString1 = "SELECT [CPUValue]  FROM [dbo].[CPU] WHERE [CPUCounterID]=" + id;
                string oString2 = "SELECT [RAMValue]  FROM [dbo].[RAM] WHERE [RAMCounterID]=" + id;

                SqlCommand oCmd1 = new SqlCommand(oString1, myConnection);
                SqlCommand oCmd2 = new SqlCommand(oString2, myConnection);
                cpu = oCmd1.ExecuteScalar().ToString();
                ram = oCmd2.ExecuteScalar().ToString();
                myConnection.Close();
                myConnection.Dispose();
            }

            var obj = new Lad
            {
                CPU = cpu,
                RAM = ram,
            };
            var json = new JavaScriptSerializer().Serialize(obj);

            return Content(json);
        }
예제 #8
0
        static void Main(string[] args)
        {
            var obj = new Lad
            {
                firstName = "Markoff",
                lastName  = "Chaney"
            };

            Lad lad1 = (Lad)obj;

            var options1 = new JsonSerializerOptions
            {
                WriteIndented = true,
            };



            //var json = new
            //Console.WriteLine(json);



            // Basic OBject
            Product product = new Product();

            product.Name       = "Apple";
            product.ExpiryDate = new DateTime(2008, 12, 28);
            product.Price      = 3.99M;
            product.Sizes      = new string[] { "Small", "Medium", "Large" };

            var options = new JsonSerializerOptions
            {
                WriteIndented = true,
            };

            //var json = new JsonSerializer();
            ////Console.WriteLine(json);

            string output = JsonSerializer.Serialize(product, options);

            Console.WriteLine(output);

            Product deserializedProduct = JsonSerializer.Deserialize <Product>(output);


            Employee     emp     = new Employee();
            EmployeeData empData = new EmployeeData();

            emp = empData.EmployeeDataOps();

            string JSONresult = JsonSerializer.Serialize(emp);

            string path = @"C:\_Angela\_GIT_CSharp\MiscTextFiles\employee.json";

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            using (var tw = new StreamWriter(path, true))
            {
                tw.WriteLine(JSONresult.ToString());
                tw.Close();
            }

            string[] subjectsTaken = new string[4] {
                "Biology", "Maths", "History", "Chemistry"
            };

            Student stu = new Student();

            stu.Name     = "Andrew Hill";
            stu.Class    = 345;
            stu.RollNo   = 100345;
            stu.Subjects = subjectsTaken;

            JSONresult = JsonSerializer.Serialize(stu);

            path = @"C:\_Angela\_GIT_CSharp\MiscTextFiles\student.json";

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            using (var tw = new StreamWriter(path, true))
            {
                tw.WriteLine(JSONresult.ToString());
                tw.Close();
            }
        }