public void TestEqual() { var left = new Null(); var right = new Null(); Assert.AreEqual(left, right); Assert.IsTrue(left == right); Assert.IsTrue(left.Equals(right)); Assert.IsTrue(left != null); // ReSharper disable EqualExpressionComparison Assert.IsTrue(left == left); // ReSharper restore EqualExpressionComparison Assert.Throws<ArgumentNullException>(() => left.AppendBytesTo(null)); Assert.AreEqual("Null", left.ToString()); }
protected internal override Node TransformNull(Null @null) { return Dispatch(@null); }
protected internal override void TraverseNull(Null @null) { // do nothing }
public NullValueWrapper(Null item) { this.Item = item; }
protected internal virtual Node TransformNull(Null @null) { return null; }
public Expression TypeCheck(Null nullLiteral, Scope scope) { var Position = nullLiteral.Position; return new Null(Position, NamedType.Nullable(TypeVariable.CreateGeneric())); }
protected internal override void TraverseNull(Null @null) { Dispatch(@null); }
public static PriorityValue NewNull(Null @null) { return new NullWrapper(@null); }
public static Mixed InvokeFunction(Mixed classObject, ArrayList parametersSupplied, Mixed functionName) { string functionNameString = Convert.ToString(functionName).value; // check if an Object was passed if (!(classObject is Object)) { Report.Warn(405); return new Null(); } // invoke MethodInfo mi = classObject.GetType().GetMethod(functionNameString); if (mi == null) { Report.Warn(214, functionNameString); return new Null(); } else { // pass parameters (only as many as needed) int parametersNeeded = mi.GetParameters().Length; object[] parametersPassed = new object[parametersNeeded]; int i = 0; for (; i < Math.Min(parametersNeeded, parametersSupplied.Count); i++) parametersPassed[i] = parametersSupplied[i]; // if less parameters actually passed then necessary, pass Null objects instead for (; i < parametersNeeded; i++) parametersPassed[i] = new Null(); // add function call to trace AddFunctionCallToTrace(classObject.GetType().Name + "->" + functionNameString); // invoke Mixed result = (Mixed)mi.Invoke(classObject, parametersPassed); // remove function call to trace RemoveFunctionCallFromTrace(); // push return value return result; } }
public static Mixed Clone(Mixed m) { if (m is Boolean) return new Boolean(((Boolean)m).value); else if (m is Integer) return new Integer(((Integer)m).value); else if (m is Double) return new Double(((Double)m).value); else if (m is String) return new String(((String)m).value); else if (m is Array) { Array a = (Array)m; Mixed clonedKey; int clonedValue; ArrayList clonedKeys = new ArrayList(); ArrayList clonedValues = new ArrayList(); for (int i = 0; i < a.keys.Count; i++) { clonedKey = Clone((Mixed)a.keys[i]); clonedValue = (int)a.values[i]; clonedKeys.Add(clonedKey); clonedValues.Add(clonedValue); } return new Array(clonedKeys, clonedValues); } else if (m is Object) { // find constructor of object to be cloned ConstructorInfo ctor = null; foreach(ConstructorInfo ci in m.GetType().GetConstructors()) { if (!ci.IsStatic) ctor = ci; } int parameterCount = ctor.GetParameters().Length; object[] parameters = new object[parameterCount]; for (int i = 0; i < parameters.Length; i++) parameters[i] = new Null(); // set the standard out to nowhere to avoid output when calling the constructor right now Console.SetOut(nowhere); // create new instance Object result = (Object)Activator.CreateInstance(m.GetType(), parameters); // set field values foreach (FieldInfo f in m.GetType().GetFields()) { // don't use the internal fields __id and __placeOnHeap if (f.Name != "__id" && f.Name != "__placeOnHeap") f.SetValue(result, f.GetValue(m)); } // if a __clone function is available, invoke MethodInfo clone = m.GetType().GetMethod("__clone", Type.EmptyTypes); if (clone != null) { clone.Invoke(result, null); } // reset the standard output Console.SetOut(stdOut); return result; } else if (m is Null) return new Null(); else return new Null(); }
private static void StoreToVariable(string scope, Mixed value, Mixed variableName) { string variableNameString = Convert.ToString(variableName).value; // use scope delivered Hashtable variablePoolOfScope; if (variablePool[scope] == null) { variablePoolOfScope = new Hashtable(); variablePool[scope] = variablePoolOfScope; } else variablePoolOfScope = (Hashtable)variablePool[scope]; // if no value passed, use Null if (value == null) value = new Null(); // determine place on heap if (value.__placeOnHeap == 0) { if (variablePoolOfScope[variableNameString] == null) value.__placeOnHeap = ++maxPlaceOnHeap; else value.__placeOnHeap = (int)variablePoolOfScope[variableNameString]; } // add variable to variable pool variablePoolOfScope[variableNameString] = value.__placeOnHeap; // store value to heap heap[value.__placeOnHeap] = value; }
protected internal override void TraverseNull(Null @null) { _writer.Write("?"); }
public TestType(Null nullValue, bool booleanValue, Option<byte> optionalValue, ITestChoice choiceValue, ReadOnlyArray<ushort> arrayValue) { this.NullValue = nullValue; this.BooleanValue = booleanValue; this.OptionalValue = optionalValue; this.ChoiceValue = choiceValue; this.ArrayValue = arrayValue; }
public static ExtendedParameter NewNull(Null @null) { return new NullWrapper(@null); }
public DefaultIncrementWrapper(Null item) { this.Item = item; }
public static ClientCOV NewDefaultIncrement(Null defaultIncrement) { return new DefaultIncrementWrapper(defaultIncrement); }
/// <summary> /// Writes a null tag to the stream /// </summary> /// <param name="value">The null value</param> /// <param name="tag">The tag number, or 255 for an application tag</param> public void WriteNull(Null value, byte tag = 255) { _writeLengthHeader(tag, ApplicationTag.Null, 0); }
public NullWrapper(Null item) { this.Item = item; }
/// <summary> /// Puts a value into the sink /// </summary> /// <param name="value">The value to put</param> public void PutNull(Null value) { _require(StreamOp.Null); _writer.WriteNull(value, _state.Tag); _moveNext(); }
static void Main(string[] args) { string community = "public"; bool showHelp = false; bool showVersion = false; VersionCode version = VersionCode.V1; int timeout = 1000; int retry = 0; Levels level = Levels.Reportable; string user = string.Empty; string authentication = string.Empty; string authPhrase = string.Empty; string privacy = string.Empty; string privPhrase = string.Empty; bool dump = false; OptionSet p = new OptionSet() .Add("c:", "Community name, (default is public)", delegate(string v) { if (v != null) community = v; }) .Add("l:", "Security level, (default is noAuthNoPriv)", delegate(string v) { if (v.ToUpperInvariant() == "NOAUTHNOPRIV") { level = Levels.Reportable; } else if (v.ToUpperInvariant() == "AUTHNOPRIV") { level = Levels.Authentication | Levels.Reportable; } else if (v.ToUpperInvariant() == "AUTHPRIV") { level = Levels.Authentication | Levels.Privacy | Levels.Reportable; } else { throw new ArgumentException("no such security mode: " + v); } }) .Add("a:", "Authentication method (MD5 or SHA)", delegate(string v) { authentication = v; }) .Add("A:", "Authentication passphrase", delegate(string v) { authPhrase = v; }) .Add("x:", "Privacy method", delegate(string v) { privacy = v; }) .Add("X:", "Privacy passphrase", delegate(string v) { privPhrase = v; }) .Add("u:", "Security name", delegate(string v) { user = v; }) .Add("h|?|help", "Print this help information.", delegate(string v) { showHelp = v != null; }) .Add("V", "Display version number of this application.", delegate(string v) { showVersion = v != null; }) .Add("d", "Display message dump", delegate(string v) { dump = true; }) .Add("t:", "Timeout value (unit is second).", delegate(string v) { timeout = int.Parse(v) * 1000; }) .Add("r:", "Retry count (default is 0)", delegate(string v) { retry = int.Parse(v); }) .Add("v:", "SNMP version (1, 2, and 3 are currently supported)", delegate(string v) { switch (int.Parse(v)) { case 1: version = VersionCode.V1; break; case 2: version = VersionCode.V2; break; case 3: version = VersionCode.V3; break; default: throw new ArgumentException("no such version: " + v); } }); if (args.Length == 0) { ShowHelp(p); return; } List<string> extra; try { extra = p.Parse(args); } catch (OptionException ex) { Console.WriteLine(ex.Message); return; } if (showHelp) { ShowHelp(p); return; } if ((extra.Count - 1) % 3 != 0) { Console.WriteLine("invalid variable number: " + extra.Count); return; } if (showVersion) { Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); return; } IPAddress ip; bool parsed = IPAddress.TryParse(extra[0], out ip); if (!parsed) { foreach (IPAddress address in Dns.GetHostAddresses(extra[0]).Where(address => address.AddressFamily == AddressFamily.InterNetwork)) { ip = address; break; } if (ip == null) { Console.WriteLine("invalid host or wrong IP address found: " + extra[0]); return; } } try { List<Variable> vList = new List<Variable>(); for (int i = 1; i < extra.Count; i = i + 3) { string type = extra[i + 1]; if (type.Length != 1) { Console.WriteLine("invalid type string: " + type); return; } ISnmpData data; switch (type[0]) { case 'i': data = new Integer32(int.Parse(extra[i + 2])); break; case 'u': data = new Gauge32(uint.Parse(extra[i + 2])); break; case 't': data = new TimeTicks(uint.Parse(extra[i + 2])); break; case 'a': data = new IP(IPAddress.Parse(extra[i + 2]).GetAddressBytes()); break; case 'o': data = new ObjectIdentifier(extra[i + 2]); break; case 'x': data = new OctetString(ByteTool.Convert(extra[i + 2])); break; case 's': data = new OctetString(extra[i + 2]); break; case 'd': data = new OctetString(ByteTool.ConvertDecimal(extra[i + 2])); break; case 'n': data = new Null(); break; default: Console.WriteLine("unknown type string: " + type[0]); return; } Variable test = new Variable(new ObjectIdentifier(extra[i]), data); vList.Add(test); } IPEndPoint receiver = new IPEndPoint(ip, 161); if (version != VersionCode.V3) { foreach (Variable variable in Messenger.Set(version, receiver, new OctetString(community), vList, timeout)) { Console.WriteLine(variable); } return; } if (string.IsNullOrEmpty(user)) { Console.WriteLine("User name need to be specified for v3."); return; } IAuthenticationProvider auth = (level & Levels.Authentication) == Levels.Authentication ? GetAuthenticationProviderByName(authentication, authPhrase) : DefaultAuthenticationProvider.Instance; IPrivacyProvider priv; if ((level & Levels.Privacy) == Levels.Privacy) { priv = new DESPrivacyProvider(new OctetString(privPhrase), auth); } else { priv = new DefaultPrivacyProvider(auth); } Discovery discovery = Messenger.GetNextDiscovery(SnmpType.SetRequestPdu); ReportMessage report = discovery.GetResponse(timeout, receiver); SetRequestMessage request = new SetRequestMessage(VersionCode.V3, Messenger.NextMessageId, Messenger.NextRequestId, new OctetString(user), vList, priv, Messenger.MaxMessageSize, report); ISnmpMessage reply = request.GetResponse(timeout, receiver); if (dump) { Console.WriteLine("Request message bytes:"); Console.WriteLine(ByteTool.Convert(request.ToBytes())); Console.WriteLine("Response message bytes:"); Console.WriteLine(ByteTool.Convert(reply.ToBytes())); } if (reply is ReportMessage) { if (reply.Pdu().Variables.Count == 0) { Console.WriteLine("wrong report message received"); return; } var id = reply.Pdu().Variables[0].Id; if (id != Messenger.NotInTimeWindow) { var error = id.GetErrorMessage(); Console.WriteLine(error); return; } // according to RFC 3414, send a second request to sync time. request = new SetRequestMessage(VersionCode.V3, Messenger.NextMessageId, Messenger.NextRequestId, new OctetString(user), vList, priv, Messenger.MaxMessageSize, reply); reply = request.GetResponse(timeout, receiver); } else if (reply.Pdu().ErrorStatus.ToInt32() != 0) // != ErrorCode.NoError { throw ErrorException.Create( "error in response", receiver.Address, reply); } foreach (Variable v in reply.Pdu().Variables) { Console.WriteLine(v); } } catch (SnmpException ex) { Console.WriteLine(ex); } catch (SocketException ex) { Console.WriteLine(ex); } }
public static LogDatumType NewNullValue(Null nullValue) { return new NullValueWrapper(nullValue); }
protected internal virtual void TraverseNull(Null @null) { @null.Unsupported(); }
public bool Write(Null value) { return this.writer.Write("null"); }