public void WhenRefValuesHaveTheSameIdButDifferentNameThenReturnTrue() { var refValue = new RefValue("someid", "somename"); var refValue2 = new RefValue("someid", "somename2"); var comparer = new RefValueComparer(); Assert.True(comparer.Equals(refValue, refValue2)); }
public void WhenRefValuesHaveDifferentIdsButSameNameThenReturnTrue() { var refValue = new RefValue("someid", "somename"); var refValue2 = new RefValue("someid2", "somename"); var comparer = new RefValueComparer(); Assert.False(comparer.Equals(refValue, refValue2)); }
public bool ConsumeMessage(MessageDTO message) { string messageName = "Message:" + message.TimeStamp; IsValıdMessage(message); if (!CheckMessage(message.Id)) { throw new Exception("Repeated Meesage"); } if (CheckType(messageName)) { throw new Exception("Repeated Meesage"); } if (!CheckType(message.Type)) { RefType entity = new RefType(); entity.InsertRefType(message.Type, null); AddRefType(entity); } RefType type = GetRefTypeParent(message.Type); RefType messageData = new RefType(); messageData.InsertRefType(messageName, type); messageData = this.AddRefType(messageData); Message messageEntity = new Message(); messageEntity.Insert(type, messageData, message.TimeStamp, message.Id); AddMessage(messageEntity); var jObj = JToken.Parse(message.Data); foreach (JProperty property in jObj.Children()) { RefType key = new RefType(); key.InsertRefType(property.Name, messageData); key = AddRefType(key); RefValue value = new RefValue(); value.InsertRefValue(property.Value.ToString(), key); AddRefValue(value); //Console.WriteLine(property.Name); //Console.WriteLine(property.Value); } return(true); }
public void WhenInvokingMethodWithRef_ThenReturnsRefValue() { dynamic target = new PrivateObject().AsDynamicReflection(); var value = default(string); var r1 = RefValue.Create(() => value, s => value = s); var result = target.Echo("hello ", r1); Assert.True(result); Assert.Equal("hello world", value); }
private void DataTableToListC2K(DataTable dt, List <RefValue> list) { list.Clear(); foreach (DataRow dr in dt.Rows) { if (dr[0].ToString() == "" || dr[1].ToString() == "") { continue; } RefValue r = new RefValue(GlobalTool.C2K((double)dr[0]), (double)dr[1]); list.Add(r); } }
public Bag(string id, RefValue brand, string serie, string flavour, string hallmark, RefValue bagType, RefValue country, string serialNumber, LocalDate insertDate, string imageId) { Id = id; Brand = brand; Serie = serie; Flavour = flavour; Hallmark = hallmark; BagType = bagType; Country = country; SerialNumber = serialNumber; InsertDate = insertDate; ImageId = imageId; }
public override string ToString() { string base_str = (NegateResult ? "Negated: " : "") + dpath.ToString() + " "; if (FilterType == StringFilterType.EQUAL) { return(base_str + "is " + RefValue.ToString()); } if (FilterType == StringFilterType.CONTAINS) { return(base_str + "contains " + RefValue.ToString()); } return(base_str + "UNKNOWN_OPERATOR" + RefValue.ToString()); }
private void AddReference(Type Type, RefValue Ref) { if (Ref.Info?.IsDefined(typeof(SectionAttribute)) ?? false) { Sections[Ref.Info.GetCustomAttribute <SectionAttribute>().SectionId].Values.Add(Ref); } else if (TypeSections.ContainsKey(Type)) { TypeSections[Type].Values.Add(Ref); } else { CurrentValue.Childs.Add(Ref); } }
public static int CompareBuffer(RefValue LHS, RefValue RHS) { if (LHS.Parent == RHS.Parent) { return(0); } else if (LHS.Parent is H3DTexture) { return(-1); } else { return(1); } }
private void WriteList(IList List) { if (List.Count == 0) { return; } Type Type = List.GetType(); Type = Type.IsArray ? Type.GetElementType() : Type.GetGenericArguments()[0]; bool IsBool = Type == typeof(bool); bool Inline = Type.IsDefined(typeof(InlineAttribute)); bool IsValue = Type.IsValueType || Type.IsEnum || Inline; BitWriter BW = new BitWriter(Writer); foreach (object Value in List) { if (!IsValue) { RefValue Ref = new RefValue() { Value = Value, Position = BaseStream.Position, HasLength = IsList(Type) }; AddReference(Type, Ref); BaseStream.Seek(Ref.HasLength ? 8 : 4, SeekOrigin.Current); } else if (IsBool) { BW.WriteBit((bool)Value); } else { WriteValue(Value); } } BW.Flush(); }
public static List <RefValue> StrToRefvalList(String in_str) { List <RefValue> values = new List <RefValue>(); string[] strs = in_str.Split(SEP1); foreach (string str in strs) { if (str == "") { continue; } string[] rvs = str.Split(SEP2); RefValue rv = new RefValue(double.Parse(rvs[0]), double.Parse(rvs[1])); values.Add(rv); } return(values); }
private void WriteSection(List <RefValue> Values, int Start = 0) { for (int Index = Start; Index < Values.Count; Index++) { CurrentValue = Values[Index]; WriteValue(Values[Index]); } int LastIndex = Values.Count; for (int Index = Start; Index < Values.Count; Index++) { WriteSection(Values[Index].Childs); } if (Values.Count > LastIndex) { WriteSection(Values, LastIndex); } }
public BagTagsTests() { BagTypeRef = new RefValue(System.Guid.NewGuid().ToString(), "Paper"); BrandRef = new RefValue(System.Guid.NewGuid().ToString(), "Twinning"); CountryRef = new RefValue(System.Guid.NewGuid().ToString(), "Norway"); Bag = new Bag { Id = System.Guid.NewGuid().ToString(), MainID = 999, Flavour = "The as At Was Earl Grey Thé", Serie = "was some Series", Hallmark = "was some Hallmark", SerialNumber = "was some serial number", BagType = BagTypeRef, Brand = BrandRef, Country = CountryRef, InsertDate = new LocalDate(1985, 08, 22), ImageId = "imageid", OwnerId = Guid.NewGuid().ToString() }; SearchableBag = new Searchable(Bag); }
public static IDisposable SetProcessAffinity(int threadCount = 1, bool assignEvenly = false) { Contract.Assert(threadCount > 0, nameof(threadCount) + " must be greater than zero!"); Contract.EndContractBlock(); var original = new RefValue<IntPtr>(); return new ManagedDelegateDisposable( () => { var mask = CalculateAffinityMask(threadCount, assignEvenly); // disable .NET thread management Thread.BeginThreadAffinity(); // set process affinity using (var process = Process.GetCurrentProcess()) { original.Value = process.ProcessorAffinity; process.ProcessorAffinity = new IntPtr(mask); } }, () => { // revert process affinity using (var process = Process.GetCurrentProcess()) { original.Value = process.ProcessorAffinity; process.ProcessorAffinity = original; } // enable .NET thread management Thread.EndThreadAffinity(); }); }
private void WriteValue(RefValue Ref) { FieldInfo Info = Ref.Info; object Parent = Ref.Parent; object Value = Ref.Value; bool Range = Info?.IsDefined(typeof(RangeAttribute)) ?? false; LengthPos LenPos = GetLengthPos(Info); if (Value != null && (!(Value is IList) || ((IList)Value).Count > 0 || Range)) { ObjectInfo ObjInfo = GetObjInfo(Value, Info); long Position = BaseStream.Position; if (ObjInfo.Position == Position) { if (Parent != null && Parent is ICustomSerializeCmd && Info?.FieldType == typeof(uint[])) { ((ICustomSerializeCmd)Parent).SerializeCmd(this, Value); } AddObjInfo(Value, Position); WriteValue(Value); } if (Ref.Position != -1) { long EndPos = BaseStream.Position; BaseStream.Seek(Ref.Position, SeekOrigin.Begin); uint Pointer = ObjInfo.Position + Ref.PointerOffset; if (LenPos == LengthPos.AfterPtr) { WritePointer(Pointer); } if (Ref.HasLength) { if (Range) { WritePointer((uint)(ObjInfo.Length != 0 ? ObjInfo.Length : EndPos)); } else if (GetLengthSize(Info) == LengthSize.Short) { Writer.Write((ushort)((IList)Value).Count); } else { Writer.Write(((IList)Value).Count); } } if (LenPos == LengthPos.BeforePtr) { WritePointer(Pointer); } if (Ref.HasTwoPtr) { WritePointer(Pointer); } BaseStream.Seek(EndPos, SeekOrigin.Begin); } } }
public void AddRefValue(RefValue refValue) { this.Context.RefValue.Add(refValue); this.Context.SaveChanges(); }
public PassiveRecoveryResource(IResource _resource, float _interval, float _percentage) : base(_resource) { this.recoveryAmount = new RefValue <int>(() => Mathf.CeilToInt(Max * _percentage)); CreateTimer(_interval); }
public static IDisposable SetThreadAffinity(int threadCount = 1, bool assignEvenly = false) { Contract.Assert(threadCount > 0, nameof(threadCount) + " must be greater than zero!"); Contract.EndContractBlock(); var original = new RefValue<IntPtr>(); return new ManagedDelegateDisposable( () => { var mask = CalculateAffinityMask(threadCount, assignEvenly); // disabling .NET thread management Thread.BeginThreadAffinity(); // setting correctly affinity original.Value = SetThreadAffinityMask(GetCurrentThread(), new IntPtr(mask)); if (original.Value == IntPtr.Zero) original.Value = Process.GetCurrentProcess().ProcessorAffinity; }, () => { // reverting to process affinity SetThreadAffinityMask(GetCurrentThread(), original.Value); // enabling .NET thread management Thread.EndThreadAffinity(); }); }
private void WriteObject(object Value) { Type ValueType = Value.GetType(); if (ValueType.IsDefined(typeof(TypeChoiceAttribute))) { foreach (TypeChoiceAttribute Attr in ValueType.GetCustomAttributes <TypeChoiceAttribute>()) { if (Attr.Type == ValueType) { Writer.Write(Attr.TypeVal); break; } } } if (Value is ICustomSerialization) { if (((ICustomSerialization)Value).Serialize(this)) { return; } } foreach (FieldInfo Info in GetFieldsSorted(ValueType)) { if (!Info.GetCustomAttribute <IfVersionAttribute>()?.Compare(FileVersion) ?? false) { continue; } if (!( Info.IsDefined(typeof(IgnoreAttribute)) || Info.IsDefined(typeof(CompilerGeneratedAttribute)))) { object FieldValue = Info.GetValue(Value); Type Type = Info.FieldType; bool Inline; Inline = Info.IsDefined(typeof(InlineAttribute)); Inline |= Type.IsDefined(typeof(InlineAttribute)); if (Type.IsValueType || Type.IsEnum || Inline) { if (Type.IsPrimitive && Info.IsDefined(typeof(VersionAttribute))) { if (Options.ForceWriteStaticVersion) { FieldValue = Convert.ChangeType(FileVersion, Type); } else { FileVersion = Convert.ToInt32(FieldValue); } } if (IsList(Type) && !Info.IsDefined(typeof(FixedLengthAttribute))) { Writer.Write(((IList)FieldValue).Count); } WriteValue(FieldValue); } else { bool HasLength = !Info.IsDefined(typeof(FixedLengthAttribute)) && IsList(Type); bool HasTwoPtr = Info.IsDefined(typeof(RepeatPointerAttribute)); RefValue Ref = new RefValue() { Parent = Value, Info = Info, Value = FieldValue, Position = BaseStream.Position, HasLength = HasLength, HasTwoPtr = HasTwoPtr }; AddReference(Type, Ref); int LenSize = HasLength ? GetIntLengthSize(Info) : 0; BaseStream.Seek(4 + LenSize + (HasTwoPtr ? 4 : 0), SeekOrigin.Current); } Align(Info.GetCustomAttribute <PaddingAttribute>()?.Size ?? 1); } } }
public static int CompareString(RefValue LHS, RefValue RHS) { return(CompareString(LHS.Value.ToString(), RHS.Value.ToString())); }