public void NotifyAboutChanges(AuditableProperty property, object entity, string to)
        {
            var notificationAware = entity as IChangesNotificationAware;

            if (notificationAware != null && !notificationAware.ShouldNotify())
            {
                return;
            }

            var mailer = PropertyChanged(property, entity);

            mailer.To = to;
            mailer.Send();
        }
Example #2
0
        public void Change_Name_Full_Name()
        {
            var oldValue = client.Name;

            client.Name += "1";
            var property = new AuditableProperty(session, payer.GetType().GetProperty("Name"), "Наименование", client.Name, oldValue);

            mailer.NotifyAboutChanges(property, client, "*****@*****.**");
            Assert.That(message.IsBodyHtml, Is.False);
            Assert.That(message.Subject, Is.EqualTo("Изменено поле 'Наименование'"));
            Assert.That(message.To.ToString(), Is.EqualTo("*****@*****.**"));

            Assert.That(message.Body, Is.StringContaining("Плательщики Тестовый плательщик"));
            Assert.That(message.Body, Is.StringContaining("Изменено 'Наименование' было 'Тестовый клиент' стало 'Тестовый клиент1'"));
            Assert.That(message.Body, Is.StringContaining(DateTime.Now.Date.ToShortDateString()));
        }
        public SiteAuditableProperties AllPropertiesForDocType(string DocTypeAlias)
        {
            var allProps = new SiteAuditableProperties();

            allProps.PropsForDoctype = DocTypeAlias;
            List <AuditableProperty> propertiesList = new List <AuditableProperty>();

            var ct        = _services.ContentTypeService.GetContentType(DocTypeAlias);
            var propsDone = new List <int>();

            //First, compositions
            foreach (var comp in ct.ContentTypeComposition)
            {
                foreach (var group in comp.CompositionPropertyGroups)
                {
                    foreach (var prop in group.PropertyTypes)
                    {
                        AuditableProperty auditProp = PropertyTypeToAuditableProperty(prop);

                        auditProp.InComposition = comp.Name;
                        auditProp.GroupName     = group.Name;

                        propertiesList.Add(auditProp);
                        propsDone.Add(prop.Id);
                    }
                }
            }

            //Next, non-comp properties
            foreach (var group in ct.CompositionPropertyGroups)
            {
                foreach (var prop in group.PropertyTypes)
                {
                    //check if already added...
                    if (!propsDone.Contains(prop.Id))
                    {
                        AuditableProperty auditProp = PropertyTypeToAuditableProperty(prop);
                        auditProp.GroupName     = group.Name;
                        auditProp.InComposition = "~NONE";
                        propertiesList.Add(auditProp);
                    }
                }
            }

            allProps.AllProperties = propertiesList;
            return(allProps);
        }
        public SiteAuditableProperties AllProperties()
        {
            var allProps = new SiteAuditableProperties();

            allProps.PropsForDoctype = "[All]";
            List <AuditableProperty> propertiesList = new List <AuditableProperty>();

            var allDocTypes = _services.ContentTypeService.GetAllContentTypes();

            foreach (var docType in allDocTypes)
            {
                //var ct = _services.ContentTypeService.Get(docTypeAlias);

                foreach (var prop in docType.PropertyTypes)
                {
                    //test for the same property already in list
                    if (propertiesList.Exists(i => i.UmbPropertyType.Alias == prop.Alias & i.UmbPropertyType.Name == prop.Name & i.UmbPropertyType.DataTypeId == prop.DataTypeId))
                    {
                        //Add current DocType to existing property
                        var info = new PropertyDoctypeInfo();
                        info.Id           = docType.Id;
                        info.DocTypeAlias = docType.Alias;
                        info.GroupName    = "";
                        propertiesList.Find(i => i.UmbPropertyType.Alias == prop.Alias).AllDocTypes.Add(info);
                    }
                    else
                    {
                        //Add new property
                        AuditableProperty auditProp = PropertyTypeToAuditableProperty(prop);

                        var info = new PropertyDoctypeInfo();
                        info.DocTypeAlias = docType.Alias;
                        info.GroupName    = "";

                        auditProp.AllDocTypes.Add(info);
                        propertiesList.Add(auditProp);
                    }
                }
            }

            allProps.AllProperties = propertiesList;
            return(allProps);
        }
        private MonorailMailer PropertyChanged(AuditableProperty property, object entity)
        {
            var propertyMessage = property.Message;
            var notifyAware     = property as INotificationAware;

            if (notifyAware != null)
            {
                propertyMessage = notifyAware.NotifyMessage;
            }

            //может быть null если property решило что не нужно отправлять
            //уведомления для этого изменения
            //например: регион который был добавлен помечен как не уведомляемый
            if (String.IsNullOrEmpty(propertyMessage))
            {
                return(this);
            }

            Subject = String.Format("Изменено поле '{0}'", property.Name);
            if (property.IsHtml)
            {
                Template   = "PropertyChanged_html";
                IsBodyHtml = true;
            }
            else
            {
                Template   = "PropertyChanged_txt";
                IsBodyHtml = false;
            }
            var message = new StringBuilder();

            message.Append(GetAdditionalMessages(entity));
            if (propertyMessage.StartsWith("$$$"))
            {
                propertyMessage = propertyMessage.Remove(0, 3);
            }
            message.AppendLine(propertyMessage);

            GeneralizationPropertyChanged(entity, message.ToString());

            return(this);
        }
        public void Send(AuditableProperty property, object entity, string to)
        {
            try {
                MonorailMailer mailer;
                if (Sender != null)
                {
                    mailer = new MonorailMailer(Sender);
                }
                else
                {
                    mailer = new MonorailMailer();
                }
                mailer.UnderTest = UnderTest;

                mailer.NotifyAboutChanges(property, entity, to);
            }
            catch (Exception ex) {
                _log.Error("Ошибка отправки уведомлений об изменении наблюдаемых полей", ex);
            }
        }
        /// <summary>
        /// Meta data about a Property for Auditing purposes.
        /// </summary>
        /// <param name="UmbPropertyType"></param>
        private AuditableProperty PropertyTypeToAuditableProperty(PropertyType UmbPropertyType)
        {
            var ap = new AuditableProperty();

            ap.UmbPropertyType = UmbPropertyType;

            ap.DataType = _services.DataTypeService.GetDataTypeDefinitionById(UmbPropertyType.DataTypeId);

            //ap.DataTypeConfigType = ap.DataType.AdditionalData.GetType();
            try
            {
                var configDict = ap.DataType.AdditionalData;
                ap.DataTypeConfigDictionary = configDict;
            }
            catch (Exception e)
            {
                //ignore
                ap.DataTypeConfigDictionary = new Dictionary <string, object>();
            }

            //var  docTypes = AuditHelper.GetDocTypesForProperty(UmbPropertyType.Alias);
            // this.DocTypes = new List<string>();

            if (ap.DataType.PropertyEditorAlias.Contains("NestedContent"))
            {
                ap.IsNestedContent = true;
                var config = new NestedContentConfig(ap.DataType.AdditionalData);
                //var contentJson = ["contentTypes"];

                //var types = JsonConvert
                //    .DeserializeObject<IEnumerable<NestedContentContentTypesConfigItem>>(contentJson);
                ap.NestedContentDocTypesConfig = config.ContentTypes;
            }

            return(ap);
        }