示例#1
0
        public void ChangeSwitch(Random rand, SwitchDevice switchDevice)
        {
            int index    = rand.Next(0, dictSwitches.Count);
            int idSwitch = dictSwitches.Keys.ToList()[index];

            if (!dictSwitches.ContainsKey(idSwitch))
            {
                Exception exception = new Exception("Can't add new switch");
                MessageBox.Show(exception.Message);

                return;
            }
            else
            {
                dictSwitches[idSwitch].SwitchDate = DateTime.Now.ToString();

                if (dictSwitches[idSwitch].SwitchValue == 0)
                {
                    dictSwitches[idSwitch].SwitchValue = 1;
                }
                else
                {
                    dictSwitches[idSwitch].SwitchValue = 0;
                }
            }

            switchDevice = new SwitchDevice(dictSwitches[idSwitch]);

            Console.WriteLine("ID: {0}, Value: {1}, Date: {2}", switchDevice.SwitchID, switchDevice.SwitchValue, switchDevice.SwitchDate);
            switchDAO.SaveSwitch(switchDevice);
            SendSwitch(switchDevice);

            Thread.Sleep(5000);
        }
 public static void Save(SwitchDevice switchDevice)
 {
     using (IDbConnection cnn = new SQLiteConnection(OpenConnection()))
     {
         cnn.Execute("insert into Switch (SwitchID, SwitchValue, SwitchDate) values (@SwitchID, @SwitchValue, @SwitchDate)", switchDevice);
     }
 }
示例#3
0
 public EncapsulationStage(SwitchDevice @switch, SwitchDevice crswitch, EnlaceDevice enlace, LongmenDevice longmen, params WrapDevice[] wraps)
 {
     _switch   = @switch;
     _crswitch = crswitch;
     _longmen  = longmen;
     _enlace   = enlace;
     _warps    = wraps;
 }
        static void Main(string[] args)
        {
            var device = new SwitchDevice("Test", 1234, IPAddress.Parse("192.168.2.121"), 8100);

            var upnp = new UpnpBroadcastResponder();

            upnp.AddDevice(device);

            Console.ReadLine();
        }
示例#5
0
        private static void StartRandom(AddSubscriber addSub)
        {
            Random       rand         = new Random(Guid.NewGuid().GetHashCode());
            SwitchDevice switchDevice = null;

            while (true)
            {
                addSub.ChangeSwitch(rand, switchDevice);
            }
        }
示例#6
0
 private void SendSwitch(SwitchDevice switchDevice)
 {
     foreach (var client in proxyDict.ToList())
     {
         try
         {
             client.Value.AddNewSwitch(switchDevice);
         }
         catch (Exception)
         {
         }
     }
 }
        public static bool CheckIfExists(SwitchDevice switchDevice)
        {
            if (dictSwitches.ContainsKey(switchDevice.SwitchID))
            {
                dictSwitches[switchDevice.SwitchID].SwitchValue = switchDevice.SwitchValue;
                dictSwitches[switchDevice.SwitchID].SwitchDate  = switchDevice.SwitchDate;

                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#8
0
        public void AddNewSwitch(SwitchDevice switchDevice)
        {
            bool exits = MainWindowViewModel.CheckIfExists(switchDevice);

            if (exits)
            {
                MainWindow.main.DataContext = new MainWindowViewModel();
            }
            else
            {
                Exception exception = new Exception("Can't add new switch");
                MessageBox.Show(exception.Message);

                return;
            }
        }
        public static Dictionary <int, SwitchDevice> Load()
        {
            using (IDbConnection cnn = new SQLiteConnection(OpenConnection()))
            {
                var output = cnn.Query <SwitchDevice>("select * from Switch", new DynamicParameters());
                List <SwitchDevice> switchesList = output.ToList();

                Dictionary <int, SwitchDevice> switchesOutputDict = new Dictionary <int, SwitchDevice>(switchesList.Count);

                foreach (SwitchDevice item in switchesList)
                {
                    SwitchDevice temp = null;
                    if (!switchesOutputDict.TryGetValue(item.SwitchID, out temp) || DateTime.Parse(item.SwitchDate) > DateTime.Parse(temp.SwitchDate))
                    {
                        switchesOutputDict[item.SwitchID] = item;
                    }
                }

                return(switchesOutputDict);
            }
        }
示例#10
0
 public void SaveSwitch(SwitchDevice switchDevice)
 {
     BaseAccess.Save(switchDevice);
 }
示例#11
0
        public override ModelBase CreateObjectByName(string objectName)
        {
            Board  retBoard = new Board();
            string xmlPath  = string.Format(@"{0}\{1}.xml", PathManager.GetBoardPath(), objectName);

            if (!File.Exists(xmlPath))
            {
                MessageBox.Show("CreateObject_Board:没有该Board对应的XML文件!");
                return(null);
            }
            XDocument xd = XDocument.Load(xmlPath);
            //根元素的Attribute
            XElement rt = xd.Element("Board");

            retBoard.Name    = rt.Attribute("Name").Value;
            retBoard.Type    = rt.Attribute("Type").Value;
            retBoard.Version = rt.Attribute("Version").Value;
            //找到Devices元素下的PPCs元素,添加PPC集合到类
            XElement ppcs = rt.Element("Devices").Element("PPCs");

            foreach (var element in ppcs.Elements())
            {
                retBoard.PPCList.Add(ModelFactory <PPC> .CreateByName(element.Attribute("Name").Value));
            }
            //找到Devices元素下的FPGAs元素,添加FPGA集合到类
            XElement fpgas = rt.Element("Devices").Element("FPGAs");

            foreach (var element in fpgas.Elements())
            {
                retBoard.FPGAList.Add(ModelFactory <FPGA> .CreateByName(element.Attribute("Name").Value));
            }
            //找到Devices元素下的ZYNQs元素,添加ZYNQ集合到类
            XElement zynqs = rt.Element("Devices").Element("ZYNQs");

            foreach (var element in zynqs.Elements())
            {
                retBoard.ZYNQList.Add(ModelFactory <ZYNQ> .CreateByName(element.Attribute("Name").Value));
            }
            //找到Devices元素下的Sws元素,添加Sw集合到类
            XElement sws = rt.Element("Devices").Element("Sws");

            foreach (var element in sws.Elements())
            {
                var category = (SwitchCategory)Enum.Parse(typeof(SwitchCategory), element.Attribute("Category").Value);
                var sw       = new SwitchDevice(category, element.Attribute("Type").Value);
                retBoard.SwitchList.Add(sw);
            }
            //找到Links元素,添加Link集合到类
            XElement links = rt.Element("Links");

            foreach (var element in links.Elements())
            {
                var link = new BoardLink();
                link.LinkType      = (LinkType)Enum.Parse(typeof(LinkType), element.Attribute("Type").Value);
                link.FirstEndType  = (EndType)Enum.Parse(typeof(EndType), element.Attribute("FirstEndType").Value);
                link.FirstEndId    = int.Parse(element.Attribute("FirstEndId").Value);
                link.SecondEndType = (EndType)Enum.Parse(typeof(EndType), element.Attribute("SecondEndType").Value);
                link.SecondEndId   = int.Parse(element.Attribute("SecondEndId").Value);
                foreach (var fPosition in element.Element("FirstEndPositionList").Elements())
                {
                    link.FirstEndPositionList.Add(int.Parse(fPosition.Value));
                }
                foreach (var sPosition in element.Element("SecondEndPositionList").Elements())
                {
                    link.SecondEndPositionList.Add(int.Parse(sPosition.Value));
                }
                retBoard.LinkList.Add(link);
            }
            return(retBoard);
        }
示例#12
0
 public EnlaceStage(SwitchDevice @switch, EnlaceDevice enlace)
 {
     _switch = @switch;
     _enlace = enlace;
 }
示例#13
0
 public PeptizationStage(SwitchDevice @switch)
 {
     _switch = @switch;
 }
示例#14
0
        public static void Test(string timeDate, int howMuch, int option)
        {
            Stopwatch sw   = new Stopwatch();
            Random    rand = new Random();

            List <SwitchDevice>            listSwitch = new List <SwitchDevice>(howMuch);
            HashSet <SwitchDevice>         hashSwitch = new HashSet <SwitchDevice>();
            Dictionary <int, SwitchDevice> dictSwitch = new Dictionary <int, SwitchDevice>(howMuch);

            HashSet <int> switchHashIds = new HashSet <int>();

            SwitchDevice switchDevice;

            for (int i = 0; i < howMuch; i++)
            {
                while (true)
                {
                    int id = rand.Next(0, howMuch * 10);
                    switchDevice = new SwitchDevice(id, 0, timeDate);

                    if (switchHashIds.Contains(id))
                    {
                        continue;
                    }
                    else
                    {
                        listSwitch.Add(switchDevice);
                        dictSwitch.Add(id, switchDevice);
                        hashSwitch.Add(switchDevice);
                        switchHashIds.Add(id);
                        break;
                    }
                }
            }

            var switchListIds = listSwitch.Select(x => x.SwitchID).ToList();

            //number from the middle of list
            int number = switchListIds[howMuch / 2];

            //Output in milliseconds for each List, HashSet and Dictionary
            long switchListMili = 0;
            long switchListHash = 0;
            long switchListDict = 0;

            if (option == 1)
            {
                sw.Start();
                switchListIds.Contains(number);
                sw.Stop();

                switchListMili = sw.ElapsedMilliseconds;

                sw.Restart();
                switchHashIds.Contains(number);
                sw.Stop();

                switchListHash = sw.ElapsedMilliseconds;

                sw.Restart();
                dictSwitch.ContainsKey(number);
                sw.Stop();

                switchListDict = sw.ElapsedMilliseconds;
            }
            else if (option == 2)
            {
                sw.Start();
                var listValue = listSwitch.First(x => x.SwitchID == number);
                sw.Stop();

                switchListMili = sw.ElapsedMilliseconds;

                sw.Restart();
                var hashValue = hashSwitch.First(x => x.SwitchID == number);
                sw.Stop();

                switchListHash = sw.ElapsedMilliseconds;

                SwitchDevice dictValue = null;
                sw.Restart();
                dictSwitch.TryGetValue(number, out dictValue);
                sw.Stop();

                switchListDict = sw.ElapsedMilliseconds;
            }
            else
            {
                sw.Start();
                foreach (var item in listSwitch)
                {
                }
                sw.Stop();

                switchListMili = sw.ElapsedMilliseconds;

                sw.Restart();
                foreach (var item in hashSwitch)
                {
                }
                sw.Stop();

                switchListHash = sw.ElapsedMilliseconds;

                sw.Restart();
                foreach (var item in dictSwitch)
                {
                }
                sw.Stop();

                switchListDict = sw.ElapsedMilliseconds;
            }

            Console.WriteLine("List with {0} elements: {1} in milliseconds", howMuch, switchListMili);
            Console.WriteLine("Hashset with {0} elements: {1} in milliseconds", howMuch, switchListHash.ToString());
            Console.WriteLine("Dictionary with {0} elements: {1} in milliseconds", howMuch, switchListDict.ToString());
            Console.WriteLine();
        }
示例#15
0
 public async Task Accept(SwitchDevice msg)
 {
     await _hueClient.SwitchDeviceAsync(msg.HueDevice);
 }
示例#16
0
        public AppModel()
        {
            SwitchDevice  = ObservableProperty.CreateSettable <object>(null, true);
            ReverseBitmap = ObservableProperty.CreateSettable <object>(null, true);

            VideoBitmap = ObservableProperty.CreateSettable <BitmapFrame>(null);
            IsRunning   = ObservableProperty.CreateSettable(false);

            var oldNewIndexes = SwitchDevice
                                .Select(_ => new
            {
                OldValue = SelectedDeviceIndex.Value,
                NewValue = (SelectedDeviceIndex.Value + 1) % _devices.Length
            })
                                .ToGetOnly(null);

            SelectedDeviceIndex = oldNewIndexes
                                  .Select(_ => _.NewValue)
                                  .ToGetOnly(0);

            BitmapScaleX = ReverseBitmap
                           .Select(_ => - 1 * BitmapScaleX.Value)
                           .ToGetOnly(-1);

            _devices = new FilterInfoCollection(FilterCategory.VideoInputDevice)
                       .Cast <FilterInfo>()
                       .Select(f => new VideoCaptureDevice(f.MonikerString))
                       .Do(d => d.VideoResolution = GetResolution(d.VideoCapabilities))
                       .ToArray();
            if (_devices.Length == 0)
            {
                return;
            }

            IsRunning
            //.Throttle(TimeSpan.FromMilliseconds(200))
            .ObserveOn(Scheduler.Default)
            .Subscribe(b =>
            {
                if (b)
                {
                    StartDevice(SelectedDeviceIndex.Value);
                }
                else
                {
                    StopDevice(SelectedDeviceIndex.Value);
                }
            });

            oldNewIndexes
            .Where(_ => IsRunning.Value)
            //.Throttle(TimeSpan.FromMilliseconds(200))
            .ObserveOn(Scheduler.Default)
            .Subscribe(_ =>
            {
                StopDevice(_.OldValue);
                // 連続してデバイスを操作すると失敗することがあるため、待機します。
                Thread.Sleep(200);
                StartDevice(_.NewValue);
            });
        }