public sealed override void PostReaction() { foreach (var network in NetworkCollection.GetWireNetworksConnectedTo(this)) { ExportFlux(network); } }
public override bool CanCombine(Point16 orig, Point16 dir) { NetworkCollection.HasFluidPipeAt(orig + dir, out FluidNetwork thisNet); NetworkCollection.HasFluidPipeAt(orig - dir, out FluidNetwork otherNet); var otherAxis = new Point16(dir.Y, dir.X); NetworkCollection.HasFluidPipeAt(orig + otherAxis, out FluidNetwork axisNet); NetworkCollection.HasFluidPipeAt(orig - otherAxis, out FluidNetwork otherAxisNet); Tile center = Framing.GetTileSafely(orig); if (ModContent.GetModTile(center.type) is TransportJunction) { //At this point, only one axis is being handled, so that's fine JunctionMerge merge = JunctionMergeable.mergeTypes[center.frameX / 18]; if (((merge & JunctionMerge.Fluids_LeftRight) != 0 && dir.X != 0) || ((merge & JunctionMerge.Fluids_UpDown) != 0 && dir.Y != 0)) { return(otherNet is null || (otherNet.liquidType == thisNet.liquidType && otherNet.gasType == thisNet.gasType)); } return(false); } //Not a junction at the center. Need to check every direction //All directions just need to be checked against this one bool hasConnOther = otherNet != null; bool hasConnAxis = axisNet != null; bool hasConnAxisOther = otherAxisNet != null; return((!hasConnOther || (otherNet.liquidType == thisNet.liquidType && otherNet.gasType == thisNet.gasType)) && (!hasConnAxis || (axisNet.liquidType == thisNet.liquidType && axisNet.gasType == thisNet.gasType)) && (!hasConnAxisOther || (otherAxisNet.liquidType == thisNet.liquidType && otherAxisNet.gasType == thisNet.gasType))); }
/// <summary> /// fill the network combo box list with a custom combo box item /// </summary> /// <param name="vSelectedNetworkName"></param> /// <param name="vConnectivity"></param> private void FillNetworkList(string vSelectedNetworkName, NetworkConnectivityLevels vConnectivity) { cbNetwork.Items.Clear(); NetworkCollection netCollection = NetworkListManager.GetNetworks(vConnectivity); // NetworkConnectivityLevels.Connected); ComboboxItemCustom comboItem; var orderedList = netCollection.OrderBy(x => x.Name); //.ThenByDescending(x => x.Name); foreach (Network n in orderedList) { { comboItem = new ComboboxItemCustom(n.Name, n.NetworkId.ToString(), n.IsConnectedToInternet); cbNetwork.Items.Add(comboItem); if (vSelectedNetworkName == n.Name) { cbNetwork.SelectedItem = comboItem; } } } if (String.IsNullOrEmpty(vSelectedNetworkName)) { cbNetwork.Text = "(Select One)"; } }
/* Lists connected networks by profile */ public List <string> NetworksByProfileList(NET_FW_PROFILE_TYPE2_ profile, NetworkConnectivityLevels level = NetworkConnectivityLevels.All) { List <string> networks = new List <string>(); NetworkCategory profileName = NetworkCategory.Public; switch (profile) { case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_DOMAIN: profileName = NetworkCategory.Authenticated; break; case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PRIVATE: profileName = NetworkCategory.Private; break; case NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_PUBLIC: profileName = NetworkCategory.Public; break; } //Install-Package WindowsAPICodePack-Core NetworkCollection nCollection = NetworkListManager.GetNetworks(level); foreach (Network net in nCollection) { if (net.Category == profileName) { networks.Add(net.Name); } } return(networks); }
static void Main(string[] args) { // check the internet connection state bool isInternetConnected = NetworkListManager.IsConnectedToInternet; Console.WriteLine("Machine connected to Internet: {0}", isInternetConnected); if (isInternetConnected) { // get the list of all network connections NetworkCollection netCollection = NetworkListManager.GetNetworks(NetworkConnectivityLevels.Connected); // work through the set of connections and write out the // name of those which are connected to the internet foreach (Network network in netCollection) { if (network.IsConnectedToInternet) { Console.WriteLine("Connection {0} is connected to the internet", network.Name); } } } Console.WriteLine("\nMain method complete. Press Enter."); Console.ReadLine(); }
private void DisplayNetworkReport(WiFiNetworkReport report) { NetworkCollection.Clear(); foreach (var network in report.AvailableNetworks) { NetworkCollection.Add(new WiFiNetworkDisplay(network, _firstAdapter)); } }
public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem) { if (!fail) { //Tile was mined. Update the networks NetworkCollection.OnFluidPipeKill(new Point16(i, j)); } }
public static void TryImportGases <T>(this T entity, Point16 pipePos, int indexToExtract) where T : MachineEntity, IGasMachine { if (indexToExtract < 0 || indexToExtract >= entity.GasEntries.Length) { return; } var entry = entity.GasEntries[indexToExtract]; if (!NetworkCollection.HasFluidPipeAt(pipePos, out FluidNetwork net) || net.liquidType != MachineLiquidID.None || net.gasType == MachineGasID.None || !entry.isInput || (entry.id != MachineGasID.None && entry.id != net.gasType) || (entry.validTypes?.Length > 0 && Array.FindIndex(entry.validTypes, id => id == net.gasType) == -1)) { return; } Tile tile = Framing.GetTileSafely(pipePos); ModTile modTile = ModContent.GetModTile(tile.type); float rate = modTile is FluidTransportTile transport ? transport.ExportRate : (modTile is FluidPumpTile ? ModContent.GetInstance <FluidTransportTile>().ExportRate : -1); if (rate <= 0) { return; } float exported = Math.Min(rate, net.Capacity); if (exported + entry.current > entry.max) { exported = entry.max - entry.current; } if (exported <= 0) { return; } if (entry.id == MachineGasID.None) { entry.id = net.gasType; } entry.current += exported; net.StoredFluid -= exported; if (net.StoredFluid <= 0) { net.gasType = MachineGasID.None; } }
public void AddNetworkFailsWhenAddingDuplicatedTarget() { NetworkCollection manager = CreateNetworkManager(); manager.UpdateStatus(); manager.Add(new Network("TestNetwork", "http://test1")); manager.Add(new Network("TestNetwork", "http://test2")); }
public void EnumerateConfiguredNetworks() { NetworkCollection manager = CreateNetworkManager(); Assert.IsNotNull(manager); Assert.IsTrue(manager.Contains("Internet")); Assert.IsTrue(manager.Contains("Work")); Assert.IsTrue(manager.Contains("Home")); }
internal static void DrawFluid(Point16 tilePos, Texture2D texture, SpriteBatch spriteBatch) { Tile tile = Framing.GetTileSafely(tilePos); if (NetworkCollection.HasFluidPipeAt(tilePos, out FluidNetwork net)) { float factor = net.StoredFluid / net.Capacity; float alpha = net.liquidType != MachineLiquidID.None ? 1f : (net.gasType != MachineGasID.None ? 0.65f * factor : 0); if (alpha == 0) { return; } Color color = net.gasType != MachineGasID.None ? Capsule.GetBackColor(net.gasType) : net.liquidType != MachineLiquidID.None ? Capsule.GetBackColor(net.liquidType) : throw new Exception(); color = MiscUtils.MixLightColors(Lighting.GetColor(tilePos.X, tilePos.Y), color); var offset = MiscUtils.GetLightingDrawOffset(); var rect = new Rectangle(tile.frameX, tile.frameY, 16, 16); if (net.liquidType != MachineLiquidID.None) { //Adjust the frame to the proper subset int subsetHeight = texture.Frame(1, 4, 0, 0).Height; if (factor < 0.3f) { rect.X += subsetHeight * 3; } else if (factor < 0.6f) { rect.X += subsetHeight * 2; } else if (factor < 0.90f) { rect.X += subsetHeight; } } spriteBatch.Draw(texture, tilePos.ToWorldCoordinates(0, 0) + offset - Main.screenPosition, rect, color * alpha, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0); } }
public static void KillMachine(int i, int j, int type) { Tile tile = Main.tile[i, j]; Machine mTile = ModContent.GetModTile(type) as Machine; mTile.GetDefaultParams(out _, out _, out _, out int itemType); int itemIndex = Item.NewItem(i * 16, j * 16, 16, 16, itemType); MachineItem item = Main.item[itemIndex].modItem as MachineItem; Point16 tePos = new Point16(i, j) - tile.TileCoord(); if (TileEntity.ByPosition.ContainsKey(tePos)) { MachineEntity tileEntity = TileEntity.ByPosition[tePos] as MachineEntity; //Drop any items the entity contains if (tileEntity.SlotsCount > 0) { for (int slot = 0; slot < tileEntity.SlotsCount; slot++) { Item drop = tileEntity.RetrieveItem(slot); //Drop the item and copy over any important data if (drop.type > ItemID.None && drop.stack > 0) { int dropIndex = Item.NewItem(i * 16, j * 16, 16, 16, drop.type, drop.stack); if (drop.modItem != null) { Main.item[dropIndex].modItem.Load(drop.modItem.Save()); } } tileEntity.ClearItem(slot); } } item.entityData = tileEntity.Save(); //Remove this machine from the wire networks if it's a powered machine if (tileEntity is PoweredMachineEntity pme) { NetworkCollection.RemoveMachine(pme); } tileEntity.Kill(i, j); if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.TileEntitySharing, remoteClient: -1, ignoreClient: Main.myPlayer, number: tileEntity.ID); } } }
public override void PlaceInWorld(int i, int j, Item item) { base.PlaceInWorld(i, j, item); item.placeStyle %= 4; var tile = Framing.GetTileSafely(i, j); //Sanity check; TileObjectData should already handle this tile.frameX = (short)(item.placeStyle * 18); NetworkCollection.OnFluidPipePlace(new Point16(i, j)); }
public override async Task OnSearch(object value = null) { await _model.SearchNetworkAsync(); Application.Current.Dispatcher.Invoke(new Action(() => { NetworkCollection.Clear(); foreach (NetworkInterfaces net in _model.NetworkCollection) { NetworkCollection.Add(net); } })); }
private void NetworkMonitoring() { while (true) { List <NetworkAdapter> adapters = networkMoniter.Refresh(); Application.Current.Dispatcher.BeginInvoke(new Action(() => { long uploadSpeed = 0; long downloadSpeed = 0; int i = 0; for (; i < adapters.Count; i += 1) { uploadSpeed += adapters[i].UploadSpeed; downloadSpeed += adapters[i].downloadSpeed; if (NetworkCollection.Count <= i) { NetworkCollection.Add(new NetworkModelView(adapters[i])); } else { NetworkCollection[i].Resolve(adapters[i]); } } while (NetworkCollection.Count > i) { NetworkCollection.RemoveAt(i); } speedQueue.Enqueue(uploadSpeed + downloadSpeed); while (speedQueue.Count > 200) { speedQueue.Dequeue(); } GlobalUploadSpeed = NetworkAdapter.GetSpeedString(uploadSpeed); GlobalDownloadSpeed = NetworkAdapter.GetSpeedString(downloadSpeed); Notify(() => GlobalUploadSpeed); Notify(() => GlobalDownloadSpeed); Notify(() => GraphPointCollection); })); Thread.Sleep(1000); } }
public override void Load(TagCompound tag) { NetworkCollection.EnsureNetworkIsInitialized(); if (tag.ContainsKey("networks")) { NetworkCollection.Load(tag.GetCompound("networks")); } if (tag.GetList <Point16>("mufflers") is List <Point16> list) { MachineMufflerTile.mufflers = list; } }
// 检查网络是否连接 private bool IsNetworkConnected() { bool isConn = false; NetworkCollection networks = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All); foreach (Network n in networks) { if (n.IsConnected)//&& n.IsConnectedToInternet) { isConn = true; break; } } return(isConn); }
public static void TryExportLiquids <T>(this T entity, Point16 pumpPos, int indexToExtract) where T : MachineEntity, ILiquidMachine { if (indexToExtract < 0 || indexToExtract >= entity.LiquidEntries.Length) { return; } var entry = entity.LiquidEntries[indexToExtract]; if (!NetworkCollection.HasFluidPipeAt(pumpPos, out FluidNetwork net) || net.gasType != MachineGasID.None || entry.isInput || (entry.id != MachineLiquidID.None && net.liquidType != MachineLiquidID.None && entry.id != net.liquidType)) { return; } Tile tile = Framing.GetTileSafely(pumpPos); ModTile modTile = ModContent.GetModTile(tile.type); if (!(modTile is FluidPumpTile pump) || pump.GetConnectedMachine(pumpPos) != entity) { return; } float rate = pump.CapacityExtractedPerPump; float extracted = Math.Min(rate, entry.current); if (net.liquidType == MachineLiquidID.None) { net.liquidType = entry.id; } if (net.StoredFluid + extracted > net.Capacity) { extracted = net.Capacity - net.StoredFluid; } net.StoredFluid += extracted; entry.current -= extracted; if (entry.current <= 0) { entry.id = MachineLiquidID.None; } }
private void LoadNetworkConnections() { NetworkCollection networks = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All); foreach (Network n in networks) { // Create a tab TabItem tabItem = new TabItem(); tabItem.Header = string.Format("Network {0} ({1})", tabControl1.Items.Count, n.Name); tabControl1.Items.Add(tabItem); // StackPanel stackPanel2 = new StackPanel(); stackPanel2.Orientation = Orientation.Vertical; // List all the properties AddProperty("Name: ", n.Name, stackPanel2); AddProperty("Description: ", n.Description, stackPanel2); AddProperty("Domain type: ", n.DomainType.ToString(), stackPanel2); AddProperty("Is connected: ", n.IsConnected.ToString(), stackPanel2); AddProperty("Is connected to the internet: ", n.IsConnectedToInternet.ToString(), stackPanel2); AddProperty("Network ID: ", n.NetworkId.ToString(), stackPanel2); AddProperty("Category: ", n.Category.ToString(), stackPanel2); AddProperty("Created time: ", n.CreatedTime.ToString(), stackPanel2); AddProperty("Connected time: ", n.ConnectedTime.ToString(), stackPanel2); AddProperty("Connectivity: ", n.Connectivity.ToString(), stackPanel2); // StringBuilder s = new StringBuilder(); s.AppendLine("Network Connections:"); NetworkConnectionCollection connections = n.Connections; foreach (NetworkConnection nc in connections) { s.AppendFormat("\n\tConnection ID: {0}\n\tDomain: {1}\n\tIs connected: {2}\n\tIs connected to internet: {3}\n", nc.ConnectionId, nc.DomainType, nc.IsConnected, nc.IsConnectedToInternet); s.AppendFormat("\tAdapter ID: {0}\n\tConnectivity: {1}\n", nc.AdapterId, nc.Connectivity); } s.AppendLine(); Label label = new Label(); label.Content = s.ToString(); stackPanel2.Children.Add(label); tabItem.Content = stackPanel2; } }
public void NetworkCollectionContainsAllNetworkConnections() { bool isConnected = NetworkListManager.IsConnected; ConnectivityStates connectivity = NetworkListManager.Connectivity; bool isConnectedToInternet = NetworkListManager.IsConnectedToInternet; NetworkCollection networks = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All); NetworkConnectionCollection connections = NetworkListManager.GetNetworkConnections(); // BUG: Both GetNetworks and GetNetworkConnections create new network objects, so // you can't do a reference comparison. // By inspection, the connections are contained in the NetworkCollection, just a different instance. foreach (NetworkConnection c in connections) { Assert.Contains(c.Network, networks); } }
private static int Chest_AfterPlacement_Hook(On.Terraria.Chest.orig_AfterPlacement_Hook orig, int x, int y, int type, int style, int direction) { int ret = orig(x, y, type, style, direction); if (ret != -1) { //A chest was able to be placed. Try to add this chest to nearby item networks Point16 coords = new Point16(x, y); TileObjectData.OriginToTopLeft(type, style, ref coords); coords -= new Point16(1, 1); //"coord" is the top-left corner of the chest for (int checkY = coords.Y; checkY < coords.Y + 4; checkY++) { for (int checkX = coords.X; checkX < coords.X + 4; checkX++) { int relX = checkX - coords.X; int relY = checkY - coords.Y; //Ignore corners if ((relX == 0 && relY == 0) || (relX == 0 && relY == 3) || (relX == 3 && relY == 0) || (relX == 3 && relY == 3)) { continue; } var point = new Point16(checkX, checkY); if (NetworkCollection.HasItemPipeAt(point, out ItemNetwork net)) { if (!net.chests.Contains(ret)) { //Add the chest to the network net.chests.Add(ret); if (!net.pipesConnectedToChests.Contains(point)) { net.pipesConnectedToChests.Add(point); } } } } } } return(ret); }
public static void TestNetwork() { NetworkCollection networks = NetworkListManager.GetNetworks(NetworkConnectivityLevels.Connected); Console.WriteLine("\t[NetworkConnections]"); foreach (Network n in networks) { if (n.Description.StartsWith("Aspit")) { SQLDB.SetConString("DBConInternal"); } else { SQLDB.SetConString("DBCon"); } } }
private void btnAgBaglantisi_Click(object sender, EventArgs e) { NetworkCollection networks = NetworkListManager. GetNetworks(NetworkConnectivityLevels.All); foreach (Network n in networks) { TreeNode ana_dugum = new TreeNode(); ana_dugum.Text = string.Format("Network {0} ({1})", treeView1.Nodes.Count, "Bağlantı İsmi= " + n.Name); treeView1.Nodes.Add(ana_dugum); ana_dugum.Nodes.Add("Tanımlama= " + n.Description); ana_dugum.Nodes.Add("Domain türü=" + n.DomainType); if (n.IsConnected == true) { ana_dugum.Nodes.Add("Ağ Bağlantısı Açık"); } else { ana_dugum.Nodes.Add("Ağ Bağlantısı Kapalı"); } if (n.IsConnectedToInternet == true) { ana_dugum.Nodes.Add("İnternet Bağlantısı Var"); } else { ana_dugum.Nodes.Add("İnternet Bağlantısı Yok"); } ana_dugum.Nodes.Add("Network Id=" + n.NetworkId.ToString()); ana_dugum.Nodes.Add("Kategori=" + n.Category.ToString()); ana_dugum.Nodes.Add("Oluşturulma Zamanı=" + n.CreatedTime.ToString()); ana_dugum.Nodes.Add("Bağlantı Zamanı=" + n.ConnectedTime.ToString()); ana_dugum.Nodes.Add("Bağlantı Protokolleri=" + n.Connectivity.ToString()); } treeView1.ExpandAll(); }
private async Task HandleContent(NetworkCollection col, CollectionModelWithLatestVersion c, CancellationToken ct, List <NetworkCollection> collections = null) { if (collections == null) { collections = new List <NetworkCollection> { col } } ; var collectionSpecs = await ProcessEmbeddedCollections(c, collections, ct).ConfigureAwait(false); var modSpecs = await ProcessMods(col, c, await _collectionInfoFetcher.GetGame(col.GameId).ConfigureAwait(false)) .ConfigureAwait(false); col.ReplaceContent(modSpecs.Concat(collectionSpecs)); }
/// <summary> /// Attempts to send the <paramref name="flux"/> to a connected <seealso cref="WireNetwork"/>. The flux is split among all connected networks. /// </summary> /// <param name="flux"></param> public void ExportFlux(WireNetwork network) { TerraFlux flux = new TerraFlux(Math.Min((float)StoredFlux, (float)ExportRate)); //Ran out of TF if ((float)flux <= 0) { return; } TerraFlux send = flux / NetworkCollection.GetWireNetworksConnectedTo(this).Count; network.ImportFlux(this, ref send); if ((float)send > 0) { ImportFlux(ref send); } }
public void NetworkCollectionSerialization() { var networks = new NetworkCollection { Networks = {new Network {Id = Guid.NewGuid()}}, NetworksLinks = {new Link("next", "http://api.com/next")} }; string json = JsonConvert.SerializeObject(networks, Formatting.None); Assert.Contains("\"networks\"", json); Assert.DoesNotContain("\"network\"", json); var result = JsonConvert.DeserializeObject<NetworkCollection>(json); Assert.NotNull(result); Assert.Equal(1, result.Count()); Assert.Equal(1, result.Networks.Count()); Assert.Equal(1, result.NetworksLinks.Count()); }