private string GetNetworkNodeName(NetworkNodes value) { var memberInfo = value.GetType().GetMember(value.ToString()); if (memberInfo.Length != 1) { return(null); } var displayAttribute = memberInfo[0].GetCustomAttributes(typeof(DisplayAttribute), false) as DisplayAttribute[]; if (displayAttribute == null || displayAttribute.Length != 1) { return(null); } return(displayAttribute[0].Name); }
void Log()//giải mã và nạp dữ liệu { WindowsForm.Loading2.Show(this); byte[] pass = AdvancedEncryptionStandard.Hash(password); //chuyển pass sang hashcode string str = AdvancedEncryptionStandard.Decoding(Encoding.Default.GetBytes(node.Name), pass); //giải mã if (NetworkNodes.CheckPassword(str)) //kiểm tra nếu đúng thì... { node.Name = str.Substring(NetworkNodes.checkingCode.Length); //loại bỏ đoạn mã dùng để nhận biết nhập đúng pâss trong str try { //giải mã và nạp các nodes con NetworkNodes.Create(node, AdvancedEncryptionStandard.Decoding(Encoding.Default.GetBytes(((Tag_of_Node)node.Tag).nodes), pass)); } catch (Exception ex) { WindowsForm.Loading2.End(); WindowsForm.Notification.Show(MessageBoxButtons.OK, "Can not create a TreeNode from the string!", ex, this); returner = true; panel1.MouseMove -= panel1_MouseMove; Hide(); return; } WindowsForm.Loading2.End(); ((Tag_of_Node)node.Tag).password = pass; ((Tag_of_Node)node.Tag).unlocked = true; ((Tag_of_Node)node.Tag).nodes = null; returner = true; panel1.MouseMove -= panel1_MouseMove; Hide(); } else { WindowsForm.Loading2.End(); WindowsForm.Notification.Show(MessageBoxButtons.OK, "Wrong!", this); textBoxPassword.Text = ""; } }
/// <summary> /// Make connection by request /// </summary> /// <param name="targetNode"></param> /// <param name="character"></param> public void MakeConnection(IPBSObject targetNode, Character character) { //source pbsObject access check _pbsObject.CheckAccessAndThrowIfFailed(character); //--- transmit radius check targetNode.ThrowIfEqual(_pbsObject, ErrorCodes.WTFErrorMedicalAttentionSuggested); var targetUnit = ((Unit)targetNode); targetUnit.CurrentPosition.IsInRangeOf2D(_pbsObject.CurrentPosition, _pbsObject.GetTransmitRadius()).ThrowIfFalse(ErrorCodes.TargetOutOfTransmitRadius); //check pair-------------------------- _pbsObject.ConnectionHandler.CheckNewConnection(targetNode, true); targetNode.ConnectionHandler.CheckNewConnection(_pbsObject, false); //-------check networks and owners var changeOwner = false; long newOwner = 0L; var sourceNetwork = NetworkNodes.ToArray(); IPBSObject[] targetNetwork = null; var dockingBaseInSourceNetwork = false; var dockingBaseInTargetNetwork = false; var isSameNetwork = sourceNetwork.Any(p => p.GetHashCode() == targetNode.GetHashCode()); if (!isSameNetwork) { //they are in different networks targetNetwork = targetNode.ConnectionHandler.NetworkNodes.ToArray(); var sourceDockingBase = sourceNetwork.FirstOrDefault(n => n is PBSDockingBase) as PBSDockingBase; var targetDockingBase = targetNetwork.FirstOrDefault(n => n is PBSDockingBase) as PBSDockingBase; dockingBaseInSourceNetwork = sourceDockingBase != null; dockingBaseInTargetNetwork = targetDockingBase != null; //check nodes in networks if (dockingBaseInSourceNetwork) { IsAnyNodeOutsideOfNetworkRange(sourceNetwork, sourceDockingBase).ThrowIfTrue(ErrorCodes.SomeNodeAreOutsideOfNetworkRange); IsAnyNodeOutsideOfNetworkRange(targetNetwork, sourceDockingBase).ThrowIfTrue(ErrorCodes.SomeNodeAreOutsideOfNetworkRange); } var sumUsage = sourceNetwork.Concat(targetNetwork).Where(n => !(n is PBSDockingBase)).Sum(n => n.GetBandwidthUsage()); //both networks have docking bases -> nono (dockingBaseInSourceNetwork && dockingBaseInTargetNetwork).ThrowIfTrue(ErrorCodes.BasesInBothNetworks); if (dockingBaseInSourceNetwork || dockingBaseInTargetNetwork) { //there must be a docking base in one of the two changeOwner = true; //-------------------------------------- number of nodes check int bandwidthCapacity; if (dockingBaseInSourceNetwork) { bandwidthCapacity = sourceDockingBase.GetBandwidthCapacity; } else { bandwidthCapacity = targetDockingBase.GetBandwidthCapacity; } sumUsage.ThrowIfGreater(bandwidthCapacity, ErrorCodes.TooManyNodesOutOfCpu); //------------------------------------------ new owner select if (dockingBaseInSourceNetwork) { newOwner = _pbsObject.Owner; } else { newOwner = targetUnit.Owner; } } else { //no docking base sumUsage.ThrowIfGreater(CPU_POWER_IN_NETWORK_WITHOUT_BASE, ErrorCodes.TooManyNodesOutOfCpu); _pbsObject.Owner.ThrowIfNotEqual(targetUnit.Owner, ErrorCodes.OwnerMismatch); } } if (changeOwner) { if (newOwner == 0) { //lekezeletlen resz %%% Debug.Assert(false, " nincs megirva"); } else { if (dockingBaseInSourceNetwork) { foreach (var n in targetNetwork) { n.TakeOver(newOwner); } } if (dockingBaseInTargetNetwork) { foreach (var n in sourceNetwork) { n.TakeOver(newOwner); } } } } //-----------------------------do actual work var outConnection = new PBSConnection(targetNode, _pbsObject, true); AttachConnection(outConnection); var inConnection = new PBSConnection(_pbsObject, targetNode, false); targetNode.ConnectionHandler.AttachConnection(inConnection); Transaction.Current.OnCommited(() => { var pbsBase = NetworkNodes.FirstOrDefault(o => o is PBSDockingBase); if (pbsBase == null) { return; } _pbsObject.ReinforceHandler.ForceDailyOffset(pbsBase.ReinforceHandler.ReinforceOffsetHours); //this node foreach (var node in NetworkNodes) { if (node.Equals(_pbsObject)) { continue; } if (node.Equals(pbsBase)) { continue; } //all reinforcable nodes in the network node.ReinforceHandler.ForceDailyOffset(pbsBase.ReinforceHandler.ReinforceOffsetHours); } }); }
/// <summary> /// Builds the config, which consists of the node graph and serialized layers. /// </summary> ModelConfig get_network_config() { var config = new ModelConfig { Name = name }; var node_conversion_map = new Dictionary <string, int>(); foreach (var layer in _layers) { var kept_nodes = _should_skip_first_node(layer) ? 1 : 0; foreach (var(original_node_index, node) in enumerate(layer.InboundNodes)) { var node_key = _make_node_key(layer.Name, original_node_index); if (NetworkNodes.Contains(node_key)) { node_conversion_map[node_key] = kept_nodes; kept_nodes += 1; } } } var layer_configs = new List <LayerConfig>(); foreach (var layer in _layers) { var filtered_inbound_nodes = new List <NodeConfig>(); foreach (var(original_node_index, node) in enumerate(layer.InboundNodes)) { var node_key = _make_node_key(layer.Name, original_node_index); if (NetworkNodes.Contains(node_key) && !node.is_input) { var node_data = node.serialize(_make_node_key, node_conversion_map); filtered_inbound_nodes.append(node_data); } } var layer_config = generic_utils.serialize_keras_object(layer); layer_config.Name = layer.Name; layer_config.InboundNodes = filtered_inbound_nodes; layer_configs.Add(layer_config); } config.Layers = layer_configs; // Gather info about inputs and outputs. var model_inputs = new List <NodeConfig>(); foreach (var i in range(_input_layers.Count)) { var(layer, node_index, tensor_index) = _input_coordinates[i]; var node_key = _make_node_key(layer.Name, node_index); if (!NetworkNodes.Contains(node_key)) { continue; } var new_node_index = node_conversion_map[node_key]; model_inputs.append(new NodeConfig { Name = layer.Name, NodeIndex = new_node_index, TensorIndex = tensor_index }); } config.InputLayers = model_inputs; var model_outputs = new List <NodeConfig>(); foreach (var i in range(_output_layers.Count)) { var(layer, node_index, tensor_index) = _output_coordinates[i]; var node_key = _make_node_key(layer.Name, node_index); if (!NetworkNodes.Contains(node_key)) { continue; } var new_node_index = node_conversion_map[node_key]; model_outputs.append(new NodeConfig { Name = layer.Name, NodeIndex = new_node_index, TensorIndex = tensor_index }); } config.OutputLayers = model_outputs; return(config); }