private long sessionID; // ид. сессии взаимодействия с сервером /// <summary> /// Конструктор /// </summary> public FrmServerStatus() { InitializeComponent(); serversSettings = new ServersSettings(); client = null; sessionID = 0; }
private void btnCreateSession_Click(object sender, EventArgs e) { var client = new AgentSvcClient(); try { if (client.CreateSession(out sessionID)) { MessageBox.Show(@"Session created: " + sessionID); string encPwd = CryptoUtils.EncryptPassword("12345", sessionID, ScadaUtils.HexToBytes(SecretKey)); if (client.Login(sessionID, "admin", encPwd, "Default", out string errMsg)) { MessageBox.Show(@"Logged on."); } else { MessageBox.Show(errMsg); } } else { MessageBox.Show(@"Unable to create session."); } } finally { client.Close(); } }
private void btnDownload_Click(object sender, EventArgs e) { var client = new AgentSvcClient(); try { var stream = client.DownloadConfig(sessionID, new ConfigOptions()); if (stream == null) { MessageBox.Show(@"Download stream is null."); } else { var t0 = DateTime.UtcNow; var buf = new byte[1024]; using (var fileStream = File.Open(DefConfigArc, FileMode.Create, FileAccess.Write, FileShare.Read)) { stream.CopyTo(fileStream); } stream.Dispose(); MessageBox.Show(@"Done in " + (int)(DateTime.UtcNow - t0).TotalMilliseconds + @" ms"); } } finally { client.Close(); } }
/// <summary> /// Соединиться с Агентом /// </summary> private static void Connect(ServersSettings.ConnectionSettings connectionSettings, StreamWriter writer, out AgentSvcClient client, out long sessionID) { // настройка соединения client = new AgentSvcClient(); client.Endpoint.Address = GetEpAddress(connectionSettings.Host, connectionSettings.Port); // создание сессии if (client.CreateSession(out sessionID)) { writer?.WriteLine(AppPhrases.SessionCreated, sessionID); } else { throw new ScadaException(AppPhrases.UnableCreateSession); } // вход в систему string encryptedPassword = ScadaUtils.Encrypt(connectionSettings.Password, connectionSettings.SecretKey, CreateIV(sessionID)); if (client.Login(out string errMsg, sessionID, connectionSettings.Username, encryptedPassword, connectionSettings.ScadaInstance)) { writer?.WriteLine(AppPhrases.LoggedOn); }
/// <summary> /// Разъединиться с удалённым сервером /// </summary> private void Disconnect() { timer.Stop(); client = null; btnConnect.Enabled = true; btnDisconnect.Enabled = false; gbStatus.Enabled = false; txtServerStatus.Text = txtCommStatus.Text = txtUpdateTime.Text = ""; }
private void button1_Click(object sender, System.EventArgs e) { AgentSvcClient client = new AgentSvcClient(); double sum = client.Sum(2, 2); client.Close(); MessageBox.Show(sum.ToString()); }
private void btnUpload_Click(object sender, EventArgs e) { var client = new AgentSvcClient(); try { var t0 = DateTime.UtcNow; using (var fileStream = File.Open(DefConfigArc, FileMode.Open, FileAccess.Read, FileShare.Read)) { client.UploadConfig(new ConfigOptions(), sessionID, fileStream); } MessageBox.Show(@"Done in " + (int)(DateTime.UtcNow - t0).TotalMilliseconds + @" ms"); } finally { client.Close(); } }
/// <summary> /// Initializes the WCF service client. /// </summary> protected void InitSvcClient() { client = new AgentSvcClient(); client.Endpoint.Address = new EndpointAddress( $"http://{connSettings.Host}:{connSettings.Port}/ScadaAgent/ScadaAgentSvc/"); }
/// <summary> /// Initializes the WCF service client. /// </summary> protected void InitSvcClient() { client = new AgentSvcClient(); client.Endpoint.Address = new EndpointAddress(string.Format( "http://{0}:{1}/ScadaAgent/ScadaAgentSvc/", connSettings.Host, connSettings.Port)); }