コード例 #1
0
        public void DatabaseUpgradeAfter(int ixVersionFrom, int ixVersionTo, CDatabaseUpgradeApi apiUpgrade)
        {
            if (ixVersionFrom <= DB_CHANGE_VERSION_MESSAGES_HTML_SANITIZE)
            {
                var sanitizer = HtmlSanitizer.SimpleHtml5Sanitizer();

                var selectQuery = this.api.Database.NewSelectQuery(ExtendedEventEntity.GetPluginTableName(this.api.Database));
                selectQuery.AddSelect("ixExtendedEvent, sMessage");
                selectQuery.AddWhere("sEventType <> @sEventType");
                selectQuery.SetParamString("@sEventType", "commit");

                var ds = selectQuery.GetDataSet();
                if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        var sMessage = row["sMessage"] as string;

                        if (!String.IsNullOrEmpty(sMessage))
                        {
                            sMessage = sanitizer.Sanitize(sMessage);

                            var ixExtendedEvent = Convert.ToInt32(row["ixExtendedEvent"]);

                            var updateQuery = this.api.Database.NewUpdateQuery(ExtendedEventEntity.GetPluginTableName(this.api.Database));
                            updateQuery.UpdateString("sMessage", sMessage);
                            updateQuery.AddWhere("ixExtendedEvent = @ixExtendedEvent");
                            updateQuery.SetParamInt("@ixExtendedEvent", ixExtendedEvent);

                            updateQuery.Execute();
                        }
                    }
                }
            }
        }
コード例 #2
0
 public void DatabaseUpgradeBefore(int ixVersionFrom, int ixVersionTo, CDatabaseUpgradeApi apiUpgrade)
 {
     if (ixVersionFrom <= DB_CHANGE_VERSION_EVENTUTC)
     {
         apiUpgrade.ChangeColumnDefinition(ExtendedEventEntity.GetPluginTableName(this.api.Database), "dtEventUtc");
     }
 }
コード例 #3
0
        public int Process()
        {
            var req = this.api.Request;

            var ixBug           = req.GetInt32("ixBug", 0);
            var sEventType      = req.GetString("sEventType", "none");
            var dtEventUtc      = req.GetDateTime("dtEventUtc", DateTime.MinValue.ToUniversalTime());
            var sPersonName     = req.GetString("sPersonName", null);
            var sMessage        = req.GetString("sMessage", null);
            var sExternalUrl    = req.GetString("sExternalUrl", null);
            var sCommitRevision = req.GetString("sCommitRevision", null);
            var sBuildName      = req.GetString("sBuildName", null);
            var sModuleName     = req.GetString("sModuleName", null);
            var sBranchName     = req.GetString("sBranchName", null);

            if (ixBug <= 0)
            {
                throw new Exception("Parameter ixBug must be positive, non-zero integer.");
            }

            if (dtEventUtc == DateTime.MinValue)
            {
                throw new Exception("Parameter dtEventUtc must be valid datetime value in ISO 8601 format.");
            }

            var ixPerson = this.TryLoadPersonId(sPersonName);

            sMessage = this.SanitizeMessage(sEventType, sMessage);

            var entity = new ExtendedEventEntity
            {
                ixBug           = ixBug,
                sEventType      = sEventType,
                dtEventUtc      = dtEventUtc,
                ixPerson        = ixPerson,
                sPersonName     = sPersonName,
                sMessage        = sMessage,
                sExternalUrl    = sExternalUrl,
                sCommitRevision = sCommitRevision,
                sBuildName      = sBuildName,
                sModuleName     = sModuleName,
                sBranchName     = sBranchName
            };

            var ixCommitEvent = entity.Save(this.api.Database);

            return(ixCommitEvent);
        }
コード例 #4
0
        public static IEnumerable <ExtendedEventEntity> QueryEvents(CDatabaseApi db, int ixBug)
        {
            var selectQuery = db.NewSelectQuery(ExtendedEventEntity.GetPluginTableName(db));

            selectQuery.AddSelect("*");
            selectQuery.AddWhere("ixBug = @ixBug");
            selectQuery.SetParamInt("@ixBug", ixBug);

            var ds = selectQuery.GetDataSet();

            if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    var entity = new ExtendedEventEntity();
                    entity.Load(row);

                    yield return(entity);
                }
            }
        }
コード例 #5
0
        public CPseudoBugEvent[] PseudoBugEvents(CBug bug, CBugEvent[] rgBugEvent)
        {
            int ixBug = bug.ixBug;

            var sanitizer = HtmlSanitizer.SimpleHtml5Sanitizer();

            var query = ExtendedEventEntity.QueryEvents(this.api.Database, ixBug);

            var events = new List <CPseudoBugEvent>();

            foreach (var entity in query)
            {
                string sMessage = entity.sMessage;
                string sTitle   = "";

                switch (entity.sEventType)
                {
                case "commit":
                    sTitle   = $"Revision {entity.sCommitRevision} commited";
                    sMessage = HttpUtility.HtmlEncode(sMessage);
                    sMessage = sMessage.Replace("\n", "<br>\n");
                    break;

                case "build-success":
                    sTitle   = $"Build {entity.sBuildName} successful";
                    sMessage = sanitizer.Sanitize(sMessage);
                    break;

                case "build-failure":
                    sTitle   = $"Build {entity.sBuildName} failed";
                    sMessage = sanitizer.Sanitize(sMessage);
                    break;

                case "releasenote":
                    sTitle   = $"Releasenotes message";
                    sMessage = sanitizer.Sanitize(sMessage);
                    break;

                case "deployment":
                    sTitle   = $"Deployed";
                    sMessage = sanitizer.Sanitize(sMessage);
                    break;

                default:
                    sMessage = HttpUtility.HtmlEncode(sMessage);
                    break;
                }

                if (entity.ixPerson == 0 && !String.IsNullOrEmpty(entity.sPersonName))
                {
                    sTitle += " by " + HttpUtility.HtmlEncode(entity.sPersonName);
                }
                else if (entity.ixPerson > 0)
                {
                    sTitle += " by";
                }

                var sChanges = new StringBuilder();
                if (!String.IsNullOrEmpty(entity.sModuleName))
                {
                    sChanges.Append(HttpUtility.HtmlEncode(entity.sModuleName));
                }

                if (!String.IsNullOrEmpty(entity.sBranchName))
                {
                    if (sChanges.Length > 0)
                    {
                        sChanges.Append(": ");
                    }
                    sChanges.Append(HttpUtility.HtmlEncode(entity.sBranchName));
                }

                if (!String.IsNullOrEmpty(entity.sExternalUrl))
                {
                    sChanges.Append($@" <a href=""{HttpUtility.HtmlAttributeEncode(entity.sExternalUrl)}"">View details</a>");
                }

                var sHtml = this.api.UI.BugEvent(entity.dtEventUtc, entity.ixPerson, sTitle, sMessage, sChanges.ToString(), $"fbee-event fbee-{entity.sEventType}");
                var evt   = new CPseudoBugEvent(entity.dtEventUtc, sHtml);
                events.Add(evt);
            }

            return(events.ToArray());
        }
コード例 #6
0
        public CTable[] DatabaseSchema()
        {
            var tblExtendedEvents = ExtendedEventEntity.TableDefinition(this.api.Database);

            return(new[] { tblExtendedEvents });
        }