Пример #1
0
        /*private string CreateFolderPath(IMediaFileFolder folder)
         * {
         *  string folderName = this.GetBinding<string>("FolderName");
         *
         *  string folderPath = folder.Path;
         *
         *  if (folderPath == "/")
         *  {
         *      folderPath = folderPath + folderName;
         *  }
         *  else
         *  {
         *      folderPath = folderPath + "/" + folderName;
         *  }
         *
         *  folderPath = folderPath.Replace('\\', '/');
         *  while (folderPath.Contains("//"))
         *  {
         *      folderPath.Replace("//", "/");
         *  }
         *
         *  if ((folderPath != "/") && (folderPath.StartsWith("/")))
         *  {
         *      folderPath.Remove(0, 1);
         *  }
         *
         *  return folderPath;
         * }*/


        private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IMediaFileFolder folder       = this.GetBinding <IMediaFileFolder>("NewFolder");
            string           folderName   = this.GetBinding <string>("FolderName");
            string           providerName = this.GetBinding <string>("ProviderName");

            string folderPath = folder.CreateFolderPath(folderName);

            folder.Path = folderPath;

            if (folder.Title == string.Empty)
            {
                folder.Title = folderPath.GetFolderName('/');
            }

            CreateParentFolder(folder.GetParentFolderPath(), providerName);

            folder = DataFacade.AddNew <IMediaFileFolder>(folder, providerName);

            addNewTreeRefresher.PostRefreshMesseges(folder.GetDataEntityToken());

            SelectElement(folder.GetDataEntityToken());
        }
        private static XElement AddData(DataType dataType, CultureInfo cultureInfo)
        {
            XElement datasElement = new XElement("Datas");

            if (cultureInfo != null)
            {
                datasElement.Add(new XAttribute("locale", cultureInfo.Name));
            }

            foreach (XElement addElement in dataType.Dataset)
            {
                IData data = DataFacade.BuildNew(dataType.InterfaceType);

                if (!dataType.InterfaceType.IsInstanceOfType(data))
                {
                    dataType.InterfaceType = GetInstalledVersionOfPendingType(dataType.InterfaceType, data);
                }

                var properties = GetDataTypeProperties(dataType.InterfaceType);

                foreach (XAttribute attribute in addElement.Attributes())
                {
                    string fieldName = attribute.Name.LocalName;
                    if (IsObsoleteField(dataType, fieldName))
                    {
                        continue;
                    }

                    PropertyInfo propertyInfo = properties[fieldName];

                    propertyInfo.SetValue(data, ValueTypeConverter.Convert(attribute.Value, propertyInfo.PropertyType), null);
                }

                ILocalizedControlled localizedControlled = data as ILocalizedControlled;
                if (localizedControlled != null)
                {
                    localizedControlled.SourceCultureName = LocalizationScopeManager.MapByType(dataType.InterfaceType).Name;
                }

                DataFacade.AddNew(data, false, true, false); // Ignore validation, this should have been done in the validation face

                XElement keysElement = new XElement("Keys");

                foreach (PropertyInfo propertyInfo in data.GetKeyProperties())
                {
                    string keyName  = propertyInfo.Name;
                    object keyValue = propertyInfo.GetValue(data, null);

                    XElement keyElement = new XElement("Key",
                                                       new XAttribute("name", keyName),
                                                       new XAttribute("value", keyValue));

                    keysElement.Add(keyElement);
                }

                datasElement.Add(keysElement);
            }

            return(datasElement);
        }
Пример #3
0
        internal static void RegisterConsole(string username, string consoleId)
        {
            using (GlobalInitializerFacade.CoreIsInitializedScope)
                lock (_lock)
                {
                    IUserConsoleInformation userConsoleInformation =
                        (from d in DataFacade.GetData <IUserConsoleInformation>()
                         where d.Username == username &&
                         d.ConsoleId == consoleId
                         select d).FirstOrDefault();

                    if (userConsoleInformation == null)
                    {
                        Log.LogVerbose(LogTitle, $"New console registred by '{username}' id = '{consoleId}'");

                        userConsoleInformation           = DataFacade.BuildNew <IUserConsoleInformation>();
                        userConsoleInformation.Id        = Guid.NewGuid();
                        userConsoleInformation.Username  = username;
                        userConsoleInformation.ConsoleId = consoleId;
                        userConsoleInformation.TimeStamp = DateTime.Now;
                        DataFacade.AddNew <IUserConsoleInformation>(userConsoleInformation);
                    }
                    else
                    {
                        userConsoleInformation.TimeStamp = DateTime.Now;
                        DataFacade.Update(userConsoleInformation);
                    }
                }
        }
Пример #4
0
        /// <exclude />
        public static void AddZip(string providerName, string parentPath, Stream compressedStream, bool recreateDirStructure, bool overwrite)
        {
            if (string.IsNullOrEmpty(providerName))
            {
                throw new ArgumentNullException("providerName");
            }
            if (string.IsNullOrEmpty(parentPath))
            {
                throw new ArgumentNullException("parentPath");
            }

            IList <IMediaFile>       files;
            IList <IMediaFileFolder> folders;

            Extract(parentPath, compressedStream, out folders, out files);

            if (recreateDirStructure)
            {
                FolderComparer folderComparer = new FolderComparer();
                IEnumerable <IMediaFileFolder> currentDirs  = DataFacade.GetData <IMediaFileFolder>().Where(x => x.Path.StartsWith(parentPath));
                IEnumerable <IMediaFileFolder> intersection = currentDirs.Intersect(folders, folderComparer);
                folders = folders.Except(intersection, folderComparer).ToList();

                DataFacade.AddNew <IMediaFileFolder>(folders, providerName);
                AddFiles(providerName, files, overwrite);
            }
            else
            {
                foreach (IMediaFile file in files)
                {
                    file.FolderPath = parentPath;
                }
                AddFiles(providerName, files, overwrite);
            }
        }
Пример #5
0
        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            IPageTypeDefaultPageContent defaultPageContent = this.GetBinding <IPageTypeDefaultPageContent>("DefaultPageContent");

            Dictionary <string, string> piggybag = PiggybagSerializer.Deserialize(this.ExtraPayload);

            DataEntityToken dataEntityToken = piggybag.GetParentEntityTokens().FindDataEntityToken(typeof(IPageType));
            IPageType       parentPageType  = (IPageType)dataEntityToken.Data;

            defaultPageContent.PageTypeId = parentPageType.Id;
            defaultPageContent.Content    = " ";

            defaultPageContent = DataFacade.AddNew <IPageTypeDefaultPageContent>(defaultPageContent);

            this.CloseCurrentView();
            this.RefreshCurrentEntityToken();

            if (!AnyTemplatesContainingPlaceholderId())
            {
                ShowMessage(C1Console.Events.DialogType.Message,
                            string.Format(RS.GetString("Composite.Plugins.PageTypeElementProvider", "PageType.AddPageTypeDefaultPageContentWorkflow.NonExistingPlaceholderId.Title"), defaultPageContent.PlaceHolderId),
                            string.Format(RS.GetString("Composite.Plugins.PageTypeElementProvider", "PageType.AddPageTypeDefaultPageContentWorkflow.NonExistingPlaceholderId.Message"), defaultPageContent.PlaceHolderId));
            }

            this.ExecuteWorklow(defaultPageContent.GetDataEntityToken(), WorkflowFacade.GetWorkflowType("Composite.Plugins.Elements.ElementProviders.PageTypeElementProvider.EditPageTypeDefaultPageContentWorkflow"));
        }
Пример #6
0
        public Guid AddPost(string title, string description, string publicationStatus)
        {
            IPage page = PageManager.GetPageById(PageId, true);

            if (page != null)
            {
                var entry = DataFacade.BuildNew <Entries>();
                entry.Date              = DateTime.Now;
                entry.Title             = title;
                entry.Content           = RelativeMediaUrl(MarkupTransformationServices.TidyHtml(description).Output.Root);
                entry.PublicationStatus = publicationStatus;
                entry.Tags              = string.Empty;
                entry.Teaser            = string.Empty;
                entry.Author            = Author.Id;
                PageFolderFacade.AssignFolderDataSpecificValues(entry, page);
                entry = DataFacade.AddNew(entry);

                if (publicationStatus == GenericPublishProcessController.Published)
                {
                    entry.PublicationStatus = publicationStatus;
                    DataFacade.Update(entry);
                }
                return(entry.Id);
            }
            return(Guid.Empty);
        }
Пример #7
0
            public void CreateMainMenu(string primaryParentCategoryId, Guid?parentMainMenuId, int depth)
            {
                if (depth == 0)
                {
                    return;
                }
                Categories.Where(d => d.PrimaryParentCategoryId == primaryParentCategoryId).ToList().ForEach(cat =>
                {
                    Guid pageId;
                    if (PageIds.TryGetValue(cat.Id, out pageId))
                    {
                        var mainMenu               = DataFacade.BuildNew <MainMenu>();
                        mainMenu.Id                = GuidUtility.Create(NavigationNamespaces.MainMenuNamespaceId, cat.Id);
                        mainMenu.PageId            = WebsiteId;
                        mainMenu.DisplayName       = GetLocalizedDisplayName(cat.Id, cat.DisplayName, Culture);
                        mainMenu.CssClassName      = string.Empty;
                        mainMenu.ParentId          = parentMainMenuId;
                        mainMenu.Url               = $"~/page({pageId})";
                        mainMenu.PublicationStatus = GenericPublishProcessController.Draft;

                        TruncateStrings(cat.Id, mainMenu);

                        mainMenu = DataFacade.AddNew(mainMenu);

                        mainMenu.PublicationStatus = GenericPublishProcessController.Published;
                        DataFacade.Update(mainMenu);

                        CreateMainMenu(cat.Id, mainMenu.Id, depth - 1);
                    }
                });
            }
Пример #8
0
        private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            UpdateTreeRefresher updateTreeRefresher = this.CreateUpdateTreeRefresher(this.EntityToken);

            WorkflowActionToken workflowActionToken = (WorkflowActionToken)this.ActionToken;

            string folderPath = null;

            if (this.EntityToken is WebsiteFileElementProviderRootEntityToken)
            {
                folderPath = "";
            }
            else
            {
                WebsiteFileElementProviderEntityToken entityToken = (WebsiteFileElementProviderEntityToken)this.EntityToken;
                folderPath = entityToken.Path;
            }

            string keyName = workflowActionToken.Payload;

            string relativeFolderPath = IFolderWhiteListExtensions.GetTildePath(folderPath);

            if (!DataFacade.GetData <IFolderWhiteList>().Any(f => f.TildeBasedPath == relativeFolderPath && f.KeyName == keyName))
            {
                IFolderWhiteList folderWhiteList = DataFacade.BuildNew <IFolderWhiteList>();
                folderWhiteList.KeyName        = keyName;
                folderWhiteList.TildeBasedPath = IFolderWhiteListExtensions.GetTildePath(folderPath);
                DataFacade.AddNew(folderWhiteList);
            }

            updateTreeRefresher.PostRefreshMesseges(this.EntityToken);
        }
Пример #9
0
        public string NewMediaObject(FileData mediaObject)
        {
            var mediaFile = new WorkflowMediaFile
            {
                FileName = mediaObject.name,
                Title    = mediaObject.name,
                Culture  = DataLocalizationFacade.DefaultLocalizationCulture.Name,
                Length   = mediaObject.bits.Count(),
                MimeType = MimeTypeInfo.GetCanonical(mediaObject.type)
            };

            if (mediaFile.MimeType == MimeTypeInfo.Default)
            {
                mediaFile.MimeType = MimeTypeInfo.GetCanonicalFromExtension(Path.GetExtension(mediaFile.FileName));
            }

            using (Stream readStream = new MemoryStream(mediaObject.bits))
            {
                using (Stream writeStream = mediaFile.GetNewWriteStream())
                {
                    readStream.CopyTo(writeStream);
                }
            }
            string folderPath = string.Format("/Blog/{0}/{1:yyyy-MM-dd}", Author.Name, DateTime.Now);

            mediaFile.FolderPath = ForceGetMediaFolderPath(folderPath);
            var addedFile = DataFacade.AddNew <IMediaFile>(mediaFile);

            return(MediaUrlHelper.GetUrl(addedFile));
        }
        /// <summary>
        /// Gets all meta data containers ordered. If none exists in the system, a default is created
        /// </summary>
        /// <returns></returns>
        public static List <KeyValuePair <Guid, string> > GetAllMetaDataContainers()
        {
            List <KeyValuePair <Guid, string> > containers;

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                bool anyExists = DataFacade.GetData <ICompositionContainer>().Any();

                if (anyExists == false)
                {
                    ICompositionContainer defaultContainer = DataFacade.BuildNew <ICompositionContainer>();

                    defaultContainer.Id    = DefaultCompositionContainerId;
                    defaultContainer.Label = "${Composite.Management, DataCompositionVisabilityFacade.DefaultContainerLabel}";

                    DataFacade.AddNew <ICompositionContainer>(defaultContainer);
                }

                containers =
                    DataFacade.GetData <ICompositionContainer>().
                    OrderBy(f => f.Label).
                    Select(f => new KeyValuePair <Guid, string>(f.Id, f.Label)).
                    ToList();

                transactionScope.Complete();
            }

            return(containers);
        }
Пример #11
0
        private void UpdatePageTypeTreeLinks(IPageType pageType)
        {
            List <string> selectedTreeIds = this.GetBinding <List <string> >("ApplicationSelected");

            var pageTypeTreeLinks = DataFacade.GetData <IPageTypeTreeLink>()
                                    .Where(f => f.PageTypeId == pageType.Id).Evaluate();

            // Remove deselected
            foreach (IPageTypeTreeLink treeLink in pageTypeTreeLinks)
            {
                if (!selectedTreeIds.Contains(treeLink.TreeId))
                {
                    DataFacade.Delete <IPageTypeTreeLink>(treeLink);
                }
            }

            // Add newly selected
            foreach (string treeId in selectedTreeIds)
            {
                if (!pageTypeTreeLinks.Any(f => f.TreeId == treeId))
                {
                    IPageTypeTreeLink pageTypeTreeLink = DataFacade.BuildNew <IPageTypeTreeLink>();
                    pageTypeTreeLink.Id         = Guid.NewGuid();
                    pageTypeTreeLink.PageTypeId = pageType.Id;
                    pageTypeTreeLink.TreeId     = treeId;

                    DataFacade.AddNew <IPageTypeTreeLink>(pageTypeTreeLink);
                }
            }
        }
Пример #12
0
        internal static void InsertIntoPositionInternal(Guid newPageId, Guid parentId, int localOrder)
        {
            List <IPageStructure> pageStructures =
                (from ps in DataFacade.GetData <IPageStructure>(false)
                 where ps.ParentId == parentId
                 orderby ps.LocalOrdering
                 select ps).ToList();

            var toBeUpdated = new List <IData>();

            for (int i = 0; i < pageStructures.Count; i++)
            {
                int newSortOrder = i < localOrder ? i : i + 1;
                if (pageStructures[i].LocalOrdering != newSortOrder)
                {
                    pageStructures[i].LocalOrdering = newSortOrder;
                    toBeUpdated.Add(pageStructures[i]);
                }
            }

            DataFacade.Update(toBeUpdated);

            if (localOrder > pageStructures.Count)
            {
                localOrder = pageStructures.Count;
            }

            var newPageStructure = DataFacade.BuildNew <IPageStructure>();

            newPageStructure.Id            = newPageId;
            newPageStructure.ParentId      = parentId;
            newPageStructure.LocalOrdering = localOrder;

            DataFacade.AddNew(newPageStructure);
        }
        /// <exclude />
        public static void AddNewMetaDataToExistingPage(this IPage page, string metaDataDefinitionName, Type metaDataType, IData newDataTemplate)
        {
            IData data = page.GetMetaData(metaDataDefinitionName, metaDataType);

            if (data != null)
            {
                return;
            }

            IPublishControlled newData = DataFacade.BuildNew(metaDataType) as IPublishControlled;

            newDataTemplate.FullCopyChangedTo(newData);
            newData.PublicationStatus = GenericPublishProcessController.Draft;

            PageMetaDataFacade.AssignMetaDataSpecificValues(newData, metaDataDefinitionName, page);

            ILocalizedControlled localizedData = newData as ILocalizedControlled;

            if (localizedData != null)
            {
                localizedData.SourceCultureName = page.SourceCultureName;
            }

            newData = (IPublishControlled)DataFacade.AddNew((IData)newData); // Cast is needed for the DataFacade to work correctly

            if (newData.PublicationStatus != page.PublicationStatus)
            {
                newData.PublicationStatus = page.PublicationStatus;
                DataFacade.Update(newData);
            }
        }
        private static void AddNewMetaDataToExistingPages(IEnumerable <IPage> affectedPages, string metaDataDefinitionName, Type metaDataType, IData newDataTemplate)
        {
            foreach (IPage affectedPage in affectedPages)
            {
                IData data = affectedPage.GetMetaData(metaDataDefinitionName, metaDataType);
                if (data != null)
                {
                    continue;
                }

                IPublishControlled newData = DataFacade.BuildNew(metaDataType) as IPublishControlled;
                newDataTemplate.FullCopyChangedTo(newData);
                newData.PublicationStatus = GenericPublishProcessController.Draft;
                PageMetaDataFacade.AssignMetaDataSpecificValues(newData, metaDataDefinitionName, affectedPage);

                ILocalizedControlled localizedData = newData as ILocalizedControlled;
                if (localizedData != null)
                {
                    localizedData.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name;
                }

                newData = DataFacade.AddNew((IData)newData) as IPublishControlled;

                if (newData.PublicationStatus != affectedPage.PublicationStatus)
                {
                    newData.PublicationStatus = affectedPage.PublicationStatus;
                    DataFacade.Update(newData);
                }
            }
        }
        private static void SavePasswordHistory(IUserFormLogin userFormLogin)
        {
            if (string.IsNullOrEmpty(userFormLogin.PasswordHash) || PasswordPolicyFacade.PasswordHistoryLength <= 0)
            {
                return;
            }

            var passwordHistoryRecord = DataFacade.BuildNew <IUserPasswordHistory>();

            passwordHistoryRecord.Id           = Guid.NewGuid();
            passwordHistoryRecord.UserId       = userFormLogin.UserId;
            passwordHistoryRecord.SetDate      = userFormLogin.LastPasswordChangeDate;
            passwordHistoryRecord.PasswordSalt = userFormLogin.PasswordHashSalt;
            passwordHistoryRecord.PasswordHash = userFormLogin.PasswordHash;

            DataFacade.AddNew(passwordHistoryRecord);

            // Cleaning up old history records
            Guid userId = userFormLogin.UserId;
            var  passwordDataToBeRemoved = DataFacade.GetData <IUserPasswordHistory>()
                                           .Where(uph => uph.UserId == userId)
                                           .OrderByDescending(uph => uph.SetDate).Skip(PasswordPolicyFacade.PasswordHistoryLength).ToList();

            if (passwordDataToBeRemoved.Any())
            {
                DataFacade.Delete((IEnumerable <IData>)passwordDataToBeRemoved);
            }
        }
        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            IPageTypeMetaDataTypeLink pageTypeMetaDataTypeLink = this.GetBinding<IPageTypeMetaDataTypeLink>("NewMetaDataTypeLink");
            IData newDataTemplate;
            this.TryGetBinding("NewDataTemplate", out newDataTemplate);

            string metaDataDefinitionName = this.GetBinding<string>("CompositionDescriptionName");
            pageTypeMetaDataTypeLink.Name = metaDataDefinitionName;

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                DataFacade.AddNew<IPageTypeMetaDataTypeLink>(pageTypeMetaDataTypeLink);

                PageMetaDataFacade.AddDefinition(
                    pageTypeMetaDataTypeLink.PageTypeId,
                    metaDataDefinitionName,
                    this.GetBinding<string>("CompositionDescriptionLabel"),
                    pageTypeMetaDataTypeLink.DataTypeId,
                    this.GetBinding<Guid>("CompositionContainerId")
                );


                if (newDataTemplate != null)
                {
                    IPageType pageType = DataFacade.GetData<IPageType>().Single(f => f.Id == pageTypeMetaDataTypeLink.PageTypeId);

                    PageMetaDataFacade.AddNewMetaDataToExistingPages(pageType, metaDataDefinitionName, newDataTemplate);
                }

                transactionScope.Complete();
            }

            this.RefreshCurrentEntityToken();
        }
        public override void OnFinish(object sender, EventArgs e)
        {
            Teaser.Name              = GetBinding <string>("Name");
            Teaser.Position          = GetBinding <string>("Position");
            Teaser.AdditionalHeader  = GetBinding <string>("AdditionalHeader");
            Teaser.ShowOnDescendants = GetBinding <bool>("ShowOnDescendants");
            Teaser.PublishDate       = GetBinding <DateTime?>("PublishDate");
            Teaser.UnpublishDate     = GetBinding <DateTime?>("UnpublishDate");

            SaveBindings();

            if (EntityToken is PageTeaserInstanceEntityToken)
            {
                DataFacade.Update(Teaser);
            }
            else
            {
                var page = PageManager.GetPageById(new Guid(EntityToken.Source));

                Teaser.Id     = Guid.NewGuid();
                Teaser.PageId = page.Id;

                DataFacade.AddNew(Teaser);
            }

            CreateSpecificTreeRefresher().PostRefreshMesseges(EntityToken);
            SetSaveStatus(true);
        }
Пример #18
0
        private void UpdatePageTemplateResctrictions(IPageType pageType)
        {
            List <Guid> selectedPageTemplateIds = this.GetBinding <List <Guid> >("TemplateRestrictionSelected");

            IEnumerable <IPageTypePageTemplateRestriction> pageTypePageTemplateRestrictions = DataFacade.GetData <IPageTypePageTemplateRestriction>().Where(f => f.PageTypeId == pageType.Id).Evaluate();

            // Remove deselected
            foreach (IPageTypePageTemplateRestriction restriction in pageTypePageTemplateRestrictions)
            {
                if (selectedPageTemplateIds.Contains(restriction.PageTemplateId) == false)
                {
                    DataFacade.Delete <IPageTypePageTemplateRestriction>(restriction);
                }
            }

            // Add newly selected
            foreach (Guid templateId in selectedPageTemplateIds)
            {
                if (pageTypePageTemplateRestrictions.Where(f => f.PageTemplateId == templateId).Any() == false)
                {
                    IPageTypePageTemplateRestriction pageTypePageTemplateRestriction = DataFacade.BuildNew <IPageTypePageTemplateRestriction>();
                    pageTypePageTemplateRestriction.Id             = Guid.NewGuid();
                    pageTypePageTemplateRestriction.PageTypeId     = pageType.Id;
                    pageTypePageTemplateRestriction.PageTemplateId = templateId;

                    DataFacade.AddNew <IPageTypePageTemplateRestriction>(pageTypePageTemplateRestriction);
                }
            }
        }
Пример #19
0
        private static void AddLockingInformation(EntityToken entityToken, object ownerId)
        {
            LockingInformation lockingInformation;

            if (_lockingInformations.TryGetValue(entityToken, out lockingInformation))
            {
                if (object.Equals(lockingInformation.OwnerId, ownerId))
                {
                    // NO OP: The owner may acquire a lock multiple times
                    return;
                }

                // This will only happen if an entity token subclass is not rightly implemented
                throw new ActionLockingException("This item is used by another user, try again.");
            }

            lockingInformation = new LockingInformation
            {
                Username = UserValidationFacade.GetUsername(),
                OwnerId  = ownerId
            };

            string serializedOwnerId = SerializeOwnerId(lockingInformation.OwnerId);

            ILockingInformation li = DataFacade.BuildNew <ILockingInformation>();

            li.Id = Guid.NewGuid();
            li.SerializedEntityToken = EntityTokenSerializer.Serialize(entityToken);
            li.SerializedOwnerId     = serializedOwnerId;
            li.Username = lockingInformation.Username;

            DataFacade.AddNew <ILockingInformation>(li);
            _lockingInformations.Add(entityToken, lockingInformation);
        }
Пример #20
0
        /// <exclude />
        public override IEnumerable <XElement> Install()
        {
            foreach (string usergroupName in _names)
            {
                IUserGroup userGroup = DataFacade.GetData <IUserGroup>().SingleOrDefault(f => f.Name == usergroupName);
                if (userGroup == null)
                {
                    continue;
                }

                IEnumerable <IUser> users = DataFacade.GetData <IUser>().Evaluate();

                foreach (IUser user in users)
                {
                    var userUserGroupRelation = DataFacade.BuildNew <IUserUserGroupRelation>();
                    userUserGroupRelation.UserId      = user.Id;
                    userUserGroupRelation.UserGroupId = userGroup.Id;
                    DataFacade.AddNew <IUserUserGroupRelation>(userUserGroupRelation);
                }

                foreach (var cultureInfo in DataLocalizationFacade.ActiveLocalizationCultures)
                {
                    var userGroupActiveLocale = DataFacade.BuildNew <IUserGroupActiveLocale>();
                    userGroupActiveLocale.UserGroupId = userGroup.Id;
                    userGroupActiveLocale.CultureName = cultureInfo.Name;
                    DataFacade.AddNew <IUserGroupActiveLocale>(userGroupActiveLocale);
                }
            }

            yield break;
        }
Пример #21
0
        private void UpdatePageTypeParentResctrictions(IPageType pageType)
        {
            List <Guid> selectedPageTypeParentRestrictions = this.GetBinding <List <Guid> >("PageTypeChildRestrictionSelected");

            var pageTypeParentRestrictions = DataFacade.GetData <IPageTypeParentRestriction>()
                                             .Where(f => f.PageTypeId == pageType.Id).Evaluate();

            // Remove deselected
            foreach (IPageTypeParentRestriction restriction in pageTypeParentRestrictions)
            {
                if (!selectedPageTypeParentRestrictions.Contains(restriction.AllowedParentPageTypeId))
                {
                    DataFacade.Delete(restriction);
                }
            }

            // Add newly selected
            foreach (Guid templateId in selectedPageTypeParentRestrictions)
            {
                if (!pageTypeParentRestrictions.Any(f => f.AllowedParentPageTypeId == templateId))
                {
                    var pageTypeParentRestriction = DataFacade.BuildNew <IPageTypeParentRestriction>();
                    pageTypeParentRestriction.Id         = Guid.NewGuid();
                    pageTypeParentRestriction.PageTypeId = pageType.Id;
                    pageTypeParentRestriction.AllowedParentPageTypeId = templateId;

                    DataFacade.AddNew(pageTypeParentRestriction);
                }
            }
        }
Пример #22
0
        private void UpdatePageTypeDataFolderTypeLinks(IPageType pageType)
        {
            List <Guid> selectedDataFolderTypeIds = this.GetBinding <List <Guid> >("DataFolderSelected");

            var pageTypeDateFolderTypeLinks = DataFacade.GetData <IPageTypeDataFolderTypeLink>()
                                              .Where(f => f.PageTypeId == pageType.Id).Evaluate();

            // Remove deselected
            foreach (IPageTypeDataFolderTypeLink dataFolderTypeLink in pageTypeDateFolderTypeLinks)
            {
                if (!selectedDataFolderTypeIds.Contains(dataFolderTypeLink.DataTypeId))
                {
                    DataFacade.Delete(dataFolderTypeLink);
                }
            }

            // Add newly selected
            foreach (Guid dataFolderTypeId in selectedDataFolderTypeIds)
            {
                if (!pageTypeDateFolderTypeLinks.Any(f => f.DataTypeId == dataFolderTypeId))
                {
                    IPageTypeDataFolderTypeLink pageTypeDateFolderTypeLink = DataFacade.BuildNew <IPageTypeDataFolderTypeLink>();
                    pageTypeDateFolderTypeLink.Id         = Guid.NewGuid();
                    pageTypeDateFolderTypeLink.PageTypeId = pageType.Id;
                    pageTypeDateFolderTypeLink.DataTypeId = dataFolderTypeId;

                    DataFacade.AddNew(pageTypeDateFolderTypeLink);
                }
            }
        }
Пример #23
0
        /// <exclude />
        public static void SetCustomForm(DataTypeDescriptor dataTypeDescriptor, string newFormMarkup)
        {
            string dynamicDataFormFolderPath = GetFolderPath(dataTypeDescriptor.Namespace);
            string dynamicDataFormFileName   = GetFilename(dataTypeDescriptor.Name);

            // Parsing for assertion
            XDocument.Parse(newFormMarkup);

            IDynamicTypeFormDefinitionFile formDefinitionFile =
                DataFacade.GetData <IDynamicTypeFormDefinitionFile>()
                .FirstOrDefault(f => f.FolderPath.Equals(dynamicDataFormFolderPath, StringComparison.OrdinalIgnoreCase) &&
                                f.FileName.Equals(dynamicDataFormFileName, StringComparison.OrdinalIgnoreCase));

            if (formDefinitionFile == null)
            {
                var newFile = DataFacade.BuildNew <IDynamicTypeFormDefinitionFile>();
                newFile.FolderPath = dynamicDataFormFolderPath;
                newFile.FileName   = dynamicDataFormFileName;
                newFile.SetNewContent(newFormMarkup);
                formDefinitionFile = DataFacade.AddNew <IDynamicTypeFormDefinitionFile>(newFile);
            }
            else
            {
                formDefinitionFile.SetNewContent(newFormMarkup);
                DataFacade.Update(formDefinitionFile);
            }
        }
Пример #24
0
        public bool AddPersistedAttachmentPoint(string treeId, Type interfaceType, object keyValue, ElementAttachingProviderPosition position = ElementAttachingProviderPosition.Top)
        {
            var attachmentPoint = DataFacade.BuildNew <IDataItemTreeAttachmentPoint>();

            attachmentPoint.Id            = Guid.NewGuid();
            attachmentPoint.TreeId        = treeId;
            attachmentPoint.Position      = position.ToString();
            attachmentPoint.InterfaceType = TypeManager.SerializeType(interfaceType);
            attachmentPoint.KeyValue      = ValueTypeConverter.Convert <string>(keyValue);

            bool added = false;

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                bool exist =
                    (from d in DataFacade.GetData <IDataItemTreeAttachmentPoint>()
                     where d.InterfaceType == attachmentPoint.InterfaceType && d.KeyValue == attachmentPoint.KeyValue && d.TreeId == treeId
                     select d).Any();

                if (!exist)
                {
                    DataFacade.AddNew <IDataItemTreeAttachmentPoint>(attachmentPoint);
                    added = true;
                }

                transactionScope.Complete();
            }

            return(added);
        }
Пример #25
0
        /// <exclude />
        public bool OnAfterDataUpdated(IData data)
        {
            DataFacade.RemoveDataTag(data, _oldPublishedStatusTag);

            if (!data.DataSourceId.DataScopeIdentifier.Equals(DataScopeIdentifier.Administrated))
            {
                return(false);
            }

            var publishControlled = (IPublishControlled)data;

            if (publishControlled.PublicationStatus == Published)
            {
                using (new DataScope(DataScopeIdentifier.Public))
                {
                    var existing = DataFacade.GetDataFromOtherScope((IData)publishControlled, DataScopeIdentifier.Public).Evaluate();

                    if (existing.Any())
                    {
                        DataFacade.Delete(existing, CascadeDeleteType.Disable);
                    }

                    DataFacade.AddNew(data);
                }

                return(true);
            }

            // Check when do we have this situation
            return(false);
        }
Пример #26
0
        /// <exclude />
        public static void AddZip(string providerName, string parentPath, Stream compressedStream, bool recreateDirStructure, bool overwrite)
        {
            Verify.ArgumentNotNullOrEmpty(providerName, nameof(providerName));
            Verify.ArgumentNotNullOrEmpty(parentPath, nameof(parentPath));

            IList <IMediaFile>       files;
            IList <IMediaFileFolder> folders;

            Extract(parentPath, compressedStream, out folders, out files);

            if (recreateDirStructure)
            {
                var folderComparer = new FolderComparer();
                var currentDirs    = DataFacade.GetData <IMediaFileFolder>().Where(x => x.Path.StartsWith(parentPath));
                folders = folders.Except(currentDirs, folderComparer).ToList();

                DataFacade.AddNew <IMediaFileFolder>(folders, providerName);
                AddFiles(providerName, files, overwrite);
            }
            else
            {
                foreach (IMediaFile file in files)
                {
                    file.FolderPath = parentPath;
                }
                AddFiles(providerName, files, overwrite);
            }
        }
Пример #27
0
        public override IEnumerable <System.Xml.Linq.XElement> Install()
        {
            // grant Perspective permissions to the current user
            string perspectiveName       = "Composite.Tools.PackageCreator";
            var    entityToken           = new VirtualElementProviderEntityToken("VirtualElementProvider", perspectiveName);
            var    serializedEntityToken = EntityTokenSerializer.Serialize(entityToken);

            var sitemapPerspective = DataFacade.BuildNew <IUserGroupActivePerspective>();
            var userGroup          = DataFacade.GetData <IUserGroup>().FirstOrDefault(u => u.Name == "Administrator");

            if (userGroup != null)
            {
                sitemapPerspective.UserGroupId           = userGroup.Id;
                sitemapPerspective.SerializedEntityToken = serializedEntityToken;
                sitemapPerspective.Id = Guid.NewGuid();
                DataFacade.AddNew(sitemapPerspective);
                Log.LogInformation("Composite.Tools.PackageCreator", $"Access to the '{perspectiveName}' granted for user group '{userGroup.Name}'.");
            }

            if (UserValidationFacade.IsLoggedIn())
            {
                var activePerspective = DataFacade.BuildNew <IUserActivePerspective>();
                activePerspective.Username = C1Console.Users.UserSettings.Username;
                activePerspective.SerializedEntityToken = serializedEntityToken;
                activePerspective.Id = Guid.NewGuid();

                DataFacade.AddNew <IUserActivePerspective>(activePerspective);
                Log.LogInformation("Composite.Tools.PackageCreator", $"Access to the '{perspectiveName}' granted for user '{C1Console.Users.UserSettings.Username}'.");
            }
            yield break;
        }
        private void finalizecodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IXsltFunction xslt = this.GetBinding <IXsltFunction>("NewXslt");
            Guid          copyFromFunctionId = this.GetBinding <Guid>(Binding_CopyFromFunctionId);

            IXsltFunction copyFromFunction = null;

            if (copyFromFunctionId != Guid.Empty)
            {
                copyFromFunction = DataFacade.GetData <IXsltFunction>().First(f => f.Id == copyFromFunctionId);
            }

            xslt.XslFilePath = xslt.CreateXslFilePath();

            IFile file = IFileServices.TryGetFile <IXsltFile>(xslt.XslFilePath);

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                if (file == null)
                {
                    IXsltFile xsltfile = DataFacade.BuildNew <IXsltFile>();

                    xsltfile.FolderPath = System.IO.Path.GetDirectoryName(xslt.XslFilePath);
                    xsltfile.FileName   = System.IO.Path.GetFileName(xslt.XslFilePath);

                    string xslTemplate = _newXsltMarkup;
                    if (copyFromFunction != null)
                    {
                        IFile copyFromFile = IFileServices.GetFile <IXsltFile>(copyFromFunction.XslFilePath);
                        xslTemplate = copyFromFile.ReadAllText();
                    }

                    xsltfile.SetNewContent(xslTemplate);

                    DataFacade.AddNew <IXsltFile>(xsltfile, "XslFileProvider");
                }

                xslt = DataFacade.AddNew <IXsltFunction>(xslt);

                UserSettings.LastSpecifiedNamespace = xslt.Namespace;


                if (copyFromFunction != null)
                {
                    CloneFunctionParameters(copyFromFunction, xslt);
                    CloneFunctionCalls(copyFromFunction, xslt);
                }

                transactionScope.Complete();
            }
            addNewTreeRefresher.PostRefreshMesseges(xslt.GetDataEntityToken());

            FlowControllerServicesContainer container = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
            var executionService = container.GetService <IActionExecutionService>();

            executionService.Execute(xslt.GetDataEntityToken(), new WorkflowActionToken(typeof(EditXsltFunctionWorkflow)), null);
        }
 /// <summary>
 /// Documentation pending
 /// </summary>
 /// <typeparam name="TData"></typeparam>
 /// <param name="item"></param>
 /// <returns></returns>
 public virtual TData Add <TData>(TData item)
     where TData : class, IData
 {
     //   using (new DataScope(this.DataScopeIdentifier, this.Locale))
     {
         return(DataFacade.AddNew <TData>(item));
     }
 }
 /// <summary>
 /// Documentation pending
 /// </summary>
 /// <typeparam name="TData"></typeparam>
 /// <param name="items"></param>
 /// <returns></returns>
 public virtual IList <TData> Add <TData>(IEnumerable <TData> items)
     where TData : class, IData
 {
     //   using (new DataScope(this.DataScopeIdentifier, this.Locale))
     {
         return(DataFacade.AddNew <TData>(items));
     }
 }