コード例 #1
0
        private void Delete_OnClicked(object sender)
        {
            MainStack.IsVisible = false;
            Indicator.IsRunning = true;
            Indicator.IsVisible = true;

            var mysched   = sender as MySchedule;
            var colection = SchedulesListView.ItemsSource as ObservableCollection <MySchedule>;

            colection.Remove(mysched);
            var    b64string   = _helper.SerializeSchedule(colection);
            string setSchedule = "SetSchedule {\"MAC\":" +
                                 p.Mac + ",\"Number\":0" +
                                 ",\"Schedule\":{\"Events\":\"" + b64string + "\"" +
                                 ",\"Scope\":0,\"Resolution\":2}}";

            connection.Send(setSchedule);
        }
コード例 #2
0
        private string SerializeScheduleLocally()
        {
            bool[] quarters    = new bool[96 * 7];
            var    fromQt      = (int)FromSlider.Value;
            var    toQt        = (int)ToSlider.Value;
            var    daysChecked = new bool[7];

            //Delete previous scheule from server
            if (IsOnPreviousState)
            {
                var schlist = plug.MyPlugState.MyScheduleList;
                schlist.RemoveAt(_index);
                var    b64string   = Helper.SerializeSchedule(schlist);
                string setSchedule = "SetSchedule {\"MAC\":" +
                                     plug.Mac + ",\"Number\":0" +
                                     ",\"Schedule\":{\"Events\":\"" + b64string + "\"" +
                                     ",\"Scope\":0,\"Resolution\":2}}";
                connection.Send(setSchedule);
            }


            //set new Schedule
            var events = Helper.SerializeSchedule(plug.MyPlugState.MyScheduleList);

            quarters = Helper.StringToQuartersDesirialize(events);



            daysChecked[0] = SatSwitch.IsToggled;
            daysChecked[1] = SunSwitch.IsToggled;
            daysChecked[2] = MonSwitch.IsToggled;
            daysChecked[3] = TueSwitch.IsToggled;
            daysChecked[4] = WedSwitch.IsToggled;
            daysChecked[5] = ThuSwitch.IsToggled;
            daysChecked[6] = FriSwitch.IsToggled;



            if (toQt <= 96)
            {
                for (var d = 0; d < daysChecked.Length; d++)
                {
                    if (daysChecked[d])
                    {
                        for (var k = fromQt; k < toQt; k++)
                        {
                            quarters[k + (d * 96)] = true;
                        }
                    }
                }
            }



            var bits = new BitArray(quarters);

            var bytes = new List <byte>();

            var currentbyte = 0x00;

            for (int i = 0; i < bits.Length;)
            {
                currentbyte = 0x00;
                for (int j = 0; j < 8 && i < bits.Length; j++, i++)
                {
                    if (bits[i])
                    {
                        currentbyte |= (0x80 >> (i % 8));
                    }
                }
                bytes.Add((byte)currentbyte);
            }



            var b64String = Convert.ToBase64String(bytes.ToArray());

            return(b64String);
        }