public ScalarValue Function(SetValue set1) { if (ReferenceEquals(set1, null)) throw new YAMPArgumentValueException("null", new string[] { "Set" }); return new ScalarValue(set1.Set.Count); }
public SetValue Function(StringValue name, ArgumentsValue args) { var set = new SetValue(name.Value, null, false); int iArgs = 1; //First is "name" foreach (var arg in args) { iArgs++; if (arg is MatrixValue) { set.AddElements((arg as MatrixValue).ToArray()); } else if (arg is StringValue) { set.Set.Add((arg as StringValue).Value); } else if (arg is NumericValue) { set.Set.Add(arg as NumericValue); } else throw new YAMPArgumentInvalidException("Element is not ScalarValue, StringValue or MatrixValue", iArgs); } return set; }
protected void TestValue(String query, SetValue result) { var parser = new Parser(); parser.LoadPlugin(typeof(SetsPlugin).Assembly); parser.UseScripting = true; var value = parser.Evaluate(query); Assert.AreEqual(result, value); }
public SignalEventItem(Signal signal, ValueStructure newValue, SetValue setValue, SetEventFlag setEventFlag, NotifyNewValue notifyNewValue) { _signal = signal; _newValue = newValue; _setEventFlag = setEventFlag; _setValue = setValue; _notifyNewValue = notifyNewValue; }
public DelegateBrowserForm() { wb = new WebBrowser(); CheckDelegate = new CheckValue(this.CheckValueMethod); SetDelegate = new SetValue(this.SetValueMethod); SubmitDelegate = new SubmitForm(this.SubmitFormMethod); ScriptDelegate = new RunScript(this.RunScriptMethod); UrlDelegate = new GetUrl(this.GetUrlMethod); }
public void SET_Add() { var set = new SetValue("otherset", true); //sorted set.Set.Add(3); set.Set.Add("2"); set.Set.Add(1); TestValue(F("newSet({0}, 1, \"2\").SetAdd(3)", setNameA), set); TestValue(F("TAdd(newSet({0}, 1, \"2\"), 3)", setNameA), set); }
public SetValue Function(SetValue set1, Value id) { if (id is MatrixValue) { set1.RemoveElements((id as MatrixValue).ToArray()); } else { set1.Set.Remove(new SetValue.ValueWrap(id)); } return set1; }
public void TestGetObjectTextSetValue() { TextValue textValue1 = new TextValue(); TextValue textValue2 = new TextValue(); textValue1.value = "value1"; textValue2.value = "value2"; SetValue setValue = new SetValue(); setValue.values = new Value[] {textValue1, textValue2}; List<object> value = PqlUtilities.GetValue(setValue) as List<object>; Assert.AreEqual(2, value.Count); Assert.True(value.Contains("value1")); Assert.True(value.Contains("value2")); }
public SetValue Function(StringValue expression, ScalarValue size, ScalarValue maxVal, ScalarValue ordered) { SetValue set = new SetValue(expression.Value, null, ordered.Value != 0); Random rnd = new Random(); int tot = (int)size.Value; for (int i = 0; i < tot; i++) { set.Set.Add(new ScalarValue(rnd.Next((int)maxVal.Value))); } return set; }
public void TestGetObjectNumberSetValue() { NumberValue numberValue1 = new NumberValue(); NumberValue numberValue2 = new NumberValue(); numberValue1.value = "1"; numberValue2.value = "2"; SetValue setValue = new SetValue(); setValue.values = new Value[] { numberValue1, numberValue2 }; List <object> value = PqlUtilities.GetValue(setValue) as List <object>; Assert.AreEqual(2, value.Count); Assert.True(value.Contains("1")); Assert.True(value.Contains("2")); }
public void TestGetObjectCommaTextSetValue() { TextValue textValue1 = new TextValue(); TextValue textValue2 = new TextValue(); textValue1.value = "value1"; textValue2.value = "comma \",\" separated"; SetValue setValue = new SetValue(); setValue.values = new Value[] { textValue1, textValue2 }; List <object> value = PqlUtilities.GetValue(setValue) as List <object>; Assert.AreEqual(2, value.Count); Assert.True(value.Contains("value1")); Assert.True(value.Contains("comma \",\" separated")); }
public void TestGetObjectNestedSetValue() { SetValue setValue = new SetValue(); SetValue innerSetValue = new SetValue(); TextValue textValue = new TextValue(); textValue.value = "value1"; innerSetValue.values = new Value[] { textValue }; setValue.values = new Value[] { innerSetValue }; Assert.Throws <ArgumentException>(() => PqlUtilities.GetValue(setValue)); }
public DelegatePropertySetAccessor(Type targetObjectType, string propName) { base.targetType = targetObjectType; base.propertyName = propName; PropertyInfo propertyInfo = base.GetPropertyInfo(targetObjectType); if (propertyInfo == null) { throw new NotSupportedException(string.Format("Property \"{0}\" does not exist for type {1}.", base.propertyName, base.targetType)); } this._propertyType = propertyInfo.PropertyType; this._canWrite = propertyInfo.CanWrite; base.nullInternal = base.GetNullInternal(this._propertyType); if (propertyInfo.CanWrite) { DynamicMethod method = new DynamicMethod("SetImplementation", null, new Type[] { typeof(object), typeof(object) }, base.GetType().Module, true); ILGenerator iLGenerator = method.GetILGenerator(); MethodInfo setMethod = propertyInfo.GetSetMethod(); Type parameterType = setMethod.GetParameters()[0].ParameterType; iLGenerator.DeclareLocal(parameterType); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Castclass, base.targetType); iLGenerator.Emit(OpCodes.Ldarg_1); if (parameterType.IsValueType) { iLGenerator.Emit(OpCodes.Unbox, parameterType); if (BaseAccessor.typeToOpcode[parameterType] != null) { OpCode opcode = (OpCode)BaseAccessor.typeToOpcode[parameterType]; iLGenerator.Emit(opcode); } else { iLGenerator.Emit(OpCodes.Ldobj, parameterType); } } else { iLGenerator.Emit(OpCodes.Castclass, parameterType); } iLGenerator.EmitCall(OpCodes.Callvirt, setMethod, null); iLGenerator.Emit(OpCodes.Ret); this._set = (SetValue)method.CreateDelegate(typeof(SetValue)); } }
protected SetValue <ValueType> CreateSetValue <ValueType>(PropertyInfo propertyInfo) { Type[] setValueArgTypes = { typeof(Object), propertyInfo.PropertyType }; DynamicMethod setValueMethod = new DynamicMethod("set_" + this.propertyName, null, setValueArgTypes, this.GetType().Module, true); ILGenerator ilGen = setValueMethod.GetILGenerator(1024); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Castclass, propertyInfo.DeclaringType); ilGen.Emit(OpCodes.Ldarg_1); ilGen.EmitCall(OpCodes.Call, propertyInfo.GetSetMethod(), null); ilGen.Emit(OpCodes.Ret); setValueMethod.DefineParameter(1, ParameterAttributes.In, "object"); setValueMethod.DefineParameter(2, ParameterAttributes.In, "value"); SetValue <ValueType> setValue = (SetValue <ValueType>)setValueMethod.CreateDelegate(typeof(SetValue <ValueType>)); return(setValue); }
public void TestGetTextValueNumberSetValue() { NumberValue numberValue1 = new NumberValue(); NumberValue numberValue2 = new NumberValue(); numberValue1.value = "1"; numberValue2.value = "2"; SetValue setValue = new SetValue(); setValue.values = new Value[] { numberValue1, numberValue2 }; Row row = new Row(); row.values = new Value[] { setValue }; string[] stringValues = PqlUtilities.GetRowStringValues(row); Assert.AreEqual(1, stringValues.Length); Assert.AreEqual("1,2", stringValues[0]); }
public void TestGetTextValueCommaTextSetValue() { TextValue textValue1 = new TextValue(); TextValue textValue2 = new TextValue(); textValue1.value = "value1"; textValue2.value = "comma \",\" separated"; SetValue setValue = new SetValue(); setValue.values = new Value[] { textValue1, textValue2 }; Row row = new Row(); row.values = new Value[] { setValue }; string[] stringValues = PqlUtilities.GetRowStringValues(row); Assert.AreEqual(1, stringValues.Length); Assert.AreEqual("value1,\"comma \"\",\"\" separated\"", stringValues[0]); }
private void OnMoveUp(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn != null) { SetValue value = btn.CommandParameter as SetValue; if (value != null) { int pos = Data.Values.IndexOf(value); if (pos > 0) { Data.Values.Remove(value); Data.Values.Insert(pos - 1, value); } } } }
public void TestGetObjectMixedSetValue() { TextValue textValue = new TextValue(); DateValue dateValue = new DateValue(); textValue.value = "value1"; Date date = new Date(); date.year = 2012; date.month = 12; date.day = 2; dateValue.value = date; SetValue setValue = new SetValue(); setValue.values = new Value[] { textValue, dateValue }; PqlUtilities.GetValue(setValue); }
public void ShowResult() { while (true) { if (que.List.Count != 0) { isBusy = true; ShowNextValue show = form.ShowNextResult; form.BeginInvoke(show); que.List.RemoveAt(0); isBusy = false; SetValue log = form.AddToLogs; form.BeginInvoke(log, new object[] { "QUE: " + DateTime.Now.ToShortTimeString() + " delete value" }); System.Threading.Thread.Sleep(1000); } } }
public void TestGetObjectMixedSetValue() { TextValue textValue = new TextValue(); DateValue dateValue = new DateValue(); textValue.value = "value1"; Date date = new Date(); date.year = 2012; date.month = 12; date.day = 2; dateValue.value = date; SetValue setValue = new SetValue(); setValue.values = new Value[] { textValue, dateValue }; Assert.Throws <ArgumentException>(() => PqlUtilities.GetValue(setValue)); }
private Property LoadProperty(Annotation annotation, Context context, DocEntry entry, Property prop, SetLiteral literal) { SetValue values = (SetValue)literal.interpret(context); IType itemType = values.ItemType; if (itemType is TypeType) { HashSet <IType> types = new HashSet <IType>(); foreach (IValue val in values.getItems()) { if (val == NullValue.Instance) { continue; } types.Add(resolveType(annotation, context, ((TypeValue)val).GetValue())); } if (types.Contains(null)) { return(null); // something went wrong } prop.SetValidator(new TypeSetValidator(types)); prop.SetRequired(types.Count == values.Length()); // no null filtered out return(prop); } else if (itemType == AnyType.Instance || itemType == TextType.Instance) { HashSet <String> texts = new HashSet <String>(); foreach (IValue val in values.getItems()) { if (val == NullValue.Instance) { continue; } texts.Add(val.ToString()); } prop.SetValidator(new ValueSetValidator(texts)); prop.SetRequired(texts.Count == values.Length()); // no null filtered out return(prop); } else { throw new SyntaxError("Expected a set of Types."); } }
private static SetValue PropValueSetterDelegate(PropSetValue propSetter, Type typeOfProperty) { // The property/field setter function automatically converts an object returned by the DB // with a possible custom IUserType SetValue setValueFunc = (obj, val) => { if (val == null) { propSetter(obj, null, null); } else { Type valType = val.GetType(); propSetter(obj, RegisteredCustomTypes.GetSystemObjectAfterCustomTypeConversion(val, typeOfProperty, valType), null); } }; return(setValueFunc); }
public void AddSetValue() { const string code = @"int ione int itwo"; const int value = 5; const int indexToAdd = 1; var commandToAdd = new SetValue("ione", value); var commandsList = GenerateCommands(code); var mutation = GetMutationForSetValue(commandsList, commandToAdd, indexToAdd); mutation.Transform(); const string resultCode = @"int ione ione = 5 int itwo"; var resultCommands = GenerateCommands(resultCode); Assert.IsTrue(AreCollectionsEquals(commandsList, resultCommands)); }
public void Edit(IPrincipal user, SetValue setValue) { setValue.Value = valuestring; var original = db.SetValue.Find(setValue.SetValueID); bool modified = original.Value != setValue.Value; if (modified) { var rev = new RevisionHistory(); rev.CreatedOn = original.ModifiedOn; rev.ModifiedBy = User.Identity.Name; //If modified exception on this line db.Entry(original).CurrentValues.SetValues(setValue); db.RevisionHistory.Add(rev); } original.ModifiedOn = DateTime.Now; original.ModifiedBy = User.Identity.Name; //if not modified exception on this line db.Entry(original).State = EntityState.Modified; db.SaveChanges(); }
public void TestGetObjectDateSetValue() { Date date = new Date(); date.year = 2012; date.month = 12; date.day = 2; DateValue dateValue = new DateValue(); dateValue.value = date; SetValue setValue = new SetValue(); setValue.values = new Value[] { dateValue }; List <object> value = PqlUtilities.GetValue(setValue) as List <object>; Assert.AreEqual(1, value.Count); Assert.True(value.Contains(date)); }
/// <summary> /// 读取内存中的全局数据 /// </summary> /// <typeparam name="T1">赋值操作对象类型。</typeparam> /// <typeparam name="T2">你希望保存组件对象类型 /// 请务必保证该类型中的泛型,是你希望保存组件对象类型</typeparam> /// <param name="component">全局对象</param> /// <returns></returns> public static bool LoadGobal <T1, T2>(this T2 component) where T1 : ISave <T2> { if (component.CheckEmpty()) { return(false); } string componentName = typeof(T2).Name; GobalData gobalData = GetGobalObjectData(componentName); SetValue setValue = GetGobalSetValue <T1, T2>(gobalData); if (null == setValue) { return(false); } bool result = GameSaveSystem.Load <T1, T2>(component, setValue); return(result); }
static Setter() { if (attribute != null && custom == null && Fields != null) { #if NOJIT fields = new sqlModel.setField[Fields.Length]; int index = 0; foreach (AutoCSer.code.cSharp.sqlModel.fieldInfo member in Fields) { fields[index++].Set(member); } #else ColumnGroup.Setter dynamicMethod = new ColumnGroup.Setter(typeof(valueType)); foreach (Field member in Fields) { dynamicMethod.Push(member); } defaultSetter = (SetValue)dynamicMethod.Create <SetValue>(); #endif } }
///GENMHASH:B2D612D796CE42937533773625556681:2F5E268055BFDB40961109D6CE6FE0CA public RegistryTaskRunImpl WithOverridingValues(IDictionary <string, Microsoft.Azure.Management.ContainerRegistry.Fluent.OverridingValue> overridingValues) { if (overridingValues.Count == 0) { return(this); } List <SetValue> overridingValuesList = new List <SetValue>(); foreach (var entry in overridingValues) { SetValue value = new SetValue { Name = entry.Key, Value = entry.Value.Value, IsSecret = entry.Value.IsSecret }; overridingValuesList.Add(value); } this.taskRunRequest.Values = overridingValuesList; return(this); }
public DelegateFieldSetAccessor(Type targetObjectType, string fieldName) { this._fieldName = fieldName; FieldInfo field = targetObjectType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (field == null) { throw new NotSupportedException(string.Format("Field \"{0}\" does not exist for type {1}.", fieldName, targetObjectType)); } this._fieldType = field.FieldType; base.nullInternal = base.GetNullInternal(this._fieldType); DynamicMethod method = new DynamicMethod("SetImplementation", null, new Type[] { typeof(object), typeof(object) }, base.GetType().Module, false); ILGenerator iLGenerator = method.GetILGenerator(); iLGenerator = method.GetILGenerator(); iLGenerator.Emit(OpCodes.Ldarg_0); iLGenerator.Emit(OpCodes.Ldarg_1); UnboxIfNeeded(field.FieldType, iLGenerator); iLGenerator.Emit(OpCodes.Stfld, field); iLGenerator.Emit(OpCodes.Ret); this._set = (SetValue)method.CreateDelegate(typeof(SetValue)); }
public GetSetGeneric(PropertyInfo info) { MethodInfo getMethod; MethodInfo setMethod = null; Name = info.Name; Info = info; CollectionType = Info.PropertyType.GetInterface("IEnumerable", true) != null; //getMethod = info.GetGetMethod(); JSC //setMethod = info.GetSetMethod(); getMethod = info.GetMethod; setMethod = info.SetMethod; //_get = (GetValue)Delegate.CreateDelegate(typeof(GetValue), getMethod); //JSC //if (setMethod != null) _set = (SetValue)Delegate.CreateDelegate(typeof(SetValue), setMethod); _get = (GetValue)getMethod.CreateDelegate(typeof(GetValue)); if (setMethod != null) { _set = (SetValue)setMethod.CreateDelegate(typeof(SetValue)); } }
static void Main() { Foo foo = new Foo(); Type type = typeof(Foo); PropertyInfo property = type.GetProperty("Bar"); // setter MethodInfo methodInfo = property.GetSetMethod(); SetValue <string> setValue = (SetValue <string>)Delegate.CreateDelegate(typeof(SetValue <string>), foo, methodInfo); setValue("abc"); // getter methodInfo = property.GetGetMethod(); GetValue <string> getValue = (GetValue <string>)Delegate.CreateDelegate(typeof(GetValue <string>), foo, methodInfo); string myValue = getValue(); // output results Console.WriteLine(myValue); }
public ColorWidget(P parent, string label, GetValue getValue, SetValue setValue) : base(parent, label, getValue, setValue) { this.r = new FloatInputWidget <P>(parent, "Red", p => getValue(p).r, (p, v) => { if (v > 0 && v < 1) { Color c = getValue(p); c.r = v; setValue(p, c); } }); this.g = new FloatInputWidget <P>(parent, "Green", p => getValue(p).g, (p, v) => { if (v > 0 && v < 1) { Color c = getValue(p); c.g = v; setValue(p, c); } }); this.b = new FloatInputWidget <P>(parent, "Blue", p => getValue(p).b, (p, v) => { if (v > 0 && v < 1) { Color c = getValue(p); c.b = v; setValue(p, c); } }); }
///GENMHASH:CB5CC47567CCCFA8E23A47A0D05562D7:39C107D338D51667A4C7C7CF4E97887B public RegistryEncodedTaskStepImpl WithOverridingValue(string name, OverridingValue overridingValue) { if (this.inner.Values == null) { this.inner.Values = new List <SetValue>(); } SetValue value = new SetValue { Name = name, Value = overridingValue.Value, IsSecret = overridingValue.IsSecret }; if (IsInCreateMode()) { this.inner.Values.Add(value); } else { this.encodedTaskStepUpdateParameters.Values.Add(value); } return(this); }
public Signal(Context context) { if (context == null) { throw new ArgumentNullException("context"); } _context = context; _iid = _context.GenerateInstanceId(); _properties = new PropertyBag(context); _constraints = new PropertyBag(context); _eventQueue = new SignalDelayedEventTimeline(context.Scheduler); _setValue = delegate(ValueStructure newValue) { if (newValue == null) { return(false); } bool different = _presentStructure == null || !_presentStructure.Equals(newValue); _presentStructure = newValue; _properties.ValidatePropertiesAfterEvent(this); _context.NotifySignalValueChanged(this); return(different); }; _setEventFlag = delegate(bool flagEvent) { _hasEvent = flagEvent; }; _notifyNewValue = delegate() { EventHandler <SignalEventArgs> handler = SignalValueChanged; if (handler != null) { handler(this, new SignalEventArgs(this)); } }; context.NotifyNewSignalConstructed(this); }
public void SET_TIntersect() { var set = new SetValue("Result"); set.Set.Add("3"); //alpha set.Set.Add(3); //numeric string sSetA = "'A', 1, 2, 3, '1', '2', '3'".Replace('\'', '\"'); string sSetB = "'B', 3, 4, 5, '3', '4', '5'".Replace('\'', '\"'); /* * a=newSortedSet("A", 1, 2, 3, "1", "2", "3") * b=newSet("B", 3, 4, 5, "3", "4", "5") * c=a&b * c=b&a * c=b.SetIntersect(a) * a&b==b&a */ TestValue(F("a=newSortedSet({0}); b=newset({1}); c=a&b", sSetA, sSetB), set); TestValue(F("a=newSortedSet({0}); b=newset({1}); c=b&a", sSetA, sSetB), set); TestValue(F("a=newSortedSet({0}); b=newset({1}); c=b.SetIntersect(a)", sSetA, sSetB), set); TestValue(F("a=newSortedSet({0}); b=newset({1}); a&b == b&a", sSetA, sSetB), 1); }
public ScalarValue Function(SetValue set1, SetValue set2) { bool eq = set1.Set.SetEquals(set2.Set); return new ScalarValue(eq); }
public StaticFieldAccessor(FieldInfo fieldInfo) { _getter = CreateFieldGetter(fieldInfo); _setter = CreateFieldSetter(fieldInfo); }
public override IValue interpret(Context context) { SetValue value = (SetValue)getValue(context); return(value.ToListValue()); }
public static string AnyscMD5(string filepath, ProgressBar pBar, Label lab) { FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read); int bufferSize = 1048576; // 缓冲区大小,1MB byte[] buff = new byte[bufferSize]; double blockcount = Math.Ceiling(fs.Length / Convert.ToDouble(bufferSize)); if (pBar.InvokeRequired == true) { SetText LSetText = new SetText(DoSetText); SetValue PSetValue = new SetValue(DoSetMax); pBar.Invoke(PSetValue, new Object[] { pBar, Convert.ToInt32(blockcount) }); lab.Invoke(LSetText, new Object[] { lab, Convert.ToString(0) + "%" }); } int i = 1; MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); md5.Initialize(); long offset = 0; while (offset < fs.Length) { long readSize = bufferSize; if (offset + readSize > fs.Length) { readSize = fs.Length - offset; } fs.Read(buff, 0, Convert.ToInt32(readSize)); // 读取一段数据到缓冲区 if (offset + readSize < fs.Length) // 不是最后一块 { md5.TransformBlock(buff, 0, Convert.ToInt32(readSize), buff, 0); } else // 最后一块 { md5.TransformFinalBlock(buff, 0, Convert.ToInt32(readSize)); } offset += bufferSize; if (pBar.InvokeRequired == true) { SetValue PSetValue = new SetValue(DoSetValue); SetText LSetText = new SetText(DoSetText); pBar.Invoke(PSetValue, new Object[] { pBar, Convert.ToInt32(i) }); lab.Invoke(LSetText, new Object[] { lab, Convert.ToString(Math.Ceiling((double)(i / blockcount) * 100)) + "%" }); i++; Application.DoEvents(); } } fs.Close(); byte[] result = md5.Hash; md5.Clear(); StringBuilder sb = new StringBuilder(32); for (int j = 0; j < result.Length; j++) { sb.Append(result[j].ToString("x2")); } return sb.ToString(); }
public ScalarValue Function(SetValue set1, Value id) { bool eq = set1.Set.Contains(new SetValue.ValueWrap(id)); return new ScalarValue(eq); }
protected override IEnumerable <IValue> getItems(Context context) { SetValue set = (SetValue)getValue(context); return(set.GetEnumerable(context)); }
/// <summary> /// Initializes a new instance of the <see cref="DelegatePropertySetAccessor"/> class /// for set property access via DynamicMethod. 本质是设置一个为属性赋值的委托函数 /// </summary> /// <param name="targetObjectType">Type of the target object.</param> /// <param name="propName">Name of the property.</param> public DelegatePropertySetAccessor(Type targetObjectType, string propName) { targetType = targetObjectType;//属性的类 propertyName = propName;//属性的名称 PropertyInfo propertyInfo = GetPropertyInfo(targetObjectType);//属性的信息 // Make sure the property exists if(propertyInfo == null) { throw new NotSupportedException( string.Format("Property \"{0}\" does not exist for type " + "{1}.", propertyName, targetType)); } _propertyType = propertyInfo.PropertyType;//属性本身的类型 _canWrite = propertyInfo.CanWrite;//可写否 nullInternal = GetNullInternal(_propertyType);//获取属性的null类型值 if (propertyInfo.CanWrite)//动态创建属性赋值的委托函数 本质部分 { DynamicMethod dynamicMethod = new DynamicMethod("SetImplementation", null, new Type[] { typeof(object), typeof(object) }, GetType().Module, true); ILGenerator ilgen = dynamicMethod.GetILGenerator(); // Emit the IL for set access. MethodInfo targetSetMethod = propertyInfo.GetSetMethod(); Type paramType = targetSetMethod.GetParameters()[0].ParameterType; ilgen.DeclareLocal(paramType); ilgen.Emit(OpCodes.Ldarg_0); //Load the first argument (target object) ilgen.Emit(OpCodes.Castclass, targetType); //Cast to the source type ilgen.Emit(OpCodes.Ldarg_1); //Load the second argument (value object) if (paramType.IsValueType) { ilgen.Emit(OpCodes.Unbox, paramType); //Unbox it if (typeToOpcode[paramType] != null) { OpCode load = (OpCode)typeToOpcode[paramType]; ilgen.Emit(load); //and load } else { ilgen.Emit(OpCodes.Ldobj, paramType); } } else { ilgen.Emit(OpCodes.Castclass, paramType); //Cast class } ilgen.EmitCall(OpCodes.Callvirt, targetSetMethod, null); //Set the property value ilgen.Emit(OpCodes.Ret); _set = (SetValue)dynamicMethod.CreateDelegate(typeof(SetValue));//最后指向设置好的委托函数 } }
public static bool InvokeTypeParser(List<Nodes.Node.ErrorCheck> result, Type type, string parStr, SetValue setter, DefaultObject node, string paramName = null) { Debug.Check(type != null); if (_typeHandlers.ContainsKey(type)) { Type typeHandler = _typeHandlers[type]; MethodInfo parserMethod = typeHandler.GetMethod("Parse"); Debug.Check(parserMethod != null); if (string.IsNullOrEmpty(parStr) && type.IsPrimitive && type == typeof(string)) { return false; } object[] pars = { node, paramName, parStr, setter }; return (bool)parserMethod.Invoke(null, pars); } else if (type.IsEnum) { Array values = Enum.GetValues(type); foreach(object enumVal in values) { string enumValueName = Enum.GetName(type, enumVal); if (enumValueName == parStr) { setter(enumVal); return true; } } } else if (Plugin.IsArrayType(type)) { object obj = DesignerArray.ParseStringValue(result, type, parStr, node); setter(obj); return true; } else if (Plugin.IsCustomClassType(type)) { object obj = Behaviac.Design.Attributes.DesignerStruct.ParseStringValue(result, type, paramName, parStr, node); setter(obj); return true; } else { string message = string.Format("parser for {0} is not registered!", type.Name); throw new Exception(message); } return false; }
public SetValue Function(SetValue set1, ArgumentsValue args) { return SetValue.TIntersect(set1, args); }
private void SetPresentProgressBarValue(int val) { if (this.presentprogressBar.InvokeRequired) { SetValue s = new SetValue(SetPresentProgressBarValue); this.Invoke(s, new object[] { val }); } else { this.presentprogressBar.Value = val; } }
public ScalarValue Function(SetValue set1) { bool eq = set1.Sorted; return new ScalarValue(eq); }
/// <summary> /// Initializes a new instance of the <see cref="T:DelegateFieldSetAccessor"/> class /// for field get access via DynamicMethod. /// </summary> /// <param name="targetObjectType">Type of the target object.</param> /// <param name="fieldName">Name of the field.</param> public DelegateFieldSetAccessor(Type targetObjectType, string fieldName) { // this.targetType = targetObjectType; _fieldName = fieldName; FieldInfo fieldInfo = targetObjectType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); // Make sure the field exists if (fieldInfo == null) { throw new NotSupportedException( string.Format("Field \"{0}\" does not exist for type " + "{1}.", fieldName, targetObjectType)); } else { _fieldType = fieldInfo.FieldType; this.nullInternal = this.GetNullInternal(_fieldType); // Emit the IL for set access. DynamicMethod dynamicMethodSet = new DynamicMethod("SetImplementation", null, new Type[] { typeof(object), typeof(object) }, this.GetType().Module, false); ILGenerator ilgen = dynamicMethodSet.GetILGenerator(); ilgen = dynamicMethodSet.GetILGenerator(); ilgen.Emit(OpCodes.Ldarg_0); ilgen.Emit(OpCodes.Ldarg_1); UnboxIfNeeded(fieldInfo.FieldType, ilgen); ilgen.Emit(OpCodes.Stfld, fieldInfo); ilgen.Emit(OpCodes.Ret); _set = (SetValue)dynamicMethodSet.CreateDelegate(typeof(SetValue)); } }
public SetValue Function(SetValue set1, ArgumentsValue args) { return SetValue.TExceptXor(set1, args); }
public static unsafe int Patch(string hPatchs, string hSources, string hDests,ProgressBar pBar,Label lab,int FileID) { try { if (pBar.InvokeRequired == true) { SetValue PSetValue = new SetValue(DoSetValue); SetText LSetText = new SetText(DoSetText); pBar.Invoke(PSetValue, new Object[] { pBar, 0 }); lab.Invoke(LSetText, new Object[] { lab, "0%" }); } UInt32 BLOCKSIZE = 16384; UInt32 temp = 0; UInt32 read; byte[] source_md5 = new byte[16]; byte[] patch_dest_md5 = new byte[16]; byte[] block = new byte[BLOCKSIZE]; int MD5Mode = 0; UInt32 patches = 0; int already_uptodate = 0,j=1; double blocks; FILETIME targetModifiedTime; DateTime dte = new DateTime() ; //write回调方法 FileStream Patchs = new FileStream(hPatchs, FileMode.Open, FileAccess.Read, FileShare.Read); FileStream Sources = new FileStream(hSources, FileMode.Open, FileAccess.Read, FileShare.Read); FileStream Dests = new FileStream(hDests, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); Hashtable Data = Program.filehash; // special 'addition' for the dll: since the patch file is now // in a seperate file, the VPAT header might be right at the start // of the file, and a pointer at the end of the file is probably missing // (because all patch generator versions don't append it, the linker/gui // does this). Patchs.Seek(0, SeekOrigin.Begin); temp = Patchs.ReadValueU32(); read = 4; // it's not at the start of file -> there must be a pointer at the end of // file then if (temp != 0x54415056) { Patchs.Seek(-4, SeekOrigin.End); temp = Patchs.ReadValueU32(); read = 4; Patchs.Seek(temp, SeekOrigin.Begin); temp = Patchs.ReadValueU32(); read = 4; if (temp != 0x54415056) return result.PATCH_CORRUPT; } // target file date is by default the current system time GetSystemTimeAsFileTime(&targetModifiedTime); // read the number of patches in the file patches = Patchs.ReadValueU32(); read = 4; if (Convert.ToBoolean(patches & 0x80000000)) MD5Mode = 1; // MSB is now reserved for future extensions, anyone wanting more than // 16 million patches in a single file is nuts anyway patches = patches & 0x00FFFFFF; if (!Convert.ToBoolean(MD5Mode)) { return result.PATCH_UNSUPPORTED; } else { source_md5 = checksum.FileMD5(Sources, Data, FileID,Program.AdvMOD); if (source_md5 == null) return result.PATCH_ERROR; } //pBar.Maximum = Convert.ToInt32(patches); while (Convert.ToBoolean(patches--)) { int patch_blocks = 0, patch_size = 0; // flag which needs to be set by one of the checksum checks int currentPatchMatchesChecksum = 0; // read the number of blocks this patch has patch_blocks = Convert.ToInt32(Patchs.ReadValueU32()); blocks = patch_blocks; read = 4; if (!Convert.ToBoolean(patch_blocks)) { return result.PATCH_CORRUPT; } if (pBar.InvokeRequired == true) { SetValue PSetValue = new SetValue(DoSetMax); pBar.Invoke(PSetValue, new Object[] { pBar, Convert.ToInt32(patch_blocks) }); } // read checksums if (!Convert.ToBoolean(MD5Mode)) { return result.PATCH_UNSUPPORTED; } else { int md5index; byte[] patch_source_md5 = new byte[16]; patch_source_md5 = Patchs.ReadBytes(16); read = 16; if (patch_source_md5 == null) { return result.PATCH_CORRUPT; } patch_dest_md5 = Patchs.ReadBytes(16); read = 16; if (patch_dest_md5 == null) { return result.PATCH_CORRUPT; } // check to see if it's already up-to-date for some patch for (md5index = 0; md5index < 16; md5index++) { if (source_md5[md5index] != patch_dest_md5[md5index]) break; if (md5index == 15) already_uptodate = 1; } for (md5index = 0; md5index < 16; md5index++) { if (source_md5[md5index] != patch_source_md5[md5index]) break; if (md5index == 15) currentPatchMatchesChecksum = 1; } } // read the size of the patch, we can use this to skip over it patch_size = Convert.ToInt32(Patchs.ReadValueU32()); read = 4; if (patch_size == null) { return result.PATCH_CORRUPT; } if (Convert.ToBoolean(currentPatchMatchesChecksum)) { while (Convert.ToBoolean(patch_blocks--)) { if (pBar.InvokeRequired == true) { SetValue PSetValue = new SetValue(DoSetValue); SetText LSetText = new SetText(DoSetText); pBar.Invoke(PSetValue, new Object[] { pBar, Convert.ToInt32(j++) }); var per = Convert.ToDouble(j-1)/Convert.ToDouble(blocks); lab.Invoke(LSetText, new Object[] { lab, Convert.ToString(Math.Ceiling(per*100)) + "%" }); Application.DoEvents(); } Byte blocktype = 0; UInt32 blocksize = 0; blocktype = Convert.ToByte(Patchs.ReadByte()); read = 1; if (blocktype==null) { return result.PATCH_CORRUPT; } switch (blocktype) { case 1: case 2: case 3: if (blocktype == 1) { Byte x; x = Convert.ToByte(Patchs.ReadByte()); read = 1; blocksize = Convert.ToUInt32(Convert.ToBoolean(x) ? x : 0); } else if (blocktype == 2) { UInt16 x; x = Patchs.ReadValueU16(); read = 2; blocksize = Convert.ToUInt32(Convert.ToBoolean(x) ? x : 0); } else { UInt32 x; x = Patchs.ReadValueU32(); read = 4; blocksize = Convert.ToUInt32(Convert.ToBoolean(x) ? x : 0); } temp = Patchs.ReadValueU32(); read = 4; if (!Convert.ToBoolean(blocksize) || temp == null || read != 4) return result.PATCH_CORRUPT; Sources.Seek(temp, SeekOrigin.Begin); //SetFilePointer(hSource, temp, 0, EMoveMethod.Begin); do { Sources.Read(block, 0, Convert.ToInt32(Math.Min(BLOCKSIZE, blocksize))); read = Math.Min(BLOCKSIZE, blocksize); if (block == null) { return result.PATCH_ERROR; } //IAsyncResult writeResult = Dests.BeginWrite(block,0,Convert.ToInt32(read),writeCallBack,"Write Target File"); //Dests.EndWrite(writeResult); Dests.Write(block, 0, Convert.ToInt32(read)); temp = read; //WriteFile(hDest, block, read, &temp, NULL); if (temp != Math.Min(BLOCKSIZE, blocksize)) return result.PATCH_ERROR; blocksize -= temp; } while (Convert.ToBoolean(temp)); break; case 5: case 6: case 7: if (blocktype == 5) { Byte x; x = Convert.ToByte(Patchs.ReadByte()); read = 1; blocksize = Convert.ToUInt32(Convert.ToBoolean(x) ? x : 0); } else if (blocktype == 6) { UInt16 x; x = Patchs.ReadValueU16(); read = 2; blocksize = Convert.ToUInt32(Convert.ToBoolean(x) ? x : 0); } else { UInt32 x; x = Patchs.ReadValueU32(); read = 4; blocksize = Convert.ToUInt32(Convert.ToBoolean(x) ? x : 0); } if (!Convert.ToBoolean(blocksize)) return result.PATCH_CORRUPT; do { Patchs.Read(block, 0, Convert.ToInt32(Math.Min(BLOCKSIZE, blocksize))); read = Math.Min(BLOCKSIZE, blocksize); if (block == null) { return result.PATCH_CORRUPT; } //IAsyncResult writeResult = Dests.BeginWrite(block, 0, Convert.ToInt32(read), writeCallBack, "Write Target File"); //Dests.EndWrite(writeResult); Dests.Write(block, 0, Convert.ToInt32(read)); temp = read; //WriteFile(hDest, block, read, &temp, NULL); if (temp != Math.Min(BLOCKSIZE, blocksize)) return result.PATCH_ERROR; blocksize -= temp; } while (Convert.ToBoolean(temp)); break; case 255: // read the file modified time from the patch targetModifiedTime.dwLowDateTime = (int)Patchs.ReadValueU32(); targetModifiedTime.dwHighDateTime = (int)Patchs.ReadValueU32(); ///////////////////////////////////////////////////////////////// //from System.Runtime.InteropServices.FILETIME to System.DateTime ///////////////////////////////////////////////////////////////// long _Value = (long) targetModifiedTime.dwHighDateTime << 32 | (long)(uint)targetModifiedTime.dwLowDateTime; dte = DateTime.FromFileTimeUtc(_Value); read = Convert.ToUInt32(Marshal.SizeOf(targetModifiedTime)); //if(targetModifiedTime) { //return result.PATCH_CORRUPT; //} break; default: return result.PATCH_CORRUPT; } } if (!Convert.ToBoolean(MD5Mode)) { return result.PATCH_UNSUPPORTED; } else { //int md5index; byte[] dest_md5 = new byte[16]; Dests.Close(); Patchs.Close(); Sources.Close(); File.Delete(hPatchs); File.Delete(hSources); File.Move(hDests, hSources); File.SetLastWriteTime(hSources, dte); //FileStream Dest = new FileStream(hSources, FileMode.Open, FileAccess.Read, FileShare.None); //dest_md5 = checksum.FileMD5(Dest, Data, -1); //Dest.Close(); //if (dest_md5 == null) //{ // return result.PATCH_ERROR; // } //for (md5index = 0; md5index < 16; md5index++) //{ // if (dest_md5[md5index] != patch_dest_md5[md5index]) return result.PATCH_ERROR; //} } // set file time //SetFileTime(hDest, NULL, NULL, &targetModifiedTime); return result.PATCH_SUCCESS; } else { Patchs.Seek(patch_size, SeekOrigin.Current); //SetFilePointer(hPatch, patch_size, NULL, EMoveMethod.Current); } } // if already up to date, it doesn't matter that we didn't match if (Convert.ToBoolean(already_uptodate)) { return result.PATCH_UPTODATE; } else { return result.PATCH_NOMATCH; } } catch (Exception Err) { MessageBox.Show("出现错误:" + Err.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return result.PATCH_ERROR; } }
public void TestGetObjectNumberSetValue() { NumberValue numberValue1 = new NumberValue(); NumberValue numberValue2 = new NumberValue(); numberValue1.value = "1"; numberValue2.value = "2"; SetValue setValue = new SetValue(); setValue.values = new Value[] { numberValue1, numberValue2 }; List<object> value = PqlUtilities.GetValue(setValue) as List<object>; Assert.AreEqual(2, value.Count); Assert.True(value.Contains("1")); Assert.True(value.Contains("2")); }
public Task AddValue([FromBody] SetValue setValue) { return(_database.SetAddAsync("autos", setValue.Value)); }
public void TestGetObjectDateSetValue() { DateTime dateTime = new DateTime(); Date date = new Date(); date.year = 2012; date.month = 12; date.day = 2; DateValue dateValue = new DateValue(); dateValue.value = date; SetValue setValue = new SetValue(); setValue.values = new Value[] { dateValue }; List<object> value = PqlUtilities.GetValue(setValue) as List<object>; Assert.AreEqual(1, value.Count); Assert.True(value.Contains(date)); }
public ScalarValue Function(SetValue set1, SetValue set2) { bool eq = set1.Set.IsSupersetOf(set2.Set); return new ScalarValue(eq); }
public string Edit(SetValue setValue, IPrincipal user=null) { try { var opv = db.OptionValue.FirstOrDefault(x => x.OptionValueID == setValue.OptionValueID); var q1 = db.TcSet.FirstOrDefault(x => x.TcSetID == setValue.TcSetID); if (ModelState.IsValid) { var q = db.TcSet.FirstOrDefault(x => x.TcSetID == setValue.TcSetID); var data = q.DataFormat.FormatType; var precision = q.DataFormat.PrecisionDigits; var scaling = q.DataFormat.ScalingDigits; double val = 0; double value; string valuestring = setValue.Value; bool flag = double.TryParse(setValue.Value, out value); if (setValue.Value != "#" && data != "String" && setValue.Value != "?") { if (!flag) { return "Error"; } if (precision != null && value >= 0) { int precision1 = precision ?? default(int); if (precision != 0) valuestring = Significant(value, precision1); else valuestring = setValue.Value; } else if (scaling != null && value >= 0) { int sca = scaling ?? default(int); valuestring = Scaling(value, sca); } } setValue.Value = valuestring; var original = db.SetValue.Find(setValue.SetValueID); bool modified = original.Value != setValue.Value; if (modified) { //var old = db.RevisionHistory.FirstOrDefault(x => x.SetValueID == setValue.SetValueID); var rev = new RevisionHistory(); rev.CreatedOn = original.ModifiedOn; rev.ModifiedOn = DateTime.Now; rev.ModifiedBy = user.Identity.Name; rev.InitialValue = original.Value; ; rev.Optionvalue = original.OptionValue.OptionVal; rev.TCSetName = original.TcSet.SetName; rev.Option = original.OptionValue.Option.OptionName; rev.SystemName = original.OptionValue.Option.Lsystem.LsystemName; rev.SetValueID = original.SetValueID; rev.ModifiedValue = setValue.Value; rev.Action = "Modified"; db.Entry(original).CurrentValues.SetValues(setValue); db.RevisionHistory.Add(rev); } original.ModifiedOn = DateTime.Now; original.ModifiedBy = user.Identity.Name; db.Entry(original).State = EntityState.Modified; db.Entry(original).Property("CreatedOn").IsModified = false; db.Entry(original).Property("CreatedBy").IsModified = false; db.Entry(original).Property("OptionValueID").IsModified = false; db.Entry(original).Property("TcSetID").IsModified = false; db.SaveChanges(); return "Success"; } return "Error"; } catch (Exception e) { ViewBag.Error = e.Message; return "Error"; } }
public void TestGetObjectDateTimeSetValue() { DateTime dateTime = new DateTime(); Date date = new Date(); date.year = 2012; date.month = 12; date.day = 2; dateTime.date = date; dateTime.hour = 12; dateTime.minute = 45; dateTime.second = 0; dateTime.timeZoneID = "Asia/Shanghai"; DateTimeValue dateTimeValue = new DateTimeValue(); dateTimeValue.value = dateTime; SetValue setValue = new SetValue(); setValue.values = new Value[] { dateTimeValue }; List<object> value = PqlUtilities.GetValue(setValue) as List<object>; Assert.AreEqual(1, value.Count); Assert.True(value.Contains(dateTime)); }
public MatrixValue Function(SetValue set1) { return SetValue.TToMatrix(set1); }
public void TestGetObjectNestedSetValue() { SetValue setValue = new SetValue(); SetValue innerSetValue = new SetValue(); TextValue textValue = new TextValue(); textValue.value = "value1"; innerSetValue.values = new Value[] { textValue }; setValue.values = new Value[] {innerSetValue}; PqlUtilities.GetValue(setValue); }