private static void HandleLine(string line, LineHandler handler) { if (line != null) { handler(line); } }
protected virtual bool ReadStats(string path, string fileTypeName, LineHandler lineHandler) { //checks file var fileName = $"{path}{Path.DirectorySeparatorChar}{fileTypeName}"; if (!File.Exists(fileName)) { return(false); } var sr = new StreamReader(fileName); //ignore header sr.ReadLine(); //reads stats from each line string line; while ((line = sr.ReadLine()) != null) { lineHandler(line); } sr.Close(); sr.Dispose(); return(true); }
public Vector2 closestPoint(Vector2 v) { Vector2 ret = new Vector2(0f, 0f); float distance = float.MaxValue, current = float.MaxValue; LineHandler tmp = lines[0]; foreach (LineHandler handler in lines) { foreach (Vector2 collisions in handler.contactPoints(v)) { current = Vector2.Distance(v, collisions); if (current < distance) { distance = current; ret = collisions; tmp = handler; } } } bool contains = tmp.contains(ret); return(ret); }
//public void WriteTo(string text,bool eol) //{ // StreamWriter writer = new StreamWriter(_file); // writer.Write(text + ((eol)?'\n':' ')); // writer.Close(); //} public short CompareTo(string format) { string[] anotherLines = format.Split('\n'); string[] lines = _value.Split('\n'); for (int i = 0, j = 0; j < anotherLines.Length && i < lines.Length;) { LineHandler one = new LineHandler(); LineHandler two = new LineHandler(); while (i < lines.Length && one.InsertLine(lines[i++])) { ; } while (j < anotherLines.Length && two.InsertLine(anotherLines[j++])) { ; } Debug.LogFormat("One:\nDistance: {0}\nAngle: {1}\nTwo:\nDistance: {2}\nAngle: {3}\n", one.Distance, one.Angle, two.Distance, two.Angle); if (!LineHandler.Check(one, two, _distanceRange, _angleRange)) { return(0); } } return(_index); }
public KeyValuePair <Vector2, float>[] reach(LineHandler origin, LineHandler destiny) { List <KeyValuePair <Vector2, float> > route = new List <KeyValuePair <Vector2, float> > (); //Scene s = (Scene) sd; //WE STORE IN A BOOLEAN IF WE HAVE VISITED OR NOT THAT LINE // Dictionary<LineHandler, bool> visited_lines = new Dictionary<LineHandler, bool>(); // Dictionary<Trajectory.Node, bool> visited_nodes = new Dictionary<Trajectory.Node, bool>(); // // foreach (LineHandler line in lines) // visited_lines.Add (line, false); // // reach (origin, destiny, visited_lines, route); Dictionary <LineHandler, KeyValuePair <float, LineHandler> > stickered = stick(origin); LineHandler current = destiny; while (current != origin) { KeyValuePair <float, LineHandler> node = stickered [current]; Trajectory.Node tmp = LineHandler.commonPoint(current, node.Value); route.Add(new KeyValuePair <Vector2, float>(LineHandler.nodeToVector2(tmp), tmp.getScale())); current = node.Value; } route.Reverse(); return(route.ToArray()); }
public static bool Check(LineHandler one, LineHandler two, float distanceRange, float angleRange) { float rangeD, rangeA; if (isSignSame(one._angle) != isSignSame(two._angle)) { return(false); } if (one._angle > two._angle) { rangeA = one._angle - two._angle; } else { rangeA = two._angle - one._angle; } if (one._distance > two._distance) { rangeD = one._distance - two._distance; } else { rangeD = two._distance - one._distance; } return((distanceRange > rangeD) && (angleRange > rangeA)); }
/*public bool reach(Trajectory.Node origin, LineHandler origin_line, LineHandler destiny, Dictionary<Trajectory.Node, bool> visited_nodes, Dictionary<LineHandler, bool> visited_lines, List<Vector2> route){ * bool reached = true; * if(visited_nodes[origin] == false && !destiny.containsNode(origin)){ * visited_nodes [origin] = true; * foreach (LineHandler line in origin_line.getNeighborLines()) { * if(visited_lines[line] == false && line.containsNode(origin)){ * visited_lines[line.Key] = true; * if (!visited_nodes[line.Key.start] && reach (line.Key.start, destiny, visited_nodes, visited_lines, route)) * route.Add (new Vector2(line.Key.start.getX () / 10f, 60 - line.Key.start.getY () / 10f)); * else if (!visited_nodes[line.Key.end] && reach (line.Key.end, destiny, visited_nodes, visited_lines, route)) * route.Add (new Vector2(line.Key.end.getX () / 10f, 60 - line.Key.end.getY () / 10f)); * else * reached = false; * } * } * } * return reached; * }*/ /*public bool reach(Trajectory.Node origin, LineHandler origin_line, LineHandler destiny, Dictionary<Trajectory.Node, bool> visited_nodes, Dictionary<LineHandler, bool> visited_lines, List<Vector2> route){ * bool reached = true; * if (!destiny.containsNode (origin)) { * visited_nodes [origin] = true; * foreach (LineHandler line in origin_line.getNeighborLines()) { * if (!visited_lines [line] && !visited_nodes [line.getOtherPoint (origin)] && reach (line.getOtherPoint (origin), origin_line, destiny, visited_nodes, visited_lines, route)) { * Trajectory.Node n = line.getOtherPoint (origin); * route.Add (new Vector2(n.getX () / 10f, 60 - n.getY () / 10f)); * } * } * } * return reached; * }*/ public bool reach(LineHandler origin, LineHandler destiny, Dictionary <LineHandler, bool> visited, List <KeyValuePair <Vector2, float> > route) { bool ret = false; if (origin == destiny) { ret = true; } else if (visited[origin]) { ret = false; } else { visited [origin] = true; foreach (LineHandler neighbor in origin.getNeighborLines()) { if (reach(neighbor, destiny, visited, route)) { Trajectory.Node point = LineHandler.commonPoint(origin, neighbor); route.Add(new KeyValuePair <Vector2, float>(LineHandler.nodeToVector2(point), point.getScale())); ret = true; break; } } } return(ret); }
public KeyValuePair<Vector2,float>[] reach(LineHandler origin, LineHandler destiny) { List<KeyValuePair<Vector2,float>> route = new List<KeyValuePair<Vector2,float>> (); //Scene s = (Scene) sd; //WE STORE IN A BOOLEAN IF WE HAVE VISITED OR NOT THAT LINE // Dictionary<LineHandler, bool> visited_lines = new Dictionary<LineHandler, bool>(); // Dictionary<Trajectory.Node, bool> visited_nodes = new Dictionary<Trajectory.Node, bool>(); // // foreach (LineHandler line in lines) // visited_lines.Add (line, false); // // reach (origin, destiny, visited_lines, route); Dictionary<LineHandler, KeyValuePair<float,LineHandler>> stickered = stick (origin); LineHandler current = destiny; while (current != origin) { KeyValuePair<float,LineHandler> node = stickered [current]; Trajectory.Node tmp = LineHandler.commonPoint (current, node.Value); route.Add (new KeyValuePair<Vector2, float>(LineHandler.nodeToVector2 (tmp),tmp.getScale())); current = node.Value; } route.Reverse (); return route.ToArray (); }
public static Trajectory.Node commonPoint(LineHandler l1, LineHandler l2) { if (l1.containsNode (l2.start)) return l2.start; else return l2.end; }
LineHandler AddLine(Pair pair) { GameObject NewLineObj = Instantiate(LinePrefab, transform.position, transform.rotation, transform); LineHandler NewLine = NewLineObj.GetComponent <LineHandler>(); NewLine.Pair = pair; NewLine.UpdatePoints(); return(NewLine); }
public static int Execute(string executable, string arguments, string workingDirectory, IDictionary <string, string> environmentVariables, LineHandler stdoutHandler, LineHandler stderrHandler, TimeSpan?timeout) { ProcessStartInfo startInfo = new ProcessStartInfo(executable) { Arguments = arguments, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false }; if (workingDirectory != null) { startInfo.WorkingDirectory = workingDirectory; } if (environmentVariables != null) { foreach (KeyValuePair <string, string> entry in environmentVariables) { startInfo.EnvironmentVariables.Add(entry.Key, entry.Value); } } Process process = Process.Start(startInfo); process.OutputDataReceived += (sender, e) => HandleLine(e.Data, stdoutHandler); process.ErrorDataReceived += (sender, e) => HandleLine(e.Data, stderrHandler); process.BeginOutputReadLine(); process.BeginErrorReadLine(); if (timeout.HasValue) { if (!process.WaitForExit((int)timeout.Value.TotalMilliseconds)) { try { process.Kill(); process.WaitForExit(); } catch (Exception) { } throw new TimeoutException(string.Format("Timed out process execution after {0} seconds.", timeout.Value.TotalSeconds)); } } // Wait for exit and for all output to be spooled. // Calling WaitForExit with a timeout is insufficient. process.WaitForExit(); return(process.ExitCode); }
public static Trajectory.Node commonPoint(LineHandler l1, LineHandler l2) { if (l1.containsNode(l2.start)) { return(l2.start); } else { return(l2.end); } }
public Dictionary <LineHandler, KeyValuePair <float, LineHandler> > stick(LineHandler origin) { Dictionary <LineHandler, KeyValuePair <float, LineHandler> > stickered = new Dictionary <LineHandler, KeyValuePair <float, LineHandler> >(); Dictionary <LineHandler, float> costs = new Dictionary <LineHandler, float>(); LineHandler current = origin, previous = origin; stickered.Add(origin, new KeyValuePair <float, LineHandler> (0, null)); float current_cost = 0, total_cost = 0; while (stickered.Count < lines.Count) { current_cost = current.side.getLength(); total_cost = stickered [current].Key; foreach (LineHandler line in current.getNeighborLines()) { if (!stickered.ContainsKey(line)) { if (costs.ContainsKey(line)) { if (costs [line] > current_cost) { costs [line] = current_cost; } } else { costs.Add(line, current_cost); } } } //obtenemos la mas corta float min = float.MaxValue; LineHandler selected = origin; foreach (KeyValuePair <LineHandler, float> line in costs) { if (line.Value < min) { selected = line.Key; min = line.Value; } } costs.Remove(selected); //establecemos la mas corta como principal y la añadimos a vecinas stickered.Add(selected, new KeyValuePair <float, LineHandler>(stickered[previous].Key + current.side.getLength(), current)); previous = current; current = selected; } return(stickered); }
void CreateGrid() { float x_offset = 0; float y_offset = 0; if (centered) { x_offset = -width / 2f; y_offset = -height / 2f; } int numSegmentsPerRow = (int)(width / maxVertexDistance) + (width % maxVertexDistance > 0 ? 1 : 0); int numPointsPerRow = numSegmentsPerRow + 1; for (int r = 0; r < rows; r++) { GameObject lineObj = new GameObject(); LineHandler lineHandler = lineObj.AddComponent <LineHandler>(); lineHandler.name = "Row " + r; float y = height / (rows - 1) * r; Vector3[] points = new Vector3[numPointsPerRow]; for (int i = 0; i < numPointsPerRow; i++) { float x = i * width / numSegmentsPerRow; points[i] = new Vector3(x + x_offset, y + y_offset, 0); } lineHandler.SetPoints(points); ColorSplitter splitter = lineHandler.gameObject.AddComponent <ColorSplitter>(); splitter.Split(); } int numSegmentsPerCol = (int)(height / maxVertexDistance) + (height % maxVertexDistance > 0 ? 1: 0); int numPointsPerCol = numSegmentsPerCol + 1; for (int c = 0; c < cols; c++) { GameObject lineObj = new GameObject(); LineHandler lineHandler = lineObj.AddComponent <LineHandler>(); lineHandler.name = "Col " + c; float x = width / (cols - 1) * c; Vector3[] points = new Vector3[numPointsPerCol]; for (int i = 0; i < numPointsPerCol; i++) { float y = i * height / numSegmentsPerCol; points[i] = new Vector3(x + x_offset, y + y_offset, 0); } lineHandler.SetPoints(points); ColorSplitter splitter = lineHandler.gameObject.AddComponent <ColorSplitter>(); splitter.Split(); } }
public static int Execute(string executable, string arguments, string workingDirectory, IDictionary<string, string> environmentVariables, LineHandler stdoutHandler, LineHandler stderrHandler, TimeSpan? timeout) { ProcessStartInfo startInfo = new ProcessStartInfo(executable) { Arguments = arguments, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false }; if (workingDirectory != null) { startInfo.WorkingDirectory = workingDirectory; } if (environmentVariables != null) { foreach (KeyValuePair<string, string> entry in environmentVariables) startInfo.EnvironmentVariables.Add(entry.Key, entry.Value); } Process process = Process.Start(startInfo); process.OutputDataReceived += (sender, e) => HandleLine(e.Data, stdoutHandler); process.ErrorDataReceived += (sender, e) => HandleLine(e.Data, stderrHandler); process.BeginOutputReadLine(); process.BeginErrorReadLine(); if (timeout.HasValue) { if (!process.WaitForExit((int)timeout.Value.TotalMilliseconds)) { try { process.Kill(); process.WaitForExit(); } catch (Exception) { } throw new TimeoutException(string.Format("Timed out process execution after {0} seconds.", timeout.Value.TotalSeconds)); } } // Wait for exit and for all output to be spooled. // Calling WaitForExit with a timeout is insufficient. process.WaitForExit(); return process.ExitCode; }
public Slice(TriangleMesh mesh, Plane plane) { //GL.Disable(EnableCap.Lighting); //GL.LineWidth(2); //GL.Begin(PrimitiveType.Lines); //float height = 0; // Slice at 3 levels and combine all segments - this obviates dealing with triangles that are exactly on the plane. for (int i = -1; i <= 1; i++) { Vector3 offset = plane.Normal * 0.0001f * (float)i; LineHandler lineHandler = new LineHandler(0.0f); Plane testPlane = new Plane(plane.Normal, plane.Point + offset); foreach (Triangle t in mesh.Triangles) { var intersect = new TrianglePlaneIntersect(t, testPlane); if (intersect.Intersects) { lineHandler.AddSegment(intersect.PointA, intersect.PointB); //GL.Color3(Color.Blue); //GL.Vertex3(intersect.PointA + new Vector3(0, 0, height + .01f)); //GL.Color3(Color.Red); //GL.Vertex3(intersect.PointB + new Vector3(0, 0, height + .01f)); } else if (intersect.all_intersect && Vector3.Dot(t.Plane.Normal, testPlane.Normal) > 0.5f) { // Entire triangle intersects // Add all the triangle edges (TODO: clean this up...) List<Vector3> vertices = new List<Vector3>(t.Vertices); for (int a = 0; a < 3; a++) { Vector3 v1 = vertices[a]; Vector3 v2 = vertices[(a + 1) % 3]; lineHandler.AddSegment(v1, v2); } } } if (this.polyTree == null) { Init(lineHandler.GetOuterLoops(), plane); } else { Slice s = new Slice(lineHandler.GetOuterLoops(), plane); this.Union(s); } } //GL.End(); //GL.Enable(EnableCap.Lighting); //GL.LineWidth(1); }
public Slice(TriangleMesh mesh, Plane plane) { //GL.Disable(EnableCap.Lighting); //GL.LineWidth(2); //GL.Begin(PrimitiveType.Lines); //float height = 0; // Slice at 3 levels and combine all segments - this obviates dealing with triangles that are exactly on the plane. for (int i = -1; i <= 1; i++) { Vector3 offset = plane.Normal * 0.0001f * (float)i; LineHandler lineHandler = new LineHandler(0.0f); Plane testPlane = new Plane(plane.Normal, plane.Point + offset); foreach (Triangle t in mesh.Triangles) { var intersect = new TrianglePlaneIntersect(t, testPlane); if (intersect.Intersects) { lineHandler.AddSegment(intersect.PointA, intersect.PointB); //GL.Color3(Color.Blue); //GL.Vertex3(intersect.PointA + new Vector3(0, 0, height + .01f)); //GL.Color3(Color.Red); //GL.Vertex3(intersect.PointB + new Vector3(0, 0, height + .01f)); } else if (intersect.all_intersect && Vector3.Dot(t.Plane.Normal, testPlane.Normal) > 0.5f) { // Entire triangle intersects // Add all the triangle edges (TODO: clean this up...) List <Vector3> vertices = new List <Vector3>(t.Vertices); for (int a = 0; a < 3; a++) { Vector3 v1 = vertices[a]; Vector3 v2 = vertices[(a + 1) % 3]; lineHandler.AddSegment(v1, v2); } } } if (this.polyTree == null) { Init(lineHandler.GetOuterLoops(), plane); } else { Slice s = new Slice(lineHandler.GetOuterLoops(), plane); this.Union(s); } } //GL.End(); //GL.Enable(EnableCap.Lighting); //GL.LineWidth(1); }
public IList <T> read(LineHandler lineHandler) { reader = new StreamReader(fileName); IList <T> result = new List <T>(); do { String line = reader.ReadLine(); result.Add(lineHandler(line.Split(separator.ToCharArray()))); } while (reader.Peek() != -1); reader.Close(); return(result); }
public void TestMethod1() { Filter filter = new Filter(); LineHandlers lineHandlers = new LineHandlers(); LineHandler[] infoHandler = new LineHandler[] { lineHandlers.GotInfo }; LineHandler[] debugHandler = new LineHandler[] { lineHandlers.GotDebug }; LineHandler[] snmpHandler = new LineHandler[] { lineHandlers.GotSnmpLibLine }; LineHandler[] trayhandler = new LineHandler[] { lineHandlers.GotTray }; filter.SetFilterHandlers("<INFO>", infoHandler); filter.SetFilterHandlers("<DEBUG>", debugHandler); filter.SetFilterHandlers("<SnmpLib::", snmpHandler); filter.SetFilterHandlers("<Tray::", trayhandler); using (FileStream fileStream = new FileStream(@"C:\temp\HP.Test.Framework.log", FileMode.Open)) { } }
public Dictionary<LineHandler, KeyValuePair<float, LineHandler>> stick(LineHandler origin) { Dictionary<LineHandler, KeyValuePair<float,LineHandler>> stickered = new Dictionary<LineHandler, KeyValuePair<float, LineHandler>>(); Dictionary<LineHandler,float> costs = new Dictionary<LineHandler, float>(); LineHandler current = origin, previous = origin; stickered.Add (origin, new KeyValuePair<float, LineHandler> (0, null)); float current_cost = 0, total_cost = 0; while (stickered.Count < lines.Count) { current_cost = current.side.getLength (); total_cost = stickered [current].Key; foreach (LineHandler line in current.getNeighborLines ()) { if(!stickered.ContainsKey(line)) if (costs.ContainsKey (line)) { if (costs [line] > current_cost) { costs [line] = current_cost; } } else { costs.Add (line, current_cost); } } //obtenemos la mas corta float min = float.MaxValue; LineHandler selected = origin; foreach (KeyValuePair<LineHandler,float> line in costs) { if (line.Value < min) { selected = line.Key; min = line.Value; } } costs.Remove(selected); //establecemos la mas corta como principal y la añadimos a vecinas stickered.Add(selected, new KeyValuePair<float, LineHandler>(stickered[previous].Key + current.side.getLength(),current)); previous = current; current = selected; } return stickered; }
public bool isNeighbor(LineHandler line) { return(neighbours.Contains(line)); }
public void addNeighbour(LineHandler n) { this.neighbours.Add(n); }
public bool isNeighbor(LineHandler line) { return neighbours.Contains (line); }
public int Execute(string executable, string arguments, string workingDirectory, IDictionary <string, string> environmentVariables, LineHandler stdoutHandler, LineHandler stderrHandler, TimeSpan?timeout) { CheckProfileCanResolveSlave(); StringBuilder message = new StringBuilder(); message.AppendLine("Executing remote command: "); message.AppendFormat(" Executable : {0}\n", executable); message.AppendFormat(" Arguments : {0}\n", arguments); if (workingDirectory != null) { message.AppendFormat(" Directory : {0}\n", workingDirectory); } if (environmentVariables != null) { message.AppendLine(" Environment :"); foreach (KeyValuePair <string, string> entry in environmentVariables) { message.AppendFormat(" {0}={1}\n", entry.Key, entry.Value); } } Log(message.ToString()); ExecuteRequest request = new ExecuteRequest(); request.Executable = executable; if (arguments.Length != 0) { request.Arguments = arguments; } if (workingDirectory != null) { request.WorkingDirectory = workingDirectory; } if (environmentVariables != null) { request.EnvironmentVariables = new Dictionary <string, string>(environmentVariables); } if (timeout.HasValue) { request.Timeout = (int)timeout.Value.TotalSeconds; } ExecuteResponse response = GetSlaveClient().Execute(request, stream => { if (stream.__isset.stdoutLine) { stdoutHandler(stream.StdoutLine); } if (stream.__isset.stderrLine) { stderrHandler(stream.StderrLine); } }); return(response.ExitCode); }
public KeyValuePair <Vector2, float>[] route(Vector2 origin, Vector2 destiny) { List <KeyValuePair <Vector2, float> > ret = new List <KeyValuePair <Vector2, float> > (); LineHandler origin_line = null, destiny_line = null; foreach (LineHandler handler in lines) { if (origin_line == null && handler.contains(origin)) { origin_line = handler; } if (destiny_line == null && handler.contains(destiny)) { destiny_line = handler; } if (origin_line != null && destiny_line != null) { break; } } Vector2 closest = Vector2.zero; if (origin_line == null) { closest = closestPoint(PlayerMB.Instance.getPosition()); foreach (LineHandler handler in lines) { if (origin_line == null && handler.contains(closest)) { origin_line = handler; break; } } } if (closest != Vector2.zero) { ret.Add(new KeyValuePair <Vector2, float>(closest, origin_line.getScaleFor(closest))); } if (origin_line != null && destiny_line != null) { //###################################################### // IF ORIGIN_LINE AND DESTINY_LINE ARE THE SAME // Return only the destiny point, dont have to go // to other node //###################################################### if (origin_line == destiny_line) { ret.Add(new KeyValuePair <Vector2, float>(destiny, destiny_line.getScaleFor(destiny))); } else { List <KeyValuePair <Vector2, float> > tmpRoute = new List <KeyValuePair <Vector2, float> >(reach(origin_line, destiny_line)); //tmpRoute.Reverse (); ret.AddRange(tmpRoute); ret.Add(new KeyValuePair <Vector2, float>(destiny, destiny_line.getScaleFor(destiny))); } } return(ret.ToArray()); }
/*public bool reach(Trajectory.Node origin, LineHandler origin_line, LineHandler destiny, Dictionary<Trajectory.Node, bool> visited_nodes, Dictionary<LineHandler, bool> visited_lines, List<Vector2> route){ bool reached = true; if(visited_nodes[origin] == false && !destiny.containsNode(origin)){ visited_nodes [origin] = true; foreach (LineHandler line in origin_line.getNeighborLines()) { if(visited_lines[line] == false && line.containsNode(origin)){ visited_lines[line.Key] = true; if (!visited_nodes[line.Key.start] && reach (line.Key.start, destiny, visited_nodes, visited_lines, route)) route.Add (new Vector2(line.Key.start.getX () / 10f, 60 - line.Key.start.getY () / 10f)); else if (!visited_nodes[line.Key.end] && reach (line.Key.end, destiny, visited_nodes, visited_lines, route)) route.Add (new Vector2(line.Key.end.getX () / 10f, 60 - line.Key.end.getY () / 10f)); else reached = false; } } } return reached; }*/ /*public bool reach(Trajectory.Node origin, LineHandler origin_line, LineHandler destiny, Dictionary<Trajectory.Node, bool> visited_nodes, Dictionary<LineHandler, bool> visited_lines, List<Vector2> route){ bool reached = true; if (!destiny.containsNode (origin)) { visited_nodes [origin] = true; foreach (LineHandler line in origin_line.getNeighborLines()) { if (!visited_lines [line] && !visited_nodes [line.getOtherPoint (origin)] && reach (line.getOtherPoint (origin), origin_line, destiny, visited_nodes, visited_lines, route)) { Trajectory.Node n = line.getOtherPoint (origin); route.Add (new Vector2(n.getX () / 10f, 60 - n.getY () / 10f)); } } } return reached; }*/ public bool reach(LineHandler origin, LineHandler destiny, Dictionary<LineHandler, bool> visited, List<KeyValuePair<Vector2,float>> route) { bool ret = false; if (origin == destiny) ret = true; else if (visited[origin]) ret = false; else{ visited [origin] = true; foreach (LineHandler neighbor in origin.getNeighborLines()) { if (reach (neighbor, destiny, visited, route)) { Trajectory.Node point = LineHandler.commonPoint (origin, neighbor); route.Add (new KeyValuePair<Vector2,float>(LineHandler.nodeToVector2 (point),point.getScale())); ret = true; break; } } } return ret; }
private static void HandleLine(string line, LineHandler handler) { if (line != null) handler(line); }
public int Execute(string executable, string arguments, string workingDirectory, IDictionary<string, string> environmentVariables, LineHandler stdoutHandler, LineHandler stderrHandler, TimeSpan? timeout) { CheckProfileCanResolveSlave(); StringBuilder message = new StringBuilder(); message.AppendLine("Executing remote command: "); message.AppendFormat(" Executable : {0}\n", executable); message.AppendFormat(" Arguments : {0}\n", arguments); if (workingDirectory != null) message.AppendFormat(" Directory : {0}\n", workingDirectory); if (environmentVariables != null) { message.AppendLine(" Environment :"); foreach (KeyValuePair<string, string> entry in environmentVariables) message.AppendFormat(" {0}={1}\n", entry.Key, entry.Value); } Log(message.ToString()); ExecuteRequest request = new ExecuteRequest(); request.Executable = executable; if (arguments.Length != 0) request.Arguments = arguments; if (workingDirectory != null) request.WorkingDirectory = workingDirectory; if (environmentVariables != null) request.EnvironmentVariables = new Dictionary<string, string>(environmentVariables); if (timeout.HasValue) request.Timeout = (int) timeout.Value.TotalSeconds; ExecuteResponse response = GetSlaveClient().Execute(request, stream => { if (stream.__isset.stdoutLine) stdoutHandler(stream.StdoutLine); if (stream.__isset.stderrLine) stderrHandler(stream.StderrLine); }); return response.ExitCode; }
/// <summary> /// Establishing server connection. Makes also first validation and check if all required /// parameters are set. /// </summary> private void Connect() { SendLine += new LineHandler(WriteContext); try { socket = new TcpClient(this.host, this.port); Connected(new EventArgs()); } catch(Exception e) { throw new IOException(e.Message); } try { stream = socket.GetStream(); readingThread = new Thread(new ThreadStart(ReadContext)); readingThread.IsBackground = true; readingThread.Name = "reading thread"; readingThread.Start(); AbstractCommand uc; if(string.IsNullOrEmpty(this.RealName) || string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(this.Mode)) throw new NoParameterException("Real name or Username or mode"); uc = new UserCommand(this.Username, this.Mode, this.RealName); SendLine(uc.execute()); uc = new NickCommand() { Nick = this.Nick }; if(string.IsNullOrEmpty(this.Nick)) throw new NoParameterException("Nick"); SendLine(uc.execute()); #if DEBUG uc = new JoinCommand() { Name = "interia" }; SendLine(uc.execute()); #endif } catch(Exception ex) { throw ex; } }
public void addNeighbour(LineHandler n) { this.neighbours.Add (n); }