public void Setup() { _piorityService = new PriorityService(); var operationFactory = new OperationFactory(); _piorityService.AddToPiority(1, operationFactory.CreateOperation(OperationEnum.Multiplication)); _piorityService.AddToPiority(1, operationFactory.CreateOperation(OperationEnum.Division)); _piorityService.AddToPiority(2, operationFactory.CreateOperation(OperationEnum.Add)); _piorityService.AddToPiority(2, operationFactory.CreateOperation(OperationEnum.Subtract)); _calculationService = new CalculationService(); }
static void Main(string[] args) { double numberOne = 0; double numberTwo = 0; string operate = ""; try { Console.WriteLine("Please enter the first number!"); numberOne = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Please enter the second number!"); numberTwo = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Please enter an operator!"); operate = Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("There is a problem with the number you entered!"); Console.WriteLine(ex.Message); } IOperation operation = OperationFactory.CreateOperation(operate); double result = operation.GetResult(numberOne, numberTwo); Console.WriteLine("The Result is " + result); Console.ReadKey(); }
public ServiceResponse DoRequest(ServiceRequest request) { Guid logGuid = Guid.NewGuid(); try { Logger.FileAddMessage(logGuid, "[==================== SERVICEREQUEST ==================]\r\n"); Logger.FileAddMessage(logGuid, Utilities.ClassToString(request)); Locker.Lock(request.TransactionId, logGuid); ServiceResponse = OperationFactory .CreateOperation(logGuid, request.Operation, new OperationProvider(new WebProvider())) .ProcessRequest(request); } catch (Exception ex) { Logger.FileAddMessage(logGuid, "[==================== ERROR PROCESSING ==================]\r\n"); string message = ex.GetAllExceptionMessage(withStack: true); Logger.FileAddMessage(logGuid, message); Logger.Error(logGuid, request.System, request.TransactionId, request.ServiceId, System.Reflection.MethodBase.GetCurrentMethod().Name, ex); } finally { Locker.Unlock(request.TransactionId, logGuid); if (ServiceResponse != null) { Logger.FileAddMessage(logGuid, $"[==================== SERVICERESPONSE ==================]\r\n" + $"{Utilities.ClassToString(ServiceResponse)}"); } Logger.FileFlushMessage(logGuid); } return(ServiceResponse); }
public double SimpleFactory(OperationRequestEntity requestEntity) { var operationFactory = new OperationFactory(); var operation = operationFactory.CreateOperation(requestEntity.OperationType); return(operation.GetResult(requestEntity.num1, requestEntity.num2)); }
public FactoryReturnClass FactoryCalculate([FromBody] JsonFactoryParameter param) { FactoryReturnClass rtn = new FactoryReturnClass(); Operation oper = OperationFactory.CreateOperation(param.oper); if (oper != null) { oper.NumberX = param.NumberX; oper.NumberY = param.NumberY; try{ rtn.Message = "Calculated successfully by factoryPattern!"; rtn.result = oper.CalculateResult(); rtn.ReturnValue = 0; } catch (Exception ex) { rtn.Message = "error:" + ex.Message; rtn.ReturnValue = 100; } finally { } } else { rtn.Message = "Operator is invalid."; rtn.ReturnValue = 101; } return(rtn); }
public void FailIfTestDoesntExists() { var factory = new OperationFactory(); Action act = () => factory.CreateOperation("XXXXX"); act.Should().Throw <OperationNotFoundException>(); }
private static void TestSimpleFactory() { var oper = OperationFactory.CreateOperation(OperationFactory.OperationType.SUB); oper.NumberA = 10; oper.NumberB = 6.6; Console.WriteLine($"result:{oper.GetResult()}"); }
public void ObtainTestExample1() { var factory = new OperationFactory(); var expectedOperation = new OperationExample1(); var actualOperation = factory.CreateOperation("Operationexample1"); actualOperation.Should().BeOfType(expectedOperation.GetType()); }
public void SimpleFactoryPatternCodeTest() { var oper = OperationFactory.CreateOperation("-"); oper.NumbleA = 1; oper.NumbleB = 3; Console.WriteLine("结果为:" + oper.GetResult()); Console.ReadKey(); }
static void Main(string[] args) { //简单工厂模式 Operation add = OperationFactory.CreateOperation("+"); add.NumberB = 10; add.NumberA = 20; Console.WriteLine(add.Result()); }
public IGitOperation Run(OperationType operationType) { IGitOperation operation = OperationFactory.CreateOperation(operationType); operation.GitConnector = GitConnector; operation.OperationParameters = OperationParameters; operation?.Run(); operation?.PrintResultsToTraceListeners(); return(operation); }
public static IOperation DeleteOperation(IList <int> data, IOperation operation) { if (data.Count() == 0 || operation.Index >= data.Count) { return(null); } int value = data[operation.Index]; data.RemoveAt(operation.Index); return(OperationFactory.CreateOperation(operation.ClientId, OperationType.Delete, operation.Index, value, operation.Timestamp)); }
public static IOperation InsertOperation(IList <int> data, IOperation operation) { // add if data is empty if (data.Count() == 0) { data.Add(operation.Value.Value); return(OperationFactory.CreateOperation(operation.ClientId, OperationType.Insert, 0, operation.Value.Value, operation.Timestamp)); } // perform binary search of the index to insert int index = FindInsertIndex(data.ToArray(), operation.Value.Value); data.Insert(index, operation.Value.Value); return(OperationFactory.CreateOperation(operation.ClientId, OperationType.Insert, index, operation.Value.Value, operation.Timestamp)); }
public static IList <IOperation> UpdateOperation(IList <int> data, IOperation operation) { List <IOperation> result = new List <IOperation>(); int value = data[operation.Index]; data.RemoveAt(operation.Index); result.Add(OperationFactory.CreateOperation(operation.ClientId, OperationType.Delete, operation.Index, value, operation.Timestamp)); int index = FindInsertIndex(data.ToArray(), operation.Value.Value); data.Insert(index, operation.Value.Value); result.Add(OperationFactory.CreateOperation(operation.ClientId, OperationType.Insert, index, operation.Value.Value, operation.Timestamp)); return(result); }
protected void StartJob() { string[] scenarios = _pkg.Job.Scenarios.Split(null); System.Timers.Timer timer = new System.Timers.Timer(); timer.AutoReset = true; int ind = 0; timer.Elapsed += (sender, e) => { // set new interval timer.Stop(); timer.Interval = (_pkg.Job.Duration + laterTime) * 1000; timer.Start(); if (ind >= scenarios.Length) { timer.Stop(); return; } string scenario = scenarios[ind++]; Util.Log($"scenario: {scenario}"); EchoOp op = (EchoOp)OperationFactory.CreateOperation(scenario, _pkg); op.Setup(); op.Process(); Util.Log($"statistics delay time: {(_pkg.Job.Duration + laterTime / 2)}s"); Task.Delay((_pkg.Job.Duration + laterTime / 2 + 5) * 1000 + 120 * 1000).ContinueWith(_ => { Util.Log($"Show statistics"); op.SaveCounters(); Util.Log($"msg send: {op.totalSentMsg}, receive: {op.totalReceivedMsg}"); }); }; timer.Start(); }