Exemplo n.º 1
0
        public override void NotifyAlertReceived(byte alertLevel, byte alertDescription)
        {
            string description = AlertDescription.GetText(alertDescription);

            AlertLevelsEnum level     = AlertLevelsEnum.Warning;
            AlertTypesEnum  alertType = AlertTypesEnum.unknown;

            if (Enum.IsDefined(typeof(AlertLevelsEnum), alertLevel))
            {
                level = (AlertLevelsEnum)alertLevel;
            }

            if (Enum.IsDefined(typeof(AlertTypesEnum), alertDescription))
            {
                alertType = (AlertTypesEnum)alertDescription;
            }

            if (alertType == AlertTypesEnum.close_notify)
            {
                logger.LogDebug(
                    $"DTLS client received close notification: {AlertLevel.GetText(alertLevel)}, {description}.");
            }
            else
            {
                logger.LogWarning(
                    $"DTLS client received unexpected alert: {AlertLevel.GetText(alertLevel)}, {description}.");
            }

            OnAlert?.Invoke(level, alertType, description);
        }
Exemplo n.º 2
0
        public override void NotifyAlertReceived(byte alertLevel, byte alertDescription)
        {
            string description = AlertDescription.GetText(alertDescription);

            AlertLevelsEnum level     = AlertLevelsEnum.Warning;
            AlertTypesEnum  alertType = AlertTypesEnum.unknown;

            if (Enum.IsDefined(typeof(AlertLevelsEnum), alertLevel))
            {
                level = (AlertLevelsEnum)alertLevel;
            }

            if (Enum.IsDefined(typeof(AlertTypesEnum), alertDescription))
            {
                alertType = (AlertTypesEnum)alertDescription;
            }

            string alertMsg = $"{AlertLevel.GetText(alertLevel)}";

            alertMsg += (!string.IsNullOrEmpty(description)) ? $", {description}." : ".";

            if (alertType == AlertTypesEnum.close_notify)
            {
                logger.LogDebug($"DTLS server received close notification: {alertMsg}");
            }
            else
            {
                logger.LogWarning($"DTLS server received unexpected alert: {alertMsg}");
            }

            OnAlert?.Invoke(level, alertType, description);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Контрол предназначен для показа сообщения пользователю в виде HTML разметки типа div.
        /// Контрол подключает к себе CSS стили из Bootstrap.css и из MT.css и использует перечисление AlertsEnum для определения стилевого оформления.
        ///  </summary>
        /// <param name="text">Текст, который будет выведен пользователю.</param>
        /// <param name="type">Перечисление типа AlertsEnum задающее стилевое оформление сообщения.</param>

        public static MvcHtmlString AlertDirective(this HtmlHelper helper, string text, object htmlAttributes = null,
                                                   AlertTypesEnum type = AlertTypesEnum.Warning)
        {
            var alertDiv   = new TagBuilder("div");
            var attributes = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            AttributeManager.AddClassAttribute(attributes, type);
            AttributeManager.AddClassAttribute(attributes, "alert alert-box-width");

            alertDiv.InnerHtml = text;
            alertDiv.MergeAttributes(attributes);
            return(new MvcHtmlString(alertDiv.ToString()));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Перегруженный метод AddClassAttribute для добавления CSS класса в зависимости от значения AlertTypesEnum
        /// </summary>
        public static void AddClassAttribute(IDictionary <string, object> attributes, AlertTypesEnum type)
        {
            string htmlClass = String.Empty;

            switch (type)
            {
            case AlertTypesEnum.Danger:
                htmlClass = "alert-danger";
                break;

            case AlertTypesEnum.Succes:
                htmlClass = "alert-success";
                break;

            case AlertTypesEnum.Warning:
                htmlClass = "alert-warning";
                break;
            }

            if (attributes.ContainsKey("class"))
            {
                attributes["class"] += " " + htmlClass;
            }
            else
            {
                attributes["class"] = htmlClass;
            }
        }