예제 #1
0
        private void GenerateWhereClause(bool use_event_type_clause, EventLogData el_data)
        {
            string cutoff = el_data.MaxDate.HasValue ? ManagementDateTimeConverter.ToDmtfDateTime(el_data.MaxDate.Value) : string.Empty;

            if (string.IsNullOrEmpty(cutoff))
            {
                // When we first start COMMON, it will collect errors from ages ago. To keep that from happening, collect
                // errors from at most 45 days ago.
                DateTime cutoff_dt = DateTime.Now - TimeSpan.FromDays(45);
                cutoff = ManagementDateTimeConverter.ToDmtfDateTime(cutoff_dt);
            }

            Context.Where = $"TimeGenerated >= '{cutoff}' AND LogFile = '{Log.ToString()}'";

            // EventType of 1 is errors
            // https://msdn.microsoft.com/en-us/library/aa394226.aspx
            if (use_event_type_clause)
            {
                Context.Where += " AND EventType = 1";

                if (el_data.MaxRecordNumber.HasValue)
                {
                    Context.Where += $" AND RecordNumber >= {el_data.MaxRecordNumber.Value}";
                }
            }

            Trace.WriteLine($"Where: {Context.Where}");
        }
예제 #2
0
    /// <summary>
    /// Button destroy history click.
    /// </summary>
    protected void btnDestroy_Click(object sender, EventArgs e)
    {
        var obj = Object;

        if (obj != null)
        {
            // Check permissions
            if (CheckPermissions && !AllowDestroy)
            {
                ShowError(GetString("History.ErrorNotAllowedToDestroy"));
                return;
            }

            var ti = obj.TypeInfo;

            ObjectVersionManager.DestroyObjectHistory(ti.ObjectType, obj.Generalized.ObjectID);

            string objType     = GetString("Objecttype." + ti.ObjectType.Replace(".", "_"));
            string description = String.Format(GetString("objectversioning.historydestroyed"), SqlHelper.GetSafeQueryString(obj.Generalized.ObjectDisplayName, false));

            var logData = new EventLogData(EventTypeEnum.Information, objType, "DESTROYHISTORY")
            {
                EventDescription = description,
                EventUrl         = RequestContext.RawURL
            };

            Service.Resolve <IEventLogService>().LogEvent(logData);

            ReloadData();
        }
        else
        {
            UIContext.EditedObject = null;
        }
    }
예제 #3
0
    /// <summary>
    /// Writes event to the event log.
    /// </summary>
    /// <param name="eventType">Type of the event. I = information, E = error, W = warning</param>
    /// <param name="source">Source of the event (Content, Administration, etc.)</param>
    /// <param name="eventCode">Event code (Security, Update, Delete, etc.)</param>
    /// <param name="nodeId">ID value of the document</param>
    /// <param name="nodeNamePath">NamePath value of the document</param>
    /// <param name="eventDescription">Detailed description of the event</param>
    public static void LogEvent(string eventType, string source, string eventCode, int nodeId, string nodeNamePath, string eventDescription)
    {
        int siteId = 0;

        if (SiteContext.CurrentSite != null)
        {
            siteId = SiteContext.CurrentSite.SiteID;
        }

        var eventTypeEnum = EventType.ToEventTypeEnum(eventType);

        var logData = new EventLogData(eventTypeEnum, source, eventCode)
        {
            EventDescription = eventDescription,
            EventUrl         = RequestContext.RawURL,
            UserID           = MembershipContext.AuthenticatedUser.UserID,
            UserName         = RequestContext.UserName,
            NodeID           = nodeId,
            DocumentName     = nodeNamePath,
            IPAddress        = RequestContext.UserHostAddress,
            SiteID           = siteId
        };

        Service.Resolve <IEventLogService>().LogEvent(logData);
    }
예제 #4
0
        public void ProperlyHandleMaxRecordNumber()
        {
            EventLogData eld = new EventLogData()
            {
                MaxRecordNumber = 123456789
            };

            Assert.True(eld.ContainsRecordNumber(123456789));
            Assert.False(eld.ContainsRecordNumber(2222222222));
        }
    /// <summary>
    /// Removes selected operator from the ACL.
    /// </summary>
    protected void btnRemoveOperator_Click(Object sender, EventArgs e)
    {
        // Check permission
        CheckPermissions(true);

        if (lstOperators.SelectedItem == null)
        {
            return;
        }

        string operatorName = lstOperators.SelectedItem.Text;
        string message;
        string operatorID = lstOperators.SelectedValue;

        if (operatorID.StartsWith("U", StringComparison.InvariantCulture))
        {
            int      userId = int.Parse(operatorID.Substring(1));
            UserInfo ui     = UserInfo.Provider.Get(userId);
            AclItemInfoProvider.RemoveUser(Node.NodeID, ui);
            message = "security.documentuserpermissionremoved";
        }
        else
        {
            RoleInfo ri = RoleInfo.Provider.Get(int.Parse(operatorID.Substring(1)));
            AclItemInfoProvider.RemoveRole(Node.NodeID, ri);
            message = "security.documentrolepermissionremoved";
        }

        // Log synchronization task and flush cache
        DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, Node.TreeProvider);
        Node.ClearCache();

        // Insert information about this event to eventlog.
        if (Tree.LogEvents)
        {
            var logData = new EventLogData(EventTypeEnum.Information, "Content", "DOCPERMISSIONSMODIFIED")
            {
                EventDescription = String.Format(ResHelper.GetAPIString(message, "Operator '{0}' has been removed from the page permissions."), operatorName),
                EventUrl         = eventUrl,
                UserID           = Tree.UserInfo.UserID,
                UserName         = Tree.UserInfo.UserName,
                NodeID           = Node.NodeID,
                DocumentName     = Node.GetDocumentName(),
                IPAddress        = ipAddress,
                SiteID           = Node.NodeSiteID
            };

            Service.Resolve <IEventLogService>().LogEvent(logData);
        }

        dsAclItems = null;
        LoadOperators(true);

        CheckButtonsActiveState();
    }
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }

            // Sadly, we can't pass around the original format of "state" into the processor.
            // There wouldn't be any point in making the whole processor class generic.\
            // We need to format the state here.
            var message = formatter(state, exception);

            if (!string.IsNullOrEmpty(message) || exception != null)
            {
                var          eventType = MapLogLevel(logLevel);
                var          siteId    = Service.ResolveOptional <ISiteService>().CurrentSite?.SiteID ?? default;
                EventLogData eventData;

                if (!string.IsNullOrEmpty(eventId.Name))
                {
                    eventData = new EventLogData(eventType, _name, eventId.Name)
                    {
                        SiteID           = siteId,
                        EventDescription = message,
                        Exception        = exception
                    };
                }
                else
                {
                    eventData = new EventLogData(eventType, _name, message)
                    {
                        SiteID    = siteId,
                        Exception = exception
                    };
                }

                // Xperience buffers all logged events in the memory, up to the point when
                // the database is available. No need to buffer or ask about the database
                // availability.
                try
                {
                    _eventLogService.LogEvent(eventData);
                }
                catch
                {
                }
            }
        }
예제 #7
0
    private void GenerateCodes(object parameter)
    {
        try
        {
            // Construct cache for code uniqueness check
            var      existingCodes = GetExistingCodes();
            BaseInfo coupon        = null;

            using (var context = new CMSActionContext())
            {
                // Do not touch parent for all codes
                context.TouchParent = false;
                context.LogEvents   = false;

                var logMessage = GetString("com.couponcode.generated");

                // Create generator
                var generator = new RandomCodeGenerator(new CodeUniquenessChecker(existingCodes), pattern, prefix);

                for (var i = 0; i < count; i++)
                {
                    // Get new code
                    var code         = generator.GenerateCode();
                    var couponConfig = GetCouponConfig(code);

                    coupon = Discount.CreateCoupon(couponConfig);

                    // Log that coupon was created
                    AddLog(string.Format(logMessage, HTMLHelper.HTMLEncode(code)));
                }
            }

            // Touch parent (one for all)
            coupon?.Generalized.TouchParent();

            // Log information that coupons were generated
            var logData = new EventLogData(EventTypeEnum.Information, "Discounts", "GENERATECOUPONCODES")
            {
                EventDescription = $"{count} coupon codes for discount '{Discount.DiscountDisplayName}' successfully generated.",
                UserID           = CurrentUser.UserID,
                UserName         = CurrentUser.UserName,
                SiteID           = SiteContext.CurrentSiteID
            };

            Service.Resolve <IEventLogService>().LogEvent(logData);
        }
        catch (Exception ex)
        {
            CurrentError = GetString("com.couponcode.generateerror");
            Service.Resolve <IEventLogService>().LogException("Discounts", "GENERATECOUPONCODES", ex);
        }
    }
예제 #8
0
        public void WriteLog(EventLogData eventLogData)
        {
            if (eventLogData.EventType == EventTypeEnum.Error)
            {
                // Checks if the error event contains an exception
                string exception = eventLogData.Exception != null?eventLogData.Exception.ToString() : "No exception logged.";

                string eventData = $"{"Error"}, {eventLogData.EventCode}, {DateTime.Now}, {eventLogData.EventDescription}, {exception}{Environment.NewLine}";

                // Writes logged error events into a 'errors.csv' file in the application's root directory
                File.AppendAllText(SystemContext.WebApplicationPhysicalPath + "\\errors.csv", eventData);
            }
        }
예제 #9
0
        public void HandleUpdateRequestProperly(string section, SystemErrorsUpdateRequest.EType type)
        {
            using (FileDeleter fd = new FileDeleter(Extensions.GetTempDBFile()))
            {
                Database    db   = new Database(new Context(fd.Fi));
                Initializer init = new Initializer(null);
                init.Initialize(db);

                RequestBus        bus       = new RequestBus();
                EventLogResponder responder = new EventLogResponder()
                {
                    DB = db
                };
                bus.Subscribe(responder);

                using (SQLiteConnection conn = db.Connection)
                {
                    conn.Open();

                    string new_path = $"machine_name.{section}.max_event_log";

                    System.DateTime dt  = GenerateTime(2019, 2, 20, 12, 23, 34, 456789);
                    EventLogData    eld = new EventLogData();
                    eld.Insert(dt, 22334455);
                    eld.Insert(dt, 22334456);

                    SystemErrorsUpdateRequest req = new SystemErrorsUpdateRequest("machine_name", type);
                    req.LogData.Assign(eld);
                    bus.MakeRequest(req);
                    Assert.True(req.IsHandled);

                    Attribute attr = new Attribute();
                    string    x    = attr.Get(new_path, conn);
                    Assert.False(string.IsNullOrEmpty(x));

                    EventLogData eld2 = JsonConvert.DeserializeObject <EventLogData>(x);
                    Assert.NotNull(eld);
                    Assert.False(eld2.MaxRecordNumber.HasValue);
                    Assert.Equal(dt, eld2.MaxDate);

                    List <ulong> record_numbers = eld2.MaxDateToRecordNumbers[dt];
                    Assert.NotNull(record_numbers);
                    Assert.Equal(2, record_numbers.Count);
                    // Sort just in case they got put in the list in a different order
                    record_numbers.Sort();
                    Assert.Equal((ulong)22334455, record_numbers[0]);
                    Assert.Equal((ulong)22334456, record_numbers[1]);
                }
            }
        }
예제 #10
0
        private static void HandleInfoRequest(SystemErrorsInfoRequest sys_request, SQLiteConnection conn)
        {
            Attribute attr                   = new Attribute();
            string    machine_name           = sys_request.MachineName.Replace(' ', '_').ToLower();
            string    section                = sys_request.Type.ToString().ToLower();
            string    max_record_number_path = $"{machine_name}.{section}.max_record_number";
            string    max_eventlog_path      = $"{machine_name}.{section}.max_event_log";

            // First, let's look for the "old" systems which just had the record number. If we find
            // those we'll convert them to the "new" system which has a JSON object.
            string max = attr.Get(max_record_number_path, conn);

            if (string.IsNullOrEmpty(max) == false &&
                ulong.TryParse(max, out ulong u))
            {
                // Yes, it's using the old system
                sys_request.LogData.MaxRecordNumber = u;
                sys_request.Handled();

                // Change the attribute so it's using the new one
                attr.Set(max_eventlog_path,
                         JsonConvert.SerializeObject(sys_request.LogData,
                                                     Formatting.None,
                                                     new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                }),
                         conn);
                attr.Clear(max_record_number_path, conn);
            }
            else
            {
                // Nope...try the new system
                max = attr.Get(max_eventlog_path, conn);
                if (string.IsNullOrEmpty(max) == false)
                {
                    try
                    {
                        EventLogData system_id = JsonConvert.DeserializeObject <EventLogData>(max);
                        if (system_id != null)
                        {
                            sys_request.LogData.Assign(system_id);
                            sys_request.Handled();
                        }
                    }
                    catch (JsonException)
                    {
                    }
                }
            }
        }
예제 #11
0
 public void Log(EventLogData eventLogData)
 {
     try
     {
         if (_auditProxy == null)
         {
             _auditProxy = _channelFactory.CreateChannel();
         }
         _auditProxy.Log(eventLogData);
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error logging data on audit service: {e.Message}");
     }
 }
예제 #12
0
    /// <summary>
    /// When exception occurs, log it to event log.
    /// </summary>
    private void LogExceptionToEventLog(Exception ex)
    {
        var logData = new EventLogData(EventTypeEnum.Error, "System deployment", "DEPLOYMENT")
        {
            EventDescription = EventLogProvider.GetExceptionLogMessage(ex),
            EventUrl         = RequestContext.RawURL,
            UserID           = CurrentUser.UserID,
            UserName         = CurrentUser.UserName,
            IPAddress        = RequestContext.UserHostAddress,
            SiteID           = SiteContext.CurrentSiteID
        };

        Service.Resolve <IEventLogService>().LogEvent(logData);
        AddError(GetString("Deployment.DeploymentFailed") + ": " + ex.Message);
    }
예제 #13
0
    private void LogExceptionToEventLog(Exception ex, string uiCulture)
    {
        var logData = new EventLogData(EventTypeEnum.Error, "Content", "TRANSLATEDOC")
        {
            EventDescription = EventLogProvider.GetExceptionLogMessage(ex),
            EventUrl         = RequestContext.RawURL,
            UserID           = currentUser.UserID,
            UserName         = currentUser.UserName,
            IPAddress        = RequestContext.UserHostAddress,
            SiteID           = SiteInfoProvider.GetSiteID(CurrentSiteName)
        };

        Service.Resolve <IEventLogService>().LogEvent(logData);

        AddError(GetString("ContentRequest.TranslationFailed", uiCulture) + ex.Message);
    }
예제 #14
0
        public void LogError(string message, string sourceText, string eventCodeText, bool logToEventLog)
        {
            string value = FAILED_SIGN + AbstractImportExportSettings.SEPARATOR + "<span class=\"SelectorError\">" + message + "</span>" + content;

            PersistentStorageHelper.SetValue(STORAGE_KEY, value);
            if (logToEventLog)
            {
                var logData = new EventLogData(EventTypeEnum.Error, sourceText, eventCodeText)
                {
                    EventDescription = message,
                    EventUrl         = RequestContext.CurrentURL
                };

                Service.Resolve <IEventLogService>().LogEvent(logData);
            }
        }
예제 #15
0
        public void LogQuit(string message, string sourceText, string eventCodeText, bool logToEventLog)
        {
            string value = QUIT_SIGN + AbstractImportExportSettings.SEPARATOR + message + content;

            PersistentStorageHelper.SetValue(STORAGE_KEY, value);
            if (logToEventLog)
            {
                var logData = new EventLogData(EventTypeEnum.Information, sourceText, eventCodeText)
                {
                    EventDescription = message,
                    EventUrl         = RequestContext.CurrentURL
                };

                Service.Resolve <IEventLogService>().LogEvent(logData);
            }
        }
예제 #16
0
    /// <summary>
    /// When exception occurs, log it to event log.
    /// </summary>
    /// <param name="ex">Exception to log</param>
    private void LogExceptionToEventLog(Exception ex)
    {
        var logData = new EventLogData(EventTypeEnum.Error, "Content", "DELETEDOC")
        {
            EventDescription = EventLogProvider.GetExceptionLogMessage(ex),
            EventUrl         = RequestContext.RawURL,
            UserID           = currentUser.UserID,
            UserName         = currentUser.UserName,
            IPAddress        = RequestContext.UserHostAddress,
            SiteID           = currentSite.SiteID
        };

        Service.Resolve <IEventLogService>().LogEvent(logData);

        AddError(GetString("ContentRequest.DeleteFailed", currentCulture) + ": " + ex.Message);
    }
예제 #17
0
        public EventLogCollector(CollectorID id, Remote remote_info, ECollectorType type)
            : base(new DataCollectorContext(id, type))
        {
            RemoteInfo = remote_info;

            m_machine_name = Context.ID.Name;
            CollectorType  = type;

            if (type != ECollectorType.SystemErrors && type != ECollectorType.ApplicationErrors)
            {
                throw new Exception($"EventLogCollector: invalid collector type {type}");
            }

            // So we don't keep getting log entries that have already been retrieved, keep track
            // of the RecordNumber, which is an ever-increasing number for each of the different
            // types of logfiles (System, or Application), and the dates.

            // We need to keep the dates because if a particular machine is rebuilt, the RecordNumber
            // will get reset and we'll stop getting any errors from the event log.
            // Originally, we just kept the record number, but that's not good enough, so we
            // switched to using the date as the primary clause.

            m_log_data = new EventLogData();

            SystemErrorsInfoRequest.EType req_type = SystemErrorsInfoRequest.EType.System;
            switch (CollectorType)
            {
            case ECollectorType.ApplicationErrors:
                req_type = SystemErrorsInfoRequest.EType.Application;
                break;

            case ECollectorType.SystemErrors:
                req_type = SystemErrorsInfoRequest.EType.System;
                break;

            default:
                throw new Exception($"EventLogCollector: failure to handle type conversion from {CollectorType}");
            }

            SystemErrorsInfoRequest request = new SystemErrorsInfoRequest(m_machine_name, req_type);

            RequestBus.Instance.MakeRequest(request);
            if (request.IsHandled)
            {
                m_log_data.Assign(request.LogData);
            }
        }
예제 #18
0
        public void Log(EventLogData eventLogData)
        {
            if (!EventLog.SourceExists(eventLogData.BankName))
            {
                EventLog.CreateEventSource(eventLogData.BankName, _logName);

                // Giving OS the time to register the source
                Thread.Sleep(50);
            }

            using (var log = new EventLog(_logName))
            {
                log.MachineName = Environment.MachineName;
                log.Source      = eventLogData.BankName;
                log.WriteEntry($"{eventLogData.AccountName}: {eventLogData.LogMessage}", eventLogData.EventLogType);
            }
        }
    /// <summary>
    /// Send e-mail to administrator about new registration.
    /// </summary>
    /// <param name="administrationApproval">Indicates if administration approval is required</param>
    private void SendEmailToAdministrator(bool administrationApproval)
    {
        MacroResolver resolver        = MembershipResolvers.GetRegistrationResolver(RegisteredUser);
        string        currentSiteName = SiteContext.CurrentSiteName;
        var           template        = EmailTemplateInfo.Provider.Get(administrationApproval ? "Registration.Approve" : "Registration.New", SiteContext.CurrentSiteID);

        if (template == null)
        {
            var logData = new EventLogData(EventTypeEnum.Error, "RegistrationForm", "GetEmailTemplate")
            {
                EventUrl = RequestContext.RawURL,
                UserName = CurrentUser.UserName,
                SiteID   = SiteContext.CurrentSiteID
            };

            Service.Resolve <IEventLogService>().LogEvent(logData);
        }
        else
        {
            // E-mail template ok
            string from = EmailHelper.GetSender(template, (!String.IsNullOrEmpty(FromAddress)) ? FromAddress : SettingsKeyInfoProvider.GetValue(currentSiteName + ".CMSNoreplyEmailAddress"));
            if (!String.IsNullOrEmpty(from))
            {
                // Email message
                EmailMessage email = new EmailMessage();
                email.EmailFormat = EmailFormatEnum.Default;
                email.Recipients  = AdministratorEmail;
                email.From        = from;
                email.Subject     = GetString("RegistrationForm.EmailSubject");

                try
                {
                    EmailSender.SendEmailWithTemplateText(currentSiteName, email, template, resolver, true);
                }
                catch
                {
                    Service.Resolve <IEventLogService>().LogError("Membership", "RegistrationApprovalEmail");
                }
            }
            else
            {
                Service.Resolve <IEventLogService>().LogError("RegistrationApproval", "EmailSenderNotSpecified");
            }
        }
    }
예제 #20
0
        public void ConvertProperly(string section, SystemErrorsInfoRequest.EType type)
        {
            using (FileDeleter fd = new FileDeleter(Extensions.GetTempDBFile()))
            {
                Database    db   = new Database(new Context(fd.Fi));
                Initializer init = new Initializer(null);
                init.Initialize(db);

                RequestBus        bus       = new RequestBus();
                EventLogResponder responder = new EventLogResponder()
                {
                    DB = db
                };
                bus.Subscribe(responder);

                using (SQLiteConnection conn = db.Connection)
                {
                    conn.Open();

                    string orig_path  = $"machine_name.{section}.max_record_number";
                    string new_path   = $"machine_name.{section}.max_event_log";
                    ulong  record_num = 234567;

                    Attribute attr = new Attribute();
                    attr.Set(orig_path, record_num.ToString(), conn);

                    SystemErrorsInfoRequest req = new SystemErrorsInfoRequest("machine_name", type);
                    bus.MakeRequest(req);
                    Assert.True(req.IsHandled);
                    Assert.True(req.LogData.MaxRecordNumber.HasValue);
                    Assert.Equal(record_num, req.LogData.MaxRecordNumber.Value);

                    string x = attr.Get(orig_path, conn);
                    Assert.True(string.IsNullOrEmpty(x));

                    x = attr.Get(new_path, conn);
                    Assert.False(string.IsNullOrEmpty(x));

                    EventLogData eld = JsonConvert.DeserializeObject <EventLogData>(x);
                    Assert.NotNull(eld);
                    Assert.True(eld.MaxRecordNumber.HasValue);
                    Assert.Equal(record_num, eld.MaxRecordNumber.Value);
                }
            }
        }
예제 #21
0
        public void HandleMaxDateProperly()
        {
            EventLogData eld = new EventLogData();

            Assert.Null(eld.MaxDate);

            ulong start_record_num = 22334455;
            ulong record_num       = start_record_num;
            int   start_ms         = 234567;
            int   ms = start_ms;

            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 45, ms++), record_num++);
            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 45, ms++), record_num++);
            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 45, ms++), record_num++);

            Assert.NotNull(eld.MaxDate);
            Assert.Equal(GenerateTime(2019, 2, 20, 12, 34, 45, ms - 1), eld.MaxDate.Value);
        }
예제 #22
0
        public void HandleMultipleRecordNumbersAtTheSameTimeProperly()
        {
            EventLogData eld = new EventLogData();
            ulong        start_record_num = 22334455;
            ulong        record_num       = start_record_num;
            DateTime     dt = GenerateTime(2019, 2, 20, 12, 34, 45, 234567);

            eld.Insert(dt, record_num++);
            eld.Insert(dt, record_num++);
            eld.Insert(dt, record_num++);

            Assert.Single(eld.MaxDateToRecordNumbers.Keys);

            List <ulong> record_numbers = eld.MaxDateToRecordNumbers[dt];

            Assert.NotNull(record_numbers);
            Assert.Equal(3, record_numbers.Count);
        }
예제 #23
0
        public void HaveContainsRecordNumberWorkProperly()
        {
            EventLogData eld = new EventLogData();
            ulong        start_record_num = 22334455;
            ulong        record_num       = start_record_num;
            int          start_ms         = 234567;
            int          ms = start_ms;

            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 45, ms++), record_num++);
            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 45, ms++), record_num++);
            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 45, ms++), record_num++);

            record_num = start_record_num;
            Assert.True(eld.ContainsRecordNumber(record_num++));
            Assert.True(eld.ContainsRecordNumber(record_num++));
            Assert.True(eld.ContainsRecordNumber(record_num++));
            Assert.False(eld.ContainsRecordNumber(record_num++));
            Assert.False(eld.ContainsRecordNumber(start_record_num - 1));
        }
예제 #24
0
        public void HaveAssignWorkProperly()
        {
            EventLogData eld = new EventLogData();

            eld.MaxRecordNumber = 2;
            Assert.True(eld.MaxRecordNumber.HasValue);
            Assert.Equal((ulong)2, eld.MaxRecordNumber.Value);

            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 56, 789), 22334455);
            Assert.True(eld.ContainsRecordNumber(22334455));

            EventLogData eld2 = new EventLogData();

            eld2.Assign(eld);

            Assert.True(eld2.MaxRecordNumber.HasValue);
            Assert.Equal((ulong)2, eld2.MaxRecordNumber.Value);
            Assert.True(eld2.ContainsRecordNumber(22334455));
        }
예제 #25
0
    protected void lnkBreakWithCopy_Click(Object sender, EventArgs e)
    {
        // Check permission
        CheckModifyPermission(true);

        // Break permission inheritance and copy parent permissions
        AclInfoProvider.BreakInheritance(Node, true);

        // Log staging task
        TaskParameters taskParam = new TaskParameters();

        taskParam.SetParameter("copyPermissions", true);
        DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.BreakACLInheritance, Node.TreeProvider, SynchronizationInfoProvider.ENABLED_SERVERS, taskParam, Node.TreeProvider.AllowAsyncActions);

        // Insert information about this event to event log.
        if (DocumentManager.Tree.LogEvents)
        {
            var logData = new EventLogData(EventTypeEnum.Information, "Content", "DOCPERMISSIONSMODIFIED")
            {
                EventDescription = ResHelper.GetAPIString("security.documentpermissionsbreakcopy", "Inheritance of the parent page permissions have been broken. Parent page permissions have been copied."),
                EventUrl         = currentUrl,
                UserID           = DocumentManager.Tree.UserInfo.UserID,
                UserName         = DocumentManager.Tree.UserInfo.UserName,
                NodeID           = Node.NodeID,
                DocumentName     = DocumentName,
                IPAddress        = ipAddress,
                SiteID           = Node.NodeSiteID
            };

            Service.Resolve <IEventLogService>().LogEvent(logData);
        }

        lblInheritanceInfo.Text = GetString("Security.InheritsInfo.DoesNotInherit");
        SwitchBackToPermissionsMode();

        // Clear and reload
        securityElem.InvalidateAcls();
        securityElem.LoadOperators(true);
    }
예제 #26
0
    protected void btnDestroy_Click(object sender, EventArgs e)
    {
        if (Node == null)
        {
            return;
        }

        // Check permissions
        if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn))
        {
            ShowError(GetString("History.ErrorNotAllowedToDestroy"));
            return;
        }
        VersionManager.ClearDocumentHistory(Node.DocumentID);
        ShowConfirmation(GetString("VersionProperties.VersionsCleared"));

        var logData = new EventLogData(EventTypeEnum.Information, "Content", "DESTROYHISTORY")
        {
            EventDescription = String.Format(ResHelper.GetAPIString("contentedit.documenthistorydestroyed", "History of the page '{0}' has been destroyed."), HTMLHelper.HTMLEncode(Node.NodeAliasPath)),
            EventUrl         = RequestContext.RawURL,
            UserID           = TreeProvider.UserInfo.UserID,
            UserName         = TreeProvider.UserInfo.UserName,
            NodeID           = Node.NodeID,
            DocumentName     = Node.GetDocumentName(),
            IPAddress        = RequestContext.UserHostAddress,
            SiteID           = Node.NodeSiteID
        };

        Service.Resolve <IEventLogService>().LogEvent(logData);

        InvalidateNode();
        ReloadData();

        if (AfterDestroyHistory != null)
        {
            AfterDestroyHistory(sender, e);
        }
    }
    /// <summary>
    /// Saves entire continuous integration log as one entry to event log.
    /// If null or empty description is passed, nothing is logged!
    /// </summary>
    /// <param name="eventType">Event log severity</param>
    /// <param name="eventCode">Event code</param>
    /// <param name="description">Event description</param>
    private void SaveIntegrationLogToEventLog(EventTypeEnum eventType, string eventCode, string description)
    {
        if (string.IsNullOrEmpty(description))
        {
            return;
        }

        var logData = new EventLogData(eventType, CONTINUOUS_INTEGRATION, eventCode)
        {
            EventDescription = description,
            EventUrl         = RequestContext.RawURL,
            UserID           = CurrentUser.UserID,
            UserName         = CurrentUser.UserName,
            IPAddress        = RequestContext.UserHostAddress,
            EventMachineName = SystemContext.MachineName,
            EventUrlReferrer = RequestContext.URLReferrer,
            EventUserAgent   = RequestContext.UserAgent,
            EventTime        = DateTime.Now,
            LoggingPolicy    = LoggingPolicy.DEFAULT
        };

        Service.Resolve <IEventLogService>().LogEvent(logData);
    }
예제 #28
0
    /// <summary>
    /// Finish button click.
    /// </summary>
    protected void FinishNextButton_Click(object sender, EventArgs e)
    {
        if (!SqlInstallationHelper.DatabaseIsSeparated())
        {
            string error = String.Empty;

            // If it doesn't support OpenQuery command, data could not have been moved so we cannot delete tables.
            if (SqlServerCapabilities.SupportsOpenQueryCommand)
            {
                var separationHelper = new DatabaseSeparationHelper();

                separationHelper.InstallScriptsFolder           = SqlInstallationHelper.GetSQLInstallPathToObjects();
                separationHelper.ScriptsFolder                  = Server.MapPath("~/App_Data/DBSeparation");
                separationHelper.InstallationConnStringSeparate = UnprotectConnectionString();
                error = separationHelper.DeleteSourceTables(separationFinished.DeleteOldDB, false);
            }

            if (!String.IsNullOrEmpty(error))
            {
                separationFinished.ErrorLabel.Visible = true;
                separationFinished.ErrorLabel.Text    = error;
                var logData = new EventLogData(EventTypeEnum.Error, "Contact management database join", "DELETEOLDDATA")
                {
                    EventDescription = error,
                    EventUrl         = RequestContext.CurrentURL
                };

                Service.Resolve <IEventLogService>().LogEvent(logData);
            }
            else
            {
                EnableTasks();
                WebFarmHelper.CreateTask(new RestartApplicationWebFarmTask());
                ScriptHelper.RegisterStartupScript(this, typeof(string), "Close dialog", ScriptHelper.GetScript("RefreshParent(); CloseDialog();"));
            }
        }
    }
예제 #29
0
        public void CleanupProperly()
        {
            EventLogData eld = new EventLogData();

            eld.MaxRecordNumber = 2;
            ulong start_record_num = 22334455;
            ulong record_num       = start_record_num;
            int   start_ms         = 234567;
            int   ms = start_ms;

            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 45, ms++), record_num++);
            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 45, ms++), record_num++);
            eld.Insert(GenerateTime(2019, 2, 20, 12, 34, 45, ms++), record_num++);

            Assert.Equal(3, eld.MaxDateToRecordNumbers.Keys.Count);
            Assert.NotNull(eld.MaxRecordNumber);

            eld.Cleanup();

            // After cleanup, only the most-recent time should be in there, and the MaxRecordNumber
            // should be null
            Assert.Single(eld.MaxDateToRecordNumbers.Keys);
            Assert.Null(eld.MaxRecordNumber);
        }
예제 #30
0
        public void HaveDefaultNullMaxRecordNumber()
        {
            EventLogData eld = new EventLogData();

            Assert.Null(eld.MaxRecordNumber);
        }