//Load Length public Dictionary<string, int> BuildLeng(List<string> list) { var leng = new Dictionary<string, int>(); foreach (string key in list.Where(word => word != "")) { leng[key] = key.Length; } return leng; }
//Load Occurances public Dictionary<string, int> BuildOccu(List<string> list) { var occu = new Dictionary<string, int>(); foreach (string key in list.Where(word => word != "")) { if (occu.ContainsKey(key)) { occu[key]++; } else { occu[key] = 1; } } return occu; }
public static AuthResult Authorize(AuthData data) { Keys keys = GetKeys(); if (keys != null && keys.Public.Equals(data.PublicKey)) { var privateKey = keys.Private; var hashCheck = General.Sha1Hash(data.Data + privateKey + data.PublicKey); if (hashCheck.Equals(data.Hash)) { var newToken = General.Sha1Hash(privateKey + hashCheck + GetDateTimeFormatted()); var computersJsonFile = GetFile("~/App_Data/", "computers.json"); var computers = new List<ComputerData>(); try { computers = JsonConvert.DeserializeObject<List<ComputerData>>(GetFileContents(computersJsonFile)); } catch { } var computerData = new ComputerData() { Name = data.HostName, IpExternal = data.IpExternal, IpInternal = data.IpInternal, LastActive = DateTime.Now, FileUploaded = null, BytesUploaded = 0, Hash = null }; computerData.Hash = Transmitter.GetComputerHash(computerData); if (computers.Where(c => c.Hash == computerData.Hash).FirstOrDefault() == null) { computers.Add(computerData); } var computersJson = JsonConvert.SerializeObject(computers); File.WriteAllText(computersJsonFile, computersJson); return new AuthResult() { Token = newToken, IpExternal = data.IpExternal }; } } return null; }
public static List<User> UserWithExpiredBooks(List<User> users) { return users.Where(user => user.Books != null && user.Books.Count > 0 && user.Books.Exists(BookController.IsExpiredBook)).ToList<User>(); }
public static List<User> UsersWithBooks(List<User> users) { return users.Where(user => user.Books != null && user.Books.Count > 0).ToList<User>(); }
public void Update() { lock (this.ThisLock) { if (this.State == ManagerState.Stop) return; { string ipv4Uri = null; try { string uri = _outoposManager.ListenUris.FirstOrDefault(n => n.StartsWith(string.Format("tcp:{0}:", IPAddress.Any.ToString()))); Regex regex = new Regex(@"(.*?):(.*):(\d*)"); var match = regex.Match(uri); if (!match.Success) throw new Exception(); int port = int.Parse(match.Groups[3].Value); List<IPAddress> myIpAddresses = new List<IPAddress>(AutoBaseNodeSettingManager.GetIpAddresses()); foreach (var myIpAddress in myIpAddresses.Where(n => n.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)) { if (IPAddress.Any.ToString() == myIpAddress.ToString() || IPAddress.Loopback.ToString() == myIpAddress.ToString() || IPAddress.Broadcast.ToString() == myIpAddress.ToString()) { continue; } if (AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("10.0.0.0")) >= 0 && AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("10.255.255.255")) <= 0) { continue; } if (AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("172.16.0.0")) >= 0 && AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("172.31.255.255")) <= 0) { continue; } if (AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("127.0.0.0")) >= 0 && AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("127.255.255.255")) <= 0) { continue; } if (AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("192.168.0.0")) >= 0 && AutoBaseNodeSettingManager.IpAddressCompare(myIpAddress, IPAddress.Parse("192.168.255.255")) <= 0) { continue; } ipv4Uri = string.Format("tcp:{0}:{1}", myIpAddress.ToString(), port); break; } } catch (Exception) { } if (ipv4Uri != _settings.Ipv4Uri) { if (this.RemoveUri(_settings.Ipv4Uri)) Log.Information(string.Format("Remove Node uri: {0}", _settings.Ipv4Uri)); } _settings.Ipv4Uri = ipv4Uri; if (_settings.Ipv4Uri != null) { if (this.AddUri(_settings.Ipv4Uri)) Log.Information(string.Format("Add Node uri: {0}", _settings.Ipv4Uri)); } } { string ipv6Uri = null; try { string uri = _outoposManager.ListenUris.FirstOrDefault(n => n.StartsWith(string.Format("tcp:[{0}]:", IPAddress.IPv6Any.ToString()))); Regex regex = new Regex(@"(.*?):(.*):(\d*)"); var match = regex.Match(uri); if (!match.Success) throw new Exception(); int port = int.Parse(match.Groups[3].Value); List<IPAddress> myIpAddresses = new List<IPAddress>(AutoBaseNodeSettingManager.GetIpAddresses()); foreach (var myIpAddress in myIpAddresses.Where(n => n.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)) { if (IPAddress.IPv6Any.ToString() == myIpAddress.ToString() || IPAddress.IPv6Loopback.ToString() == myIpAddress.ToString() || IPAddress.IPv6None.ToString() == myIpAddress.ToString()) { continue; } if (myIpAddress.ToString().StartsWith("fe80:")) { continue; } if (myIpAddress.ToString().StartsWith("2001:")) { continue; } if (myIpAddress.ToString().StartsWith("2002:")) { continue; } ipv6Uri = string.Format("tcp:[{0}]:{1}", myIpAddress.ToString(), port); break; } } catch (Exception) { } if (ipv6Uri != _settings.Ipv6Uri) { if (this.RemoveUri(_settings.Ipv6Uri)) Log.Information(string.Format("Remove Node uri: {0}", _settings.Ipv6Uri)); } _settings.Ipv6Uri = ipv6Uri; if (_settings.Ipv6Uri != null) { if (this.AddUri(_settings.Ipv6Uri)) Log.Information(string.Format("Add Node uri: {0}", _settings.Ipv6Uri)); } } { string upnpUri = null; try { string uri = _outoposManager.ListenUris.FirstOrDefault(n => n.StartsWith(string.Format("tcp:{0}:", IPAddress.Any.ToString()))); Regex regex = new Regex(@"(.*?):(.*):(\d*)"); var match = regex.Match(uri); if (!match.Success) throw new Exception(); int port = int.Parse(match.Groups[3].Value); using (UpnpClient client = new UpnpClient()) { client.Connect(new TimeSpan(0, 0, 10)); string ip = client.GetExternalIpAddress(new TimeSpan(0, 0, 10)); if (string.IsNullOrWhiteSpace(ip)) throw new Exception(); upnpUri = string.Format("tcp:{0}:{1}", ip, port); if (upnpUri != _settings.UpnpUri) { if (_settings.UpnpUri != null) { try { var match2 = regex.Match(_settings.UpnpUri); if (!match2.Success) throw new Exception(); int port2 = int.Parse(match2.Groups[3].Value); client.ClosePort(UpnpProtocolType.Tcp, port2, new TimeSpan(0, 0, 10)); Log.Information(string.Format("UPnP Close port: {0}", port2)); } catch (Exception) { } } client.ClosePort(UpnpProtocolType.Tcp, port, new TimeSpan(0, 0, 10)); if (client.OpenPort(UpnpProtocolType.Tcp, port, port, "Outopos", new TimeSpan(0, 0, 10))) { Log.Information(string.Format("UPnP Open port: {0}", port)); } } } } catch (Exception) { } if (upnpUri != _settings.UpnpUri) { if (this.RemoveUri(_settings.UpnpUri)) Log.Information(string.Format("Remove Node uri: {0}", _settings.UpnpUri)); } _settings.UpnpUri = upnpUri; if (_settings.UpnpUri != null) { if (this.AddUri(_settings.UpnpUri)) Log.Information(string.Format("Add Node uri: {0}", _settings.UpnpUri)); } } } }
public static List<Book> ExpiredBooks(List<Book> books) { return books.Where(book => IsExpiredBook(book)).ToList<Book>(); }
private ListView GetListView(string text, bool? isActive, DateTime date) { ListView lv = new ListView(); if (NhatKyNguyenLieuBus.GetCount(text, isActive, date) > 0 && HoaDonBus.GetByDate(date) != null) { List<DTO.NhatKyNguyenLieu> listNLLyThuyet = new List<DTO.NhatKyNguyenLieu>(); List<DTO.NhatKyNguyenLieu> listNLThucTe = NhatKyNguyenLieuBus.GetList(string.Empty, true, date, string.Empty, string.Empty, 0, 0); List<DTO.HoaDon> listHoaDon = HoaDonBus.GetList(string.Empty, 0, 0, date, string.Empty, string.Empty, 0, 0); foreach (DTO.NhatKyNguyenLieu data in listNLThucTe) { DTO.NhatKyNguyenLieu dataNKNL = new DTO.NhatKyNguyenLieu(); dataNKNL.IdNguyenLieu = data.IdNguyenLieu; dataNKNL.SuDung = 0; listNLLyThuyet.Add(dataNKNL); } foreach (DTO.HoaDon hoaDon in listHoaDon) { List<DTO.HoaDonDetail> listHoaDonDetail = HoaDonDetailBus.GetListByIdHoaDon(hoaDon.Id); foreach (DTO.HoaDonDetail data in listHoaDonDetail) { List<DTO.DinhLuong> listDL = DinhLuongBus.GetListByIdSP(data.IdSanPham); foreach (DTO.DinhLuong dataDL in listDL) { listNLLyThuyet.Where(p => p.IdNguyenLieu == dataDL.IdNguyenLieu).FirstOrDefault().SuDung += dataDL.SoLuong * data.SoLuong; } } } for (int i = 0; i < lvThongTin.Columns.Count; i++) { lv.Columns.Add((ColumnHeader)lvThongTin.Columns[i].Clone()); } for (int i = 0; i < listNLThucTe.Count; i++) { double lyThuyet = listNLLyThuyet[i].SuDung; double thucTe = listNLThucTe[i].SuDung; double chenhLech = thucTe - lyThuyet; double percentChenhLech = ((thucTe / lyThuyet) - 1) * 100; ListViewItem lvi = new ListViewItem(); lvi.Text = (lv.Items.Count + 1).ToString(); lvi.SubItems.Add(listNLThucTe[i].NguyenLieu.Ten); lvi.SubItems.Add(listNLThucTe[i].NguyenLieu.DonViTinh); lvi.SubItems.Add(lyThuyet.ToString()); lvi.SubItems.Add(thucTe.ToString()); lvi.SubItems.Add(chenhLech.ToString()); if (double.IsNaN(percentChenhLech)) { lvi.SubItems.Add(Constant.NaN); } else if (double.IsInfinity(percentChenhLech)) { lvi.SubItems.Add(Constant.INFINITY); } else { lvi.SubItems.Add(percentChenhLech.ToString(Constant.DEFAULT_FORMAT_PERCENT) + Constant.SYMBOL_PERCENT); } lv.Items.Add(lvi); } } return lv; }
public List<Item> GetItemsByYear(List<Item> itemList, ushort year) { return itemList.Where<Item>(x => x.Year == year).ToList<Item>(); }