/// <summary> /// Проверяет доступность хоста по указанному адресу через ICMP ECHO. /// </summary> /// <param name="address">Адрес хоста</param> /// <param name="timeout">Тайм-аут</param> /// <returns>Результат .</returns> public static IPStatus ProbeIcmp(IPAddress address, int timeout = 5000) { if (address == null) { throw new ArgumentNullException("address"); } if (0 > timeout) { throw new ArgumentOutOfRangeException("timeout"); } var ping = new Ping(); try { var reply = ping.Send(address, timeout); if (null == reply) { throw new InvalidOperationException("Ping.Send() returns null on a synchronous operation."); } return(reply.Status); } catch (PingException px) { DebugOutput.WriteLine("PingException in NetworkResource.ProbeIcmp(): {0}", px.InnerException.Message); return(IPStatus.Unknown); } }
/// <inheritdoc /> public ConstructorBuilder Define() { if (this.ctor != null) { return(this.ctor); } if (this.define != null) { this.ctor = this.define( this.MethodAttributes, this.callingConvention, this.parameters.Select(p => p.ParameterType).ToArray(), null, null); int i = 0; foreach (var parm in this.parameters) { this.ctor.DefineParameter(++i, parm.Attributes, parm.ParameterName); } } else if (this.defineDefault != null) { this.ctor = this.defineDefault(this.MethodAttributes); } DebugOutput.WriteLine("======================================="); DebugOutput.WriteLine("New Constructor ({0})", string.Join(", ", this.parameters.Select(p => $"{p.ParameterType} {p.ParameterName}"))); DebugOutput.WriteLine("Calling Convention: {0}", this.callingConvention); DebugOutput.WriteLine(""); return(this.ctor); }
/// <inheritdoc /> public PropertyBuilder Define() { if (this.propertyBuilder == null) { this.propertyBuilder = this.define( this.name, this.PropertyAttributes, this.callingConvention, this.propertyType, null, null, null, null, null); if (this.GetMethod != null) { this.propertyBuilder.SetGetMethod(this.GetMethod.Define()); } if (this.SetMethod != null) { this.propertyBuilder.SetSetMethod(this.SetMethod.Define()); } DebugOutput.WriteLine(""); DebugOutput.WriteLine("======================================="); DebugOutput.WriteLine("Property {0} Defined", this.name); DebugOutput.WriteLine("Calling Convention: {0}", this.callingConvention); DebugOutput.WriteLine("Attributes: {0}", this.propertyBuilder.Attributes); DebugOutput.WriteLine(""); } return(this.propertyBuilder); }
/// <inheritdoc /> public FieldBuilder Define() { if (this.fieldBuilder == null) { this.fieldBuilder = this.defineFunc( this.FieldName, this.FieldType, null, null, this.fieldAttributes); DebugOutput.WriteLine("======================================="); DebugOutput.WriteLine("New Field '{0}' [{1}]", this.FieldName, this.FieldType); DebugOutput.WriteLine("Field Attributes: {0}", this.fieldAttributes); DebugOutput.WriteLine(""); } return(this.fieldBuilder); }
/// <summary> /// Builds the type. /// </summary> /// <returns>The type.</returns> public TypeBuilder Define() { if (this.typeBuilder == null) { DebugOutput.WriteLine("======================================="); DebugOutput.WriteLine("Type '{0}' defined", this.typeName); DebugOutput.WriteLine("Type Attributes: {0}", this.TypeAttributes); DebugOutput.WriteLine("Base Type: {0}", this.baseType); DebugOutput.WriteLine("Implements: {0}", string.Join(", ", this.interfaces.Select(i => i.Name))); this.typeBuilder = this.moduleBuilder.DefineType( this.typeName, this.TypeAttributes, this.baseType, this.interfaces.ToArray()); this.BuildGenericParameters(); this.customAttributes.SetCustomAttributes(a => this.typeBuilder.SetCustomAttribute(a)); } return(this.typeBuilder); }
private Response ExecuteQuery(Query query) { TcpClient connection = new TcpClient(); #if NETCORE connection.ConnectAsync(Host, Port).Wait(); #else connection.Connect(Host, Port); #endif byte[][] data = query.Encode(); if (!ReferenceEquals(DebugOutput, null)) { DebugOutput.WriteLine("QUERY {0}:", QueryID); DebugOutput.WriteLine(); Utility.DumpBytes(DebugOutput, data[0]); Utility.DumpBytes(DebugOutput, data[1]); DebugOutput.WriteLine(); } NetworkStream stream = connection.GetStream(); stream.Write(data[0], 0, data[0].Length); stream.Write(data[1], 0, data[1].Length); return(new Response(this, connection, stream)); }
/// <inheritdoc/> public MethodBuilder Define() { if (this.methodBuilder != null) { return(this.methodBuilder); } int parmCount = this.parms.Count; Type[] parameterTypes = new Type[parmCount]; for (int i = 0; i < parmCount; i++) { parameterTypes[i] = this.parms[i].ParameterType; } this.methodBuilder = this.defineMethod( this.methodName, this.Attributes, this.callingConvention, this.returnType, null, null, parameterTypes, null, null); if (this.genericParameterBuilders != null) { this.genericParameters = this.methodBuilder.DefineGenericParameters( this.genericParameterBuilders.Select(g => g.ParameterName).ToArray()); for (int i = 0; i < this.genericParameterBuilders.Count; i++) { this.genericParameterBuilders[i].Build(this.genericParameters[i]); } } int parmIndex = 0; foreach (var parm in this.parms) { var paramBuilder = this.methodBuilder .DefineParameter(++parmIndex, parm.Attributes, parm.ParameterName); parm.CustomAttributes.SetCustomAttributes(a => paramBuilder.SetCustomAttribute(a)); } this.customAttributes.SetCustomAttributes(a => this.methodBuilder.SetCustomAttribute(a)); DebugOutput.WriteLine(""); DebugOutput.WriteLine("======================================="); DebugOutput.Write($"New Method {this.methodBuilder.Name}"); if (this.methodBuilder.IsGenericMethodDefinition == true) { DebugOutput.Write($"<{string.Join(", ", this.methodBuilder.GetGenericArguments().Select(t => t.Name))}>"); } DebugOutput.WriteLine($"({string.Join(", ", this.parms.Select(p => $"{p.Attributes} {p.ParameterType} {p.ParameterName}"))})"); DebugOutput.WriteLine("Calling Convention: {0}", this.methodBuilder.CallingConvention); DebugOutput.WriteLine("Attributes: {0}", this.Attributes); DebugOutput.WriteLine(""); return(this.methodBuilder); }