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);
            }
        }
        private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var justAdded = false;

            var isValid = ValidateBindings();
            var helper  = GetDataTypeDescriptorFormsHelper();

            var newData = GetBinding <IData>("NewData");

            if (!BindAndValidate(helper, newData))
            {
                isValid = false;
            }

            if (isValid)
            {
                if (!BindingExist("DataAdded"))
                {
                    newData   = DataFacade.AddNew(newData);
                    justAdded = true;

                    AcquireLock(newData.GetDataEntityToken());

                    UpdateBinding("NewData", newData);
                    Bindings.Add("DataAdded", true);

                    PublishControlledHelper.PublishIfNeeded(newData, _doPublish, Bindings, ShowMessage);

                    var specificTreeRefresher = CreateParentTreeRefresher();
                    specificTreeRefresher.PostRefreshMesseges(EntityToken);
                }
                else
                {
                    var updateTreeRefresher = CreateUpdateTreeRefresher(EntityToken);

                    DataFacade.Update(newData);
                    EntityTokenCacheFacade.ClearCache(newData.GetDataEntityToken());

                    var published = PublishControlledHelper.PublishIfNeeded(newData, _doPublish, Bindings, ShowMessage);
                    if (!published)
                    {
                        updateTreeRefresher.PostRefreshMesseges(EntityToken);
                    }
                }
            }

            if (justAdded)
            {
                SetSaveStatus(true, newData);
            }
            else
            {
                SetSaveStatus(isValid);
            }
        }
        private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var isValid             = ValidateBindings();
            var updateTreeRefresher = CreateUpdateTreeRefresher(EntityToken);
            var helper = GetDataTypeDescriptorFormsHelper();

            var data = ((DataEntityToken)EntityToken).Data;

            if (!BindAndValidate(helper, data))
            {
                isValid = false;
            }

            var fieldsWithBrokenReferences = new List <string>();

            if (!data.TryValidateForeignKeyIntegrity(fieldsWithBrokenReferences))
            {
                isValid = false;

                foreach (var fieldName in fieldsWithBrokenReferences)
                {
                    ShowFieldMessage(fieldName, StringResourceSystemFacade.GetString("Composite.Management", "Validation.BrokenReference"));
                }
            }

            if (isValid)
            {
                // published data stayed as published data - change to draft if status is published
                if (data is IPublishControlled)
                {
                    var publishControlledData = (IPublishControlled)data;
                    if (publishControlledData.PublicationStatus == GenericPublishProcessController.Published)
                    {
                        publishControlledData.PublicationStatus = GenericPublishProcessController.Draft;
                    }
                }

                DataFacade.Update(data);

                EntityTokenCacheFacade.ClearCache(EntityToken);

                updateTreeRefresher.PostRefreshMesseges(EntityToken);

                PublishControlledHelper.PublishIfNeeded(data, _doPublish, Bindings, ShowMessage);

                SetSaveStatus(true);
            }
            else
            {
                SetSaveStatus(false);
            }
        }
示例#4
0
        private void saveCodeActivity_UpdateData_ExecuteCode(object sender, EventArgs e)
        {
            UpdateTreeRefresher updateTreeRefresher = this.CreateUpdateTreeRefresher(this.EntityToken);

            IData data = ((DataEntityToken)this.EntityToken).Data;

            bool isValid = ValidateBindings();

            if (!BindAndValidate(this.FormsHelper, data))
            {
                isValid = false;
            }

            var fieldsWithBrokenReferences = new List <string>();

            if (!data.TryValidateForeignKeyIntegrity(fieldsWithBrokenReferences))
            {
                isValid = false;

                foreach (string fieldName in fieldsWithBrokenReferences)
                {
                    ShowFieldMessage(fieldName, LocalizationFiles.Composite_Management.Validation_BrokenReference);
                }
            }

            if (isValid)
            {
                if (data is IPublishControlled)
                {
                    IPublishControlled publishControlledData = (IPublishControlled)data;
                    if (publishControlledData.PublicationStatus == GenericPublishProcessController.Published)
                    {
                        publishControlledData.PublicationStatus = GenericPublishProcessController.Draft;
                    }
                }

                DataFacade.Update(data);

                EntityTokenCacheFacade.ClearCache(EntityToken);

                updateTreeRefresher.PostRefreshMesseges(this.EntityToken);

                PublishControlledHelper.PublishIfNeeded(data, _doPublish, Bindings, ShowMessage);
            }

            SetSaveStatus(isValid);
        }
        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);
            }
        }
        public FlowToken Execute(EntityToken entityToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            var  token = (GeneratedDataTypesElementProviderTypeEntityToken)entityToken;
            var  type  = TypeManager.GetType(token.SerializedTypeName);
            Guid guid  = type.GetImmutableTypeId();

            var oldDataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(guid);
            var superInfterface       = ((ToggleSuperInterfaceActionToken)actionToken).InterfaceType;

            var newDataTypeDescriptor = oldDataTypeDescriptor.Clone();

            if (newDataTypeDescriptor.SuperInterfaces.Contains(superInfterface))
            {
                newDataTypeDescriptor.RemoveSuperInterface(superInfterface);
            }
            else
            {
                newDataTypeDescriptor.AddSuperInterface(superInfterface);
            }

            if (newDataTypeDescriptor.DataScopes.Count == 0)
            {
                newDataTypeDescriptor.DataScopes.Add(DataScopeIdentifier.Public);
            }

            if (oldDataTypeDescriptor.DataScopes.Count == 0)
            {
                oldDataTypeDescriptor.DataScopes.Add(DataScopeIdentifier.Public);
            }

            var updateDescriptor = new UpdateDataTypeDescriptor(oldDataTypeDescriptor, newDataTypeDescriptor, true);

            GeneratedTypesFacade.UpdateType(updateDescriptor);

            EntityTokenCacheFacade.ClearCache();

            var treeRefresher = new ParentTreeRefresher(flowControllerServicesContainer);

            treeRefresher.PostRefreshMesseges(entityToken);

            return(null);
        }
示例#7
0
        private void saveDataCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var isValid             = ValidateBindings();
            var updateTreeRefresher = CreateUpdateTreeRefresher(EntityToken);
            var helper = GetDataTypeDescriptorFormsHelper();

            var data = ((DataEntityToken)EntityToken).Data;

            if (!BindAndValidate(helper, data))
            {
                isValid = false;
            }

            if (isValid)
            {
                // published data stayed as published data - change to draft if status is published
                if (data is IPublishControlled)
                {
                    var publishControlledData = (IPublishControlled)data;
                    if (publishControlledData.PublicationStatus == GenericPublishProcessController.Published)
                    {
                        publishControlledData.PublicationStatus = GenericPublishProcessController.Draft;
                    }
                }

                DataFacade.Update(data);

                EntityTokenCacheFacade.ClearCache(data.GetDataEntityToken());

                var published = PublishControlledHelper.PublishIfNeeded(data, _doPublish, Bindings, ShowMessage);
                if (!published)
                {
                    updateTreeRefresher.PostRefreshMesseges(EntityToken);
                }

                SetSaveStatus(true);
            }
            else
            {
                SetSaveStatus(false);
            }
        }
示例#8
0
        public DataGroupingProviderHelper(ElementProviderContext elementProviderContext)
        {
            _elementProviderContext = elementProviderContext;
            _undefinedLabelValue    = StringResourceSystemFacade.GetString("Composite.Plugins.GeneratedDataTypesElementProvider", "UndefinedLabelTemplate");

            this.FolderOpenIcon   = GetIconHandle("datagroupinghelper-folder-open");
            this.FolderClosedIcon = GetIconHandle("datagroupinghelper-folder-closed");

            this.OnCreateLeafElement      = d => new Element(_elementProviderContext.CreateElementHandle(d.GetDataEntityToken()));
            this.OnGetDataScopeIdentifier = t => DataScopeIdentifier.Administrated;
            this.OnAddActions             = (e, p) => e;

            AuxiliarySecurityAncestorFacade.AddAuxiliaryAncestorProvider <DataEntityToken>(this);
            AuxiliarySecurityAncestorFacade.AddAuxiliaryAncestorProvider <DataGroupingProviderHelperEntityToken>(this);

            DataEventSystemFacade.SubscribeToDataAfterUpdate(typeof(IData), (sender, args) =>
            {
                if (!OnOwnsType(args.DataType))
                {
                    return;
                }

                var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(args.DataType);

                IEnumerable <DataFieldDescriptor> groupingDataFieldDescriptors =
                    from dfd in dataTypeDescriptor.Fields
                    where dfd.GroupByPriority != 0
                    orderby dfd.GroupByPriority
                    select dfd;

                if (groupingDataFieldDescriptors.Any())
                {
                    EntityTokenCacheFacade.ClearCache(args.Data.GetDataEntityToken());
                }
            }, false);
        }
示例#9
0
        public bool OnElementDraggedAndDropped(EntityToken draggedEntityToken, EntityToken newParentEntityToken, int dropIndex, DragAndDropType dragAndDropType, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            IPage draggedPage = (IPage)((DataEntityToken)draggedEntityToken).Data;

            Verify.IsNotNull(draggedPage, "Dragged page does not exist");

            Guid newParentPageId;

            if (newParentEntityToken is PageElementProviderEntityToken)
            {
                newParentPageId = Guid.Empty;
            }
            else if (newParentEntityToken is DataEntityToken)
            {
                IPage newParentPage = (IPage)((DataEntityToken)newParentEntityToken).Data;
                newParentPageId = newParentPage.Id;
            }
            else
            {
                throw new NotImplementedException();
            }

            IPage oldParent   = null;
            Guid  oldParentId = draggedPage.GetParentId();

            if (oldParentId != Guid.Empty)
            {
                oldParent = DataFacade.GetData <IPage>(f => f.Id == oldParentId).Single();
            }

            if (dragAndDropType == DragAndDropType.Move)
            {
                using (var transactionScope = TransactionsFacade.CreateNewScope())
                {
                    string urlTitle = draggedPage.UrlTitle;
                    int    counter  = 1;

                    while (true)
                    {
                        bool urlTitleClash =
                            (from p in PageServices.GetChildren(newParentPageId).AsEnumerable()
                             where p.UrlTitle == urlTitle && p.Id != draggedPage.Id
                             select p).Any();


                        if (!urlTitleClash)
                        {
                            break;
                        }

                        urlTitle = string.Format("{0}{1}", draggedPage.UrlTitle, counter++);
                    }

                    draggedPage.UrlTitle = urlTitle;

                    // Real drop index takes into account pages from other locales
                    int realDropIndex = GetRealDropIndex(draggedPage, newParentPageId, dropIndex);

                    draggedPage.MoveTo(newParentPageId, realDropIndex, false);

                    DataFacade.Update(draggedPage);

                    EntityTokenCacheFacade.ClearCache(draggedPage.GetDataEntityToken());

                    transactionScope.Complete();
                }
            }
            else
            {
                throw new NotImplementedException();
            }


            if (oldParent != null)
            {
                var oldParentParentTreeRefresher = new ParentTreeRefresher(flowControllerServicesContainer);
                oldParentParentTreeRefresher.PostRefreshMesseges(oldParent.GetDataEntityToken());
            }
            else
            {
                var oldParentspecificTreeRefresher = new SpecificTreeRefresher(flowControllerServicesContainer);
                oldParentspecificTreeRefresher.PostRefreshMesseges(new PageElementProviderEntityToken(_context.ProviderName));
            }

            var newParentParentTreeRefresher = new ParentTreeRefresher(flowControllerServicesContainer);

            newParentParentTreeRefresher.PostRefreshMesseges(newParentEntityToken);

            return(true);
        }
示例#10
0
        private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var dataTypeDescriptor = GetBinding <DataTypeDescriptor>("DataTypeDescriptor");

            var newData = GetBinding <IData>("NewData");

            var helper = new DataTypeDescriptorFormsHelper(dataTypeDescriptor, true, newData.GetDataEntityToken());

            var generatedTypesHelper = new GeneratedTypesHelper(dataTypeDescriptor);

            helper.AddReadOnlyFields(generatedTypesHelper.NotEditableDataFieldDescriptorNames);


            var isValid = ValidateBindings();

            if (!BindAndValidate(helper, newData))
            {
                isValid = false;
            }

            var justAdded = false;

            if (isValid)
            {
                var published = false;

                if (!BindingExist("DataAdded"))
                {
                    var dataScopeIdentifier = DataScopeIdentifier.Public;
                    if (dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
                    {
                        dataScopeIdentifier = DataScopeIdentifier.Administrated;
                    }

                    using (new DataScope(dataScopeIdentifier))
                    {
                        newData = DataFacade.AddNew(newData);

                        justAdded = true;
                    }

                    PublishControlledHelper.PublishIfNeeded(newData, _doPublish, Bindings, ShowMessage);

                    AcquireLock(newData.GetDataEntityToken());

                    UpdateBinding("NewData", newData);
                    Bindings.Add("DataAdded", true);
                }
                else
                {
                    var publishedControlled = newData as IPublishControlled;
                    if (publishedControlled != null)
                    {
                        var refreshedData = (IPublishControlled)DataFacade.GetDataFromDataSourceId(newData.DataSourceId);
                        if (refreshedData != null && refreshedData.PublicationStatus == GenericPublishProcessController.Published)
                        {
                            refreshedData.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.Update(refreshedData);
                        }
                    }

                    DataFacade.Update(newData);

                    published = PublishControlledHelper.PublishIfNeeded(newData, _doPublish, Bindings, ShowMessage);

                    EntityTokenCacheFacade.ClearCache(newData.GetDataEntityToken());
                }

                if (!published)
                {
                    var specificTreeRefresher = CreateParentTreeRefresher();
                    specificTreeRefresher.PostRefreshMesseges(EntityToken);
                }

                if (justAdded)
                {
                    SetSaveStatus(true, newData);
                }
                else
                {
                    SetSaveStatus(true);
                }
            }
            else
            {
                SetSaveStatus(false);
            }
        }
        private void initializeCodeActivity_Copy_ExecuteCode(object sender, EventArgs e)
        {
            var castedEntityToken = (DataEntityToken)this.EntityToken;

            IPage newPage;

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                CultureInfo sourceCultureInfo = UserSettings.ForeignLocaleCultureInfo;

                IPage sourcePage;
                List <IPagePlaceholderContent> sourcePagePlaceholders;
                List <IData> sourceMetaDataSet;

                using (new DataScope(sourceCultureInfo))
                {
                    var  pageFromEntityToken = (IPage)castedEntityToken.Data;
                    Guid sourcePageId        = pageFromEntityToken.Id;
                    Guid sourcePageVersionId = pageFromEntityToken.VersionId;

                    using (new DataScope(DataScopeIdentifier.Administrated))
                    {
                        sourcePage = DataFacade.GetData <IPage>(f => f.Id == sourcePageId).Single();
                        sourcePage = sourcePage.GetTranslationSource();

                        using (new DataScope(sourcePage.DataSourceId.DataScopeIdentifier))
                        {
                            sourcePagePlaceholders = DataFacade
                                                     .GetData <IPagePlaceholderContent>(f => f.PageId == sourcePageId && f.VersionId == sourcePageVersionId)
                                                     .ToList();
                            sourceMetaDataSet = sourcePage.GetMetaData().ToList();
                        }
                    }
                }


                CultureInfo targetCultureInfo = UserSettings.ActiveLocaleCultureInfo;

                using (new DataScope(targetCultureInfo))
                {
                    newPage = DataFacade.BuildNew <IPage>();
                    sourcePage.ProjectedCopyTo(newPage);

                    newPage.SourceCultureName = targetCultureInfo.Name;
                    newPage.PublicationStatus = GenericPublishProcessController.Draft;
                    newPage = DataFacade.AddNew <IPage>(newPage);

                    foreach (IPagePlaceholderContent sourcePagePlaceholderContent in sourcePagePlaceholders)
                    {
                        IPagePlaceholderContent newPagePlaceholderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                        sourcePagePlaceholderContent.ProjectedCopyTo(newPagePlaceholderContent);

                        newPagePlaceholderContent.SourceCultureName = targetCultureInfo.Name;
                        newPagePlaceholderContent.PublicationStatus = GenericPublishProcessController.Draft;
                        DataFacade.AddNew <IPagePlaceholderContent>(newPagePlaceholderContent);
                    }

                    foreach (IData metaData in sourceMetaDataSet)
                    {
                        ILocalizedControlled localizedData = metaData as ILocalizedControlled;

                        if (localizedData == null)
                        {
                            continue;
                        }

                        IEnumerable <ReferenceFailingPropertyInfo> referenceFailingPropertyInfos = DataLocalizationFacade.GetReferencingLocalizeFailingProperties(localizedData).Evaluate();

                        if (!referenceFailingPropertyInfos.Any())
                        {
                            IData newMetaData = DataFacade.BuildNew(metaData.DataSourceId.InterfaceType);
                            metaData.ProjectedCopyTo(newMetaData);

                            ILocalizedControlled localizedControlled = newMetaData as ILocalizedControlled;
                            localizedControlled.SourceCultureName = targetCultureInfo.Name;

                            IPublishControlled publishControlled = newMetaData as IPublishControlled;
                            publishControlled.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.AddNew(newMetaData);
                        }
                        else
                        {
                            foreach (ReferenceFailingPropertyInfo referenceFailingPropertyInfo in referenceFailingPropertyInfos)
                            {
                                Log.LogVerbose("LocalizePageWorkflow",
                                               "Meta data of type '{0}' is not localized because the field '{1}' is referring some not yet localzed data"
                                               .FormatWith(metaData.DataSourceId.InterfaceType, referenceFailingPropertyInfo.DataFieldDescriptor.Name));
                            }
                        }
                    }
                }

                EntityTokenCacheFacade.ClearCache(sourcePage.GetDataEntityToken());
                EntityTokenCacheFacade.ClearCache(newPage.GetDataEntityToken());

                foreach (var folderType in PageFolderFacade.GetDefinedFolderTypes(newPage))
                {
                    EntityTokenCacheFacade.ClearCache(new AssociatedDataElementProviderHelperEntityToken(
                                                          TypeManager.SerializeType(typeof(IPage)),
                                                          PageElementProvider.DefaultConfigurationName,
                                                          newPage.Id.ToString(),
                                                          TypeManager.SerializeType(folderType)));
                }


                transactionScope.Complete();
            }

            ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher();

            parentTreeRefresher.PostRefreshMesseges(newPage.GetDataEntityToken(), 2);

            this.ExecuteWorklow(newPage.GetDataEntityToken(), typeof(EditPageWorkflow));
        }
示例#12
0
        private void localizeDataCodeActivity_Localize_ExecuteCode(object sender, EventArgs e)
        {
            DataEntityToken      dataEntityToken = (DataEntityToken)this.EntityToken;
            ILocalizedControlled data            = dataEntityToken.Data as ILocalizedControlled;

            CultureInfo targetCultureInfo = UserSettings.ActiveLocaleCultureInfo;

            if (ExistsInLocale(data, targetCultureInfo))
            {
                this.ShowMessage(
                    DialogType.Message,
                    StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeData.ShowError.Layout.Label"),
                    StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeData.ShowError.AlreadyTranslated")
                    );

                return;
            }


            IEnumerable <ReferenceFailingPropertyInfo> referenceFailingPropertyInfos = DataLocalizationFacade.GetReferencingLocalizeFailingProperties(data).Evaluate();

            IData newData;

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                data = data.GetTranslationSource();

                using (new DataScope(targetCultureInfo))
                {
                    newData = DataFacade.BuildNew(data.DataSourceId.InterfaceType);

                    data.ProjectedCopyTo(newData);

                    ILocalizedControlled localizedControlled = newData as ILocalizedControlled;
                    localizedControlled.SourceCultureName = targetCultureInfo.Name;

                    if (newData is IPublishControlled)
                    {
                        IPublishControlled publishControlled = newData as IPublishControlled;
                        publishControlled.PublicationStatus = GenericPublishProcessController.Draft;
                    }

                    foreach (ReferenceFailingPropertyInfo referenceFailingPropertyInfo in referenceFailingPropertyInfos)
                    {
                        PropertyInfo propertyInfo = data.DataSourceId.InterfaceType.GetPropertiesRecursively().Single(f => f.Name == referenceFailingPropertyInfo.DataFieldDescriptor.Name);
                        if (propertyInfo.PropertyType.IsGenericType &&
                            propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                        {
                            propertyInfo.SetValue(newData, null, null);
                        }
                        else if (propertyInfo.PropertyType == typeof(string))
                        {
                            propertyInfo.SetValue(newData, null, null);
                        }
                        else
                        {
                            propertyInfo.SetValue(newData, referenceFailingPropertyInfo.DataFieldDescriptor.DefaultValue.Value, null);
                        }
                    }

                    newData = DataFacade.AddNew(newData);
                }

                EntityTokenCacheFacade.ClearCache(data.GetDataEntityToken());
                EntityTokenCacheFacade.ClearCache(newData.GetDataEntityToken());

                transactionScope.Complete();
            }

            ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher();

            parentTreeRefresher.PostRefreshMesseges(newData.GetDataEntityToken(), 2);
        }
        private void localizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            DataEntityToken      dataEntityToken = (DataEntityToken)this.EntityToken;
            ILocalizedControlled data            = dataEntityToken.Data as ILocalizedControlled;

            CultureInfo targetCultureInfo = UserSettings.ActiveLocaleCultureInfo;

            if (ExistsInLocale(data, targetCultureInfo))
            {
                string title       = Texts.LocalizeDataWorkflow_ShowError_LayoutLabel;
                string description = Texts.LocalizeDataWorkflow_ShowError_AlreadyTranslated;

                var messageBox = new MessageBoxMessageQueueItem
                {
                    DialogType = DialogType.Message,
                    Message    = description,
                    Title      = title
                };

                ConsoleMessageQueueFacade.Enqueue(messageBox, GetCurrentConsoleId());
                return;
            }

            IEnumerable <ReferenceFailingPropertyInfo> referenceFailingPropertyInfos = DataLocalizationFacade.GetReferencingLocalizeFailingProperties(data).Evaluate();

            IData newData;

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                data = data.GetTranslationSource();

                using (new DataScope(targetCultureInfo))
                {
                    newData = DataFacade.BuildNew(data.DataSourceId.InterfaceType);

                    data.ProjectedCopyTo(newData);

                    ILocalizedControlled localizedControlled = newData as ILocalizedControlled;
                    localizedControlled.SourceCultureName = targetCultureInfo.Name;

                    if (newData is IPublishControlled)
                    {
                        IPublishControlled publishControlled = newData as IPublishControlled;
                        publishControlled.PublicationStatus = GenericPublishProcessController.Draft;
                    }

                    foreach (ReferenceFailingPropertyInfo referenceFailingPropertyInfo in referenceFailingPropertyInfos)
                    {
                        PropertyInfo propertyInfo = data.DataSourceId.InterfaceType.GetPropertiesRecursively().Single(f => f.Name == referenceFailingPropertyInfo.DataFieldDescriptor.Name);
                        if (propertyInfo.PropertyType.IsGenericType &&
                            propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                        {
                            propertyInfo.SetValue(newData, null, null);
                        }
                        else if (propertyInfo.PropertyType == typeof(string))
                        {
                            propertyInfo.SetValue(newData, null, null);
                        }
                        else
                        {
                            propertyInfo.SetValue(newData, referenceFailingPropertyInfo.DataFieldDescriptor.DefaultValue.Value, null);
                        }
                    }

                    newData = DataFacade.AddNew(newData, false, false, true);
                }

                EntityTokenCacheFacade.ClearCache(data.GetDataEntityToken());
                EntityTokenCacheFacade.ClearCache(newData.GetDataEntityToken());

                transactionScope.Complete();
            }

            ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher();

            parentTreeRefresher.PostRefreshMesseges(newData.GetDataEntityToken());

            if (this.Payload == "Global")
            {
                this.ExecuteWorklow(newData.GetDataEntityToken(), typeof(EditDataWorkflow));
            }
            else if (this.Payload == "Pagefolder")
            {
                this.ExecuteWorklow(newData.GetDataEntityToken(), WorkflowFacade.GetWorkflowType("Composite.C1Console.Elements.ElementProviderHelpers.AssociatedDataElementProviderHelper.EditAssociatedDataWorkflow"));
            }
        }