private static void Validate(IpAddress entity) { if (StringUtils.IsBlank(entity.IpAddressValue)) { throw new InvalidIpAddressException("IP Address cannot be blank"); } const string pattern = @"[0-9]{1,3}(.[0-9]{1,3}){3,3}"; if (!Regex.IsMatch(entity.IpAddressValue, pattern)) { throw new InvalidIpAddressException("The entered value does not appear to be a valid IP address"); } IpAddressFinder finder = new IpAddressFinder(); finder.IpAddressValue = entity.IpAddressValue; IpAddress ipAddress = IpAddress.FindOne(finder); if (!ipAddress.IsNull) { if (entity.IsNew) { throw new InvalidIpAddressException("That IP Address already exists"); } if (entity.IpAddressId.Equals(ipAddress.IpAddressId)) { throw new InvalidIpAddressException("That IP Address already exists"); } } }
/// <summary> /// Checks if the IP address belongs to the approved IP address list /// </summary> public static bool IsApprovedIpAddress(string ipAddress) { if (StringUtils.IsBlank(ipAddress)) { return(false); } IpAddressFinder ipRestrictionFinder = new IpAddressFinder { IpAddressValue = ipAddress }; return(IpAddress.GetCount(ipRestrictionFinder) != 0); }
protected override void BindGrid(int page) { IpAddressFinder finder = new IpAddressFinder(); finder.SortExpressions.AddRange(Grid.GetSortExpressions()); EntityList <IpAddress> data = IpAddress.FindMany(finder, page - 1, PageSize); Grid.DataSource = data; Grid.DataBind(); Grid.Visible = (data.Count > 0); NoResultsPanel.Visible = (data.Count == 0); UpdatePagingControls(data.PagingInfo); }
private static void Main(string[] args) { if (args.Length > 0) { if (args[0] == "?") { Console.WriteLine("Argument expected: XML File Path."); Console.WriteLine("Example: "); Console.WriteLine(" HdHomeRunEpgXml " + '"' + "hdEpg.xml" + '"'); Console.WriteLine(" HdHomeRunEpgXml " + '"' + "C:\\hdEpg.xml" + '"'); Console.WriteLine(""); Console.WriteLine("You can also specify the device."); Console.WriteLine(" HdHomeRunEpgXml " + '"' + "C:\\hdEpg.xml" + '"' + " <DeviceID>"); } } if (args.Length == 0) { Console.WriteLine("Argument expected: XML File Path."); Console.WriteLine("Example: "); Console.WriteLine(" HdHomeRunEpgXml " + '"' + "hdEpg.xml" + '"'); Console.WriteLine(" HdHomeRunEpgXml " + '"' + "C:\\hdEpg.xml" + '"'); Console.WriteLine(""); Console.WriteLine("Press enter to exit."); Console.ReadLine(); return; } DownloadImdb(); DownloadImdbRatings(); string selectedDevice = null; if (args.Length == 2) { selectedDevice = args[1]; } IpAddressFinder.PrintLocalIPAddress(); var tvShows = new List <XmlElement>(); var doc = new XmlDocument(); var xmlDeclaration = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null); var root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); var eleTv = doc.CreateElement(string.Empty, "tv", string.Empty); doc.AppendChild(eleTv); var processedChannel = new List <string>(); //Fetch the devices registered. List <HdConnectDevice> devices = null; try { devices = JsonCalls.GetHdConnectDevices(); } catch (Exception e) { Console.WriteLine("!!!!!It appears you do not have any HdHomeRun devices.!!!!!"); Console.WriteLine("Press <enter> to exit"); Console.ReadLine(); Environment.Exit(0); } if (devices == null) { Console.WriteLine("Devices are null! Can't find recievers."); } else { try { //For Each device. foreach (var device in devices) { if (selectedDevice != null) { if (!selectedDevice.Trim().Equals(device.DeviceID.Trim(), StringComparison.InvariantCultureIgnoreCase)) { continue; } } Console.WriteLine("Processing Device: " + device.DeviceID); //Get the Auth info var discover = device.GetHdConnectDiscover(); //Get the channels var channels = discover.GetHdConnectChannels(); //For each channel foreach (var channel in channels) { //If we already processed this channel, then skip if (processedChannel.Contains(channel.GuideNumber)) { continue; } //Process the channel processedChannel.Add(channel.GuideNumber); //Add the tv shows tvShows.AddRange(doc.ProcessChannel(eleTv, channel, discover.DeviceAuth)); } } } catch (Exception e) { Console.WriteLine("Error processing devices."); Console.WriteLine(e); } } //Append the shows to the list foreach (var element in tvShows) { eleTv.AppendChild(element); } try { //Save the file doc.Save(args[0]); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("Finished."); Console.WriteLine("Epg file saved to: " + args[0]); }