private void AddMails(IPlatformDataSource source, Guid adminId, Guid mainGroupId, string directory, List <MailContentTemplate> templateContent, EntityType mailType, string from, DateTime date, string[] supportedCultures)
        {
            var           allFiles  = Directory.GetFiles(directory).Where(f => !f.ToLower().Split('\\').Last().StartsWith("mailtemplate") && f.EndsWith(".html"));
            List <string> mailFiles = new List <string>();

            foreach (var file in allFiles)
            {
                var normalisedName = file.Contains("_") ? file.Split('_').First() + "." + file.Split('.').Last() : file;

                if (!mailFiles.Contains(normalisedName))
                {
                    mailFiles.Add(normalisedName);
                }
            }

            foreach (var mailFile in mailFiles)
            {
                var mailData = this._fileSystemWrapper.GetHtmlTemplate(directory, mailFile.Split('\\').Last().Split('.').First(), null);

                var entity = new PlatformEntity
                {
                    Id          = Guid.NewGuid(),
                    GroupId     = mainGroupId,
                    Url         = mailFile.Split('\\').Last().Split('.').First().ToLower(),
                    EntityType  = mailType,
                    OwnerUserId = adminId
                };

                source.Save(entity);

                foreach (var data in mailData.Where(t => supportedCultures.Contains(t.Culture.ToLower())))
                {
                    var template = templateContent.First(t => t.Culture == data.Culture);

                    var content = new MailContent
                    {
                        Id                = Guid.NewGuid(),
                        EntityId          = entity.Id,
                        Entity            = entity,
                        Template          = template,
                        TemplateId        = template.Id,
                        Culture           = data.Culture,
                        VersionNumber     = 1,
                        Name              = mailFile.Split('\\').Last().Split('.').First(),
                        CreatedByUserId   = adminId,
                        CreatedOn         = date,
                        UpdatedByUserId   = adminId,
                        UpdatedOn         = date,
                        IsCurrentVersion  = true,
                        PublishedByUserId = adminId,
                        PublishedOn       = date,
                        From              = from,
                        Subject           = data.Subject,
                        Body              = data.Body
                    };

                    source.Save(content);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create new content for an entity.
        /// </summary>
        /// <param name="entityType">The entity type for which to create the content</param>
        /// <param name="content">The content to use as source</param>
        /// <param name="entity">The entity to create the content for</param>
        /// <param name="currentUserId">The id of the currently active user creating the content</param>
        /// <returns>The new content</returns>
        private IContent CreateNewContent(Type entityType, IContent content, PlatformEntity entity, Guid currentUserId)
        {
            var theContent = this.Get(entityType, null) as IContent;

            if (!string.IsNullOrWhiteSpace(content.Culture))
            {
                theContent.Culture = content.Culture;
            }

            theContent.Id   = Guid.NewGuid();
            theContent.Name = content.Name;

            if (string.IsNullOrWhiteSpace(content.Entity.Url) && !string.IsNullOrWhiteSpace(content.Name))
            {
                theContent.Entity.Url = theContent.Name;
            }

            theContent.EntityId        = entity.Id;
            theContent.Entity          = entity;
            theContent.CreatedByUserId = currentUserId;
            theContent.CreatedOn       = DateTime.Now;
            theContent.UpdatedByUserId = currentUserId;
            theContent.UpdatedOn       = theContent.CreatedOn;
            return(theContent);
        }
Esempio n. 3
0
        /// <summary>
        /// If the content has an entity id, check whether a platform entity with this id exists. If
        /// the content has no entity id or no platform entity with the id exists, create a new
        /// platform entity.
        /// </summary>
        /// <param name="entityType">The type of the entity to create</param>
        /// <param name="currentUserId">The id of the currently active user creating the entity</param>
        /// <returns>The new entity</returns>
        private static PlatformEntity CreateEntity(Type entityType, Guid currentUserId)
        {
            var entity = new PlatformEntity
            {
                Id           = Guid.NewGuid(),
                EntityTypeId = EntityHelper.GetEntityTypeId(entityType),
                GroupId      = StrixPlatform.User.GroupId,
                OwnerUserId  = currentUserId
            };

            return(entity);
        }
        private List <MailContentTemplate> AddMailTemplate(IPlatformDataSource source, Guid adminId, Guid mainGroupId, string directory, EntityType mailTemplateType, DateTime date, string[] supportedCultures)
        {
            // Add the mail template
            var templateName = "Default";
            var templateData = this._fileSystemWrapper.GetHtmlTemplate(directory, "MailTemplate", null);
            List <MailContentTemplate> templateContent = new List <MailContentTemplate>();

            var templateEntity = new PlatformEntity
            {
                Id          = Guid.NewGuid(),
                GroupId     = mainGroupId,
                Url         = templateName.ToLower(),
                EntityType  = mailTemplateType,
                OwnerUserId = adminId
            };

            source.Save(templateEntity);

            foreach (var data in templateData.Where(t => supportedCultures.Contains(t.Culture.ToLower())))
            {
                var template = new MailContentTemplate
                {
                    Id                = Guid.NewGuid(),
                    EntityId          = templateEntity.Id,
                    Entity            = templateEntity,
                    Culture           = data.Culture,
                    VersionNumber     = 1,
                    Name              = "Default",
                    CreatedByUserId   = adminId,
                    CreatedOn         = date,
                    UpdatedByUserId   = adminId,
                    UpdatedOn         = date,
                    IsCurrentVersion  = true,
                    PublishedByUserId = adminId,
                    PublishedOn       = date,
                    Body              = data.Body
                };

                templateContent.Add(template);
                source.Save(template);
            }

            return(templateContent);
        }
        private void AddMails(IPlatformDataSource source, Guid adminId, Guid mainGroupId, string directory, List<MailContentTemplate> templateContent, EntityType mailType, string from, DateTime date, string[] supportedCultures)
        {
            var allFiles = Directory.GetFiles(directory).Where(f => !f.ToLower().Split('\\').Last().StartsWith("mailtemplate") && f.EndsWith(".html"));
            List<string> mailFiles = new List<string>();

            foreach (var file in allFiles)
            {
                var normalisedName = file.Contains("_") ? file.Split('_').First() + "." + file.Split('.').Last() : file;

                if (!mailFiles.Contains(normalisedName))
                {
                    mailFiles.Add(normalisedName);
                }
            }

            foreach (var mailFile in mailFiles)
            {
                var mailData = this._fileSystemWrapper.GetHtmlTemplate(directory, mailFile.Split('\\').Last().Split('.').First(), null);

                var entity = new PlatformEntity
                {
                    Id = Guid.NewGuid(),
                    GroupId = mainGroupId,
                    Url = mailFile.Split('\\').Last().Split('.').First().ToLower(),
                    EntityType = mailType,
                    OwnerUserId = adminId
                };

                source.Save(entity);

                foreach (var data in mailData.Where(t => supportedCultures.Contains(t.Culture.ToLower())))
                {
                    var template = templateContent.First(t => t.Culture == data.Culture);

                    var content = new MailContent
                    {
                        Id = Guid.NewGuid(),
                        EntityId = entity.Id,
                        Entity = entity,
                        Template = template,
                        TemplateId = template.Id,
                        Culture = data.Culture,
                        VersionNumber = 1,
                        Name = mailFile.Split('\\').Last().Split('.').First(),
                        CreatedByUserId = adminId,
                        CreatedOn = date,
                        UpdatedByUserId = adminId,
                        UpdatedOn = date,
                        IsCurrentVersion = true,
                        PublishedByUserId = adminId,
                        PublishedOn = date,
                        From = from,
                        Subject = data.Subject,
                        Body = data.Body
                    };

                    source.Save(content);
                }
            }
        }
        private List<MailContentTemplate> AddMailTemplate(IPlatformDataSource source, Guid adminId, Guid mainGroupId, string directory, EntityType mailTemplateType, DateTime date, string[] supportedCultures)
        {
            // Add the mail template
            var templateName = "Default";
            var templateData = this._fileSystemWrapper.GetHtmlTemplate(directory, "MailTemplate", null);
            List<MailContentTemplate> templateContent = new List<MailContentTemplate>();

            var templateEntity = new PlatformEntity
            {
                Id = Guid.NewGuid(),
                GroupId = mainGroupId,
                Url = templateName.ToLower(),
                EntityType = mailTemplateType,
                OwnerUserId = adminId
            };

            source.Save(templateEntity);

            foreach (var data in templateData.Where(t => supportedCultures.Contains(t.Culture.ToLower())))
            {
                var template = new MailContentTemplate
                {
                    Id = Guid.NewGuid(),
                    EntityId = templateEntity.Id,
                    Entity = templateEntity,
                    Culture = data.Culture,
                    VersionNumber = 1,
                    Name = "Default",
                    CreatedByUserId = adminId,
                    CreatedOn = date,
                    UpdatedByUserId = adminId,
                    UpdatedOn = date,
                    IsCurrentVersion = true,
                    PublishedByUserId = adminId,
                    PublishedOn = date,
                    Body = data.Body
                };

                templateContent.Add(template);
                source.Save(template);
            }

            return templateContent;
        }
Esempio n. 7
0
        /// <summary>
        /// Maps one content to another, preserving all important properties that should not be overwritten.
        /// </summary>
        /// <param name="entityType">The type of the content to map</param>
        /// <param name="first">The source content</param>
        /// <param name="second">The target content</param>
        private static void MapContent(Type entityType, IContent first, IContent second)
        {
            Guid           id                           = second.Id;
            Guid           entityId                     = second.EntityId;
            PlatformEntity entity                       = second.Entity;
            string         culture                      = second.Culture;
            bool           isCurrent                    = second.IsCurrentVersion;
            int            versionNumber                = second.VersionNumber;
            Guid           createdByUserId              = second.CreatedByUserId;
            DateTime       createdOn                    = second.CreatedOn;
            Guid           updatedByUserId              = second.UpdatedByUserId;
            DateTime       updatedOn                    = second.UpdatedOn;
            Guid?          publishedByUserId            = second.PublishedByUserId;
            DateTime?      publishedOn                  = second.PublishedOn;
            int            numberOfComments             = second.NumberOfComments;
            DateTime?      lastCommentDate              = second.LastCommentDate;
            IDictionary <string, object> fileValues     = GetFileValues(entityType, first, second);
            IDictionary <string, object> relationValues = GetRelationValues(entityType, first, second);

            first.Map(entityType, second);

            second.Id                = id;
            second.EntityId          = entityId;
            second.Entity            = entity;
            second.Culture           = culture;
            second.IsCurrentVersion  = isCurrent;
            second.VersionNumber     = versionNumber;
            second.CreatedByUserId   = createdByUserId;
            second.CreatedOn         = createdOn;
            second.UpdatedByUserId   = updatedByUserId;
            second.UpdatedOn         = updatedOn;
            second.PublishedByUserId = publishedByUserId;
            second.PublishedOn       = publishedOn;
            second.NumberOfComments  = numberOfComments;
            second.LastCommentDate   = lastCommentDate;

            if (fileValues.Count > 0)
            {
                int index = 0;

                foreach (var prop in fileValues.Keys)
                {
                    if (fileValues[prop] != null)
                    {
                        second.SetPropertyValue(prop, fileValues[prop]);
                    }

                    index++;
                }
            }

            if (relationValues.Count > 0)
            {
                int index = 0;

                foreach (var prop in relationValues.Keys)
                {
                    if (relationValues[prop] != null)
                    {
                        var collection  = second.GetPropertyValue(prop);
                        var values      = relationValues[prop];
                        var clearMethod = collection.GetType().GetMethod("Clear");
                        var addMethod   = collection.GetType().GetMethod("Add");
                        clearMethod.Invoke(collection, null);

                        foreach (var item in (IEnumerable <ValidationBase>)values)
                        {
                            addMethod.Invoke(collection, new object[] { item });
                        }
                    }

                    index++;
                }
            }
        }