Пример #1
0
 /// <summary>
 /// Runs the operation to process items produced by the <see cref="DoubleBufferedQueueProducer{T}"/>s.
 /// </summary>
 internal void SignalItemHandler()
 {
     if ((object)m_itemHandlingOperation != null)
     {
         m_itemHandlingOperation.RunOnceAsync();
     }
 }
Пример #2
0
        public ManualResetEventSlim Flush()
        {
            m_writeLogWaitHandle.Reset();
            m_writeLogOperation.RunOnceAsync();

            return(m_writeLogWaitHandle);
        }
Пример #3
0
        private void UpdateSelectAllStates()
        {
            try
            {
                // Prevent unwanted check change event on radio buttons - this code is just making UI match current selections, i.e., all or none states
                m_updatingSelectAllStates = true;

                if (FilterApplied)
                {
                    radioButtonSelectAll.Checked = m_filteredActionAdapters.All(adapter => adapter.Enabled);

                    if (!radioButtonSelectAll.Checked)
                    {
                        radioButtonUnselectAll.Checked = m_filteredActionAdapters.All(adapter => !adapter.Enabled);
                    }
                }
                else
                {
                    radioButtonSelectAll.Checked = m_actionAdapters.All(adapter => adapter.Enabled);

                    if (!radioButtonSelectAll.Checked)
                    {
                        radioButtonUnselectAll.Checked = m_actionAdapters.All(adapter => !adapter.Enabled);
                    }
                }
            }
            finally
            {
                m_updatingSelectAllStates = false;
            }

            m_updateTotals?.RunOnceAsync();
        }
Пример #4
0
        private static Dictionary <string, string[]> StartUserSynchronization()
        {
            Dictionary <string, string[]> userRoles = new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase);

            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
                using (UserRoleCache userRoleCache = UserRoleCache.GetCurrentCache())
                {
                    TableOperations <UserAccount> userAccountTable = new TableOperations <UserAccount>(connection);

                    foreach (UserAccount user in userAccountTable.QueryRecords())
                    {
                        string   userName = user.AccountName;
                        string[] roles;

                        if (userRoleCache.TryGetUserRole(userName, out roles))
                        {
                            userRoles[userName] = roles;
                        }
                    }

                    if (userRoles.Count > 0)
                    {
                        Interlocked.Exchange(ref s_latestSecurityContext, userRoles);
                        s_synchronizeUsers.RunOnceAsync();
                    }
                }

            return(userRoles);
        }
        private void ShowUpdateMessage(string message)
        {
            if (m_formClosing)
            {
                return;
            }

            lock (m_appendOutputMessages)
                m_messages.AppendLine(message);

            m_log.Publish(MessageLevel.Info, "StatusMessage", message);
            m_appendOutputMessages.RunOnceAsync();
        }
        private static Dictionary <string, string[]> StartUserSynchronization(string currentUserName)
        {
            Dictionary <string, string[]> userRoles = new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase);

            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
                using (UserRoleCache userRoleCache = UserRoleCache.GetCurrentCache())
                {
                    TableOperations <UserAccount> userAccountTable = new TableOperations <UserAccount>(connection);
                    string[] roles;

                    foreach (UserAccount user in userAccountTable.QueryRecords())
                    {
                        string userName = user.AccountName;

                        if (userRoleCache.TryGetUserRole(userName, out roles))
                        {
                            userRoles[userName] = roles;
                        }
                    }

                    // Also make sure current user is added since user may have implicit rights based on group
                    if (!string.IsNullOrEmpty(currentUserName))
                    {
                        if (!userRoles.ContainsKey(currentUserName) && userRoleCache.TryGetUserRole(currentUserName, out roles))
                        {
                            userRoles[currentUserName] = roles;
                        }
                    }

                    if (userRoles.Count > 0)
                    {
                        Interlocked.Exchange(ref s_latestSecurityContext, userRoles);
                        s_manualSynchronization = true;
                        s_synchronizeUsers.RunOnceAsync();
                    }
                }

            return(userRoles);
        }
Пример #7
0
 /// <summary>
 /// Inserts an element into the <see cref="OutageLog"/> at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which <paramref name="outage"/> should be inserted.</param>
 /// <param name="outage">The <see cref="Outage"/> to insert.</param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="index"/> is less than zero.-or-
 /// <paramref name="index"/> is greater than <see cref="Collection{T}.Count"/>.
 /// </exception>
 protected override void InsertItem(int index, Outage outage)
 {
     base.InsertItem(index, outage);
     m_condenseLogOperation.RunOnceAsync();
     QueueWriteLog();
 }
Пример #8
0
 /// <summary>
 /// Initiates a log read.
 /// </summary>
 protected void InitiateRead()
 {
     m_readLogOperation.RunOnceAsync();
 }
Пример #9
0
 private void m_connection_Disconnected(object sender, EventArgs e)
 {
     // Since we may get a plethora of these requests, we use a synchronized operation to restart once
     m_restartConnection.RunOnceAsync();
 }
Пример #10
0
        private void PostMeasurementsToArchive(IMeasurement[] measurements)
        {
            const string PostFormat = "{{\"name\":\"{0}\",\"columns\":[\"time\",\"value\",\"quality\"],\"points\":[[{1},{2},\"{3}\"]]}}";

            try
            {
                HttpWebRequest request = WebRequest.Create(m_requestUri) as HttpWebRequest;

                if ((object)request == null)
                {
                    throw new InvalidOperationException("Failed to create an HTTP request from " + m_requestUri);
                }

                request.Method      = "POST";
                request.KeepAlive   = true;
                request.SendChunked = true;
                request.AllowWriteStreamBuffering = true;
                request.ContentType = "application/json";

                // Build a JSON post expression with measurement values to use as post data
                StringBuilder jsonData = new StringBuilder();

                foreach (IMeasurement measurement in measurements)
                {
                    if (jsonData.Length > 0)
                    {
                        jsonData.Append(',');
                    }
                    else
                    {
                        jsonData.Append('[');
                    }

                    jsonData.AppendFormat(PostFormat, measurement.Key, GetEpochMilliseconds(measurement.Timestamp), measurement.AdjustedValue, measurement.StateFlags);
                }

                jsonData.Append(']');

                // Encode JSON data as UTF8
                byte[] postData = Encoding.UTF8.GetBytes(jsonData.ToString());

                // Write data to request stream
                request.ContentLength = postData.Length;

                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(postData, 0, postData.Length);
                }

                // Post data
                WebResponse response = request.GetResponse();
                response.Dispose();

                Interlocked.Add(ref m_totalValues, measurements.Length);
                Interlocked.Increment(ref m_totalPosts);
            }
            catch (Exception ex)
            {
                if (RequeueOnException)
                {
                    InternalProcessQueue.InsertRange(0, measurements);
                }

                bool ignoreError = false;

                // Under load, 400 and 500 status code errors seem to be occasionally reported - we ignore these
                WebException webex = ex as WebException;

                if ((object)webex != null)
                {
                    HttpWebResponse webResponse = webex.Response as HttpWebResponse;

                    if ((object)webResponse != null)
                    {
                        HttpStatusCode statusCode = webResponse.StatusCode;
                        ignoreError = (statusCode == HttpStatusCode.BadRequest || statusCode == HttpStatusCode.InternalServerError);
                    }
                }

                if (!ignoreError)
                {
                    OnProcessException(MessageLevel.Warning, ex);

                    // So long as user hasn't requested to stop, restart connection cycle when exceptions occur
                    m_requestRestart.RunOnceAsync();
                }
                else
                {
                    Interlocked.Increment(ref m_ignoredErrors);
                }
            }
        }
 private static void AdoSecurityProvider_SecurityContextRefreshed(object sender, EventArgs <Dictionary <string, string[]> > e)
 {
     Interlocked.Exchange(ref s_latestSecurityContext, e.Argument);
     s_synchronizeUsers?.RunOnceAsync();
 }
Пример #12
0
 public void QueueTasks()
 {
     m_pollingOperation?.RunOnceAsync();
 }
Пример #13
0
 /// <summary>
 /// Resets all sliding memory caches used by Grafana data sources.
 /// </summary>
 public static void ResetAll()
 {
     s_resetAllCaches.RunOnceAsync();
 }
Пример #14
0
 private void checkedListBoxDevices_ItemCheck(object sender, ItemCheckEventArgs e)
 {
     m_updateTotals?.RunOnceAsync();
 }
Пример #15
0
 private void QueueSubscriberOperation(Action operation)
 {
     m_subscriberOperationQueue.Enqueue(operation);
     m_subscriberOperations.RunOnceAsync();
 }