Example #1
0
        public void RemoveUserGroupPermissionDefinition(Guid userGroupId, string serializedEntityToken)
        {
            var entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken);

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                IList <IUserGroupPermissionDefinition> toDelete;

                if (entityToken.IsValid())
                {
                    toDelete = DataFacade.GetData <IUserGroupPermissionDefinition>()
                               .Where(ugpd => ugpd.UserGroupId == userGroupId)
                               .ToList()
                               .Where(d => entityToken.Equals(DeserializeSilent(d.SerializedEntityToken)))
                               .ToList();
                }
                else
                {
                    toDelete = DataFacade.GetData <IUserGroupPermissionDefinition>()
                               .Where(ugpd => ugpd.UserGroupId == userGroupId && ugpd.SerializedEntityToken == serializedEntityToken).ToList();
                }

                if (toDelete.Any())
                {
                    DataFacade.Delete <IUserGroupPermissionDefinition>(toDelete);
                }

                transactionScope.Complete();
            }
        }
Example #2
0
        private void saveCodeActivity_Save_ExecuteCode(object sender, EventArgs e)
        {
            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                var args = new ConditionalEventArgs();
                editCodeActivity_ValidateBindings(this, args);
                if (!args.Result)
                {
                    return;
                }

                IPageType pageType = this.GetBinding <IPageType>("PageType");

                UpdatePageTemplateResctrictions(pageType);
                UpdatePageTypeParentResctrictions(pageType);
                UpdatePageTypeDataFolderTypeLinks(pageType);
                UpdatePageTypeTreeLinks(pageType);

                DataFacade.Update(pageType);

                transactionScope.Complete();
            }

            this.RefreshParentEntityToken();

            SetSaveStatus(true);
        }
        private void finalizeCodeActivity_DeleteFunction_ExecuteCode(object sender, EventArgs e)
        {
            IInlineFunction function = GetDataItemFromEntityToken <IInlineFunction>();

            if (DataFacade.WillDeleteSucceed(function))
            {
                DeleteTreeRefresher treeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken);

                using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
                {
                    DataFacade.Delete <IInlineFunctionAssemblyReference>(f => f.Function == function.Id);
                    DataFacade.Delete <IParameter>(f => f.OwnerId == function.Id);

                    function.DeleteFunctionCode();

                    DataFacade.Delete(function);

                    transactionScope.Complete();
                }

                treeRefresher.PostRefreshMesseges();
            }
            else
            {
                this.ShowMessage(
                    DialogType.Error,
                    StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "CascadeDeleteErrorTitle"),
                    StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "CascadeDeleteErrorMessage")
                    );
            }
        }
        public static void DeleteNamespace(string ns, string resourceSet)
        {
            if (resourceSet == String.Empty)
            {
                resourceSet = null;
            }

            using (var transaction = TransactionsFacade.CreateNewScope())
            {
                using (var data = new DataConnection())
                {
                    var keys = data.Get <IResourceKey>().Where(r => r.ResourceSet == resourceSet && r.Key.StartsWith(ns)).ToList();
                    foreach (var key in keys)
                    {
                        var values = data.Get <IResourceValue>().Where(v => v.KeyId == key.Id);

                        data.Delete <IResourceValue>(values);
                    }

                    data.Delete <IResourceKey>(keys);
                }

                transaction.Complete();
            }
        }
        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);
        }
        /// <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);
        }
        public bool RemovePersistedAttachmentPoint(string treeId, Type interfaceType, object keyValue)
        {
            string serializedInterfaceType = TypeManager.SerializeType(interfaceType);
            string serializedKeyValue      = ValueTypeConverter.Convert <string>(keyValue);

            bool removed = false;

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                IEnumerable <IDataItemTreeAttachmentPoint> dataItemTreeAttachmentPoints =
                    (from d in DataFacade.GetData <IDataItemTreeAttachmentPoint>()
                     where d.InterfaceType == serializedInterfaceType && d.KeyValue == serializedKeyValue && d.TreeId == treeId
                     select d).Evaluate();

                if (dataItemTreeAttachmentPoints.Any())
                {
                    DataFacade.Delete <IDataItemTreeAttachmentPoint>(dataItemTreeAttachmentPoints);
                    removed = true;
                }

                transactionScope.Complete();
            }

            return(removed);
        }
        public void DeleteResource(string key)
        {
            Verify.ArgumentNotNullOrEmpty(key, nameof(key));

            using (var transaction = TransactionsFacade.CreateNewScope())
            {
                using (var data = new DataConnection())
                {
                    var resourceKey = data.Get <IResourceKey>().SingleOrDefault(r => Equals(r.ResourceSet, _resourceSet) && r.Key == key);
                    if (resourceKey != null)
                    {
                        var resourceValue = data.Get <IResourceValue>().SingleOrDefault(r => r.KeyId == resourceKey.Id && r.Culture == _cultureName);
                        if (resourceValue != null)
                        {
                            data.Delete(resourceValue);
                        }

                        if (!data.Get <IResourceValue>().Any(v => v.KeyId == resourceKey.Id))
                        {
                            data.Delete(resourceKey);
                        }
                    }
                }

                transaction.Complete();
            }
        }
        public void AddResource(string key, object value)
        {
            Verify.ArgumentNotNullOrEmpty(key, nameof(key));
            Verify.ArgumentNotNull(value, nameof(value));

            using (var transaction = TransactionsFacade.CreateNewScope())
            {
                using (var data = new DataConnection())
                {
                    var resourceKey = data.Get <IResourceKey>().SingleOrDefault(k => Equals(k.ResourceSet, _resourceSet) && k.Key == key);
                    if (resourceKey == null)
                    {
                        resourceKey = data.CreateNew <IResourceKey>();

                        resourceKey.Id          = Guid.NewGuid();
                        resourceKey.Key         = key;
                        resourceKey.ResourceSet = _resourceSet;

                        data.Add(resourceKey);
                    }

                    var resourceValue = data.CreateNew <IResourceValue>();

                    resourceValue.Id      = Guid.NewGuid();
                    resourceValue.KeyId   = resourceKey.Id;
                    resourceValue.Culture = _cultureName;
                    resourceValue.Value   = value.ToString();

                    data.Add(resourceValue);
                }

                transaction.Complete();
            }
        }
        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();
        }
        internal static void FullDelete(IEnumerable <IData> dataset)
        {
            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                foreach (var data in dataset)
                {
                    if (data is IPublishControlled)
                    {
                        using (new DataScope(DataScopeIdentifier.Public))
                        {
                            IEnumerable <IData> datasDelete = DataFacade.GetDataFromOtherScope(data, DataScopeIdentifier.Public).Evaluate();

                            DataFacade.Delete(datasDelete, CascadeDeleteType.Disable);
                        }
                    }

                    using (new DataScope(DataScopeIdentifier.Administrated))
                    {
                        DataFacade.Delete(data);
                    }
                }

                transactionScope.Complete();
            }
        }
Example #12
0
        public void RemoveUserPermissionDefinition(UserToken userToken, string serializedEntityToken)
        {
            string username = userToken.Username;

            var entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken);

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                IList <IUserPermissionDefinition> toDelete;
                if (entityToken.IsValid())
                {
                    toDelete = DataFacade.GetData <IUserPermissionDefinition>()
                               .Where(upd => upd.Username == username)
                               .ToList()
                               .Where(d => entityToken.EqualsWithVersionIgnore(DeserializeSilent(d.SerializedEntityToken)))
                               .ToList();
                }
                else
                {
                    toDelete = DataFacade.GetData <IUserPermissionDefinition>()
                               .Where(upd => upd.Username == username && upd.SerializedEntityToken == serializedEntityToken)
                               .ToList();
                }

                if (toDelete.Count > 0)
                {
                    DataFacade.Delete <IUserPermissionDefinition>(toDelete);
                }

                transactionScope.Complete();
            }
        }
Example #13
0
        private void deleteCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            DeleteTreeRefresher treeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken);
            DataEntityToken     token         = (DataEntityToken)this.EntityToken;

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                IMediaFileFolder folder = DataFacade.GetDataFromDataSourceId(token.DataSourceId, false) as IMediaFileFolder;

                // Media folder may already be deleted at this point
                if (folder != null)
                {
                    if (!DataFacade.WillDeleteSucceed(folder))
                    {
                        this.ShowMessage(
                            DialogType.Error,
                            StringResourceSystemFacade.GetString("Composite.Management", "DeleteMediaFolderWorkflow.CascadeDeleteErrorTitle"),
                            StringResourceSystemFacade.GetString("Composite.Management", "DeleteMediaFolderWorkflow.CascadeDeleteErrorMessage")
                            );

                        return;
                    }

                    DataFacade.Delete(folder);
                }

                transactionScope.Complete();
            }

            treeRefresher.PostRefreshMesseges();
        }
        private void finalizeStateCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            DataTypeDescriptor dataTypeDescriptor = GetDataTypeDescriptor();

            string errorMessage;

            if (!GeneratedTypesFacade.CanDeleteType(dataTypeDescriptor, out errorMessage))
            {
                this.ShowMessage(DialogType.Warning,
                                 "${Composite.Plugins.GeneratedDataTypesElementProvider, DeleteCompositionTypeWorkflow.ErrorTitle}",
                                 errorMessage);
                return;
            }

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                PageMetaDataFacade.RemoveAllDefinitions(dataTypeDescriptor.DataTypeId, false);

                transactionScope.Complete();
            }

            GeneratedTypesFacade.DeleteType(dataTypeDescriptor);

            GeneratedDataTypesElementProviderRootEntityToken entityToken = new GeneratedDataTypesElementProviderRootEntityToken(this.EntityToken.Source, GeneratedDataTypesElementProviderRootEntityToken.PageMetaDataTypeFolderId);
            SpecificTreeRefresher specificTreeRefresher = this.CreateSpecificTreeRefresher();

            specificTreeRefresher.PostRefreshMesseges(entityToken);
        }
        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);
        }
        protected override void Execute()
        {
            var type = TypeManager.GetType(DataType);

            using (new DataScope(DataScopeIdentifier.Administrated, CultureInfo.CreateSpecificCulture(LocaleName)))
            {
                DataEntityToken dataEntityToken;

                using (var transaction = TransactionsFacade.CreateNewScope())
                {
                    var unpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(type, DataId, LocaleName);
                    Verify.IsNotNull(unpublishSchedule, "Missing an unpublish data schedule record");

                    DataFacade.Delete(unpublishSchedule);

                    var deletePublished = false;

                    var data = (IPublishControlled)DataFacade.GetDataByUniqueKey(type, DataId);
                    Verify.IsNotNull(data, "The data with the id {0} does not exist", DataId);

                    dataEntityToken = data.GetDataEntityToken();

                    var transitions = ProcessControllerFacade.GetValidTransitions(data).Keys;

                    if (transitions.Contains(GenericPublishProcessController.Draft))
                    {
                        data.PublicationStatus = GenericPublishProcessController.Draft;

                        DataFacade.Update(data);

                        deletePublished = true;
                    }
                    else
                    {
                        Log.LogWarning(LogTitle, "Scheduled unpublishing of data with label '{0}' could not be done because the data is not in a unpublisheble state", data.GetLabel());
                    }


                    if (deletePublished)
                    {
                        using (new DataScope(DataScopeIdentifier.Public))
                        {
                            var deletedData = (IPublishControlled)DataFacade.GetDataByUniqueKey(type, DataId);
                            if (deletedData != null)
                            {
                                DataFacade.Delete(deletedData, CascadeDeleteType.Disable);

                                Log.LogVerbose(LogTitle, "Scheduled unpublishing of data with label '{0}' is complete", deletedData.GetLabel());
                            }
                        }
                    }

                    transaction.Complete();
                }

                EntityTokenCacheFacade.ClearCache(dataEntityToken);
                PublishControlledHelper.ReloadDataElementInConsole(dataEntityToken);
            }
        }
        public void OnAfterDataUpdated(IData data)
        {
            var page = (IPage)data;

            IEnumerable <IPagePlaceholderContent> pagePlaceholderContents;

            using (new DataScope(DataScopeIdentifier.Administrated))
            {
                pagePlaceholderContents =
                    (from content in DataFacade.GetData <IPagePlaceholderContent>()
                     where content.PageId == page.Id && content.VersionId == page.VersionId
                     select content).ToList();
            }

            if (page.PublicationStatus == GenericPublishProcessController.Published)
            {
                using (var transactionScope = TransactionsFacade.CreateNewScope())
                {
                    using (new DataScope(DataScopeIdentifier.Public))
                    {
                        DataFacade.Delete <IPagePlaceholderContent>(
                            f => f.PageId == page.Id && f.VersionId == page.VersionId);
                    }

                    foreach (var pagePlaceholderContent in pagePlaceholderContents)
                    {
                        pagePlaceholderContent.PublicationStatus = page.PublicationStatus;

                        DataFacade.Update(pagePlaceholderContent);
                    }

                    using (new DataScope(DataScopeIdentifier.Administrated))
                    {
                        var publishSchedule = PublishScheduleHelper.GetPublishSchedule(typeof(IPage),
                                                                                       page.Id.ToString(), page.DataSourceId.LocaleScope.Name);

                        if (publishSchedule != null)
                        {
                            DataFacade.Delete(publishSchedule);
                        }
                    }

                    transactionScope.Complete();
                }
            }
            else
            {
                foreach (var pagePlaceholderContent in pagePlaceholderContents)
                {
                    if (pagePlaceholderContent.PublicationStatus != page.PublicationStatus)
                    {
                        pagePlaceholderContent.PublicationStatus = page.PublicationStatus;

                        DataFacade.Update(pagePlaceholderContent);
                    }
                }
            }
        }
        public static void CopyNamespace(string ns, string newNs, string resourceSet)
        {
            Verify.ArgumentNotNull(ns, "ns");
            Verify.ArgumentNotNull(newNs, "newNs");

            if (resourceSet == String.Empty)
            {
                resourceSet = null;
            }

            using (var transaction = TransactionsFacade.CreateNewScope())
            {
                using (var data = new DataConnection())
                {
                    var keysToAdd   = new List <IResourceKey>();
                    var valuesToAdd = new List <IResourceValue>();

                    var resources = (from key in data.Get <IResourceKey>()
                                     join value in data.Get <IResourceValue>() on key.Id equals value.KeyId into values
                                     where key.ResourceSet == resourceSet && key.Key.StartsWith(ns + ".")
                                     select new
                    {
                        Key = key,
                        Values = values
                    }).ToList();

                    foreach (var resource in resources)
                    {
                        var keyToAdd = data.CreateNew <IResourceKey>();

                        keyToAdd.Id          = Guid.NewGuid();
                        keyToAdd.Key         = resource.Key.Key.Remove(0, ns.Length).Insert(0, newNs);
                        keyToAdd.ResourceSet = resource.Key.ResourceSet;
                        keyToAdd.Type        = resource.Key.Type;

                        keysToAdd.Add(keyToAdd);

                        foreach (var value in resource.Values)
                        {
                            var valueToAdd = data.CreateNew <IResourceValue>();

                            valueToAdd.Id      = Guid.NewGuid();
                            valueToAdd.KeyId   = keyToAdd.Id;
                            valueToAdd.Culture = value.Culture;
                            valueToAdd.Value   = value.Value;

                            valuesToAdd.Add(valueToAdd);
                        }
                    }

                    data.Add <IResourceKey>(keysToAdd);
                    data.Add <IResourceValue>(valuesToAdd);
                }

                transaction.Complete();
            }
        }
Example #19
0
        private void DoUninstall()
        {
            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                DoUninstallWithoutTransaction();

                transactionScope.Complete();
            }
        }
        public override void OnFinish(object sender, EventArgs e)
        {
            var key  = GetBinding <string>("Key");
            var type = GetBinding <string>("Type");

            using (var transaction = TransactionsFacade.CreateNewScope())
            {
                using (var data = new DataConnection())
                {
                    if (key != ResourceKey.Key || type != ResourceKey.Type)
                    {
                        ResourceKey.Key  = key;
                        ResourceKey.Type = type;

                        data.Update(ResourceKey);

                        var treeRefresher = CreateSpecificTreeRefresher();

                        treeRefresher.PostRefreshMesseges(new LocalizationElementProviderEntityToken());
                    }

                    var resourceValues = data.Get <IResourceValue>().Where(v => v.KeyId == ResourceKey.Id).ToDictionary(v => v.Culture);

                    foreach (var culture in DataLocalizationFacade.ActiveLocalizationCultures)
                    {
                        var bindingKey = GetBindingKey(culture);

                        var value = GetBinding <string>(bindingKey);

                        IResourceValue resourceValue;
                        if (resourceValues.TryGetValue(culture.Name, out resourceValue))
                        {
                            resourceValue.Value = value;

                            data.Update(resourceValue);
                        }
                        else
                        {
                            resourceValue = data.CreateNew <IResourceValue>();

                            resourceValue.Id      = Guid.NewGuid();
                            resourceValue.KeyId   = ResourceKey.Id;
                            resourceValue.Culture = culture.Name;
                            resourceValue.Value   = value;

                            data.Add(resourceValue);
                        }
                    }
                }

                transaction.Complete();
            }

            SetSaveStatus(true);
        }
Example #21
0
        protected override void Execute()
        {
            using (new DataScope(DataScopeIdentifier.Administrated, CultureInfo.CreateSpecificCulture(LocaleName)))
            {
                IPage page;

                using (var transaction = TransactionsFacade.CreateNewScope())
                {
                    var pageUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(typeof(IPage), PageId.ToString(), LocaleName);
                    Verify.IsNotNull(pageUnpublishSchedule, "Missing an unpublish page schedule record.");

                    DataFacade.Delete(pageUnpublishSchedule);

                    var deletePublished = false;

                    page = DataFacade.GetData <IPage>(p => p.Id == PageId).FirstOrDefault();

                    var transitions = ProcessControllerFacade.GetValidTransitions(page).Keys;
                    if (transitions.Contains(GenericPublishProcessController.Draft))
                    {
                        page.PublicationStatus = GenericPublishProcessController.Draft;

                        DataFacade.Update(page);

                        deletePublished = true;
                    }
                    else
                    {
                        Log.LogWarning(LogTitle, "Scheduled unpublishing of page with title '{0}' could not be done because the page is not in a unpublisheble state", page.Title);
                    }

                    if (deletePublished)
                    {
                        using (new DataScope(DataScopeIdentifier.Public))
                        {
                            var deletePage = DataFacade.GetData <IPage>(p => p.Id == PageId).FirstOrDefault();
                            if (deletePage != null)
                            {
                                var metaDataSet = deletePage.GetMetaData(DataScopeIdentifier.Public).Evaluate();

                                DataFacade.Delete(deletePage, CascadeDeleteType.Disable);
                                DataFacade.Delete(metaDataSet, CascadeDeleteType.Disable);

                                Log.LogVerbose(LogTitle, "Scheduled unpublishing of page with title '{0}' is complete", deletePage.Title);
                            }
                        }
                    }

                    transaction.Complete();
                }

                PublishControlledHelper.ReloadPageElementInConsole(page);
            }
        }
        /// <summary>
        /// Adds a locale to the system. Throws exception if the given locale has already been installed or
        /// if the given url mapping name has already been used. If the given locale is the first, its set
        /// to be the default locale.
        /// </summary>
        /// <param name="cultureInfo"></param>
        /// <param name="urlMappingName"></param>
        /// <param name="addAccessToAllUsers"></param>
        /// <param name="makeFlush"></param>
        /// <param name="isDefault"></param>
        internal static void AddLocale(CultureInfo cultureInfo, string urlMappingName, bool addAccessToAllUsers, bool makeFlush, bool isDefault)
        {
            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                Verify.That(!IsLocaleInstalled(cultureInfo), "The locale '{0}' has already been added to the system", cultureInfo);
                Verify.That(!IsUrlMappingNameInUse(urlMappingName), "The url mapping name '{0}' has already been used in the system", urlMappingName);

                if (!DataLocalizationFacade.ActiveLocalizationCultures.Any())
                {
                    addAccessToAllUsers = true;
                }

                var systemActiveLocale = DataFacade.BuildNew <ISystemActiveLocale>();
                systemActiveLocale.Id             = Guid.NewGuid();
                systemActiveLocale.CultureName    = cultureInfo.Name;
                systemActiveLocale.UrlMappingName = urlMappingName;
                systemActiveLocale.IsDefault      = isDefault;
                DataFacade.AddNew(systemActiveLocale);

                if (addAccessToAllUsers)
                {
                    List <string> usernames =
                        (from u in DataFacade.GetData <IUser>()
                         select u.Username).ToList();

                    foreach (string username in usernames)
                    {
                        UserSettings.AddActiveLocaleCultureInfo(username, cultureInfo);

                        if (UserSettings.GetCurrentActiveLocaleCultureInfo(username) == null)
                        {
                            UserSettings.SetCurrentActiveLocaleCultureInfo(username, cultureInfo);
                            UserSettings.SetForeignLocaleCultureInfo(username, cultureInfo);
                        }
                    }
                }

                if (DataLocalizationFacade.DefaultLocalizationCulture == null)
                {
                    DataLocalizationFacade.DefaultLocalizationCulture = cultureInfo;
                }

                transactionScope.Complete();
            }

            DynamicTypeManager.AddLocale(cultureInfo);

            if (makeFlush)
            {
                C1Console.Events.GlobalEventSystemFacade.FlushTheSystem(false);
            }
        }
        public void SetUserPassword(string username, string password)
        {
            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                IUser user = DataFacade.GetData <IUser>().FirstOrDefault(u => u.Username == username);
                Verify.IsNotNull(user, "The userFormLogin '{0}' does not exists", username);

                var userFormLogin = user.GetUserFormLogin();

                UserFormLoginManager.SetPassword(userFormLogin, password);

                transactionScope.Complete();
            }
        }
Example #24
0
        /// <exclude />
        public void AddLocale(string providerName, CultureInfo cultureInfo)
        {
            Verify.ArgumentNotNullOrEmpty(providerName, nameof(providerName));
            Verify.ArgumentNotNull(cultureInfo, nameof(cultureInfo));

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                DataProviderPluginFacade.AddLocale(providerName, cultureInfo);
                transactionScope.Complete();
            }

            if (!SystemSetupFacade.SetupIsRunning)
            {
                CodeGenerationManager.GenerateCompositeGeneratedAssembly(true);
            }
        }
Example #25
0
        /// <summary>
        /// Removes the given locale, all data is lost
        /// </summary>
        /// <param name="cultureInfo"></param>
        /// <param name="makeFlush"></param>
        public static void RemoveLocale(CultureInfo cultureInfo, bool makeFlush = true)
        {
            Verify.That(!IsDefaultLocale(cultureInfo), "The locale '{0}' is the default locale and can not be removed", cultureInfo);
            Verify.That(!IsOnlyActiveLocaleForSomeUsers(cultureInfo), "The locale '{0}' is the only locale for some user(s) and can not be removed", cultureInfo);

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                string cultureName = cultureInfo.Name;

                var systemActiveLocale = DataFacade.GetData <ISystemActiveLocale>().SingleOrDefault(f => f.CultureName == cultureName);

                Verify.IsNotNull(systemActiveLocale, "The locale '{0}' has not beed added and can not be removed", cultureInfo);

                List <string> usernames =
                    (from u in DataFacade.GetData <IUser>()
                     select u.Username).ToList();

                foreach (string username in usernames)
                {
                    if (cultureInfo.Equals(UserSettings.GetCurrentActiveLocaleCultureInfo(username)))
                    {
                        CultureInfo fallbackCultureInfo = UserSettings.GetActiveLocaleCultureInfos(username).First(f => !f.Equals(cultureInfo));

                        UserSettings.SetCurrentActiveLocaleCultureInfo(username, fallbackCultureInfo);
                    }

                    if (cultureInfo.Equals(UserSettings.GetForeignLocaleCultureInfo(username)))
                    {
                        UserSettings.SetForeignLocaleCultureInfo(username, null);
                    }

                    UserSettings.RemoveActiveLocaleCultureInfo(username, cultureInfo);
                }

                DataFacade.Delete <ISystemActiveLocale>(systemActiveLocale);

                transactionScope.Complete();
            }

            DynamicTypeManager.RemoveLocale(cultureInfo);

            if (makeFlush)
            {
                C1Console.Events.GlobalEventSystemFacade.FlushTheSystem(false);
            }
        }
Example #26
0
        public void DeleteType(string providerName, DataTypeDescriptor dataTypeDescriptor, bool makeAFlush)
        {
            Verify.ArgumentNotNullOrEmpty(providerName, "providerName");
            Verify.ArgumentNotNull(dataTypeDescriptor, "dataTypeDescriptor");

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                DynamicTypeManager.DropStore(providerName, dataTypeDescriptor, makeAFlush);

                transactionScope.Complete();
            }

            if (makeAFlush && dataTypeDescriptor.IsCodeGenerated)
            {
                CodeGenerationManager.GenerateCompositeGeneratedAssembly(true);
            }
        }
        protected override void Execute()
        {
            Type type = TypeManager.GetType(DataType);

            using (new DataScope(DataScopeIdentifier.Administrated, CultureInfo.CreateSpecificCulture(LocaleName)))
            {
                DataEntityToken dataEntityToken;

                using (var transaction = TransactionsFacade.CreateNewScope())
                {
                    var publishSchedule = PublishScheduleHelper.GetPublishSchedule(type, DataId, LocaleName);
                    DataFacade.Delete(publishSchedule);

                    var data = (IPublishControlled)DataFacade.TryGetDataByUniqueKey(type, DataId);
                    if (data == null)
                    {
                        Log.LogWarning(LogTitle, $"Failed to find data of type '{type}' by id '{DataId}'.");

                        transaction.Complete();
                        return;
                    }

                    dataEntityToken = data.GetDataEntityToken();

                    var transitions = ProcessControllerFacade.GetValidTransitions(data).Keys;

                    if (transitions.Contains(GenericPublishProcessController.Published))
                    {
                        data.PublicationStatus = GenericPublishProcessController.Published;

                        DataFacade.Update(data);

                        Log.LogVerbose(LogTitle, $"Scheduled publishing of data with label '{data.GetLabel()}' is complete");
                    }
                    else
                    {
                        Log.LogWarning(LogTitle, $"Scheduled publishing of data with label '{data.GetLabel()}' could not be done because the data is not in a publisheble state");
                    }

                    transaction.Complete();
                }

                EntityTokenCacheFacade.ClearCache(dataEntityToken);
                PublishControlledHelper.ReloadDataElementInConsole(dataEntityToken);
            }
        }
Example #28
0
        private static void AddFiles(string providerName, IEnumerable <IMediaFile> files, bool overwrite)
        {
            foreach (IMediaFile file in files)
            {
                using (var transactionScope = TransactionsFacade.CreateNewScope(ExtrationTimeout))
                {
                    EnsureFolderExistence(file.FolderPath);

                    if (overwrite)
                    {
                        if (Exists(file))
                        {
                            IMediaFile currentFile = DataFacade.GetData <IMediaFile>()
                                                     .First(x => x.FolderPath == file.FolderPath && x.FileName == file.FileName);
                            using (Stream readStream = file.GetReadStream())
                            {
                                using (Stream writeStream = currentFile.GetNewWriteStream())
                                {
                                    readStream.CopyTo(writeStream);
                                }
                            }
                            DataFacade.Update(currentFile);
                        }
                        else
                        {
                            DataFacade.AddNew <IMediaFile>(file, providerName);
                        }
                    }
                    else
                    {
                        int    counter   = 0;
                        string extension = Path.GetExtension(file.FileName);
                        string name      = file.FileName.GetNameWithoutExtension();
                        while (Exists(file))
                        {
                            counter++;
                            file.FileName = name + counter.ToString() + extension;
                        }
                        DataFacade.AddNew <IMediaFile>(file, providerName);
                    }

                    transactionScope.Complete();
                }
            }
        }
Example #29
0
        /// <exclude />
        public void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor, bool forceCompile)
        {
            DataTypeChangeDescriptor dataTypeChangeDescriptor = updateDataTypeDescriptor.CreateDataTypeChangeDescriptor();

            dataTypeChangeDescriptor.AlteredType.Validate();

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                DataMetaDataFacade.PersistMetaData(dataTypeChangeDescriptor.AlteredType);

                if (dataTypeChangeDescriptor.AlteredTypeHasChanges)
                {
                    DataProviderPluginFacade.AlterStore(updateDataTypeDescriptor, forceCompile);
                }

                transactionScope.Complete();
            }
        }
Example #30
0
        /// <exclude />
        public void DropStore(string providerName, DataTypeDescriptor typeDescriptor, bool makeAFlush)
        {
            Verify.ArgumentNotNullOrEmpty(providerName, "providerName");
            Verify.ArgumentNotNull(typeDescriptor, "typeDescriptor");

            typeDescriptor.Validate();

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                DataProviderPluginFacade.DropStore(providerName, typeDescriptor);
                DataMetaDataFacade.DeleteMetaData(typeDescriptor.DataTypeId);
                transactionScope.Complete();
            }

            if (makeAFlush)
            {
                GlobalEventSystemFacade.FlushTheSystem();
            }
        }