示例#1
0
        private void AutoRefreshThreadStart(C1Connection connection, bool ignoreTimeouts, bool stayAlwaysConnected)
        {
            bool stopOnServiceActivationError = true;

            while (true)             // Supposed to be stopped by ThreadAbortException
            {
                Thread.Sleep(600);

                LogEntry[] newEntries;

                try
                {
                    DateTime serverTime;

                    using (var client = connection.Connect())
                    {
                        serverTime = client.Channel.GetServerTime();
                        newEntries = client.Channel.GetLogEntries(_lastRefreshingDate.AddTicks(1), serverTime, true,
                                                                  MaximimLogLinesCount);
                    }

                    if (newEntries.Length > 0)
                    {
                        _lastRefreshingDate = serverTime;
                    }

                    stopOnServiceActivationError = false;
                }
                catch (Exception ex)
                {
                    // Ignoring singular occurances of ServiceActivationException as they may occur during AppDomain recycling
                    if ((ex is ServiceActivationException) && !stopOnServiceActivationError)
                    {
                        Thread.Sleep(3000);
                        stopOnServiceActivationError = true;
                        continue;
                    }

                    if (stayAlwaysConnected || (ignoreTimeouts && ex is TimeoutException))
                    {
                        Thread.Sleep(5000);
                        continue;
                    }

                    _autoRefreshingException = ex;
                    return;
                }

                lock (_syncRoot)
                {
                    if (_loadedEntries == null)
                    {
                        _loadedEntries = new List <LogEntry>();
                    }
                    _loadedEntries.AddRange(newEntries);
                }
            }
        }
示例#2
0
            public ConnectionWithContext(C1Connection connection)
            {
                _client = new LogServiceClient(connection.Binding, connection.EndpointAddress);
                _operationContextScope = new OperationContextScope(_client.InnerChannel);

                var           mhg       = new MessageHeader <string>(connection._authenticationInfo.AuthToken);
                MessageHeader authToken = mhg.GetUntypedHeader("AuthToken", "Composite.Logger");

                OperationContext.Current.OutgoingMessageHeaders.Add(authToken);
            }
示例#3
0
        private void ShowConnectionDialog()
        {
            var dialogResult = _connectionForm.ShowDialog();

            if (dialogResult != DialogResult.OK)
            {
                return;
            }

            _connection = ConnectionForm.CurrentConnection;

            string connectionTitle = _connection.Title;

            this.Text = (connectionTitle == string.Empty ? string.Empty : (connectionTitle + " - ")) + _title;

            _currentLogEntriesSet = new List <LogEntry>();
            RefreshGrid();

            btnStart.Enabled      = true;
            btnShowByDate.Enabled = true;

            lstDates.Enabled = true;
            DateTime[] logginDates;
            using (var client = _connection.Connect())
            {
                logginDates = client.Channel.GetLoggingDates();
            }

            lstDates.Items.Clear();

            lstDates.Items.Add("Today");
            foreach (DateTime date in logginDates)
            {
                lstDates.Items.Add(date.ToString(DateFormatString));
            }

            if (lstDates.Items.Count > 0)
            {
                lstDates.SelectedIndex = 0;
            }
        }
示例#4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            bool useAdminPassword = rbnAdminUser.Checked;

            AuthenticationInfo authenticationInfo;

            if (useAdminPassword)
            {
                string login = txtLogin.Text.Trim();
                if (string.IsNullOrEmpty(login))
                {
                    MessageBox.Show("Login cannot be empty");
                    return;
                }

                string password = txtPassword.Text;
                if (string.IsNullOrEmpty(password))
                {
                    MessageBox.Show("Password cannot be empty");
                    return;
                }

                authenticationInfo = new AuthenticationInfo(login, password);
            }
            else
            {
                Guid authToken;

                string loggerPassword = txtLoggerPassword.Text;

                if (string.IsNullOrEmpty(loggerPassword)
                    || !TryParseGuid(loggerPassword, out authToken))
                {
                    MessageBox.Show(string.IsNullOrEmpty(loggerPassword) ?
                        "Logger password cannot be empty"
                        : "Logger password should be a valid guid");
                    return;
                }

                authenticationInfo = AuthenticationInfo.FromLoggerPassword(loggerPassword);
            }

            //bool useHttp = rbnHttp.Checked;

            C1Connection connection;

            //if(useHttp)
            {
                string url = txtUrl.Text;

                if (string.IsNullOrEmpty(url))
                {
                    MessageBox.Show("URL is empty");
                    return;
                }

                connection = new C1Connection(url, authenticationInfo);
            }
            //else
            //{

            //    int portNumber;

            //    if(!int.TryParse(txtPort.Text, out portNumber))
            //    {
            //        MessageBox.Show("Port number is invalid.");
            //        return;
            //    }

            //    string host = txtHost.Text;

            //    if (string.IsNullOrEmpty(host))
            //    {
            //        MessageBox.Show("Host is empty");
            //        return;
            //    }

            //    connection = new C1Connection(host, portNumber, authenticationInfo);
            //}

            bool authenticated;
            try
            {
                authenticated = connection.Authenticate();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to establish connection. Exception message: " + ex.Message);
                return;
            }

            if (!authenticated)
            {
                MessageBox.Show("Login or password is not correct or the user does not have administrative rights.");
                return;
            }

            DialogResult = DialogResult.OK;
            CurrentConnection = connection;
            Close();

            UpdateRecentUrlList(txtUrl.Text, connection.AuthenticationInfo.AuthToken);
        }
示例#5
0
            public ConnectionWithContext(C1Connection connection)
            {
                _client = new LogServiceClient(connection.Binding, connection.EndpointAddress);
                _operationContextScope = new OperationContextScope(_client.InnerChannel);

                var mhg = new MessageHeader<string>(connection._authenticationInfo.AuthToken);
                MessageHeader authToken = mhg.GetUntypedHeader("AuthToken", "Composite.Logger");

                OperationContext.Current.OutgoingMessageHeaders.Add(authToken);
            }
示例#6
0
        private void ShowConnectionDialog()
        {
            var dialogResult = _connectionForm.ShowDialog();

            if (dialogResult != DialogResult.OK)
            {
                return;
            }

            _connection = ConnectionForm.CurrentConnection;

            string connectionTitle = _connection.Title;
            this.Text = (connectionTitle == string.Empty ? string.Empty : (connectionTitle + " - ")) + _title;

            _currentLogEntriesSet = new List<LogEntry>();
            RefreshGrid();

            btnStart.Enabled = true;
            btnShowByDate.Enabled = true;

            lstDates.Enabled = true;
            DateTime[] logginDates;
            using (var client = _connection.Connect())
            {
                logginDates = client.Channel.GetLoggingDates();
            }

            lstDates.Items.Clear();

            lstDates.Items.Add("Today");
            foreach (DateTime date in logginDates)
            {
                lstDates.Items.Add(date.ToString(DateFormatString));
            }

            if (lstDates.Items.Count > 0)
            {
                lstDates.SelectedIndex = 0;
            }
        }
示例#7
0
        private void AutoRefreshThreadStart(C1Connection connection, bool ignoreTimeouts, bool stayAlwaysConnected)
        {
            bool stopOnServiceActivationError = true;

            while (true) // Supposed to be stopped by ThreadAbortException
            {
                Thread.Sleep(600);

                LogEntry[] newEntries;

                try
                {
                    DateTime serverTime;

                    using (var client = connection.Connect())
                    {
                        serverTime = client.Channel.GetServerTime();
                        newEntries = client.Channel.GetLogEntries(_lastRefreshingDate.AddTicks(1), serverTime, true,
                                                                  MaximimLogLinesCount);
                    }

                    if (newEntries.Length > 0)
                    {
                        _lastRefreshingDate = serverTime;
                    }

                    stopOnServiceActivationError = false;
                }
                catch (Exception ex)
                {
                    // Ignoring singular occurances of ServiceActivationException as they may occur during AppDomain recycling
                    if ((ex is ServiceActivationException) && !stopOnServiceActivationError)
                    {
                        Thread.Sleep(3000);
                        stopOnServiceActivationError = true;
                        continue;
                    }

                    if (stayAlwaysConnected || (ignoreTimeouts && ex is TimeoutException))
                    {
                        Thread.Sleep(5000);
                        continue;
                    }

                    _autoRefreshingException = ex;
                    return;
                }

                lock (_syncRoot)
                {
                    if (_loadedEntries == null)
                    {
                        _loadedEntries = new List<LogEntry>();
                    }
                    _loadedEntries.AddRange(newEntries);
                }
            }
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            bool useAdminPassword = rbnAdminUser.Checked;

            AuthenticationInfo authenticationInfo;

            if (useAdminPassword)
            {
                string login = txtLogin.Text.Trim();
                if (string.IsNullOrEmpty(login))
                {
                    MessageBox.Show("Login cannot be empty");
                    return;
                }

                string password = txtPassword.Text;
                if (string.IsNullOrEmpty(password))
                {
                    MessageBox.Show("Password cannot be empty");
                    return;
                }

                authenticationInfo = new AuthenticationInfo(login, password);
            }
            else
            {
                Guid authToken;

                string loggerPassword = txtLoggerPassword.Text;

                if (string.IsNullOrEmpty(loggerPassword) ||
                    !TryParseGuid(loggerPassword, out authToken))
                {
                    MessageBox.Show(string.IsNullOrEmpty(loggerPassword) ?
                                    "Logger password cannot be empty"
                                                : "Logger password should be a valid guid");
                    return;
                }

                authenticationInfo = AuthenticationInfo.FromLoggerPassword(loggerPassword);
            }


            //bool useHttp = rbnHttp.Checked;

            C1Connection connection;

            //if(useHttp)
            {
                string url = txtUrl.Text;

                if (string.IsNullOrEmpty(url))
                {
                    MessageBox.Show("URL is empty");
                    return;
                }

                connection = new C1Connection(url, authenticationInfo);
            }
            //else
            //{

            //    int portNumber;

            //    if(!int.TryParse(txtPort.Text, out portNumber))
            //    {
            //        MessageBox.Show("Port number is invalid.");
            //        return;
            //    }

            //    string host = txtHost.Text;

            //    if (string.IsNullOrEmpty(host))
            //    {
            //        MessageBox.Show("Host is empty");
            //        return;
            //    }

            //    connection = new C1Connection(host, portNumber, authenticationInfo);
            //}

            bool authenticated;

            try
            {
                authenticated = connection.Authenticate();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to establish connection. Exception message: " + ex.Message);
                return;
            }

            if (!authenticated)
            {
                MessageBox.Show("Login or password is not correct or the user does not have administrative rights.");
                return;
            }

            DialogResult      = DialogResult.OK;
            CurrentConnection = connection;
            Close();

            UpdateRecentUrlList(txtUrl.Text, connection.AuthenticationInfo.AuthToken);
        }