// Load vsChannels private void LoadChannels(XmlTextReader reader) { try { // load all vsChannels while (reader.Name == "Channel") { int depth = reader.Depth; // create new camera VsChannel view = new VsChannel(reader.GetAttribute("name"), SyncTimer); view.LocalHost = LocalHost; view.LocalStorage = LocalStorage; view.ChannelID = int.Parse(reader.GetAttribute("id")); view.Description = reader.GetAttribute("desc"); // view size view.Rows = short.Parse(reader.GetAttribute("rows")); view.Cols = short.Parse(reader.GetAttribute("cols")); view.CellWidth = short.Parse(reader.GetAttribute("width")); view.CellHeight = short.Parse(reader.GetAttribute("height")); // read vsCameras string[] strIDs = reader.GetAttribute("cameras").Split(','); for (int i = 0; i < VsChannel.MaxCam; i++) { if (strIDs[i].Length > 0) { int id = int.Parse(strIDs[i]); view.SetCamera(id, GetCameraByID(id)); } } view.SetLayout(ChannelLayout.TH_GRID_1); // view configuration view.Analyser = vsAnalysers.GetAnalyserByName(reader.GetAttribute("analyzer")); view.Encoder = vsEncoders.GetEncoderByName(reader.GetAttribute("encoder")); // load analyser configuration if (view.Analyser != null) view.AnalyserConfiguration = view.Analyser.LoadConfiguration(reader); // load encoder configuration if (view.Encoder != null) view.EncoderConfiguration = view.Encoder.LoadConfiguration(reader); // add view vsChannels.Add(view); if (view.ChannelID >= vsNextChannelID) vsNextChannelID = view.ChannelID + 1; // move to next node reader.Read(); // move to next element node while (reader.NodeType == XmlNodeType.EndElement) reader.Read(); if (reader.Depth < depth) return; } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
// Add channel public bool AddChannel(String channelName, String[] cameraList) { try { // if this name is already exist if (GetChannelByName(channelName) != null) return false; VsChannel vsChannel = new VsChannel(channelName, SyncTimer); // set layout vsChannel.SetLayout(ChannelLayout.TH_GRID_1); vsChannel.Rows = 5; vsChannel.Cols = 5; foreach (String cameraName in cameraList) { VsCamera vsCam = GetCameraByName(cameraName); if (vsCam != null) vsChannel.SetCamera(vsCam.CameraID, vsCam); } // add to views collection AddChannel(vsChannel); } catch (Exception ex) { Console.WriteLine(ex.Message); } return true; }