public ChannelTreeItem(ChannelListEntry value, ChannelListEntry parent) { Channel = value; ParentChannel = ParentChannel; Children = new List <ChannelTreeItem>(); Clients = new List <ClientListEntry>(); }
public void StoreChannel(int ChannelId) { var ThisChannelInfo = ServerQueryConnection.QueryRunner.GetChannelInfo((uint)ChannelId); Models.StoredChannels storedChannel = new Models.StoredChannels(this.Subscriber.SubscriberId, this.Subscriber.SubscriberUniqueId); List <ChannelListEntry> ChannelList = ServerQueryConnection.QueryRunner.GetChannelList(true).ToList(); ChannelListEntry ThisChannelEntry = ChannelList.SingleOrDefault(x => x.ChannelId == ChannelId); Props.ChannelWithSubChannelsPackager ChannelWithSubChannels = new Props.ChannelWithSubChannelsPackager(this.Subscriber.SubscriberId, this.Subscriber.SubscriberUniqueId); ChannelWithSubChannels.Store(ServerQueryConnection.QueryRunner, ChannelList, ThisChannelInfo, ThisChannelEntry, StoreSingleChannel); }
private static void SortChannels(List <ChannelListEntry> channels) { if (channels.Count < 2) { return; } Dictionary <uint, ChannelListEntry> channelDict = new Dictionary <uint, ChannelListEntry>(); channels.ForEach(c => channelDict[c.Order] = c); if (!channelDict.ContainsKey(0)) { return; } ChannelListEntry lastAddedChannelEntry = channelDict[0]; List <ChannelListEntry> temporaryChannels = new List <ChannelListEntry> { lastAddedChannelEntry }; do { ChannelListEntry nextSiblingChannelEntry; if (!channelDict.TryGetValue(lastAddedChannelEntry.ChannelId, out nextSiblingChannelEntry)) { break; } temporaryChannels.Add(nextSiblingChannelEntry); lastAddedChannelEntry = nextSiblingChannelEntry; }while (true); if (temporaryChannels.Count != channels.Count) { return; } channels.Clear(); channels.AddRange(temporaryChannels); }
private static void AddChildren(ChannelTreeItem parentChannelTreeItem, List <ChannelTreeItem> channelTree, List <ChannelListEntry> remainingChannels, List <ClientListEntry> remainingClients) { uint parentChannelId = parentChannelTreeItem == null ? 0 : parentChannelTreeItem.Channel.ChannelId; List <ChannelTreeItem> targetChannelList = parentChannelTreeItem == null ? channelTree : parentChannelTreeItem.Children; List <ChannelListEntry> children = new List <ChannelListEntry>(); for (int i = remainingChannels.Count - 1; i >= 0; i--) { ChannelListEntry channel = remainingChannels[i]; if (channel.ParentChannelId != parentChannelId) { continue; } children.Add(channel); remainingChannels.RemoveAt(i); } SortChannels(children); foreach (ChannelListEntry channel in children) { ChannelTreeItem channelTreeItem = new ChannelTreeItem(channel, parentChannelTreeItem == null ? null : parentChannelTreeItem.ParentChannel); targetChannelList.Add(channelTreeItem); if (remainingClients.Count > 0) { List <ClientListEntry> clients = remainingClients.Where(c => c.ChannelId == channelTreeItem.Channel.ChannelId).ToList(); clients.Sort(SortUser); channelTreeItem.Clients.AddRange(clients); } AddChildren(channelTreeItem, null, remainingChannels, remainingClients); } }
public DTControl(double frequency, int[] analogChannels, Logger log, DoneSignalHandler callback) { try { m_deviceMgr = DeviceMgr.Get(); if (!m_deviceMgr.HardwareAvailable()) throw new Exception("No Devices Available."); // Get first available device m_device = m_deviceMgr.GetDevice(m_deviceMgr.GetDeviceNames()[0]); // Get subsystems m_ainSS = m_device.AnalogInputSubsystem(0); m_dinSS = m_device.DigitalInputSubsystem(0); m_doutSS = m_device.DigitalOutputSubsystem(0); /* * ANALOG SETUP */ //Add event handlers m_ainSS.DriverRunTimeErrorEvent += HandleDriverRunTimeErrorEvent; m_ainSS.BufferDoneEvent += HandleBufferDone; m_ainSS.QueueDoneEvent += HandleQueueDone; m_ainSS.QueueStoppedEvent += HandleQueueStopped; // Set frequency m_frequency = (m_ainSS.Clock.MaxFrequency < frequency) ? m_ainSS.Clock.MaxFrequency : frequency; m_ainSS.Clock.Frequency = m_frequency; m_ainSS.VoltageRange = new Range(-10, 10); // Setup buffers m_ainSS.BufferQueue.FreeAllQueuedBuffers(); //just in case some are in the queue m_daqBuffers = new OlBuffer[MaxBuffers]; for (int i = 0; i < MaxBuffers; i++) { // Allocate and place each buffer in queue m_daqBuffers[i] = new OlBuffer(SampleSize, m_ainSS); m_ainSS.BufferQueue.QueueBuffer(m_daqBuffers[i]); } // Set for continuous operation m_ainSS.DataFlow = DataFlow.Continuous; // Set channel list m_ainSS.ChannelList.Clear(); m_physicalChannels = new List<int>(); foreach (int channel in analogChannels) { ChannelListEntry channelListEntry = new ChannelListEntry(m_ainSS.SupportedChannels.GetChannelInfo(SubsystemType.AnalogInput, channel)); channelListEntry.Gain = 1.0; m_ainSS.ChannelList.Add(channelListEntry); m_physicalChannels.Add(channel); } // Save configuration m_ainSS.Config(); /* * DIGITAL SETUP */ m_dinSS.DataFlow = DataFlow.SingleValue; m_doutSS.DataFlow = DataFlow.SingleValue; m_dinSS.Config(); m_doutSS.Config(); doneSignalHandler += callback; Log = log; Log("DT9816 and all subsystems initialized."); // Display actual hardware frequency set Log(String.Format("Actual Hardware Frequency = {0:0.000}", m_ainSS.Clock.Frequency)); } catch (Exception ex) { throw ex; } }
public DTControl(double frequency, int[] analogChannels, Logger log, DoneSignalHandler callback) { try { m_deviceMgr = DeviceMgr.Get(); if (!m_deviceMgr.HardwareAvailable()) { throw new Exception("No Devices Available."); } // Get first available device m_device = m_deviceMgr.GetDevice(m_deviceMgr.GetDeviceNames()[0]); // Get subsystems m_ainSS = m_device.AnalogInputSubsystem(0); m_dinSS = m_device.DigitalInputSubsystem(0); m_doutSS = m_device.DigitalOutputSubsystem(0); /* * ANALOG SETUP */ //Add event handlers m_ainSS.DriverRunTimeErrorEvent += HandleDriverRunTimeErrorEvent; m_ainSS.BufferDoneEvent += HandleBufferDone; m_ainSS.QueueDoneEvent += HandleQueueDone; m_ainSS.QueueStoppedEvent += HandleQueueStopped; // Set frequency m_frequency = (m_ainSS.Clock.MaxFrequency < frequency) ? m_ainSS.Clock.MaxFrequency : frequency; m_ainSS.Clock.Frequency = m_frequency; m_ainSS.VoltageRange = new Range(-10, 10); // Setup buffers m_ainSS.BufferQueue.FreeAllQueuedBuffers(); //just in case some are in the queue m_daqBuffers = new OlBuffer[MaxBuffers]; for (int i = 0; i < MaxBuffers; i++) { // Allocate and place each buffer in queue m_daqBuffers[i] = new OlBuffer(SampleSize, m_ainSS); m_ainSS.BufferQueue.QueueBuffer(m_daqBuffers[i]); } // Set for continuous operation m_ainSS.DataFlow = DataFlow.Continuous; // Set channel list m_ainSS.ChannelList.Clear(); m_physicalChannels = new List <int>(); foreach (int channel in analogChannels) { ChannelListEntry channelListEntry = new ChannelListEntry(m_ainSS.SupportedChannels.GetChannelInfo(SubsystemType.AnalogInput, channel)); channelListEntry.Gain = 1.0; m_ainSS.ChannelList.Add(channelListEntry); m_physicalChannels.Add(channel); } // Save configuration m_ainSS.Config(); /* * DIGITAL SETUP */ m_dinSS.DataFlow = DataFlow.SingleValue; m_doutSS.DataFlow = DataFlow.SingleValue; m_dinSS.Config(); m_doutSS.Config(); doneSignalHandler += callback; Log = log; Log("DT9816 and all subsystems initialized."); // Display actual hardware frequency set Log(String.Format("Actual Hardware Frequency = {0:0.000}", m_ainSS.Clock.Frequency)); } catch (Exception ex) { throw ex; } }
private void StoreSingleChannel(int ChannelId, ChannelInfoResponse ChannelInfo, ChannelListEntry Channel) { //var channel = ServerQueryConnection.QueryRunner.GetChannelInfo((uint)ChannelId); var channel = ChannelInfo; Models.StoredChannels storedChannel = new Models.StoredChannels(this.Subscriber.SubscriberId, this.Subscriber.SubscriberUniqueId); storedChannel.Parse(ChannelId, channel); using (var db = new CoreContext()) { // Store the channel db.StoredChannels.Add(storedChannel); // Store the channel group assignments var channelGroupClients = ServerQueryConnection.QueryRunner.GetChannelGroupClientList((uint?)ChannelId, null, null).ToList(); foreach (var channelGroupClient in channelGroupClients) { var storeChannel = new Models.StoredChannelGroupClients(Subscriber.SubscriberId, Subscriber.SubscriberUniqueId, channelGroupClient); db.StoredChannelGroupClients.Add(storeChannel); } // Successfully stored the channel, now we can delete it from the server var response = ServerQueryConnection.QueryRunner.DeleteChannel((uint)ChannelId); do { if (response.IsErroneous) { if (response.ErrorMessage == "channel not empty") { var usersInChannel = ServerQueryConnection.QueryRunner.GetClientList(false).Where(client => client.ChannelId == ChannelId); foreach (var user in usersInChannel) { var kickResponse = ServerQueryConnection.QueryRunner.KickClient(user.ClientId, TS3QueryLib.Core.CommandHandling.KickReason.Channel, "Channel is being stored away."); if (kickResponse.IsErroneous) { throw new Exception(kickResponse.ResponseText + " (" + kickResponse.ErrorMessage + ")"); } response = ServerQueryConnection.QueryRunner.DeleteChannel((uint)ChannelId); } } else { throw new Exception(response.ResponseText + " (" + response.ErrorMessage + ")"); } } } while (response.IsErroneous == true); db.SaveChanges(); } }
private void btn_init_Click(object sender, System.EventArgs e) { string keyvalue = ConfigurationManager.AppSettings["keyname"].ToString(); int numberOfBuffers = Convert.ToInt32(ConfigurationManager.AppSettings["NumberOfbuffers"]); string clockFreq = ConfigurationManager.AppSettings["clockFreq"].ToString(); string sensor0gain = ConfigurationManager.AppSettings["sensor0gain"].ToString(); string sensor1gain = ConfigurationManager.AppSettings["sensor1gain"].ToString(); string sensor0offset = ConfigurationManager.AppSettings["sensor0offset"].ToString(); string sensor1offset = ConfigurationManager.AppSettings["sensor1offset"].ToString(); string samplesPerBuffer = ConfigurationManager.AppSettings["samplesPerBuffer"]; statusBarPanel.Text = "No Error"; string deviceName = (string)deviceComboBox.SelectedItem; try { serialPort.PortName = "COM1"; serialPort.BaudRate = 9600; serialPort.DataBits = 8; serialPort.Parity = Parity.None; serialPort.StopBits = StopBits.One; serialPort.Open(); } catch (Exception ex) { MessageBox.Show("Port je vec otvoren" + ex.ToString()); } try { // Create the device object device = deviceMgr.GetDevice(deviceName); // Create the device's analog input subsystem wiht element zero ainSS = device.AnalogInputSubsystem(0); // Create an event handler delegate to handle driver runtime error events ainSS.DriverRunTimeErrorEvent += new DriverRunTimeErrorEventHandler(HandleDriverRunTimeErrorEvent); // Create an event handler delegate to handle buffer done events ainSS.BufferDoneEvent += new BufferDoneHandler(HandleBufferDone); // Create an event handler delegate to handle queue done events ainSS.QueueDoneEvent += new QueueDoneHandler(HandleQueueDone); // Create and event handler delegate to handle queue stopped events ainSS.QueueStoppedEvent += new QueueStoppedHandler(HandleQueueStopped); } catch (OlException ex) { string err = ex.Message; statusBarPanel.Text = err; return; } if (device == null) { MessageBox.Show("No Device Selected.", "Error"); return; } try { // int numberOfBuffers = Convert.ToInt32(6); // Free all previously allocated buffers in case we are updating the number // or the size of buffers ainSS.BufferQueue.FreeAllQueuedBuffers(); daqBuffers = new OlBuffer[Convert.ToInt32(numberOfBuffers)]; // Create the buffers to store the raw data // Place the buffers onto the queue of analog input subsystem for (int i = 0; i < numberOfBuffers; ++i) { daqBuffers[i] = new OlBuffer(int.Parse(samplesPerBuffer), ainSS); ainSS.BufferQueue.QueueBuffer(daqBuffers[i]); } // Set the data flow to continuous to setup for buffered I/O ainSS.DataFlow = DataFlow.Continuous; // Update the Clock object with the frequency ainSS.Clock.Frequency = float.Parse(clockFreq); // Clear the analog input subsystem channel list ainSS.ChannelList.Clear(); int physicalChannelNumber = Convert.ToInt32(0); // Create a channel object and add it to the channel list of the // analog input subsystem SupportedChannelInfo channelInfo = ainSS.SupportedChannels.GetChannelInfo(SubsystemType.AnalogInput, 0); SupportedChannelInfo channelInfo1 = ainSS.SupportedChannels.GetChannelInfo(SubsystemType.AnalogInput, 1); // Set the channel sensor parameters channelInfo.SensorGain = Convert.ToDouble(sensor0gain); channelInfo.SensorOffset = Convert.ToDouble(sensor0offset); channelInfo1.SensorGain = Convert.ToDouble(sensor1gain); channelInfo1.SensorOffset = Convert.ToDouble(sensor1offset); ChannelListEntry channelToRead = new ChannelListEntry(channelInfo); ChannelListEntry channelToRead1 = new ChannelListEntry(channelInfo1); // Add the channel object to the channel list ainSS.ChannelList.Add(channelToRead); ainSS.ChannelList.Add(channelToRead1); // Configure the subsystem to apply all the previous settings to the hardware ainSS.Config(); // Check the closest clock frequency set by the hardware clockFreq = String.Format("{0:0.000}", ainSS.Clock.Frequency); btn_start.Enabled = true; } catch (OlException ex) { string err = ex.Message; statusBarPanel.Text = err; return; } }
public void Store(QueryRunner QueryRunner, List <ChannelListEntry> ChannelList, ChannelInfoResponse ChannelInfo, ChannelListEntry Channel, Action <int, ChannelInfoResponse, ChannelListEntry> StoreMethod) { this.QueryRunner = QueryRunner; this.Parse(ChannelInfo, Channel); for (int i = 0; i < ChannelList.Count; i++) { if (ChannelList[i].ParentChannelId == Channel.ChannelId) { var SubChannelInfo = QueryRunner.GetChannelInfo(ChannelList[i].ChannelId); SubChannels.Add(new ChannelWithSubChannelsPackager(this.SubscriberId, this.SubscriberUniqueId, QueryRunner, ChannelList, SubChannelInfo, ChannelList[i], StoreMethod)); } } StoreMethod.Invoke((int)this.ChannelId, ChannelInfo, Channel); }
public ChannelWithSubChannelsPackager(int SubscriberId, string SubscriberUniqueId, QueryRunner QueryRunner, List <ChannelListEntry> ChannelList, ChannelInfoResponse ChannelInfo, ChannelListEntry Channel, Action <int, ChannelInfoResponse, ChannelListEntry> StoreMethod) : base(SubscriberId, SubscriberUniqueId) { Store(QueryRunner, ChannelList, ChannelInfo, Channel, StoreMethod); }
public void Parse(ChannelListEntry entry, bool overWriteExisting = false) { if (overWriteExisting || IsDefaultChannel == null) { IsDefaultChannel = entry.IsDefaultChannel; } if (overWriteExisting || IsPasswordProtected == null) { IsPasswordProtected = entry.IsPasswordProtected; } if (overWriteExisting || IsPermanent == null) { IsPermanent = entry.IsPermanent; } if (overWriteExisting || IsSemiPermanent == null) { IsSemiPermanent = entry.IsSemiPermanent; } if (overWriteExisting || IsSpacer == null) { IsSpacer = entry.IsSpacer; } if (overWriteExisting || CodecQuality == null) { CodecQuality = entry.CodecQuality; } if (overWriteExisting || MaxClients == null) { MaxClients = entry.MaxClients; } if (overWriteExisting || MaxFamilyClients == null) { MaxFamilyClients = entry.MaxFamilyClients; } if (overWriteExisting || TotalClients == null) { TotalClients = entry.TotalClients; } if (overWriteExisting || TotalClientsFamily == null) { TotalClientsFamily = entry.TotalClientsFamily; } if (overWriteExisting || Name == null) { Name = entry.Name; } if (overWriteExisting || Topic == null) { Topic = entry.Topic; } if (overWriteExisting || ChannelId == null) { ChannelId = (int?)entry.ChannelId; } if (overWriteExisting || NeededSubscribePower == null) { NeededSubscribePower = (int?)entry.NeededSubscribePower; } if (overWriteExisting || NeededTalkPower == null) { NeededTalkPower = (int?)entry.NeededTalkPower; } if (overWriteExisting || Order == null) { Order = (int?)entry.Order; } if (overWriteExisting || ParentChannelId == null) { ParentChannelId = (int?)entry.ParentChannelId; } if (overWriteExisting || ChannelIconId == null) { ChannelIconId = (int?)entry.ChannelIconId; } if (overWriteExisting || Codec == null) { Codec = (short?)entry.Codec; } }
// Parsing TS3 Channels public void Parse(ChannelInfoResponse info, ChannelListEntry entry, bool overWriteExisting = false) { if (overWriteExisting || ForcedSilence == null) { ForcedSilence = info.ForcedSilence; } if (overWriteExisting || IsDefaultChannel == null) { IsDefaultChannel = info.IsDefaultChannel; } if (overWriteExisting || IsMaxClientsUnlimited == null) { IsMaxClientsUnlimited = info.IsMaxClientsUnlimited; } if (overWriteExisting || IsMaxFamilyClientsInherited == null) { IsMaxFamilyClientsInherited = info.IsMaxFamilyClientsInherited; } if (overWriteExisting || IsMaxFamilyClientsUnlimited == null) { IsMaxFamilyClientsUnlimited = info.IsMaxFamilyClientsUnlimited; } if (overWriteExisting || IsPasswordProtected == null) { IsPasswordProtected = info.IsPasswordProtected; } if (overWriteExisting || IsPermanent == null) { IsPermanent = info.IsPermanent; } if (overWriteExisting || IsSemiPermanent == null) { IsSemiPermanent = info.IsSemiPermanent; } if (overWriteExisting || IsSpacer == null) { IsSpacer = entry.IsSpacer; } if (overWriteExisting || IsUnencrypted == null) { IsUnencrypted = info.IsUnencrypted; } if (overWriteExisting || CodecQuality == null) { CodecQuality = info.CodecQuality; } if (overWriteExisting || MaxClients == null) { MaxClients = info.MaxClients; } if (overWriteExisting || MaxFamilyClients == null) { MaxFamilyClients = info.MaxFamilyClients; } if (overWriteExisting || SecondsEmpty == null) { SecondsEmpty = info.SecondsEmpty; } if (overWriteExisting || TotalClients == null) { TotalClients = entry.TotalClients; } if (overWriteExisting || TotalClientsFamily == null) { TotalClientsFamily = entry.TotalClientsFamily; } if (overWriteExisting || Description == null) { Description = info.Description; } if (overWriteExisting || FilePath == null) { FilePath = info.FilePath; } if (overWriteExisting || Name == null) { Name = info.Name; } if (overWriteExisting || PasswordHash == null) { PasswordHash = info.PasswordHash; } if (overWriteExisting || PhoneticName == null) { PhoneticName = info.PhoneticName; } if (overWriteExisting || SecuritySalt == null) { SecuritySalt = info.SecuritySalt; } if (overWriteExisting || Topic == null) { Topic = info.Topic; } if (overWriteExisting || ChannelId == null) { ChannelId = (int?)entry.ChannelId; } if (overWriteExisting || DeleteDelay == null) { DeleteDelay = (int?)info.DeleteDelay; } if ((overWriteExisting || IconId == null) && info.IconId != 0) { IconId = (int?)info.IconId; } if (overWriteExisting || LatencyFactor == null) { LatencyFactor = (int?)info.LatencyFactor; } if (overWriteExisting || NeededSubscribePower == null) { NeededSubscribePower = (int?)entry.NeededSubscribePower; } if (overWriteExisting || NeededTalkPower == null) { NeededTalkPower = (int?)info.NeededTalkPower; } if (overWriteExisting || Order == null) { Order = (int?)info.Order; } if (overWriteExisting || ParentChannelId == null) { ParentChannelId = (int?)info.ParentChannelId; } if (overWriteExisting || ChannelIconId == null) { ChannelIconId = (int?)entry.ChannelIconId; } if (overWriteExisting || Codec == null) { Codec = (short?)info.Codec; } }
/// <summary> /// Sorts a list of channels just like windows sorts its folders (digit-sorting supported) /// </summary> /// <param name="_channels">List of (unsorted) channels</param> /// <returns>A sorted array of channels</returns> private ChannelListEntry[] SortChannels_GetArray(List <ChannelListEntry> _channels) { List <ChannelListEntry> relevant_channels = _channels; ChannelListEntry[] sorted_relevant_channels; sorted_relevant_channels = new ChannelListEntry[relevant_channels.Count()]; //var lengths = (from element in _channels // orderby element.Name // select element).ToList<ChannelListEntry>(); for (int i = 0; i < relevant_channels.Count; i++) { int index = 0; for (int j = 0; j < relevant_channels.Count; j++) { for (int i_char = 0; i_char < relevant_channels[i].Name.Length; i_char++) { string i_digits = ""; string j_digits = ""; for (int idig = i_char; idig < relevant_channels[i].Name.Length; idig++) { if (Char.IsNumber(relevant_channels[i].Name[idig]) == true) { i_digits += relevant_channels[i].Name[idig].ToString(); } else { idig = relevant_channels[i].Name.Length; i_digits = ""; } } for (int idig = i_char; idig < relevant_channels[j].Name.Length; idig++) { if (Char.IsNumber(relevant_channels[j].Name[idig]) == true) { j_digits += relevant_channels[j].Name[idig].ToString(); } else { idig = relevant_channels[j].Name.Length; j_digits = ""; } } if (i_digits.Length > 1 || j_digits.Length > 1) { if (Convert.ToInt32(i_digits) > Convert.ToInt32(j_digits)) { index++; i_char = relevant_channels[i].Name.Length; } else { i_char = relevant_channels[i].Name.Length; } } else { if (i_char < relevant_channels[j].Name.ToLower().Length) { if ((int)relevant_channels[i].Name.ToLower()[i_char] > (int)relevant_channels[j].Name.ToLower()[i_char]) { index++; i_char = relevant_channels[i].Name.Length; } else if ((int)relevant_channels[i].Name.ToLower()[i_char] < (int)relevant_channels[j].Name.ToLower()[i_char]) { i_char = relevant_channels[i].Name.Length; } } } } } sorted_relevant_channels[index] = relevant_channels[i]; } return(sorted_relevant_channels); }