public static void UseSystem() { InternalSystem system = new InternalSystem(); Console.WriteLine("Employees to test login\n"); Director Account1 = new Director("159.753.398-04"); Account1.Name = "Roberta Fierro"; Account1.Password = "******"; AccountManager Account2 = new AccountManager("326.985.628-89"); Account2.Name = "Camila Caballo"; Account2.Password = "******"; CommercialPartner Account3 = new CommercialPartner(); Account3.Password = "******"; Console.WriteLine("\nLogin status\n"); system.Login(Account1, "123"); system.Login(Account2, "abcd"); system.Login(Account3, "456"); }
public static void Login() { InternalSystem Is = new InternalSystem(); Directors al = new Directors("321.589.620.02"); al.Name = "Albert Parkinson"; al.Password = "******"; ComercialPartner cp = new ComercialPartner(); cp.Password = "******"; Is.Login(cp, "4567898"); Is.Login(cp, "1236456"); Is.Login(al, "123"); Is.Login(al, "abc"); Console.ReadKey(); }
public static void UseSystem() { InternalSystem internalSystem = new InternalSystem(); Director roberta = new Director(name: "Roberta", cpf: "159.753.398-04"); roberta.Password = "******"; internalSystem.Login(roberta, "1234"); ManagerOfAccount camila = new ManagerOfAccount(name: "Camila", cpf: "326.985.628-89"); camila.Password = "******"; internalSystem.Login(camila, "abcd"); ComercialPartner comercialPartner = new ComercialPartner(); comercialPartner.Password = "******"; internalSystem.Login(comercialPartner, "456"); }
public static void UsingSystem() { InternalSystem internalSystem = new InternalSystem(); Ceo roberta = new Ceo("13123213"); roberta.Name = "Roberta"; roberta.Password = "******"; SalesPartner camila = new SalesPartner(); camila.Password = "******"; Console.WriteLine("roberta"); internalSystem.SignIn(roberta, "123"); internalSystem.SignIn(roberta, "345"); Console.WriteLine("camila"); internalSystem.SignIn(camila, "123"); internalSystem.SignIn(camila, "345"); }
public static void UseInternalSystem() { InternalSystem internalSystem = new InternalSystem(); Director robert = new Director("159.753.398-04"); robert.Name = "Robert"; robert.Password = "******"; AccountManager caroline = new AccountManager("326.985.628-89"); caroline.Name = "Caroline"; caroline.Password = "******"; CommercialPartner commercialPartner = new CommercialPartner(); commercialPartner.Password = "******"; internalSystem.LogInto(robert, "123"); internalSystem.LogInto(caroline, "abc"); internalSystem.LogInto(commercialPartner, "123456"); }
internal CharEnumerator (InternalSystem.String _string) { internalString = _string; index = -1; }
internal unsafe static uint CallFilter (InternalSystem.Exception exception, ExceptionHandlingClause handler, void* callerBP) { Diagnostics.Error ("Unimplemented - ExceptionHandling.CallFilter"); return 0; }
internal static unsafe object IsInst (InternalSystem.Object obj, TypeInfo type) { if (obj != null && IsBaseClassOf (obj.VTable.Type, type)) return obj; else return null; }
internal static unsafe object CastClass (InternalSystem.Object obj, TypeInfo type) { if (obj != null && IsBaseClassOf (obj.VTable.Type, type)) return obj; Throw (new InternalSystem.InvalidCastException (), 3); // It doesn't come so far return null; }
internal unsafe static void CallFinallyFault (InternalSystem.Exception exception, ExceptionHandlingClause handler, void* callerBP) { Diagnostics.Error ("Unimplemented - ExceptionHandling.CallFinallyFault"); }
internal unsafe static void CallFinallyFault (InternalSystem.Exception exception, SharpOS.Korlib.Runtime.ExceptionHandlingClause handler, void* callerBP) { uint _callerBP = (uint) callerBP; uint targetIP = (uint) handler.HandlerBegin; // Set the address where it will jump to handle the exception Asm.MOV (R32.ECX, &targetIP); // This is very dependent of the way the AOT generates the prolog of the method Asm.MOV (R32.EAX, &_callerBP); Asm.PUSH (R32.EBP); Asm.PUSH (R32.EBX); Asm.PUSH (R32.ESI); Asm.PUSH (R32.EDI); Asm.MOV (R32.EBP, new DWordMemory (null, R32.EAX, null, 0, 0)); Asm.MOV (R32.EBX, new DWordMemory (null, R32.EAX, null, 0, -4)); Asm.MOV (R32.ESI, new DWordMemory (null, R32.EAX, null, 0, -8)); Asm.MOV (R32.EDI, new DWordMemory (null, R32.EAX, null, 0, -12)); // Push target address of the handler Asm.CALL (R32.ECX); Asm.POP (R32.EDI); Asm.POP (R32.ESI); Asm.POP (R32.EBX); Asm.POP (R32.EBP); }
internal unsafe static uint CallFilter (InternalSystem.Exception exception, SharpOS.Korlib.Runtime.ExceptionHandlingClause handler, void* callerBP) { uint _callerBP = (uint) callerBP; uint targetIP = (uint) handler.FilterBegin; uint exceptionAddress = (uint) Runtime.GetPointerFromObject (exception); uint result = 0; // The address (EDX) will be then used in the handler Asm.MOV (R32.EDX, &exceptionAddress); // Set the address where it will jump to handle the exception Asm.MOV (R32.ECX, &targetIP); // This is very dependent of the way the AOT generates the prolog of the method Asm.MOV (R32.EAX, &_callerBP); Asm.PUSH (R32.EBP); Asm.PUSH (R32.EBX); Asm.PUSH (R32.ESI); Asm.PUSH (R32.EDI); Asm.MOV (R32.EBP, new DWordMemory (null, R32.EAX, null, 0, 0)); Asm.MOV (R32.EBX, new DWordMemory (null, R32.EAX, null, 0, -4)); Asm.MOV (R32.ESI, new DWordMemory (null, R32.EAX, null, 0, -8)); Asm.MOV (R32.EDI, new DWordMemory (null, R32.EAX, null, 0, -12)); // Assign EAX the address of the exception object Asm.MOV (R32.EAX, R32.EDX); // Push target address of the handler Asm.CALL (R32.ECX); Asm.POP (R32.EDI); Asm.POP (R32.ESI); Asm.POP (R32.EBX); Asm.POP (R32.EBP); // Get the result of the filter Asm.MOV (&result, R32.EAX); return result; }
internal unsafe static void CallHandler (InternalSystem.Exception exception, SharpOS.Korlib.Runtime.ExceptionHandlingClause handler, void* callerBP) { uint _callerBP = (uint) callerBP; uint targetIP = (uint) handler.HandlerBegin; uint exceptionAddress = (uint) Runtime.GetPointerFromObject (exception); // The address (EDX) will be then used in the handler Asm.MOV (R32.EDX, &exceptionAddress); // Set the address where it will jump to handle the exception Asm.MOV (R32.ECX, &targetIP); // This is very dependent of the way the AOT generates the prolog of the method Asm.MOV (R32.EAX, &_callerBP); Asm.SUB (R32.EAX, 12); Asm.MOV (R32.ESP, R32.EAX); Asm.POP (R32.EDI); Asm.POP (R32.ESI); Asm.POP (R32.EBX); Asm.POP (R32.EBP); // Just dump the address of the caller Asm.POP (R32.EAX); // Assign EAX the address of the exception object Asm.MOV (R32.EAX, R32.EDX); // Push target address of the handler Asm.PUSH (R32.ECX); Asm.RET (); }
/// <summary> /// Gets the exception handler. /// </summary> /// <param name="exception">The exception.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> private unsafe static void GetExceptionHandler (InternalSystem.Exception exception, out int start, out int end) { ExceptionHandlingClause handler = null; int i = exception.CurrentStackFrame; // In the first pass we just look for a possible Exception Handler for (; i < exception.CallingStack.Length && handler == null; i++) { MethodBoundary methodBoundary = exception.CallingStack [i].MethodBoundary; for (int j = 0; j < exception.CallingStack [i].MethodBoundary.ExceptionHandlingClauses.Length; j++) { ExceptionHandlingClause exceptionHandlingClause = methodBoundary.ExceptionHandlingClauses [j]; if (exception.CallingStack [i].IgnoreMethodBoundaryClause [j]) continue; if (exceptionHandlingClause.ExceptionType == ExceptionHandlerType.Finally) continue; if (exceptionHandlingClause.ExceptionType == ExceptionHandlerType.Fault) continue; if (exception.CallingStack [i].IP < exceptionHandlingClause.TryBegin || exception.CallingStack [i].IP >= exceptionHandlingClause.TryEnd) continue; if (exceptionHandlingClause.ExceptionType == ExceptionHandlerType.Catch && !Runtime.IsBaseClassOf (exception.VTable.Type, exceptionHandlingClause.TypeInfo)) continue; if (handler == null) handler = exceptionHandlingClause; else if ((exceptionHandlingClause.TryBegin >= handler.TryBegin && exceptionHandlingClause.TryEnd < handler.TryEnd) || (exceptionHandlingClause.TryBegin >= handler.TryBegin && exceptionHandlingClause.TryEnd < handler.TryEnd)) handler = exceptionHandlingClause; } } // TODO this should check out if the error occured in a thread or a process if (handler == null) { TextMode.Write ("Unhandled exception: "); TextMode.Write (exception.VTable.Type.Name); TextMode.Write (": "); TextMode.WriteLine (exception.Message); PrintCallingStackToScreen (exception.CallingStack); Debug.COM1.Write ("Unhandled exception: "); Debug.COM1.Write (exception.VTable.Type.Name); Debug.COM1.Write (": "); Debug.COM1.WriteLine (exception.Message); PrintCallingStack (exception.IgnoreStackFramesCount, exception.CallingStack); Diagnostics.Panic ("No exception handler found"); } start = exception.CurrentStackFrame; end = i; exception.CurrentStackFrame = i - 1; }
internal static unsafe void Throw (InternalSystem.Exception exception) { Throw (exception, 3); }
/// <summary> /// Calls the handler. /// </summary> /// <param name="exception">The exception.</param> /// <param name="getNewHandler">if set to <c>true</c> [get new handler].</param> /// <param name="handler">The handler.</param> /// <param name="i">The i.</param> /// <param name="clauseIndex">Index of the clause.</param> /// <param name="callerBP">The caller BP.</param> /// <returns></returns> private unsafe static bool CallHandler (InternalSystem.Exception exception, bool getNewHandler, ExceptionHandlingClause handler, int i, int clauseIndex, void* callerBP) { if (handler != null) { #if DEBUG_EXCEPTION_HANDLING Debug.COM1.Write ("Calling the found handler from Frame: #"); Debug.COM1.WriteNumber ((int) (i - exception.IgnoreStackFramesCount), false); Debug.COM1.Write ("/Clause: #"); Debug.COM1.WriteNumber ((int) clauseIndex, false); Debug.COM1.WriteLine (); #endif exception.CallingStack [i].IgnoreMethodBoundaryClause [clauseIndex] = true; if (handler.ExceptionType == ExceptionHandlerType.Finally || handler.ExceptionType == ExceptionHandlerType.Fault) { ExceptionHandling.CallFinallyFault (exception, handler, callerBP); } else if (handler.ExceptionType == ExceptionHandlerType.Filter) { // If it is a filter and it fails look for the next Exception Handler if (ExceptionHandling.CallFilter (exception, handler, callerBP) == 0) getNewHandler = true; else ExceptionHandling.CallHandler (exception, handler, callerBP); } else if (handler.ExceptionType == ExceptionHandlerType.Catch) ExceptionHandling.CallHandler (exception, handler, callerBP); } return getNewHandler; }
internal static unsafe void Throw (InternalSystem.Exception exception, int skipFrames) { // TODO check the exception's type to make sure it is an exception StackFrame [] stackFrames = ExceptionHandling.GetCallingStack (); if (exception.CallingStack == null) { exception.CallingStack = stackFrames; exception.IgnoreStackFramesCount = skipFrames; exception.CurrentStackFrame = skipFrames; } #if DEBUG_EXCEPTION_HANDLING PrintCallingStack (exception.IgnoreStackFramesCount, exception.CallingStack); PrintCallingStack (0, stackFrames); #endif while (true) { bool getNewHandler = false; int start; int end; GetExceptionHandler (exception, out start, out end); for (int i = start; i < end && !getNewHandler; i++) { int candidates; do { int clauseIndex = 0; candidates = 0; MethodBoundary methodBoundary = exception.CallingStack [i].MethodBoundary; ExceptionHandlingClause handler = null; for (int j = 0; j < exception.CallingStack [i].MethodBoundary.ExceptionHandlingClauses.Length; j++) { ExceptionHandlingClause exceptionHandlingClause = methodBoundary.ExceptionHandlingClauses [j]; if (exception.CallingStack [i].IgnoreMethodBoundaryClause [j]) continue; if (exception.CallingStack [i].IP < exceptionHandlingClause.TryBegin || exception.CallingStack [i].IP >= exceptionHandlingClause.TryEnd) continue; if (exceptionHandlingClause.ExceptionType == ExceptionHandlerType.Catch && !Runtime.IsBaseClassOf (exception.VTable.Type, exceptionHandlingClause.TypeInfo)) continue; if (handler == null) { clauseIndex = j; handler = exceptionHandlingClause; } else { if ((exceptionHandlingClause.TryBegin >= handler.TryBegin && exceptionHandlingClause.TryEnd < handler.TryEnd) || (exceptionHandlingClause.TryBegin >= handler.TryBegin && exceptionHandlingClause.TryEnd < handler.TryEnd)) { clauseIndex = j; handler = exceptionHandlingClause; } candidates++; } } void* bp = stackFrames [stackFrames.Length - (exception.CallingStack.Length - i + 1)].BP; getNewHandler = CallHandler (exception, getNewHandler, handler, i, clauseIndex, bp); } while (candidates != 0 && !getNewHandler); } } }