/// <summary> /// Initializes the log refresh process. /// </summary> private void InitRefresh() { IAgentClient agentClient = environment.AgentClient; stateBox.AgentClient = agentClient; logBox.AgentClient = agentClient; if (agentClient == null) { stateBox.SetFirstLine(CommShellPhrases.ConnectionUndefined); logBox.SetFirstLine(CommShellPhrases.ConnectionUndefined); tmrRefresh.Interval = ScadaUiUtils.LogRemoteRefreshInterval; } else { stateBox.SetFirstLine(CommShellPhrases.Loading); logBox.SetFirstLine(CommShellPhrases.Loading); if (agentClient.IsLocal) { tmrRefresh.Interval = ScadaUiUtils.LogLocalRefreshInterval; stateBox.LogFileName = Path.Combine(environment.AppDirs.LogDir, CommUtils.AppStateFileName); logBox.LogFileName = Path.Combine(environment.AppDirs.LogDir, CommUtils.AppLogFileName); } else { tmrRefresh.Interval = ScadaUiUtils.LogRemoteRefreshInterval; stateBox.LogPath = new RelPath(ConfigParts.Comm, AppFolder.Log, CommUtils.AppStateFileName); logBox.LogPath = new RelPath(ConfigParts.Comm, AppFolder.Log, CommUtils.AppLogFileName); } } }
/// <summary> /// Sends the command to the service. /// </summary> private static void ControlService(IAgentClient client, ServiceApp serviceApp, ServiceCommand command) { if (client == null) { return; } try { bool commandResult; lock (client) { commandResult = client.ControlService(serviceApp, command, 0); } if (commandResult) { ScadaUiUtils.ShowInfo(AppPhrases.ControlServiceSuccessful); } else { ScadaUiUtils.ShowError(AppPhrases.UnableControlService); } } catch (Exception ex) { ScadaUiUtils.ShowError(ex.BuildErrorMessage(AppPhrases.ControlServiceError)); } }
/// <summary> /// Gets the current status of the specified service asynchronously. /// </summary> private async Task GetServiceStatusAsync(IAgentClient client, ServiceApp serviceApp, TextBox statusTextBox) { await Task.Run(() => { if (client == null) { return; } try { lock (client) { bool statusOK = client.GetServiceStatus(serviceApp, out ServiceStatus status); if (connected) { statusTextBox.Text = statusOK ? status.ToString(Locale.IsRussian) : CommonPhrases.UndefinedSign; txtUpdateTime.Text = DateTime.Now.ToLocalizedString(); } } } catch (Exception ex) { if (connected) { statusTextBox.Text = ex.Message; txtUpdateTime.Text = DateTime.Now.ToLocalizedString(); } } }); }
public override void OneTimeSetup() { base.OneTimeSetup(); IAgentClient client = ClientFactory.CreateTcpAgentClient(settings); clients.Add(client); }
private async void timer_Tick(object sender, EventArgs e) { timer.Stop(); // initialize a client if (agentClient == null) { DeploymentProfile profile = ctrlProfileSelector.SelectedProfile; if (profile != null) { ConnectionSettings connSettings = profile.ConnectionSettings.Clone(); connSettings.ScadaInstance = instance.Name; agentClient = new AgentWcfClient(connSettings); } } // request status if (agentClient != null) { await GetServerStatusAsync(); await GetCommStatusAsync(); if (agentClient != null) { timer.Start(); } } }
/// <summary> /// Initializes the log refresh process. /// </summary> private void InitRefresh() { IAgentClient agentClient = environment.AgentClient; stateBox.AgentClient = agentClient; logBox.AgentClient = agentClient; if (agentClient == null) { stateBox.SetFirstLine(CommShellPhrases.SetProfile); logBox.SetFirstLine(CommShellPhrases.SetProfile); tmrRefresh.Interval = ScadaUiUtils.LogRemoteRefreshInterval; } else { stateBox.SetFirstLine(CommShellPhrases.Loading); logBox.SetFirstLine(CommShellPhrases.Loading); string stateFileName = CommUtils.GetLineStateFileName(commLine.Number); string logFileName = CommUtils.GetLineLogFileName(commLine.Number); if (agentClient.IsLocal) { tmrRefresh.Interval = ScadaUiUtils.LogLocalRefreshInterval; stateBox.LogFileName = Path.Combine(environment.AppDirs.LogDir, stateFileName); logBox.LogFileName = Path.Combine(environment.AppDirs.LogDir, logFileName); } else { tmrRefresh.Interval = ScadaUiUtils.LogRemoteRefreshInterval; stateBox.LogPath = new RelPath(ConfigParts.Comm, AppFolder.Log, stateFileName); logBox.LogPath = new RelPath(ConfigParts.Comm, AppFolder.Log, logFileName); } } }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmInstanceStatus(AppData appData, DeploymentSettings deploymentSettings, Instance instance) : this() { this.appData = appData ?? throw new ArgumentNullException("appData"); this.deploymentSettings = deploymentSettings ?? throw new ArgumentNullException("deploymentSettings"); this.instance = instance ?? throw new ArgumentNullException("instance"); agentClient = null; }
/// <summary> /// Tests the connection with the Agent service. /// </summary> private void TestAgentConnection(IAgentClient agentClient) { transferControl.WriteMessage(ExtensionPhrases.TestAgentConn); if (!agentClient.TestConnection(out string errMsg)) { throw new ScadaException(errMsg); } progressTracker.TaskIndex++; }
/// <summary> /// Initializes a new instance of the class. /// </summary> public ServiceStarter(IAgentClient agentClient, ProjectInstance instance, UploadOptions uploadOptions, ITransferControl transferControl, ProgressTracker progressTracker) { this.agentClient = agentClient ?? throw new ArgumentNullException(nameof(agentClient)); this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); this.uploadOptions = uploadOptions ?? throw new ArgumentNullException(nameof(uploadOptions)); this.transferControl = transferControl ?? throw new ArgumentNullException(nameof(transferControl)); this.progressTracker = progressTracker ?? throw new ArgumentNullException(nameof(progressTracker)); ProcessTimeout = 0; }
/// <summary> /// Transfers the configuration file to the Agent appliction. /// </summary> private void TransferConfig(string srcFileName, IAgentClient agentClient) { transferControl.ThrowIfCancellationRequested(); transferControl.WriteLine(); transferControl.WriteMessage(ExtensionPhrases.TransferConfig); transferControl.WriteMessage(string.Format(ExtensionPhrases.ArchiveSize, new FileInfo(srcFileName).Length.ToString("N0", Locale.Culture))); agentClient.UploadConfig(srcFileName, transferControl.CancellationToken); progressTracker.TaskIndex++; }
/// <summary> /// Disconnects from the remote server. /// </summary> private void Disconnect() { timer.Stop(); agentClient = null; btnConnect.Enabled = true; btnDisconnect.Enabled = false; gbStatus.Enabled = false; txtServerStatus.Text = ""; txtCommStatus.Text = ""; txtUpdateTime.Text = ""; }
public WebAssemblyAgentTicket( IAgentProcessManager processManager, IMessageService messageService, Action disconnectedHandler) { // WASM doesn't currently use these, but we may someday. this.processManager = processManager; this.disconnectedHandler = disconnectedHandler; this.messageService = messageService; client = new WebAssemblyAgentClient(); }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmInstanceStatus(AppData appData, ScadaProject project, ProjectInstance instance) : this() { this.appData = appData ?? throw new ArgumentNullException(nameof(appData)); this.project = project ?? throw new ArgumentNullException(nameof(project)); this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); initialProfile = null; agentClient = null; connected = false; ProfileChanged = false; ConnectionModified = false; }
/// <summary> /// Constructs a static agent with the given area. /// </summary> /// <param name="area">The area of this agent.</param> /// <param name="gridLayer">Reference to the grid layer that this agent is placed.</param> /// <param name="client">Reference to the client of this agent.</param> public Agent(RCIntRectangle area, Grid gridLayer, IAgentClient client) { this.agentArea = area; this.grid = gridLayer; this.movingSize = area.Width == area.Height && area.Width <= this.grid.MaxMovingSize ? area.Width : -1; this.client = client; this.currentPath = null; this.currentStepIndex = -1; this.movingStatus = this.movingSize != -1 ? AgentMovingStatusEnum.Stopped : AgentMovingStatusEnum.Static; this.stoppedStateTimer = this.movingStatus == AgentMovingStatusEnum.Stopped ? STOPPED_STATE_WAITING_TIME : -1; this.deadlockTimer = -1; this.agentsWaitingFor = new RCSet <Agent>(); }
AgentConnection( IAgentTicket ticket, AgentType type, AgentIdentity identity, IAgentClient apiClient, AgentFeatures features) { this.ticket = ticket; Type = type; Identity = identity; Api = apiClient; Features = features; }
/// <summary> /// Creates and places an agent with the given area to this grid. /// </summary> /// <param name="area">The rectangular area of the agent.</param> /// <param name="client">The client of the placed agent that will provide additional informations for the pathfinder component.</param> /// <returns>A reference to the agent or null if the placement failed.</returns> public Agent CreateAgent(RCIntRectangle area, IAgentClient client) { Agent newAgent = new Agent(area, this, client); RCSet <Agent> collidingAgents = null; if (this.ValidatePositionForAgent(newAgent, this[newAgent.Area.X, newAgent.Area.Y], out collidingAgents)) { this.PlaceAgentOnGrid(newAgent); this.agents.Add(newAgent); newAgent.MovingStatusChanged += this.OnAgentMovingStatusChanged; return(newAgent); } else { return(null); } }
/// <summary> /// Updates the Agent client of the log box. /// </summary> private void UpdateAgentClient() { IAgentClient agentClient = adminContext.MainForm.GetAgentClient(ChildFormTag?.TreeNode, false); dataBox.AgentClient = agentClient; if (agentClient == null) { dataBox.SetFirstLine(AdminPhrases.AgentNotEnabled); btnSendCommand.Enabled = false; } else { dataBox.SetFirstLine(AdminPhrases.FileLoading); btnSendCommand.Enabled = true; } }
/// <see cref="IPathfinder.PlaceAgent"/> public IAgent PlaceAgent(RCIntRectangle area, IAgentClient client) { if (this.grid == null) { throw new InvalidOperationException("The pathfinder component is not initialized!"); } if (area == RCIntRectangle.Undefined) { throw new ArgumentNullException("area"); } if (client == null) { throw new ArgumentNullException("client"); } return(this.grid.CreateAgent(area, client)); }
/// <summary> /// Updates the Agent clients of the log boxes. /// </summary> private void UpdateAgentClients() { IAgentClient agentClient = adminContext.MainForm.GetAgentClient(ChildFormTag?.TreeNode, false); stateBox.AgentClient = agentClient; logBox.AgentClient = agentClient; if (agentClient == null) { stateBox.SetFirstLine(AdminPhrases.AgentNotEnabled); logBox.SetFirstLine(AdminPhrases.AgentNotEnabled); } else { stateBox.SetFirstLine(AdminPhrases.FileLoading); logBox.SetFirstLine(AdminPhrases.FileLoading); } }
private void FrmInstanceStatus_Load(object sender, EventArgs e) { Translator.TranslateForm(this, ctrlProfileSelector.GetType().FullName); Translator.TranslateForm(this, GetType().FullName); if (ScadaUtils.IsRunningOnMono) { ctrlProfileSelector.Width = gbStatus.Width; } ProfileChanged = false; ConnSettingsModified = false; ctrlProfileSelector.Init(appData, deploymentSettings, instance); initialProfile = ctrlProfileSelector.SelectedProfile; initialConnSettings = initialProfile?.ConnectionSettings.Clone(); agentClient = null; if (ctrlProfileSelector.SelectedProfile != null) { Connect(); } }
static void Main(string[] args) { Console.Title = @"Scheduling Clients Console"; EndpointSettings endpointSettings = null; Parser.Default.ParseArguments <ConfigureEndpointSettingsOptions>(args) .WithParsed <ConfigureEndpointSettingsOptions>(o => { endpointSettings = o.CreateTcpEndpointSettings(); } ) .WithNotParsed <ConfigureEndpointSettingsOptions>(o => { Environment.Exit(-1); }); IAgentClient agentClient = ClientFactory.CreateTcpAgentClient(endpointSettings); IJobStateClient jobStateClient = ClientFactory.CreateTcpJobStateClient(endpointSettings); while (true) { Console.Write("sc>"); args = Console.ReadLine().Split(); Parser.Default.ParseArguments <Agent_GetAllAgentsInService, JobState_GetCurrentJobSummaryForAgentId> (args) .MapResult( (Agent_GetAllAgentsInService opts) => opts.ExecuteOption(agentClient), (JobState_GetCurrentJobSummaryForAgentId opts) => opts.ExecuteOption(jobStateClient), errs => ServiceCallResultFactory.FromClientException(new Exception("Operation failed")) ); } }
private async void timer_Tick(object sender, EventArgs e) { timer.Stop(); // initialize client if (agentClient == null && ctrlProfileSelector.SelectedProfile != null && ctrlProfileSelector.SelectedProfile.AgentEnabled) { agentClient = new AgentClient(ctrlProfileSelector.SelectedProfile.AgentConnectionOptions); } // request status if (agentClient != null) { await GetServiceStatusAsync(agentClient, ServiceApp.Server, txtServerStatus); await GetServiceStatusAsync(agentClient, ServiceApp.Comm, txtCommStatus); if (connected) { timer.Start(); } } }
/// <see cref="IAgentClient.IsOverlapEnabled"/> public bool IsOverlapEnabled(IAgentClient otherClient) { GroundPathTracker otherPathTracker = (GroundPathTracker)otherClient; return(this.ControlledEntity.IsOverlapEnabled(otherPathTracker.ControlledEntity)); }
/// <summary> /// Initializes a new instance of the class. /// </summary> public RemoteLogBox(ListBox listBox, bool colorize = false) : base(listBox, colorize) { agentClient = null; logPath = new RelativePath(); }
/// <see cref="IAgentClient.IsOverlapEnabled"/> public bool IsOverlapEnabled(IAgentClient otherClient) { return(false); }