Example #1
0
        int AddTempRecord(JObject input)
        {
            TempRecord tempRecord   = new TempRecord();
            var        tempHexBytes = input.SelectToken("payload_hex").ToString().Substring(12);

            tempRecord.temperature = Convert.ToInt32(tempHexBytes, 16) / 10;
            tempRecord.location    = "Källbergsgatan 3";
            DateTime date = DateTime.UtcNow;

            date            = date.AddHours(2);
            tempRecord.time = date.ToString("dd/MM/yyyy HH:mm:ss");

            SqlConnection sqlConnection = new SqlConnection("Data Source=smartlakes.cnhjmr9oh4re.us-east-2.rds.amazonaws.com;Initial Catalog=SmartLakes;Integrated Security=False;User ID=SmartLakesNFK;Password=NFKsmartlakes;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            string        query         = "INSERT INTO TempRecords VALUES(@temperature, @location, @time)";

            using (SqlCommand command = new SqlCommand(query, sqlConnection))
            {
                command.Parameters.Add("@temperature", SqlDbType.Float).Value = tempRecord.temperature;
                command.Parameters.Add("@location", SqlDbType.VarChar).Value  = tempRecord.location;
                command.Parameters.Add("@time", SqlDbType.VarChar).Value      = tempRecord.time;
                command.Connection.Open();
                int rowsAffected = command.ExecuteNonQuery();
                command.Connection.Close();
                return(rowsAffected);
            }
        }
Example #2
0
        static void Main()
        {
            var tempRecord = new TempRecord();

            tempRecord[3] = 58.3F;

            for (int i = 0; i < tempRecord.Length; i++)
            {
                Console.WriteLine($"Element #{i} = {tempRecord[i]}");
            }
        }
        static void Main(string[] args)
        {
            TempRecord tempRecord = new TempRecord();

            float temp1 = tempRecord[5];       //Simplified syntax + purpose more intuitive.
            float temp2 = tempRecord.temps[1]; //Weird to read, as we already know tempRecord has temperatures.

            Console.WriteLine(temp1);
            Console.WriteLine(temp2);

            Console.ReadLine();
        }
        public void ShouldDumpObjectWithIndexer_IntegerArray_IgnoredByDefaultDumpOptions()
        {
            // Arrange
            var tempRecord = new TempRecord
            {
                [0] = 58.3f,
                [1] = 60.1f,
            };

            // Act
            var dump = ObjectDumperCSharp.Dump(tempRecord);

            // Assert
            this.testOutputHelper.WriteLine(dump);
            dump.Should().NotBeNull();
            dump.Should().Be("var tempRecord = new TempRecord\r\n{\r\n  AProp = 0,\r\n  ZProp = null\r\n};");
        }
    static void Main()
    {
        TempRecord tempRecord = new TempRecord();
        // Use the indexer's set accessor
        tempRecord[3] = 58.3F;
        tempRecord[5] = 60.1F;

        // Use the indexer's get accessor
        for (int i = 0; i < 10; i++)
        {
            System.Console.WriteLine("Element #{0} = {1}", i, tempRecord[i]);
        }

        // Keep the console window open in debug mode.
        System.Console.WriteLine("Press any key to exit.");
        System.Console.ReadKey();
    }
Example #6
0
    static void Main()
    {
        TempRecord tempRecord = new TempRecord();

        // Use the indexer's set accessor
        tempRecord[3] = 58.3F;
        tempRecord[5] = 60.1F;

        // Use the indexer's get accessor
        for (int i = 0; i < 10; i++)
        {
            System.Console.WriteLine("Element #{0} = {1}", i, tempRecord[i]);
        }

        // Keep the console window open in debug mode.
        System.Console.WriteLine("Press any key to exit.");
        System.Console.ReadKey();
    }
Example #7
0
    static void Main()
    {
        var tempRecord = new TempRecord();

        // Use the indexer's set accessor
        tempRecord[3] = 58.3F;
        tempRecord[5] = 60.1F;

        // Use the indexer's get accessor
        for (int i = 0; i < 10; i++)
        {
            Console.WriteLine($"Element #{i} = {tempRecord[i]}");
        }

        // Keep the console window open in debug mode.
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
        public void ShouldDumpObjectWithIndexer_IntegerArray()
        {
            // Arrange
            var tempRecord = new TempRecord
            {
                AProp = 99,
                [0]   = 58.3f,
                [1]   = 60.1f,
                ZProp = "ZZ"
            };

            var dumpOptions = new DumpOptions
            {
                IgnoreIndexers = false
            };

            // Act
            var dump = ObjectDumperCSharp.Dump(tempRecord, dumpOptions);

            // Assert
            this.testOutputHelper.WriteLine(dump);
            dump.Should().NotBeNull();
            dump.Should().Be("var tempRecord = new TempRecord\r\n{\r\n  AProp = 99,\r\n  [0] = 58.3f,\r\n  [1] = 60.1f,\r\n  ZProp = \"ZZ\"\r\n};");
        }
Example #9
0
        static void Main(string[] args)
        {
            //Коллекция нетипизированная ОЧЕРЕДЬ
            Queue q1 = new Queue();

            q1.Enqueue("1");
            q1.Enqueue('2');
            q1.Enqueue("Three");
            q1.Enqueue(5);
            Console.WriteLine("First element: " + q1.Peek());
            Console.WriteLine("All elements: " + q1.Count);

            while (q1.Count > 0)
            {
                Console.WriteLine(q1.Dequeue());
            }

            /*
             * foreach (var item in q1)
             *  Console.WriteLine(item);
             */

            //Коллекция СТЕК
            Stack s1 = new Stack();

            s1.Push(6);
            s1.Push("2");
            s1.Push('1');
            s1.Push(3);
            Console.WriteLine("Upper element: " + s1.Peek());
            Console.WriteLine("All elements: " + s1.Count);
            //Извлечение элементов
            while (s1.Count > 0)
            {
                Console.WriteLine(" " + s1.Pop());
            }

            /*
             * //С первого элемента!
             * foreach (var item in s1)
             *  Console.WriteLine(s1.Pop());
             */

            Num n = new Num(2, 5, 9);

            foreach (var item in n)
            {
                Console.WriteLine(item);
            }

            Demo d = new Demo();

            foreach (int item in d)
            {
                Console.WriteLine(item);
            }

            TempRecord tr = new TempRecord();

            //Установка значений через индексатор
            //через set устанавливаются значения
            tr[3] = 15;
            tr[4] = 17;

            //Получение значений через индексатор
            for (int i = 0; i < tr.Length; i++)
            {
                Console.WriteLine("Element #{0} equals {1}", i, tr[i]);
            }

            //пример индексатора где индексатор принимает строку
            DemoStringIndex dm = new DemoStringIndex(5, 6);

            Console.WriteLine("{0}    {1}", dm["first"], dm["second"]);

            DemoArray a = new DemoArray(3, 3);

            for (int i = 0; i < a.LengthN; i++, Console.WriteLine())
            {
                for (int j = 0; j < a.LengthM; j++)
                {
                    a[i, j] = i * j; //использование индексаторов
                    Console.WriteLine("{0,5}", a[i, j]);
                }
            }
            Console.WriteLine();
            try
            {
                //Раскомментировать по очереди чтобы посмотреть на разные ошибки
                //Console.WriteLine(a[3, 3]);
                //a[0, 0] = 200;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Cat      fluffy   = new Cat();
            Elephant slon     = new Elephant();
            Dog      goldy    = new Dog();
            Patients SickPets = new Patients();

            SickPets.AdmitPatient(fluffy);
            SickPets.AdmitPatient(slon);
            SickPets.AdmitPatient(goldy);
            foreach (object pet in SickPets)
            {
                Console.WriteLine(pet);
            }



            Console.ReadKey();
        }