private void RemoveMediaCore(IEnumerable <IMedia> media, EventMessages messages)
        {
            if (UmbracoSearchFactory.HasActiveIndex)
            {
                foreach (var item in media)
                {
                    try
                    {
                        var indexService = UmbracoSearchFactory.GetMediaIndexService(item);
                        var indexName    = UmbracoSearchFactory.ActiveIndexName;
                        if (indexService != null && indexService.ShouldIndex(item))
                        {
                            RemoveMedia(indexService, item, indexName);
                            if (item.IndexError())
                            {
                                throw new InvalidOperationException(item.GetIndexingStatus().Message);
                            }

                            messages?.Add(new EventMessage("Search", "Removed media from search index", EventMessageType.Success));
                            LogHelper.Debug(GetType(), () => $"Media ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}' has been removed from search index");
                        }
                    }
                    catch (Exception ex)
                    {
                        messages?.Add(new EventMessage("Search", $"Unable to index media : '{item.Name}' => {ex.Message}", EventMessageType.Error));
                        LogHelper.WarnWithException(GetType(), $"Unable to index media ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}'", ex);
                    }
                }
            }
            else
            {
                messages?.Add(new EventMessage("Search", "No active index available for indexing", EventMessageType.Error));
                LogHelper.Warn(GetType(), "No active index available for indexing");
            }
        }
        private void IndexContentCore(IEnumerable <IContent> entities, EventMessages messages, [CallerMemberName] string eventCaller = null)
        {
            if (UmbracoSearchFactory.HasActiveIndex)
            {
                LogHelper.Debug(GetType(), () => $"Content indexing triggered ({eventCaller})");
                foreach (var item in entities)
                {
                    item.SetIndexingStatus(IndexingStatusOption.InProgress, "Content indexing triggered");
                    var indexService = UmbracoSearchFactory.GetContentIndexService(item);
                    var indexName    = UmbracoSearchFactory.ActiveIndexName;
                    if (indexService != null)
                    {
                        try
                        {
                            if (indexService.IsExcludedFromIndex(item))
                            {
                                RemoveContent(indexService, item, indexName);
                                if (item.IndexError())
                                {
                                    throw new InvalidOperationException(item.GetIndexingStatus().Message);
                                }

                                messages?.Add(new EventMessage("Search", "Content removed from search index", EventMessageType.Success));
                                LogHelper.Debug(GetType(), () => $"Content ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}' has been removed from search index");
                            }
                            else
                            {
                                IndexContent(indexService, item, indexName);
                                if (item.IndexError())
                                {
                                    throw new InvalidOperationException(item.GetIndexingStatus().Message);
                                }

                                messages?.Add(new EventMessage("Search", "Content added to search index", EventMessageType.Success));
                                LogHelper.Debug(GetType(), () => $"Content ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}' has been indexed");
                            }
                        }
                        catch (Exception ex)
                        {
                            messages?.Add(new EventMessage("Search", $"Unable to index content : '{item.Name}' => {ex.Message}", EventMessageType.Error));
                            LogHelper.WarnWithException(GetType(), $"Unable to index content ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}'", ex);
                        }
                    }
                }
            }
            else
            {
                messages?.Add(new EventMessage("Search", "No active index available for indexing", EventMessageType.Error));
                LogHelper.Warn(GetType(), "No active index available for indexing");
            }
        }
예제 #3
0
        public void CombineWith(EventMessagesCollection nextEventMessagesCollection)
        {
            Guid = nextEventMessagesCollection.Guid;
            NextCollectionGuid = nextEventMessagesCollection.NextCollectionGuid;

            EventMessages.Add(nextEventMessagesCollection.EventMessages);
        }
예제 #4
0
 /// <summary>
 ///     Creates a failed operation attempt indicating that an exception was thrown during the operation.
 /// </summary>
 /// <param name="eventMessages">The event messages produced by the operation.</param>
 /// <param name="exception">The exception that caused the operation to fail.</param>
 /// <returns>A new attempt instance.</returns>
 public static Attempt <OperationResult?> Fail(EventMessages eventMessages, Exception exception)
 {
     eventMessages.Add(new EventMessage(string.Empty, exception.Message, EventMessageType.Error));
     return(Core.Attempt.Fail(
                new OperationResult(OperationResultType.FailedExceptionThrown, eventMessages),
                exception));
 }
예제 #5
0
        private void CopyToLog(string handlerName, bool selectedOnly)
        {
            Debug.Assert(ActiveMdiChild is LogForm, "ActiveMdiChild is LogForm");

            // Create the message handler and set its initialisation string, prompting the user if necessary.

            IMessageHandler handler = _modules.CreateMessageHandler(handlerName);

            /*
             *          IMessageComponentInitialise initialise = handler as IMessageComponentInitialise;
             *          if ( initialise != null )
             *          {
             *                  IConfigurationHandler configurationHandler = _modules.CreateMessageHandlerConfiguration(handlerName);
             *                  if ( !initialise.Prompt(this, configurationHandler) )
             *                          return;
             *          }
             */

            // Copy the selected messages.

            using (new LongRunningMonitor(this))
            {
                var childForm             = (LogForm)ActiveMdiChild;
                IList <EventMessage> list = (selectedOnly ? childForm.GetSelectedEventMessages() : childForm.GetAllEventMessages());

                var messages = new EventMessages();
                foreach (EventMessage message in list)
                {
                    messages.Add(message);
                }

                handler.HandleEventMessages(messages);
            }
        }
예제 #6
0
        private void PurgeCache(EventMessages messages, IEnumerable <int> contentIds)
        {
            using (var context = _umbracoContextFactory.EnsureUmbracoContext())
            {
                var content = contentIds.Select(context.UmbracoContext.Content.GetById);

                try
                {
                    var result = Task.Run(() => _contentCdnService.PurgeAsync(content)).GetAwaiter().GetResult();

                    if (result.Result == Models.PurgeResult.Success)
                    {
                        messages.Add(new EventMessage("CloudPurge",
                                                      "Cleared CDN cache", EventMessageType.Success));
                    }
                    else if (result.Result == Models.PurgeResult.Fail)
                    {
                        _logger.Error <CloudPurgeComposer>("Failed to purge cache for {FailedUrlCount} urls ((failedUrls}). With messages {failMessages}",
                                                           result.FailedUrls.Count(),
                                                           result.FailedUrls,
                                                           result.FailMessages);

                        messages.Add(new EventMessage("CloudPurge",
                                                      "Something went wrong clearing CDN cache", EventMessageType.Warning));

                        foreach (var failMessage in result.FailMessages.Take(5))
                        {
                            messages.Add(new EventMessage("CloudPurge", failMessage, EventMessageType.Error));
                        }
                    }
                }
                catch (TimeoutException)
                {
                    messages.Add(new EventMessage("CloudPurge",
                                                  "Looks like it's taking a little while to clear the CDN cache...", EventMessageType.Warning));
                }
                catch (Exception ex)
                {
                    _logger.Error <CloudPurgeComposer>("Failed to purge cache", ex);

                    messages.Add(new EventMessage("CloudPurge",
                                                  "Something went wrong clearing CDN cache", EventMessageType.Error));
                }
            }
        }
예제 #7
0
        private bool ReadMessageBatch(SqlConnection connection)
        {
            if (SupportsNotify)
            {
                return(ReadNotifyMessages(connection));
            }

            var messages = new EventMessages();

            using (var command = new SqlCommand(Sql.GetMessageRange, connection))
            {
                command.CommandType = CommandType.StoredProcedure;

                // The stored procedure takes a time (in ticks) as parameter instead of message ID, because
                // messages in the database are not necessarily ordered by ID.

                command.Parameters.Add("@fromTime", SqlDbType.BigInt).Value   = _lastReadMessageTime;
                command.Parameters.Add("@afterSequence", SqlDbType.Int).Value = _lastReadMessageSequence;

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        _lastReadMessageTime     = reader.GetInt64(1);
                        _lastReadMessageSequence = reader.GetInt32(2);

                        var    time         = new System.DateTime(_lastReadMessageTime);
                        string exceptionXml = (reader.IsDBNull(8) ? null : reader.GetString(8));

                        var message = new SqlEventMessage(this, reader.GetInt32(0),
                                                          reader.GetString(4), reader.GetString(3), reader.GetString(5), reader.GetString(6),
                                                          reader.GetString(7), time, exceptionXml);
                        message.Intern(_interner);
                        SetMessageSequence(message, _lastReadMessageSequence);

                        messages.Add(message);
                    }
                }
            }

            // Note that the messages don't have parameters or details at this stage - those will be read as needed.

            if (messages.Count > 0)
            {
                _raiseExistingRead = true;                 // We have more messages.
                HandleEventMessages(messages);
                return(true);
            }

            if (_raiseExistingRead)
            {
                _raiseExistingRead = false;         // Don't raise again until we've read some messages.
                OnExistingMessagesRead(System.EventArgs.Empty);
            }

            return(false);
        }
예제 #8
0
 /// <summary>
 /// Refreshes the config and rules
 /// </summary>
 /// <param name="e">The event message collection</param>
 private void Reload(EventMessages e)
 {
     if (!RefreshConfig(e))
     {
         return;
     }
     RefreshRules();
     if (VisualiseRules)
     {
         e.Add(new EventMessage("KeepOut Security", "KeepOut Security updated. Refresh the node tree to show changes", EventMessageType.Info));
     }
 }
예제 #9
0
        private EventMessages Matches(IEnumerable <EventMessage> messages)
        {
            var filteredMessages = new EventMessages();

            foreach (var message in messages)
            {
                if (Match(message))
                {
                    filteredMessages.Add(message);
                }
            }

            return(filteredMessages);
        }
예제 #10
0
        private static int GetEventMessages(EventMessages eventMessages, System.Messaging.Message message)
        {
            Debug.Assert(message != null, "message != null");

            var reader = new BinaryReader(message.BodyStream);

            switch (message.Label)
            {
            case Constants.MessageComponents.Msmq.MessageLabel:

                // A single message.

                var newEventMessage = new EventMessage();
                newEventMessage.Read(reader);
                eventMessages.Add(newEventMessage);
                return(1);

            case Constants.MessageComponents.Msmq.MessagesLabel:

                // Multiple messages.

                var newEventMessages = new EventMessages();
                newEventMessages.Read(reader);
                foreach (EventMessage eventMessage in newEventMessages)
                {
                    eventMessages.Add(eventMessage);
                }
                return(newEventMessages.Count);

            default:

                Debug.WriteLine("Unexpected MSMQ message label '" + message.Label
                                + "' - not recognised as a LinkMe Instrumentation message.");
                return(0);
            }
        }
예제 #11
0
        protected override void ReadAll()
        {
            var messages = new EventMessages();

            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                using (var command = new SqlCommand(Sql.GetAllMessages, connection))
                {
                    command.CommandType = CommandType.StoredProcedure;

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var    time         = new System.DateTime(reader.GetInt64(1));
                            string exceptionXml = (reader.IsDBNull(8) ? null : reader.GetString(8));

                            var message = new SqlEventMessage(null, reader.GetInt32(0),
                                                              reader.GetString(4), reader.GetString(3), reader.GetString(5), reader.GetString(6),
                                                              reader.GetString(7), time, exceptionXml);
                            message.Intern(_interner);
                            SetMessageSequence(message, reader.GetInt32(2));

                            messages.Add(message);
                        }
                    }
                }

                // Read the parameters immediately.

                foreach (SqlEventMessage message in messages)
                {
                    message.SetParameters(ReadParameters(connection, message.Id));
                }
            }

            if (messages.Count > 0)
            {
                HandleEventMessages(messages);
            }
        }
예제 #12
0
        private void GetMessages(EventMessages messages, SqlEventMessageIdentifier sqlStartIdentifier, SqlEventMessageIdentifier sqlEndIdentifier)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                using (var command = new SqlCommand(Sql.GetMessageTimeRange, connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@fromTime", SqlDbType.BigInt).Value = sqlStartIdentifier.Time;
                    command.Parameters.Add("@toTime", SqlDbType.BigInt).Value   = sqlEndIdentifier.Time;

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            messages.Add(ReadMessage(reader));
                        }
                    }
                }
            }
        }
예제 #13
0
        protected override void Read()
        {
            using (var reader = new StreamReader(_fileName))
            {
                // Similar to EventMessages.ReadOuterXml(), but send the messages to the handler as we
                // read them.

                var adaptor = new XmlReadAdaptor(new XmlTextReader(reader), Xml.Namespace);

                if (adaptor.IsReadingElement(Xml.EventMessagesElement))
                {
                    var messages = new EventMessages();

                    while (adaptor.ReadElement(Xml.EventMessageElement))
                    {
                        // Check the reader wait handles - should we stop or pause?

                        if (StopEvent.WaitOne(0, false))
                        {
                            return;
                        }

                        if (PauseEvent.WaitOne(0, false))
                        {
                            // Paused - wait for stop or continue.

                            var pauseHandles = new[] { StopEvent, ContinueEvent };
                            switch (WaitHandle.WaitAny(pauseHandles))
                            {
                            case 0:
                                return;                                         // Stop.

                            case 1:
                                break;                                         // Continue.
                            }
                        }

                        var message = new EventMessage();
                        message.ReadXml(adaptor.XmlReader);
                        adaptor.ReadEndElement();

                        // Send to the message handler, if we have enough.

                        messages.Add(message);

                        if (messages.Count == Constants.MessageComponents.EventFile.MessageReaderBatchSize)
                        {
                            HandleEventMessages(messages);
                            messages = new EventMessages();
                        }
                    }

                    // Send any remaining messages to the message handler.

                    if (messages.Count > 0)
                    {
                        HandleEventMessages(messages);
                    }
                }
            }

            OnExistingMessagesRead(System.EventArgs.Empty);
        }