/// <summary> /// Викликає діалог вибору обєкту з буфера з перевіркою його валідності /// </summary> /// <param name="validator">валідатор обєктів</param> /// <returns>тру, якщо був обраний валідний обєкт</returns> public BufferData LoadDialog(ValidationCallback validator) { //validator = delegate(BufferData obj) { return obj.ToString().Length>7 ;}; frmSelectBufferData frm_load = new frmSelectBufferData(validator); if (frm_load.ShowDialog() == DialogResult.OK) { BufferData selectedBd = Load(frm_load.SelectedName); if (validator == null) { return(selectedBd); } else { int valKey = getValidationDelegateHashCode(validator); if (selectedBd.ValidatorsResults.ContainsKey(valKey) && selectedBd.ValidatorsResults[valKey]) { return(selectedBd); } else { return(null); } } } else { return(null); } }
static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage validation_custom.exe mw-id=<middleware ID>"); return(-1); } Config config = new Config(args); InitializeLogging(config); //o Enable Message validation. This parameter is "false" by default. config.AddValue("GMSEC-MSG-CONTENT-VALIDATE", "true"); // TODO: Once available, replace this statement with usage of // ConnectionManager::getAPIVersion (See RTC 4798) Log.Info(Connection.GetAPIVersion()); try { ConnectionManager connMgr = new ConnectionManager(config); Log.Info("Opening the connection to the middleware server"); connMgr.Initialize(); Log.Info(connMgr.GetLibraryVersion()); //o Set up the ValidationCallback and subscribe ValidationCallback vc = new ValidationCallback(); connMgr.Subscribe(PROD_MESSAGE_SUBJECT, vc); //o Start the AutoDispatcher connMgr.StartAutoDispatch(); //o Create and publish a simple Product File Message SetupStandardFields(connMgr); GMSEC.API.MIST.MESSAGE.ProductFileMessage productMessage = CreateProductFileMessage(connMgr, "//hostname/dir/filename"); connMgr.Publish(productMessage); productMessage = CreateProductFileMessage(connMgr, "//badhost/dir/filename"); //o Publish the message to the middleware bus connMgr.Publish(productMessage); connMgr.StopAutoDispatch(); //o Disconnect from the middleware and clean up the Connection connMgr.Cleanup(); } catch (GMSEC_Exception e) { Log.Error(e.ToString()); return(-1); } return(0); }
/// <summary> Return a list of node indices in a specified range around the given node. /// The returned list is in no specific order. Excludes invalid nodes. </summary> /// <param name="idx"> The central node index. </param> /// <param name="radius"> Radius from central node that ring starts. </param> /// <param name="width"> Width of the ring. </param> /// <param name="callback"> An optional callback that can first check if the node is "valid" and /// return True if so, else it should return False. </param> /// <returns>Returns null if there was an error. </returns> public virtual List <int> NodeIndicesRing(int idx, int radius, int width, ValidationCallback callback) { if (radius < 1) { radius = 1; } if (width < 1) { width = 1; } List <int> all = NodeIndicesAround(idx, radius + (width - 1), false, callback); List <int> inner = radius > 1 ? NodeIndicesAround(idx, radius - 1, false, callback) : new List <int>(); if (all == null || inner == null) { return(null); } for (int i = 0; i < inner.Count; i++) { if (all.Contains(inner[i])) { all.Remove(inner[i]); } } return(all); }
public static void HandleSubmit(FormElement form, DomEvent evt, AjaxOptions ajaxOptions) { evt.PreventDefault(); // run validation ArrayList validationCallbacks = (ArrayList)Type.GetField(form, "validationCallbacks"); if (validationCallbacks != null) { for (int i = 0; i < validationCallbacks.Length; i++) { ValidationCallback callback = (ValidationCallback)validationCallbacks[i]; if (!callback()) { return; // bail out since validation failed } } } string body = MvcHelpers.SerializeForm(form); MvcHelpers.AsyncRequest(form.Action, form.Method ?? "post", body, form, ajaxOptions); }
/// <summary> Return a list of nodes that are considered to be on the border of a range of nodes that /// where provided. A border node is a node that is present in the list but for which one of its /// neighbour nodes are not in the list or is an invalid node. This is useful when trying to find /// the border nodes for a range of valid nodes a unit can move to. </summary> /// <param name="nodes"> List of nodes considered to be valid and from which the border nodes must be determined. </param> /// <param name="callback"> An optional callback that is used to determine if a neighbour node is valid. </param> /// <returns>Returns null if there was an error. </returns> public virtual List <T> GetBorderNodes <T>(List <T> nodes, ValidationCallback callback) where T : MapNavNode { List <T> res = new List <T>(); for (int i = 0; i < nodes.Count; i++) { List <T> nn = NodesAround <T>(nodes[i], true, false, callback); for (int j = 0; j < nn.Count; j++) { // is a border when there is an invalid tile next to it if (nn[j] == null || false == nodes.Contains(nn[j])) { res.Add(nodes[i]); break; } } } return(res); }
/// <summary> /// Обчислює хеш-код делегата /// </summary> /// <param name="validator">делегат</param> /// <returns>хеш-код</returns> private int getValidationDelegateHashCode(ValidationCallback validator) { return(validator.Method.MetadataToken); }
/// <summary> Return list of indices for nodes in a certain range around given node. /// The returned list is in no specific order. Excludes invalid nodes. </summary> /// <param name="idx"> Index of the central node around which to get neighbouring nodes.</param> /// <param name="range"> The radius around the central node. </param> /// <param name="includeCentralNode">Should the central node be included? It will be added first in the list if so.</param> /// <param name="callback"> An optional callback that can first check if the node is "valid" and return True if /// so, else it should return False. </param> /// <returns>Returns null if there was an error. </returns> public virtual List <int> NodeIndicesAround(int idx, int range, bool includeCentralNode, ValidationCallback callback) { return(null); }
/// <summary> Return a list of nodes in a specified range around the given node. /// The returned list is in no specific order. Excludes invalid nodes. </summary> /// <param name="node"> The central node. </param> /// <param name="radius"> Radius from central node that ring starts. </param> /// <param name="width"> Width of the ring. </param> /// <param name="callback"> An optional callback that can first check if the node is "valid" and /// return True if so, else it should return False. </param> /// <returns>Returns null if there was an error. </returns> public virtual List <T> NodesRing <T>(MapNavNode node, int radius, int width, ValidationCallback callback) where T : MapNavNode { if (radius < 1) { radius = 1; } if (width < 1) { width = 1; } List <T> all = NodesAround <T>(node, radius + (width - 1), false, callback); List <T> inner = radius > 1 ? NodesAround <T>(node, radius - 1, false, callback) : new List <T>(); if (all == null || inner == null) { return(null); } for (int i = 0; i < inner.Count; i++) { if (all.Contains(inner[i])) { all.Remove(inner[i]); } } return(all); }
/// <summary> Return list of nodes in a certain range around given node. /// The returned list is in no specific order. Excludes invalid nodes. /// </summary> /// <param name="node"> The central node around which to get neighbouring nodes.</param> /// <param name="range"> The radius around the central node. </param> /// <param name="includeCentralNode">Should the central node be included? It will be added first in the list if so.</param> /// <param name="callback"> An optional callback that can first check if the node is "valid" and return True if /// so, else it should return False. </param> /// <returns>Returns null if there was an error. </returns> public virtual List <T> NodesAround <T>(MapNavNode node, int range, bool includeCentralNode, ValidationCallback callback) where T : MapNavNode { return(null); }
/// <summary> /// Return list of indices for nodes in a certain range around given node. /// The returned list is in no specific order. Excludes invalid nodes. /// </summary> /// <param name="idx"> Index of the central node around which to get neighboring nodes.</param> /// <param name="radius"> The radius around the central node. </param> /// <param name="includeCentralNode">Should the central node be included? It will be added first in the list if so.</param> /// <param name="callback"> An optional callback that can first check if the node is "valid" and return True if /// so, else it should return False. </param> /// <returns>Returns null if there was an error. </returns> public override List <int> NodeIndicesAround(int idx, int radius, bool includeCentralNode, ValidationCallback callback) { if (radius < 1) { radius = 1; } if (radius == 1) { return(NodeIndicesAround(idx, false, includeCentralNode, callback)); } List <int> nodes = new List <int>(0); if (idx < 0 || idx >= grid.Length) { return(null); } if (includeCentralNode) { if (grid[idx] != null) { if (grid[idx].isValid) { if (callback != null) { if (true == callback(grid[idx])) { nodes.Add(idx); } } else { nodes.Add(idx); } } } } for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { int q = grid[idx].q + x; int r = grid[idx].r + y; if (q < 0 || r < 0 || q >= mapHorizontalSize || r >= mapVerticalSize) { continue; } int id = (r * mapHorizontalSize + q); if (id == idx) { continue; } if (id >= 0 && id < grid.Length) { if (grid[id].isValid) { if (callback != null) { if (false == callback(grid[id])) { continue; } } if (false == nodes.Contains(id)) { nodes.Add(id); } } } } } return(nodes); }
/// <summary> /// Returns list of nodes indices starting at the "next" node and going anti-clockwise around the central node. /// </summary> /// <param name="idx"> Index of the central node around which to get neighboring nodes.</param> /// <param name="includeInvalid"> Should "invalid" nodes be included? If so then a -1 entry will be added to the /// returned list for invalid nodes. An invalid node might be one that is stored in /// the grid array but not considered to be in the grid. This normally happens with /// Hexa grids. An invalid node might also be one marked as invalid by the callback function. </param> /// <param name="includeCentralNode">Should the central node be included? It will be added first in the list if so.</param> /// <param name="callback"> An optional callback that can first check if the node is "valid" and return True if /// so, else it should return False. </param> /// <returns>Returns null if there was an error. </returns> public override List <int> NodeIndicesAround(int idx, bool includeInvalid, bool includeCentralNode, ValidationCallback callback) { List <int> nodes = new List <int>(); if (idx < 0 || idx >= grid.Length) { return(null); } if (includeCentralNode) { if (grid[idx] != null) { if (callback != null) { if (false == grid[idx].isValid || false == callback(grid[idx])) { if (includeInvalid) { nodes.Add(-1); } } else { nodes.Add(idx); } } else { if (grid[idx].isValid) { nodes.Add(idx); } else if (includeInvalid) { nodes.Add(-1); } } } else if (includeInvalid) { nodes.Add(-1); } } //int[,] neighbours = diagonalNeighbours ? Neighbours8 : Neighbours4; int[,] neighbours = Neighbours8; // always use 8-neighbour for this so that a ring around can be selected. // the special select function witch takes "cost" into account will // take 4-neighbour type selection into account for (int i = 0; i < neighbours.GetLength(0); i++) { int x = grid[idx].q + neighbours[i, 0]; int y = grid[idx].r + neighbours[i, 1]; int id = NodeIdx(x, y); if (id < 0) { if (includeInvalid) { nodes.Add(-1); } continue; } if (grid[id] == null) { if (includeInvalid) { nodes.Add(-1); } continue; } if (false == grid[id].isValid) { if (includeInvalid) { nodes.Add(-1); } continue; } if (callback != null) { if (false == callback(grid[id])) { if (includeInvalid) { nodes.Add(-1); } continue; } } nodes.Add(id); } return(nodes); }
/// <summary> /// Return list of nodes in a certain range around given node. /// The returned list is in no specific order. Excludes invalid nodes. /// </summary> /// <param name="node"> The central node around which to get neighboring nodes.</param> /// <param name="radius"> The radius around the central node. </param> /// <param name="includeCentralNode">Should the central node be included? It will be added first in the list if so.</param> /// <param name="callback"> An optional callback that can first check if the node is "valid" and return True if /// so, else it should return False. </param> /// <returns>Returns null if there was an error. </returns> public override List <T> NodesAround <T>(MapNavNode node, int radius, bool includeCentralNode, ValidationCallback callback) { if (radius < 1) { radius = 1; } if (node == null) { return(null); } if (radius == 1) { return(NodesAround <T>(node, false, includeCentralNode, callback)); } List <T> nodes = new List <T>(0); if (node.idx < 0 || node.idx >= grid.Length) { return(null); } if (includeCentralNode) { if (node.isValid) { if (callback != null) { if (true == callback(node)) { nodes.Add((T)node); } } else { nodes.Add((T)node); } } } for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { //if (Mathf.Abs(x + y) > radius) continue; int q = node.q + x; int r = node.r + y; if (q < 0 || r < 0 || q >= mapHorizontalSize || r >= mapVerticalSize) { continue; } int id = (r * mapHorizontalSize + q); if (id == node.idx) { continue; } if (id >= 0 && id < grid.Length) { if (grid[id].isValid) { if (callback != null) { if (false == callback(grid[id])) { continue; } } if (false == nodes.Contains((T)grid[id])) { nodes.Add((T)grid[id]); } } } } } return(nodes); }
/// <summary> /// Returns list of nodes starting at the "next" node and going anti-clockwise around the central node. /// </summary> /// <param name="node"> The central node around which to get neighboring nodes.</param> /// <param name="includeInvalid"> Should "invalid" nodes be included? If so then a NULL entry will be added to the /// returned list for invalid nodes. An invalid node might be one that is stored in /// the grid array but not considered to be in the grid. This normally happens with /// Hexa grids. An invalid node might also be one marked as invalid by the callback function. </param> /// <param name="includeCentralNode">Should the central node be included? It will be added first in the list if so.</param> /// <param name="callback"> An optional callback that can first check if the node is "valid" and return True if /// so, else it should return False. </param> /// <returns>Returns null if there was an error. </returns> public override List <T> NodesAround <T>(MapNavNode node, bool includeInvalid, bool includeCentralNode, ValidationCallback callback) { if (node == null) { return(null); } List <T> nodes = new List <T>(includeCentralNode ? 7 : 6); if (node.idx < 0 || node.idx >= grid.Length) { return(null); } if (includeCentralNode) { if (callback != null) { if (false == node.isValid || false == callback(node)) { if (includeInvalid) { nodes.Add(null); } } else { nodes.Add((T)node); } } else { if (node.isValid) { nodes.Add((T)node); } else if (includeInvalid) { nodes.Add(null); } } } //int[,] neighbours = diagonalNeighbours ? Neighbours8 : Neighbours4; int[,] neighbours = Neighbours8; // always use 8-neighbour for this so that a ring around can be selected. // the special select function witch takes "cost" into account will // take 4-neighbour type selection into account for (int dir = 0; dir < neighbours.GetLength(0); dir++) { int q = grid[node.idx].q + neighbours[dir, 0]; int r = grid[node.idx].r + neighbours[dir, 1]; MapNavNode n = NodeAt <MapNavNode>(q, r); if (n == null) { if (includeInvalid) { nodes.Add(null); } continue; } if (false == n.isValid) { if (includeInvalid) { nodes.Add(null); } continue; } if (callback != null) { if (false == callback(n)) { if (includeInvalid) { nodes.Add(null); } continue; } } nodes.Add((T)n); } return(nodes); }