コード例 #1
0
        /// <summary>
        /// Creates an agent
        /// </summary>
        /// <param name="agentType"></param>
        /// <param name="agentServerRef"></param>
        /// <returns></returns>
        public int Create(int agentTypeID, int agentServerID, bool enabled = false)
        {
            int agentID = -1;

            var agentType = new Securable <ObjectIdentifier>(new ObjectIdentifier {
                ArtifactID = agentTypeID
            });
            var agentServer = new Securable <ObjectIdentifier>(new ObjectIdentifier {
                ArtifactID = agentServerID
            });
            var agentToCreate = new AgentRequest()
            {
                AgentType    = agentType,
                Enabled      = enabled,
                Interval     = 5,
                AgentServer  = agentServer,
                Keywords     = "Integration Test Agent",
                LoggingLevel = 1
            };

            using (var agentManager = _helper.GetServicesManager().CreateProxy <Relativity.Services.Interfaces.Agent.IAgentManager>(ExecutionIdentity.System))
            {
                // Confirms an agent may be created
                List <AgentInstanceLimitResult> results = agentManager.ValidateCreateInstanceLimitAsync(-1, agentToCreate, 1).Result;
                foreach (var result in results)
                {
                    Console.WriteLine(result.Limit.ToString());
                }

                agentID = agentManager.CreateAsync(-1, agentToCreate).Result;
            }
            return(agentID);
        }
コード例 #2
0
        public HttpResponseMessage getIdleAgent([FromBody] AgentRequest nAgentRequest)
        {
            AgentResult agentResult_ = new AgentResult();

            agentResult_.mErrorCode  = ConstAspect.mFail;
            agentResult_.mServerInfo = ServerAspect.getServerInfo(nAgentRequest.mOperatorName, nAgentRequest.mVersionNo, nAgentRequest.mServerId);
            agentResult_.mAgentIp    = "";
            agentResult_.mAgentPort  = "";

            int classify_ = 0;

            if (null != agentResult_.mServerInfo)
            {
                classify_ = agentResult_.mServerInfo.mClassify;
            }
            if (0 == classify_)
            {
                agentResult_.mErrorCode = ConstAspect.mServerId;
                return(toJson(agentResult_));
            }

            AgentInfo agentInfo_ = AgentAspect.getIdleAgent(nAgentRequest.mOperatorName, nAgentRequest.mVersionNo, classify_);

            if (null == agentInfo_)
            {
                agentResult_.mErrorCode = ConstAspect.mAgent;
                return(toJson(agentResult_));
            }
            agentResult_.mErrorCode = ConstAspect.mSucess;
            agentResult_.mAgentIp   = agentInfo_.mAgentIp;
            agentResult_.mAgentPort = agentInfo_.mAgentPort;
            return(toJson(agentResult_));
        }
コード例 #3
0
 public PowerShellAgentRunner(AgentRequest request, string workingDirectory, TimeSpan timeout, ClrVersion clrVersion)
 {
     _outputBuilder    = new SynchronizedStringBuilder(new StringBuilder(0x1000));
     _request          = request;
     _workingDirectory = workingDirectory;
     _timeout          = timeout;
     _clrVersion       = clrVersion;
 }
コード例 #4
0
        public override async Task <AgentStatusResponse> AgentStatus(AgentRequest request, ServerCallContext context)
        {
            var status = await client.GetGrain <IAgentRegistryGrain>(0).IsAgentRunning(request.Uuid);

            return(new AgentStatusResponse()
            {
                Running = status
            });
        }
コード例 #5
0
        public void PowerShellAgentRunner_should_return_formatted_objects()
        {
            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = string.Format("Get-ChildItem -Path Env:")
            };

            var runner = new PowerShellAgentRunner(request, Path.GetTempPath(), TimeSpan.Zero, ClrVersion.Version2);

            runner.Run();

            StringAssert.Contains(runner.Output, Environment.GetEnvironmentVariable("TEMP"));
        }
コード例 #6
0
        public void PowerShellAgentRunner_should_return_output_prior_to_a_script_error()
        {
            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = string.Format("'Output this first'\nthrow 'fail'")
            };

            var runner = new PowerShellAgentRunner(request, Path.GetTempPath(), TimeSpan.Zero, ClrVersion.Version2);

            runner.Run();

            StringAssert.Contains(runner.Output, "Output this first");
        }
コード例 #7
0
        public void PowerShellAgentRunner_should_return_output_from_Console_WriteLine()
        {
            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = "[Console]::WriteLine('written to the console')"
            };

            var runner = new PowerShellAgentRunner(request, Path.GetTempPath(), TimeSpan.MaxValue, ClrVersion.Version2);

            runner.Run();

            StringAssert.Contains(runner.Output, "written to the console");
        }
コード例 #8
0
        public void PowerShellAgentRunner_should_return_output_from_native_executable()
        {
            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = "cmd /c echo Written by native executable"
            };

            var runner = new PowerShellAgentRunner(request, Path.GetTempPath(), TimeSpan.Zero, ClrVersion.Version2);

            runner.Run();

            StringAssert.Contains(runner.Output, "Written by native executable");
        }
コード例 #9
0
        public void PowerShellAgentRunner_should_terminate_if_timeout_period_exceeded()
        {
            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = string.Format("'Begin'; Start-Sleep -Seconds 10; 'End'")
            };

            var runner   = new PowerShellAgentRunner(request, Path.GetTempPath(), TimeSpan.FromSeconds(2), ClrVersion.Version2);
            var exitCode = runner.Run();

            StringAssert.Contains(runner.Output, "Begin");
            StringAssert.DoesNotMatch(runner.Output, new Regex("End"));
            Assert.AreNotEqual(0, exitCode);
        }
コード例 #10
0
        public void PowerShellAgentRunner_should_return_readable_errors_instead_of_CliXml()
        {
            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = string.Format("'Output this first'\nthrow 'my error message'")
            };

            var runner = new PowerShellAgentRunner(request, Path.GetTempPath(), TimeSpan.Zero, ClrVersion.Version2);

            runner.Run();

            StringAssert.Contains(runner.Output, "my error message");
            StringAssert.DoesNotMatch(runner.Output, new Regex("CLIXML"));
        }
コード例 #11
0
        public void PowerShellAgentRunner_should_support_PowerShell_v2()
        {
            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = "'PS:' + $PSVersionTable.PSVersion"
            };

            var workingDirectory = Path.GetTempPath();

            var runner = new PowerShellAgentRunner(request, workingDirectory, TimeSpan.Zero, ClrVersion.Version2);

            runner.Run();

            StringAssert.Contains(runner.Output, "PS:2.0");
        }
コード例 #12
0
        public void PowerShellAgentRunner_should_return_output_from_CLR_executable()
        {
            var msBuildPath = Path.Combine(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), "msbuild.exe");

            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = string.Format("& \"{0}\" /version", msBuildPath)
            };

            var runner = new PowerShellAgentRunner(request, Path.GetTempPath(), TimeSpan.Zero, ClrVersion.Version2);

            runner.Run();

            StringAssert.Contains(runner.Output, "Build Engine");
        }
コード例 #13
0
 public IActionResult UpdateAgent(AgentRequest request)
 {
     try
     {
         if (string.IsNullOrEmpty(request.Agent) || string.IsNullOrEmpty(request.Content))
         {
             return(Problem("Missing agent or content argument!"));
         }
         var path = GetAgentPath(request.Agent);
         System.IO.File.WriteAllText(path, request.Content);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(Problem("Could not get agent. " + ex.Message));
     }
 }
コード例 #14
0
        private Process StartProcessWithRequest(AgentRequest request, string workingDirectory)
        {
            var agentPath = request.GetType().Assembly.Location;


            var startInfo = new ProcessStartInfo(agentPath)
            {
                WorkingDirectory       = workingDirectory,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                CreateNoWindow         = true
            };

            using (var activationDirectory = new WorkingDirectory())
            {
                startInfo.EnvironmentVariables["COMPLUS_ApplicationMigrationRuntimeActivationConfigPath"] = activationDirectory.DirectoryInfo.FullName;
                if (_clrVersion == ClrVersion.Version4)
                {
                    var configPath = Path.Combine(activationDirectory.DirectoryInfo.FullName, string.Concat(Path.GetFileName(agentPath), ".activation_config"));
                    File.WriteAllText(configPath, ClrVersion4ActivationConfigContent);
                }

                var namedPipeName = string.Format("{0}.{1}", GetType().FullName, Guid.NewGuid());
                startInfo.Arguments = namedPipeName;
                using (var pipeServer = new NamedPipeServerStream(namedPipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous))
                {
                    var messagePipe = new MessagePipe(pipeServer);

                    var ar = pipeServer.BeginWaitForConnection(null, pipeServer);

                    var process = Process.Start(startInfo);

                    pipeServer.EndWaitForConnection(ar);

                    messagePipe.WriteMessage(request);

                    pipeServer.WaitForPipeDrain();

                    return(process);
                }
            }
        }
コード例 #15
0
        public DeployAgentResult Deploy(DeployAgentData deployAgentData)
        {
            var request = new AgentRequest
            {
                NoProfile = true,
                Command   = PrepareImportGlobalVariablesScript(deployAgentData) + PrepareDeploymentScript(deployAgentData)
            };

            var runner = new PowerShellAgentRunner(request, deployAgentData.DeployScriptRoot, deployAgentData.Timeout, _clrVersion);

            if (_deploymentEventRecorder != null)
            {
                _deploymentEventRecorder.SetDeploymentOutputDelegate(deployAgentData.DeploymentId, () => runner.Output);
            }

            var exitCode = runner.Run();
            var result   = new DeployAgentResult {
                HasErrors = exitCode != 0, Output = runner.Output
            };

            return(result);
        }
コード例 #16
0
        public void Update(int agentID, int agentTypeID, int agentServerID, bool enabled = true)
        {
            var agentType = new Securable <ObjectIdentifier>(new ObjectIdentifier {
                ArtifactID = agentTypeID
            });
            var agentServer = new Securable <ObjectIdentifier>(new ObjectIdentifier {
                ArtifactID = agentServerID
            });

            var request = new AgentRequest
            {
                Enabled      = enabled,
                AgentServer  = agentServer,
                AgentType    = agentType,
                LoggingLevel = 1,
                Interval     = 5
            };

            using (var agentManager = _helper.GetServicesManager().CreateProxy <Relativity.Services.Interfaces.Agent.IAgentManager>(ExecutionIdentity.System))
            {
                agentManager.UpdateAsync(-1, agentID, request).Wait();
            }
        }
コード例 #17
0
        public static async Task <AgentRequest> AgentActivity(
            [ActivityTrigger] AgentRequest request,
            TraceWriter log)
        {
            const int concurentNumber = 100;
            var       tasks           = new Task <List <string> > [concurentNumber];
            var       rowKeys         = request.ProcessedRowKeys;

            foreach (var i in Enumerable.Range(request.Id * concurentNumber, concurentNumber))
            {
                var index = i - (request.Id * concurentNumber);
                if (rowKeys.ContainsKey(index))
                {
                    tasks[index] = executeAgent(request.ProcessedRowKeys[index], i);
                }
                else
                {
                    tasks[index] = executeAgent(new List <string>(), i);
                }
            }
            await Task.WhenAll(tasks);

            foreach (var i in Enumerable.Range(0, concurentNumber))
            {
                if (rowKeys.ContainsKey(i))
                {
                    rowKeys[i] = await tasks[i];
                }
                else
                {
                    rowKeys.Add(i, await tasks[i]);
                }
            }
            request.ProcessedRowKeys = rowKeys;
            return(request);
        }
コード例 #18
0
        public async Task <AgentRequest> CreateAgent([FromBody] AgentRequest agentRequest)
        {
            var agentResponse = await _agentService.CreateAgent(agentRequest);

            return(agentRequest);
        }
コード例 #19
0
        public override async Task <Scynet.Void> AgentStop(AgentRequest request, ServerCallContext context)
        {
            await client.GetGrain <IAgentRegistryGrain>(0).AgentStop(request.Uuid);

            return(new Scynet.Void());;
        }
コード例 #20
0
        //
        // GET: /Ims/Agent/
        public ActionResult Index(AgentRequest request)
        {
            var result = this.ImsService.GetAgentList(request);

            return(View(result));
        }
コード例 #21
0
        public async Task <AgentRequest> CreateAgent(AgentRequest agentRequest)
        {
            string generatedRequestID = await CreateRequestID();

            int agentID = await CreateAgentID();

            int authID = await CreateAgentID();

            int masterAgentCode    = 0;
            int submasteragentCode = 0;

            if (agentRequest.Masteridlist != null)
            {
                submasteragentCode = await CreateMasterSubID();

                masterAgentCode = Convert.ToInt32(agentRequest.Masteridlist);
            }
            else
            {
                masterAgentCode = await CreateMasterSubID();

                submasteragentCode = 0;
            }

            Agent agent = new Agent
            {
                AgentID                                        = agentID,
                BusinessName                                   = agentRequest.BusinessName,
                City                                           = agentRequest.City,
                CompanyTIN                                     = agentRequest.Comptin,
                CorporateName                                  = agentRequest.CorpName,
                Country                                        = agentRequest.Country,
                CreatedDateTime                                = DateTime.Now,
                CTCNo                                          = agentRequest.CTCNo,
                DailyDepositLimit                              = agentRequest.DailyDepLimit,
                FirstName                                      = agentRequest.FirstName,
                IsBusiness                                     = agentRequest.IsBusinessName != null?bool.Parse(agentRequest.IsBusinessName) : false,
                                                   IsCorporate = agentRequest.IsCorpName != null?bool.Parse(agentRequest.IsCorpName) : false,
                                                                     IsMerchCategory = agentRequest.IsMerchcategory != null?bool.Parse(agentRequest.IsMerchcategory) : false,
                                                                                           LastName          = agentRequest.LastName,
                                                                                           LastUserUpdate    = agentRequest.User,
                                                                                           MasterAgentCodeID = masterAgentCode,
                                                                                           MerchantCategory  = agentRequest.Merchcategory,
                                                                                           MiddleName        = agentRequest.MiddleName,
                                                                                           PhoneNo           = agentRequest.PhoneNo,
                                                                                           PostalCode        = Convert.ToInt32(agentRequest.PostalCode),
                                                                                           RequestID         = generatedRequestID,
                                                                                           StreetNo          = agentRequest.StreetNo,
                                                                                           SubAgentCodeID    = submasteragentCode,
                                                                                           Town           = agentRequest.Town,
                                                                                           UpdateDeteTime = DateTime.Now,
                                                                                           UserCreate     = agentRequest.User,
                                                                                           Status         = "Pending",
                                                                                           IsDeleted      = false
            };

            Bank bank = new Bank
            {
                BankAccountName = agentRequest.Bankaccname,
                City            = agentRequest.BCity,
                Country         = agentRequest.BCountry,
                CreatedDateTime = DateTime.Now,
                DepositoryBank  = agentRequest.DepBank,
                LastUserUpdate  = agentRequest.User,
                PostalCode      = Convert.ToInt32(agentRequest.BPostalCode),
                RBOContactNo    = agentRequest.RBOContactNo,
                RBOEmailAdd     = agentRequest.RBOEmailAdd,
                RBOFName        = agentRequest.RBOFirstName,
                RBOLName        = agentRequest.RBOLastName,
                RBOMName        = agentRequest.RBOMiddleName,
                RBOType         = agentRequest.RBOType,
                RequestID       = generatedRequestID,
                StreetNo        = agentRequest.BStreetNo,
                Town            = agentRequest.BTown,
                UpdateDeteTime  = DateTime.Now,
                UserCreate      = agentRequest.User,
                IsDeleted       = false
            };

            Contact contact = new Contact
            {
                BillingContactNo  = agentRequest.CBillContactNo,
                BillingFirstName  = agentRequest.CBillFName,
                BillingLastName   = agentRequest.CBillLName,
                BillingMiddleName = agentRequest.CBillMName,
                ContactNo         = agentRequest.CContactno,
                CreatedDateTime   = DateTime.Now,
                Department        = agentRequest.CDepartment,
                Designation       = agentRequest.CDesignation,
                EmailAddress      = agentRequest.CEmailAdd,
                FaxNo             = agentRequest.CFaxno,
                FirstName         = agentRequest.CFirstName,
                LastName          = agentRequest.CLastName,
                LastUserUpdate    = agentRequest.User,
                MiddleName        = agentRequest.CMiddleName,
                RequestID         = generatedRequestID,
                UpdateDeteTime    = DateTime.Now,
                UserCreate        = agentRequest.User,
                IsDeleted         = false
            };

            for (int i = 0; i < agentRequest.AgentBranches?.Count(); i++)
            {
                AgentBranches agentBranches = new AgentBranches
                {
                    RequestID       = generatedRequestID,
                    AgentBranchName = agentRequest.AgentBranches[i].ABranchName,
                    StreetNo        = agentRequest.AgentBranches[i].AStreetNo,
                    Town            = agentRequest.AgentBranches[i].ATown,
                    City            = agentRequest.AgentBranches[i].ACity,
                    Country         = agentRequest.AgentBranches[i].Acountry,
                    PostalCode      = Convert.ToInt32(agentRequest.AgentBranches[i].APostalCode),
                    PhoneNo         = agentRequest.AgentBranches[i].APhoneNo,
                    UserCreate      = agentRequest.User,
                    CreatedDateTime = DateTime.Now,
                    LastUserUpdate  = agentRequest.User,
                    UpdateDeteTime  = DateTime.Now,
                    IsDeleted       = false
                };
                var agentBranchesResponse = await _agentRepository.CreateAgentBranches(agentBranches);
            }


            for (int i = 0; i < agentRequest.Terminal?.Count(); i++)
            {
                Terminal terminal = new Terminal
                {
                    RequestID         = generatedRequestID,
                    POSTerminalName   = agentRequest.Terminal[i].TerminalName,
                    TypeOfPOSTerminal = agentRequest.Terminal[i].TerminalType,
                    CreatedDateTime   = DateTime.Now,
                    UserCreate        = agentRequest.User,
                    LastUserUpdate    = agentRequest.User,
                    UpdateDeteTime    = DateTime.Now,
                    IsDeleted         = false,
                    TerminalID        = agentRequest.Terminal[i].TerminalID,
                    MerchantID        = agentRequest.Terminal[i].MerchantID,
                };
                var terminalResponse = await _agentRepository.CreateTerminal(terminal);
            }

            for (int i = 0; i < agentRequest.Auth?.Count(); i++)
            {
                Moa moa = new Moa
                {
                    AuthDesignation = agentRequest.Auth[i].AuthDesignation,
                    AuthFirstName   = agentRequest.Auth[i].AuthFirstName,
                    AuthID          = authID,
                    AuthLastName    = agentRequest.Auth[i].AuthLastName,
                    AuthMiddleName  = agentRequest.Auth[i].AuthMiddleName,
                    CreatedDateTime = DateTime.Now,
                    LastUserUpdate  = agentRequest.User,
                    RequestID       = generatedRequestID,
                    UpdateDeteTime  = DateTime.Now,
                    UserCreate      = agentRequest.User,
                    ValidIDExpdate  = agentRequest.Auth[i].ValidIDExpdate,
                    ValidIDNumber   = agentRequest.Auth[i].ValidIDNo,
                    ValidIDType     = agentRequest.Auth[i].ValidIDType
                };
                var moaResponse = await _agentRepository.CreateMoa(moa);
            }

            for (int i = 0; i < agentRequest.BankFeesList?.Count(); i++)
            {
                BankFees bankFees = new BankFees
                {
                    RequestID       = generatedRequestID,
                    AgentID         = agentID,
                    MerchantID      = agentID.ToString(),
                    TransactionType = agentRequest.BankFeesList[i].TransName,
                    ConvenienceFee  = agentRequest.BankFeesList[i].ConvFee,
                    Quota           = null,
                    CreatedDateTime = DateTime.Now,
                    UserCreate      = agentRequest.User,
                    LastUserUpdate  = agentRequest.User,
                    UpdateDeteTime  = DateTime.Now,
                    IsDeleted       = false
                };
                var bankResponse = await _agentRepository.CreateBankFees(bankFees);
            }

            var agentResponse = await _agentRepository.CreateAgent(agent, bank, contact);

            return(agentRequest);
        }