コード例 #1
0
        private void Log(NodeEventArgs e, string sourcePath, Node target)
        {
            if (!Journal.CreateJournalItems)
            {
                return;
            }
            if (e.SourceNode == null)
            {
                return;
            }
            if (e.SourceNode.NodeOperation == NodeOperation.TemplateChildCopy || e.SourceNode.NodeOperation == NodeOperation.HiddenJournal)
            {
                return;
            }

            string path;

            try
            {
                path = e.SourceNode.Path;
            }
            catch (Exception ee) // logged
            {
                SnLog.WriteException(ee);
                path = "[error]";
            }

            var userName = "******";

            try
            {
                if (e.User != null)
                {
                    userName = e.User.Name;
                }
            }
            catch (Exception eee) // logged
            {
                SnLog.WriteException(eee);
                userName = "******";
            }
            string info = null;

            if (e.ChangedData != null)
            {
                var sb = new StringBuilder();
                foreach (var changedData in e.ChangedData)
                {
                    if (changedData.Name == "ModificationDate" ||
                        changedData.Name == "ModifiedById" ||
                        changedData.Name == "ModifiedBy" ||
                        changedData.Name == "VersionModificationDate" ||
                        changedData.Name == "VersionModifiedById" ||
                        changedData.Name == "VersionModifiedBy")
                    {
                        continue;
                    }

                    sb.Append(changedData.Name + ", ");
                }
                info = "{{$Wall:ChangedFields}}: " + sb.ToString().TrimEnd(',', ' ');
            }

            var displayName       = string.IsNullOrEmpty(e.SourceNode.DisplayName) ? e.SourceNode.Name : e.SourceNode.DisplayName;
            var targetPath        = target?.Path;
            var targetDisplayName = target == null ? null : string.IsNullOrEmpty(target.DisplayName) ? target.Name : target.DisplayName;

            try
            {
                Journals.Add(e.EventType.ToString(), path, userName, e.Time, e.SourceNode.Id, displayName, e.SourceNode.NodeType.Name, sourcePath, targetPath, targetDisplayName, info, false);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex, "Journal log failed.", EventId.Portal,
                                     properties: new Dictionary <string, object>
                {
                    { "Path", path },
                    { "Event type", e.EventType.ToString() },
                    { "Target path", targetPath }
                });
            }
        }
コード例 #2
0
        private void Log(NodeEventArgs e, string sourcePath, Node target)
        {
            if (!CreateJournalItems)
            {
                return;
            }

            var path = "[null]";

            if (e.SourceNode == null)
            {
                return;
            }

            if (e.SourceNode.NodeOperation == NodeOperation.TemplateChildCopy || e.SourceNode.NodeOperation == NodeOperation.HiddenJournal)
            {
                return;
            }

            try
            {
                path = e.SourceNode.Path;
            }
            catch (Exception ee) //logged
            {
                Logger.WriteException(ee);
                path = "[error]";
            }

            var userName = "******";

            try
            {
                if (e.User != null)
                {
                    userName = e.User.Name;
                }
            }
            catch (Exception eee) //logged
            {
                Logger.WriteException(eee);
                userName = "******";
            }
            string info = null;

            if (e.ChangedData != null)
            {
                var sb = new StringBuilder();
                foreach (var changedData in e.ChangedData)
                {
                    if (changedData.Name == "NodeModificationDate" ||
                        changedData.Name == "NodeModifiedById" ||
                        changedData.Name == "NodeModifiedBy" ||
                        changedData.Name == "ModificationDate" ||
                        changedData.Name == "ModifiedById" ||
                        changedData.Name == "ModifiedBy")
                    {
                        continue;
                    }

                    sb.Append(changedData.Name + ", ");
                }
                info = "Changed Fields: " + sb.ToString().TrimEnd(',', ' ');
            }

            var displayName       = string.IsNullOrEmpty(e.SourceNode.DisplayName) ? e.SourceNode.Name : e.SourceNode.DisplayName;
            var targetPath        = target == null ? null : target.Path;
            var targetDisplayName = target == null ? null : string.IsNullOrEmpty(target.DisplayName) ? target.Name : target.DisplayName;

            Journals.Add(e.EventType.ToString(), path, userName, e.Time, e.SourceNode.Id, displayName, e.SourceNode.NodeType.Name, sourcePath, targetPath, targetDisplayName, info, false);
        }