public DelegateExample() { InitializeComponent(); operationTypes = new List <OperationType>(); values = new List <string>(); operationPerformer = new OperationPerformer(); }
public void StartListener() { if (!isListening) { status += "Starting TCP listener. "; } isListening = true; listenerThread = new Thread(new ThreadStart(listenToPort)); try { listener.Start(); listenerThread.Start(); string result = OperationPerformer.Instance().Initialize(this); status += result; } catch (SocketException ex) { if (ErrorOccurred != null) { CPMErrorEventArgs args = new CPMErrorEventArgs(); args.Message = ex.Message; args.time = DateTime.Now; ErrorOccurred(this, args); } status = "Error occurred when starting TCP listener: " + ex.Message; isListening = false; return; } }
public void LogInTest() { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(Host, Port); var operationPerformer = new OperationPerformer(socket); operationPerformer.OmitWelcomeResponse(); operationPerformer.LogIn(Username, Password); Assert.IsTrue(true); }
public void CalcBracketLessExpressionTestMethod() { // arrange var expressionBracketsLess = "8/4+6-5-4"; var performer = new OperationPerformer(); // act var actualResult = performer.CalcBracketLessExpression(expressionBracketsLess); // assert Assert.AreEqual("-1", actualResult); }
public void DownloadFileTest() { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(Host, Port); var operationPerformer = new OperationPerformer(socket); operationPerformer.OmitWelcomeResponse(); operationPerformer.LogIn(Username, Password); operationPerformer.ActiveMode = false; operationPerformer.DownloadFile("FTP.txt", "G:\\hp\\Desktop\\test1.txt"); operationPerformer.ActiveMode = true; operationPerformer.DownloadFile("FTP.txt", "G:\\hp\\Desktop\\test2.txt"); operationPerformer.LogOut(); Assert.IsTrue(true); }
public void ListFilesTest() { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(Host, Port); var operationPerformer = new OperationPerformer(socket); operationPerformer.OmitWelcomeResponse(); operationPerformer.LogIn(Username, Password); operationPerformer.ActiveMode = false; operationPerformer.ListFiles("/").ForEach(x => Console.WriteLine(x)); operationPerformer.ActiveMode = true; operationPerformer.ListFiles("/").ForEach(x => Console.WriteLine(x)); operationPerformer.LogOut(); Assert.IsTrue(true); }
public void RenameFileTest() { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(Host, Port); var operationPerformer = new OperationPerformer(socket); operationPerformer.OmitWelcomeResponse(); operationPerformer.LogIn(Username, Password); operationPerformer.DownloadFile("FTP.txt", "haha.txt"); operationPerformer.UploadFile("haha.txt", "haha.txt"); operationPerformer.RenameFile("haha.txt", "hehe.txt"); Assert.IsTrue(true); }
public void Run() { OperationPerformer.PerformOperation opAdd = PerformAddition; OperationPerformer.PerformOperation opSub = PerformSubtraction; OperationPerformer perfAdd = new OperationPerformer(opAdd); perfAdd.Perform(); /*OperationPerformer perfAddWithMethod = new OperationPerformer(PerformAddition); * perfAddWithMethod.Perform(); * * OperationPerformer perfSub = new OperationPerformer(opSub); * perfSub.Perform(); * OperationPerformer perfSubWithMethod = new OperationPerformer(PerformSubtraction); * perfSubWithMethod.Perform();*/ }
public void ChangeDirectoryTest() { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(Host, Port); var operationPerformer = new OperationPerformer(socket); operationPerformer.OmitWelcomeResponse(); operationPerformer.LogIn(Username, Password); operationPerformer.ChangeDirectory(".."); operationPerformer.ChangeDirectory("."); operationPerformer.ChangeDirectory(".settings"); operationPerformer.ChangeDirectory(".././../.settings/../."); operationPerformer.LogOut(); Assert.IsTrue(true); }
public void RemoveDirectoryTest() { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(Host, Port); var operationPerformer = new OperationPerformer(socket); operationPerformer.OmitWelcomeResponse(); operationPerformer.LogIn(Username, Password); try { operationPerformer.RemoveDirectory("testDir/testR"); } catch (Exception) { // ignored } try { operationPerformer.RemoveDirectory("testDir"); } catch (Exception) { // ignored } operationPerformer.MakeDirectory("testDir"); operationPerformer.MakeDirectory("testDir/testR"); operationPerformer.ChangeDirectory("testDir"); operationPerformer.RemoveDirectory("testR"); Assert.IsTrue(operationPerformer.ListFiles().Count == 2); operationPerformer.ChangeDirectory(".."); operationPerformer.RemoveDirectory("testDir"); Assert.IsTrue(operationPerformer.ListFiles().FindIndex(x => x.Name == "testDir") == -1); operationPerformer.LogOut(); Assert.IsTrue(true); }
public void UploadFileTest() { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(Host, Port); var operationPerformer = new OperationPerformer(socket); operationPerformer.OmitWelcomeResponse(); operationPerformer.LogIn(Username, Password); operationPerformer.ActiveMode = false; operationPerformer.UploadFile("haha.txt", "G:\\hp\\Desktop\\test1.txt"); var fileList = operationPerformer.ListFiles("/"); Assert.IsTrue(fileList.FindIndex(x => x.Name == "haha.txt") >= 0); operationPerformer.ActiveMode = true; operationPerformer.UploadFile("hehe.txt", "G:\\hp\\Desktop\\test1.txt"); fileList = operationPerformer.ListFiles("/"); Assert.IsTrue(fileList.FindIndex(x => x.Name == "hehe.txt") >= 0); operationPerformer.LogOut(); Assert.IsTrue(true); }
private operationresult HowAreYou(string curDate, string checksum) { status = "HowAreYou() was called"; string calculatedMD5 = HashUtility.CalculateMD5(curDate); if (!calculatedMD5.Equals(checksum)) { return(new operationresult(IntegerConstants.WRONG_CHECKSUM, "неправильная контрольная сумма", "CPMTcpServer.HowAreYou()")); } DateTime externalDate = DateTime.ParseExact(curDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentCulture); DateTime now = DateTime.Now; CPMPayAgentService.LoggingLayer.PayAgentLogger.Instance().logError("HOWYOU Now: " + now.ToString() + " curdate: " + externalDate.ToString() + (externalDate.CompareTo(now.AddMinutes(15)) < 0) + " " + (externalDate.CompareTo(now.AddMinutes(-15)) > 0)); if (!(externalDate.CompareTo(now.AddMinutes(15)) < 0 && (externalDate.CompareTo(now.AddMinutes(-15)) > 0))) { return(new operationresult(IntegerConstants.WRONG_TIME, "неправильное время", "Server.HowAreYou()")); } long diff = DateTime.Now.Ticks - beginTime.Ticks; TimeSpan span = new TimeSpan(diff); string livetime = "" + span.Days + "d " + (int)span.Hours + "h " + span.Minutes + "m "; operationresult result = new operationresult(); RegistrationResultItem item; try { item = OperationPerformer.Instance().getRegistrationResult(); } catch (Exception e) { result.result = IntegerConstants.SUCCESS; result.status = "-500"; result.statusNote = "Сервис не готов к работе! " + e.Message; result.livetime = livetime; return(result); } switch (item) { case RegistrationResultItem.RegistrationFailed: result.result = IntegerConstants.SUCCESS; result.status = "-1"; result.statusNote = "Сервис не готов к работе!"; break; case RegistrationResultItem.RegistrationSuccefully: result.result = IntegerConstants.SUCCESS; result.status = "1"; result.statusNote = "Сервис готов к работе!"; break; case RegistrationResultItem.Unknown: result.result = IntegerConstants.SUCCESS; result.status = "-500"; result.statusNote = "Сервис не готов к работе!"; break; default: break; } result.livetime = livetime; return(result); }
private operationresult performOperation(string xmlStr, string endPoint) { status = "performOperation() was called. "; try { TextReader txtReader = new StringReader(xmlStr); request mcmessage; XmlSerializer serializer = new XmlSerializer(typeof(request)); mcmessage = (request)serializer.Deserialize(txtReader); CPMPayAgentService.LoggingLayer.PayAgentLogger.Instance().logError("Message deserialized. " + mcmessage.ToString() + "\r\n" + xmlStr); if (mcmessage.duetOper != null) { return(OperationPerformer.Instance().PerformDuetOperation(mcmessage.duetOper.sessionID, mcmessage.duetOper.clientAccountID , mcmessage.duetOper.counterAgentAccountID, mcmessage.duetOper.counterAgentClientAccountID , mcmessage.duetOper.contractBindID, mcmessage.duetOper.externalDocDate, mcmessage.duetOper.externalDocNumber , mcmessage.duetOper.feeAmount, mcmessage.duetOper.functionType , mcmessage.duetOper.paymentDetails, mcmessage.duetOper.transactAmount, mcmessage.duetOper.checksum, mcmessage.duetOper.curDate, endPoint, this)); } else if (mcmessage.operSuccess != null) { return(OperationPerformer.Instance().IsOperationSuccessful(mcmessage.operSuccess.sessionid, mcmessage.operSuccess.curdate, mcmessage.operSuccess.checksum)); } else if (mcmessage.howYou != null) { return(HowAreYou(mcmessage.howYou.curdate, mcmessage.howYou.checksum)); } else if (mcmessage.operStatus != null) { return(OperationPerformer.Instance().GetOperationsStatus(mcmessage.operStatus.result, mcmessage.operStatus.from, mcmessage.operStatus.to, mcmessage.operStatus.curdate, mcmessage.operStatus.checksum)); } else if (mcmessage.confirmduetoperation != null) { CPMPayAgentService.LoggingLayer.PayAgentLogger.Instance().logError("Message deserialized - ConfirmOperation"); return(OperationPerformer.Instance().ConfirmDuetOperation(mcmessage.confirmduetoperation.sessionID , mcmessage.confirmduetoperation.externalDocDate, mcmessage.confirmduetoperation.externalDocNumber , mcmessage.confirmduetoperation.curDate, endPoint, this)); } else if (mcmessage.prepareduetoperation != null) { CPMPayAgentService.LoggingLayer.PayAgentLogger.Instance().logError("Message deserialized - PrepareOperation"); return(OperationPerformer.Instance().PrepareDuetOperation(mcmessage.prepareduetoperation.sessionID, mcmessage.prepareduetoperation.clientAccountID , mcmessage.prepareduetoperation.counterAgentAccountID, mcmessage.prepareduetoperation.counterAgentClientAccountID , mcmessage.prepareduetoperation.contractBindID, mcmessage.prepareduetoperation.externalDocDate, mcmessage.prepareduetoperation.externalDocNumber , mcmessage.prepareduetoperation.feeAmount, mcmessage.prepareduetoperation.functionType , mcmessage.prepareduetoperation.paymentDetails, mcmessage.prepareduetoperation.transactAmount, mcmessage.prepareduetoperation.checksum, mcmessage.prepareduetoperation.curDate, endPoint, this)); } else if (mcmessage.cancelduetoperation != null) { return(OperationPerformer.Instance().CancelDuetOperation(mcmessage.cancelduetoperation.sessionID , mcmessage.cancelduetoperation.externalDocDate, mcmessage.cancelduetoperation.externalDocNumber , mcmessage.cancelduetoperation.curDate, endPoint, this)); } else if (mcmessage.blockcardaccount != null) { return(OperationPerformer.Instance().BlockCardAccount(mcmessage.blockcardaccount.sessionid, mcmessage.blockcardaccount.clientAccountID, mcmessage.blockcardaccount.blockType, mcmessage.blockcardaccount.blockAction, mcmessage.blockcardaccount.reason, mcmessage.blockcardaccount.checksum, mcmessage.blockcardaccount.curDate, endPoint)); } else if (mcmessage.emvload != null) { return(OperationPerformer.Instance().EMVLoadOperation(mcmessage.emvload.sessionid, mcmessage.emvload.amount, mcmessage.emvload.emvaccountid, mcmessage.emvload.externalDocDate, mcmessage.emvload.externalDocNumber, mcmessage.emvload.checksum, mcmessage.emvload.curDate, endPoint)); } else if (mcmessage.emvunload != null) { return(OperationPerformer.Instance().EMVUnLoadOperation(mcmessage.emvunload.sessionid, mcmessage.emvunload.amount, mcmessage.emvunload.emvaccountid, mcmessage.emvunload.externalDocDate, mcmessage.emvunload.externalDocNumber, mcmessage.emvunload.checksum, mcmessage.emvunload.curDate, endPoint)); } else if (mcmessage.openclient != null) { return(OperationPerformer.Instance().OpenClientOperation(mcmessage.openclient.sessionid, mcmessage.openclient.name, mcmessage.openclient.address, mcmessage.openclient.index, mcmessage.openclient.bankid , mcmessage.openclient.participantid, mcmessage.openclient.region, mcmessage.openclient.clientClass , mcmessage.openclient.contractNumber, mcmessage.openclient.contractDate, mcmessage.openclient.taxID1 , mcmessage.openclient.taxID2, mcmessage.openclient.INN, mcmessage.openclient.OKPO, mcmessage.openclient.checksum, mcmessage.openclient.curDate, endPoint)); } else if (mcmessage.openaccount != null) { return(OperationPerformer.Instance().OpenAccountOperation(mcmessage.openaccount.sessionid, mcmessage.openaccount.clientDataId, mcmessage.openaccount.accountSubNumber, mcmessage.openaccount.counterAgentAccountID , mcmessage.openaccount.extAccountNumber, mcmessage.openaccount.externalDocNumber, mcmessage.openaccount.cPart , mcmessage.openaccount.checksum, mcmessage.openaccount.curDate, endPoint)); } else if (mcmessage.emvcardblockunblock != null) { return(OperationPerformer.Instance().BlockUnblockEMVCardAccount(mcmessage.emvcardblockunblock.sessionid, mcmessage.emvcardblockunblock.clientdataid, mcmessage.emvcardblockunblock.emvaccountid, mcmessage.emvcardblockunblock.emvcardid, mcmessage.emvcardblockunblock.reason, mcmessage.emvcardblockunblock.checksum, mcmessage.emvcardblockunblock.curDate, endPoint)); } } catch (Exception ex) { return(new operationresult(IntegerConstants.WRONG_PARAMS, "не удалось конвертировать запрос. неправильный формат.", "performOperation(string)" + ex.Message + " " + ex.StackTrace)); } return(new operationresult(IntegerConstants.ERROR, "неизвестная ошибка.", "performOperation(string)")); }