protected void Run(LogicMethod logicMethod) { int i = 0; var methodClassName = logicMethod.Method.ReflectedType?.Name ?? throw new Exception("Reflected Name of Method cannot be a null."); foreach (var testCase in _casesDictionary[methodClassName]) { var writer = new StringWriter(); Console.SetOut(writer); var reader = new StringReader(testCase.Input); Console.SetIn(reader); logicMethod(); var result = writer.ToString().TrimEnd('\r', '\n'); Assert.Equal(testCase.Expected, result); _output.WriteLine($"Test case #{i++}:"); _output.WriteLine($"Input:\n{testCase.Input}"); _output.WriteLine($"Expected:\n{testCase.Expected}"); _output.WriteLine($"Actual:\n{result}"); _output.WriteLine(""); } }
protected override void OnDeleteSubscribedToDeletionEvent(Entity entity) { base.OnDeleteSubscribedToDeletionEvent(entity); if (this.abQ == entity) { this.abQ = null; } }
/// <summary> /// 图像逻辑运算 /// </summary> /// <param name="bgImage">二值背景</param> /// <param name="fgImage">二值前景</param> /// <param name="logicMethod">逻辑运算方法</param> /// <returns></returns> public Bitmap LogicOperate(Bitmap bgImage, Bitmap fgImage, LogicMethod logicMethod) { Bitmap dstImage = (Bitmap)bgImage.Clone(); Graphics g = System.Drawing.Graphics.FromImage(dstImage); // 计算有效区域 Region validRegion = bgRegion; validRegion.Intersect(fgRegion); RectangleF validRect = validRegion.GetBounds(g); RectangleF fgRect = fgRegion.GetBounds(g); RegionClip bgRegionClip = new RegionClip(validRegion); Bitmap background = bgRegionClip.Hold((Bitmap)bgImage.Clone()); RegionClip fgRegionClip = new RegionClip(validRegion); validRegion.Translate(-fgRect.X, -fgRect.Y); Bitmap foreground = fgRegionClip.Hold((Bitmap)fgImage.Clone()); validRegion.Translate(fgRect.X, fgRect.Y); // 先将原始二值图转化为二维数组 byte[,] bgGray = Image2Array(background); byte[,] fgGray = Image2Array(foreground); // 进行逻辑运算处理后的灰度二维数组 byte[,] dstGray = null; // 进行逻辑运算 switch (logicMethod) { case LogicMethod.And: dstGray = LogicAnd(bgGray, fgGray); break; case LogicMethod.Or: dstGray = LogicOr(bgGray, fgGray); break; case LogicMethod.Xor: dstGray = LogicXor(bgGray, fgGray); break; } // 将二值数组转化为灰度图 Bitmap validImage = Array2Image(dstGray); g.DrawImage(validImage, validRect, new Rectangle(0, 0, (int)validRect.Width, (int)validRect.Height), GraphicsUnit.Pixel); bgImage.Dispose(); fgImage.Dispose(); return(dstImage); } // end of LogicOperate
public void Init(LogicMethod method) { string[] array = new string[method.Parameters.Count]; for (int i = 0; i < method.Parameters.Count; i++) { array[i] = method.Parameters[i].ParameterType.Name; } base.InitMethodNameAndParameterTypes(null, array); this.abQ = method; base.SubscribeToDeletionEvent(this.abQ); }
protected override void OnClone(Entity source) { base.OnClone(source); LogicCallThisMethodAction logicCallThisMethodAction = (LogicCallThisMethodAction)source; if (logicCallThisMethodAction.LogicMethod != null) { this.abQ = logicCallThisMethodAction.LogicMethod; base.SubscribeToDeletionEvent(this.abQ); } this.abq = logicCallThisMethodAction.EntityOwnerProperty; }
public void Init(LogicMethod method) { this.abP = null; this.abp = null; this.abo = method.ParentClass.ClassName; string[] array = new string[method.Parameters.Count]; for (int i = 0; i < method.Parameters.Count; i++) { array[i] = method.Parameters[i].ParameterType.Name; } base.InitMethodNameAndParameterTypes(method.MethodName, array); }
private LogicMethod a() { if (string.IsNullOrEmpty(base.MethodName)) { return(null); } if (this.abp == null && this.A() != null) { this.abp = this.A().GetMethodByName(base.MethodName); } return(this.abp); }
public LogicExecuteMethodInformation(LogicMethod method, Type staticClassType) { this.aAO = method; this.aAo = staticClassType; }
public LogicExecuteMethodInformation(LogicMethod method, LogicEntityObject logicEntityObject) { this.aAO = method; this.aAp = logicEntityObject; this.aAo = logicEntityObject.GetType(); }
internal bool A(TextBlock textBlock) { if (textBlock.IsAttributeExist("method")) { this.aAO = (Entities.Instance.GetLoadingEntityBySerializedUIN(uint.Parse(textBlock.GetAttribute("method"))) as LogicMethod); } if (textBlock.IsAttributeExist("logicClassType")) { string attribute = textBlock.GetAttribute("logicClassType"); Type left = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { Assembly assembly = assemblies[i]; left = assembly.GetType(attribute); if (left != null) { break; } } if (left == null) { Log.Warning("Entity System: Serialization error. The logic class type is not found \"{0}\".", attribute); return(false); } this.aAo = left; } if (textBlock.IsAttributeExist("logicEntityObjectOwnerEntity")) { this.aAP = Entities.Instance.GetLoadingEntityBySerializedUIN(uint.Parse(textBlock.GetAttribute("logicEntityObjectOwnerEntity"))); } if (textBlock.IsAttributeExist("needReturn")) { this.aAQ = bool.Parse(textBlock.GetAttribute("needReturn")); } if (textBlock.IsAttributeExist("needReturnForWait")) { this.aAq = bool.Parse(textBlock.GetAttribute("needReturnForWait")); } TextBlock textBlock2 = textBlock.FindChild("localVariablesBlock"); if (textBlock2 != null) { foreach (TextBlock current in textBlock2.Children) { LogicLocalVariable logicLocalVariable = new LogicLocalVariable(); if (!logicLocalVariable.A(current)) { return(false); } this.aAR.Add(logicLocalVariable.Name, logicLocalVariable); } } if (textBlock.IsAttributeExist("currentClassActionsLevelIndex")) { this.aAr = int.Parse(textBlock.GetAttribute("currentClassActionsLevelIndex")); } if (textBlock.IsAttributeExist("callActionsLevelIndexes")) { string[] array = textBlock.GetAttribute("callActionsLevelIndexes").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string[] array2 = array; for (int j = 0; j < array2.Length; j++) { string s = array2[j]; this.aAS.Add(int.Parse(s)); } } return(true); }