Exemplo n.º 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 void FinalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);


            addNewTreeRefresher.PostRefreshMesseges(this.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);
        }
Exemplo n.º 4
0
        private void stepFinalize_codeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IPage newPage = this.GetBinding <IPage>("NewPage");

            newPage.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name;

            Guid pageTypeId            = newPage.PageTypeId;
            Guid?defaultPageTemplateId = PageServices.GetDefaultPageTemplateId(pageTypeId);

            if (defaultPageTemplateId != null)
            {
                newPage.TemplateId = defaultPageTemplateId.Value;
            }

            string sortOrder = this.GetBinding <string>("SelectedSortOrder");

            Guid parentId = GetParentId();

            using (new DataScope(DataScopeIdentifier.Administrated))
            {
                IPageInsertionPosition position;

                if (sortOrder == SortOrder.Top)
                {
                    position = PageInsertPosition.Top;
                }
                else if (sortOrder == SortOrder.Bottom)
                {
                    position = PageInsertPosition.Bottom;
                }
                else if (sortOrder == SortOrder.Alphabetic)
                {
                    position = PageInsertPosition.Alphabetic;
                }
                else if (sortOrder == SortOrder.Relative)
                {
                    Guid relativeSelectedPageId = this.GetBinding <Guid>("RelativeSelectedPageId");

                    position = PageInsertPosition.After(relativeSelectedPageId);
                }
                else
                {
                    throw new InvalidOperationException($"Not handled page instert position '{sortOrder}'");
                }

                newPage = newPage.Add(parentId, position);
            }

            SetSaveStatus(true);

            addNewTreeRefresher.PostRefreshMesseges(newPage.GetDataEntityToken());

            this.ExecuteWorklow(newPage.GetDataEntityToken(), typeof(EditPageWorkflow));
        }
        private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IMethodBasedFunctionInfo methodBasedFunctionInfo = this.GetBinding <IMethodBasedFunctionInfo>("NewMethodBasedFunction");

            methodBasedFunctionInfo.Id = Guid.NewGuid();

            methodBasedFunctionInfo = DataFacade.AddNew <IMethodBasedFunctionInfo>(methodBasedFunctionInfo);

            addNewTreeRefresher.PostRefreshMesseges(methodBasedFunctionInfo.GetDataEntityToken());
        }
Exemplo n.º 6
0
        private void finalizecodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            ISqlConnection sqlConnection = this.GetBinding <ISqlConnection>("NewSqlConnection");
            string         connection    = this.GetBinding <string>("ConnectionString");

            sqlConnection.EncryptedConnectionString = connection.Encrypt();

            sqlConnection = DataFacade.AddNew <ISqlConnection>(sqlConnection);

            addNewTreeRefresher.PostRefreshMesseges(sqlConnection.GetDataEntityToken());
        }
        private void finalizeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            ISqlFunctionInfo sqlFunctionInfo = this.GetBinding <ISqlFunctionInfo>("NewSqlQueryInfo");

            sqlFunctionInfo = DataFacade.AddNew <ISqlFunctionInfo>(sqlFunctionInfo);

            UserSettings.LastSpecifiedNamespace = sqlFunctionInfo.Namespace;

            addNewTreeRefresher.PostRefreshMesseges(sqlFunctionInfo.GetDataEntityToken());

            this.ExecuteWorklow(sqlFunctionInfo.GetDataEntityToken(), typeof(EditSqlFunctionProviderWorkflow));
        }
Exemplo n.º 8
0
        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IUserGroup userGroup = this.GetBinding <IUserGroup>("NewUserGroup");

            userGroup = DataFacade.AddNew <IUserGroup>(userGroup);

            this.CloseCurrentView();

            LoggingService.LogVerbose("UserManagement", String.Format("New C1 Console user group '{0}' created by '{1}'.", userGroup.Name, UserValidationFacade.GetUsername()), LoggingService.Category.Audit);

            addNewTreeRefresher.PostRefreshMesseges(userGroup.GetDataEntityToken());

            this.ExecuteWorklow(userGroup.GetDataEntityToken(), typeof(EditUserGroupWorkflow));
        }
        private void finalizecodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            var provider = GetFunctionProvider <RazorFunctionProvider>();

            string functionName      = this.GetBinding <string>(Binding_Name);
            string functionNamespace = ChangeNamespaceAccordingToExistingFolders(provider, this.GetBinding <string>(Binding_Namespace));
            string functionFullName  = functionNamespace + "." + functionName;

            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            string fileName = functionName + ".cshtml";
            string folder   = Path.Combine(provider.PhysicalPath, functionNamespace.Replace('.', '\\'));

            string cshtmlFilePath = Path.Combine(folder, fileName);

            string code;

            string copyFromFunction = this.GetBinding <string>(Binding_CopyFromFunctionName);

            if (string.IsNullOrEmpty(copyFromFunction))
            {
                code = NewRazorFunction_CSHTML;
            }
            else
            {
                code = GetFunctionCode(copyFromFunction);
            }

            C1Directory.CreateDirectory(folder);
            C1File.WriteAllText(cshtmlFilePath, code);

            UserSettings.LastSpecifiedNamespace = functionNamespace;

            provider.ReloadFunctions();

            var newFunctionEntityToken = new FileBasedFunctionEntityToken(provider.Name, functionFullName);

            addNewTreeRefresher.PostRefreshMesseges(newFunctionEntityToken);

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

            executionService.Execute(newFunctionEntityToken, new WorkflowActionToken(typeof(EditRazorFunctionWorkflow)), null);
        }
Exemplo n.º 10
0
        private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            Guid   newTemplateId = Guid.NewGuid();
            string newTitle      = this.GetBinding <string>(Binding_Title);

            string newPageTemplate_Markup, newPageTemplate_Codebehind, templateFolder;

            Guid copyOfId = this.GetBinding <Guid>("CopyOfId");

            if (copyOfId == Guid.Empty)
            {
                newPageTemplate_Markup     = NewMasterPage_Markup;
                newPageTemplate_Codebehind = NewMasterPage_Codebehind;

                templateFolder = GetMasterPagesRootFolder();
            }
            else
            {
                ParseTemplateForCopying(copyOfId, out newPageTemplate_Markup, out newPageTemplate_Codebehind, out templateFolder);
            }

            string masterFilePath, codeFilePath;

            GenerateFileNames(templateFolder, newTitle, newTemplateId, out masterFilePath, out codeFilePath);

            newPageTemplate_Markup     = newPageTemplate_Markup.Replace(Marker_Codebehind, Path.GetFileName(codeFilePath));
            newPageTemplate_Codebehind = newPageTemplate_Codebehind
                                         .Replace(Marker_TemplateId, newTemplateId.ToString())
                                         .Replace(Marker_TemplateTitle, CSharpEncodeString(newTitle));

            C1File.WriteAllText(codeFilePath, newPageTemplate_Codebehind);
            C1File.WriteAllText(masterFilePath, newPageTemplate_Markup);

            var entityToken = new PageTemplateEntityToken(newTemplateId);

            PageTemplateProviderRegistry.FlushTemplates();

            addNewTreeRefresher.PostRefreshMesseges(entityToken);

            this.ExecuteAction(entityToken, new WorkflowActionToken(typeof(EditMasterPageWorkflow)));
        }
Exemplo n.º 11
0
        private void finalizecodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            string functionName         = this.GetBinding <string>(Binding_Name);
            string functionNamespace    = this.GetBinding <string>(Binding_Namespace);
            string copyFromFunctionName = this.GetBinding <string>(Binding_CopyFromFunctionName);
            string functionFullName     = functionNamespace + "." + functionName;

            var provider = GetFunctionProvider <UserControlFunctionProvider>();

            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            string fileName       = functionName + ".ascx";
            string folder         = Path.Combine(provider.PhysicalPath, functionNamespace.Replace('.', '\\'));
            string markupFilePath = Path.Combine(folder, fileName);
            string codeFilePath   = markupFilePath + ".cs";

            string markupTemplate = NewUserControl_Markup;
            string code           = NewUserControl_CodeFile;

            if (!copyFromFunctionName.IsNullOrEmpty())
            {
                GetFunctionCode(copyFromFunctionName, out markupTemplate, out code);
            }

            C1Directory.CreateDirectory(folder);
            C1File.WriteAllText(codeFilePath, code);
            C1File.WriteAllText(markupFilePath, markupTemplate.Replace(Marker_CodeFile, functionName + ".ascx.cs"));


            UserSettings.LastSpecifiedNamespace = functionNamespace;

            provider.ReloadFunctions();

            var newFunctionEntityToken = new FileBasedFunctionEntityToken(provider.Name, functionFullName);

            addNewTreeRefresher.PostRefreshMesseges(newFunctionEntityToken);

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

            executionService.Execute(newFunctionEntityToken, new WorkflowActionToken(typeof(EditUserControlFunctionWorkflow)), null);
        }
        private void stepFinalize_codeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher updateTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IVisualFunction newFunction = this.GetBinding <IVisualFunction>("Function");

            newFunction.MaximumItemsToList = 10;
            newFunction.OrderbyAscending   = true;
            newFunction.OrderbyFieldName   = (GetDataTypeDescriptor().LabelFieldName ?? GetDataTypeDescriptor().Fields.First().Name);

            XhtmlDocument defaultDocument = BuildDefaultDocument(newFunction);

            newFunction.XhtmlTemplate = defaultDocument.ToString();

            updateTreeRefresher.PostRefreshMesseges(this.EntityToken);

            var createdFunction = DataFacade.AddNew <IVisualFunction>(newFunction);

            this.ExecuteWorklow(createdFunction.GetDataEntityToken(), typeof(EditVisualFunctionWorkflow));
        }
Exemplo n.º 13
0
        private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IUser newUser             = this.GetBinding <IUser>(BindingNames.NewUser);
            var   bindedUserFormLogin = this.GetBinding <IUserFormLogin>(BindingNames.UserFormLogin);

            NormalizeUsername(newUser);

            string password = this.GetBinding <string>(BindingNames.Password);

            newUser = DataFacade.AddNew <IUser>(newUser);

            UserFormLoginManager.CreateUserFormLogin(newUser.Id, password, bindedUserFormLogin.Folder);

            string cultureName             = this.GetBinding <string>("CultureName");
            string c1ConsoleUiLanguageName = this.GetBinding <string>("C1ConsoleUiLanguageName");

            UserSettings.SetUserCultureInfo(newUser.Username, CultureInfo.CreateSpecificCulture(cultureName));
            UserSettings.SetUserC1ConsoleUiLanguage(newUser.Username, CultureInfo.CreateSpecificCulture(c1ConsoleUiLanguageName));

            CultureInfo locale = DataLocalizationFacade.DefaultLocalizationCulture;

            UserSettings.AddActiveLocaleCultureInfo(newUser.Username, locale);
            UserSettings.SetCurrentActiveLocaleCultureInfo(newUser.Username, locale);
            UserSettings.SetForeignLocaleCultureInfo(newUser.Username, locale);

            this.CloseCurrentView();

            addNewTreeRefresher.PostRefreshMesseges(newUser.GetDataEntityToken());

            LoggingService.LogEntry("UserManagement",
                                    $"New C1 Console user '{newUser.Username}' created by '{UserValidationFacade.GetUsername()}'.",
                                    LoggingService.Category.Audit,
                                    TraceEventType.Information);


            this.ExecuteWorklow(newUser.GetDataEntityToken(), typeof(EditUserWorkflow));
        }
        private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            Guid   newTemplateId = Guid.NewGuid();
            string newTitle      = this.GetBinding <string>(Binding_Title);

            string newPageTemplateMarkup, folderPath;

            Guid copyOfId = this.GetBinding <Guid>("CopyOfId");

            if (copyOfId == Guid.Empty)
            {
                newPageTemplateMarkup = DefaultRazorTemplateMarkup;
                folderPath            = GetRazorTemplatesRootFolder();
            }
            else
            {
                ParseExistingTemplateForCopying(copyOfId, out newPageTemplateMarkup, out folderPath);
            }

            newPageTemplateMarkup = newPageTemplateMarkup
                                    .Replace(Marker_TemplateId, newTemplateId.ToString())
                                    .Replace(Marker_TemplateTitle, CSharpEncodeString(newTitle));


            string filePath = GeneratedCshtmlFileName(folderPath, newTitle, newTemplateId);

            C1File.WriteAllText(filePath, newPageTemplateMarkup);

            var entityToken = new PageTemplateEntityToken(newTemplateId);

            PageTemplateProviderRegistry.FlushTemplates();

            addNewTreeRefresher.PostRefreshMesseges(entityToken);

            this.ExecuteAction(entityToken, new WorkflowActionToken(typeof(EditRazorPageTemplateWorkflow)));
        }
        private void codeActivity2_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IXmlPageTemplate newPageTemplate = this.GetBinding <IXmlPageTemplate>("NewPageTemplate");

            string newPageTemplateMarkup = null;
            Guid   copyOfId = this.GetBinding <Guid>("CopyOfId");

            if (copyOfId == Guid.Empty)
            {
                newPageTemplateMarkup = _defaultTemplateMarkup.Replace("    ", "\t");
            }
            else
            {
                XDocument copyDocument = TemplateInfo.GetTemplateDocument(copyOfId);
                newPageTemplateMarkup = copyDocument.ToString();
            }

            IPageTemplateFile pageTemplateFile = DataFacade.BuildNew <IPageTemplateFile>();

            pageTemplateFile.FolderPath = "/";
            pageTemplateFile.FileName   = string.Format("{0}.xml", PathUtil.CleanFileName(newPageTemplate.Title, true) ?? newPageTemplate.Id.ToString());
            //if (FileNameAlreadyUsed(pageTemplateFile)) pageTemplateFile.FileName = newPageTemplate.Id.ToString() + pageTemplateFile.FileName;
            pageTemplateFile.SetNewContent(newPageTemplateMarkup);

            DataFacade.AddNew <IPageTemplateFile>(pageTemplateFile, "PageTemplateFileProvider");

            newPageTemplate.PageTemplateFilePath = "/" + pageTemplateFile.FileName;
            newPageTemplate = DataFacade.AddNew <IXmlPageTemplate>(newPageTemplate);

            PageTemplateProviderRegistry.FlushTemplates();

            addNewTreeRefresher.PostRefreshMesseges(newPageTemplate.GetDataEntityToken());

            this.ExecuteAction(newPageTemplate.GetDataEntityToken(), new WorkflowActionToken(typeof(EditXmlPageTemplateWorkflow)));
        }
Exemplo n.º 16
0
        private void stepFinalize_codeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            Guid parentId = GetParentId();

            IPage newPage = this.GetBinding <IPage>("NewPage");

            newPage.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name;

            IPageType selectedPageType = DataFacade.GetData <IPageType>().Single(f => f.Id == newPage.PageTypeId);

            IQueryable <IPageTypePageTemplateRestriction> templateRestrictions =
                DataFacade.GetData <IPageTypePageTemplateRestriction>().
                Where(f => f.PageTypeId == newPage.PageTypeId);

            if (selectedPageType.DefaultTemplateId != Guid.Empty)
            {
                newPage.TemplateId = selectedPageType.DefaultTemplateId;
            }
            else if (templateRestrictions.Any())
            {
                newPage.TemplateId = templateRestrictions.First().PageTemplateId;
            }

            bool addToTop        = this.GetBinding <string>("SelectedSortOrder") == "Top";
            bool addToBottom     = this.GetBinding <string>("SelectedSortOrder") == "Bottom";
            bool addToAlphabetic = this.GetBinding <string>("SelectedSortOrder") == "Alphabetic";
            bool addToRelative   = this.GetBinding <string>("SelectedSortOrder") == "Relative";

            using (new DataScope(DataScopeIdentifier.Administrated))
            {
                if (addToTop)
                {
                    newPage = newPage.AddPageAtTop(parentId);
                }
                else if (addToBottom)
                {
                    newPage = newPage.AddPageAtBottom(parentId);
                }
                else if (addToAlphabetic)
                {
                    newPage = newPage.AddPageAlphabetic(parentId);
                }
                else if (addToRelative)
                {
                    Guid relativeSelectedPageId = this.GetBinding <Guid>("RelativeSelectedPageId");

                    newPage = newPage.AddPageAfter(parentId, relativeSelectedPageId);
                }
            }

            // Adding default page content
            IEnumerable <IPageTypeDefaultPageContent> pageTypeDefaultPageContents =
                DataFacade.GetData <IPageTypeDefaultPageContent>().
                Where(f => f.PageTypeId == selectedPageType.Id).
                Evaluate();

            foreach (IPageTypeDefaultPageContent pageTypeDefaultPageContent in pageTypeDefaultPageContents)
            {
                IPagePlaceholderContent pagePlaceholderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                pagePlaceholderContent.PageId        = newPage.Id;
                pagePlaceholderContent.PlaceHolderId = pageTypeDefaultPageContent.PlaceHolderId;
                pagePlaceholderContent.Content       = pageTypeDefaultPageContent.Content;
                DataFacade.AddNew <IPagePlaceholderContent>(pagePlaceholderContent);
            }


            // Adding page folders
            IEnumerable <IPageTypeDataFolderTypeLink> pageTypeDataFolderTypeLinks =
                DataFacade.GetData <IPageTypeDataFolderTypeLink>().
                Where(f => f.PageTypeId == selectedPageType.Id).
                Evaluate().
                RemoveDeadLinks();

            foreach (IPageTypeDataFolderTypeLink pageTypeDataFolderTypeLink in pageTypeDataFolderTypeLinks)
            {
                newPage.AddFolderDefinition(pageTypeDataFolderTypeLink.DataTypeId);
            }


            // Adding applications
            IEnumerable <IPageTypeTreeLink> pageTypeTreeLinks =
                DataFacade.GetData <IPageTypeTreeLink>().
                Where(f => f.PageTypeId == selectedPageType.Id).
                Evaluate().
                RemoveDeadLinks();


            foreach (IPageTypeTreeLink pageTypeTreeLink in pageTypeTreeLinks)
            {
                Tree tree = TreeFacade.GetTree(pageTypeTreeLink.TreeId);
                if (tree.HasAttachmentPoints(newPage.GetDataEntityToken()))
                {
                    continue;
                }

                TreeFacade.AddPersistedAttachmentPoint(pageTypeTreeLink.TreeId, typeof(IPage), newPage.Id);
            }

            SetSaveStatus(true);

            addNewTreeRefresher.PostRefreshMesseges(newPage.GetDataEntityToken());

            this.ExecuteWorklow(newPage.GetDataEntityToken(), typeof(EditPageWorkflow));
        }
Exemplo n.º 17
0
        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            UploadedFile uploadedFile = this.GetBinding <UploadedFile>("UploadedFile");
            string       filename;

            if (this.BindingExist("Filename"))
            {
                filename = this.GetBinding <string>("Filename");
            }
            else
            {
                filename = uploadedFile.FileName;
            }

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                IMediaFileStore store = DataFacade.GetData <IMediaFileStore>(x => x.Id == this.StoreId).First();

                IMediaFile existingFile = GetExistingFile(this.FolderPath, filename);

                if (existingFile == null)
                {
                    WorkflowMediaFile mediaFile = new WorkflowMediaFile();
                    mediaFile.FileName    = System.IO.Path.GetFileName(filename);
                    mediaFile.FolderPath  = this.FolderPath;
                    mediaFile.Title       = this.GetBinding <string>("Title");
                    mediaFile.Description = this.GetBinding <string>("Description");
                    mediaFile.Tags        = this.GetBinding <string>("Tags");
                    mediaFile.Culture     = C1Console.Users.UserSettings.ActiveLocaleCultureInfo.Name;
                    mediaFile.Length      = uploadedFile.ContentLength;
                    mediaFile.MimeType    = MimeTypeInfo.GetMimeType(uploadedFile);

                    using (System.IO.Stream readStream = uploadedFile.FileStream)
                    {
                        using (System.IO.Stream writeStream = mediaFile.GetNewWriteStream())
                        {
                            readStream.CopyTo(writeStream);
                        }
                    }

                    IMediaFile addedFile = DataFacade.AddNew <IMediaFile>(mediaFile, store.DataSourceId.ProviderName);

                    addNewTreeRefresher.PostRefreshMesseges(addedFile.GetDataEntityToken());

                    SelectElement(addedFile.GetDataEntityToken());
                }
                else
                {
                    Guid           fileId   = existingFile.Id;
                    IMediaFileData fileData = DataFacade.GetData <IMediaFileData>(file => file.Id == fileId).FirstOrDefault();

                    fileData.Title       = this.GetBinding <string>("Title");
                    fileData.Description = this.GetBinding <string>("Description");
                    fileData.Tags        = this.GetBinding <string>("Tags");
                    fileData.MimeType    = MimeTypeInfo.GetMimeType(uploadedFile);
                    fileData.Length      = uploadedFile.ContentLength;

                    using (System.IO.Stream readStream = uploadedFile.FileStream)
                    {
                        using (System.IO.Stream writeStream = existingFile.GetNewWriteStream())
                        {
                            readStream.CopyTo(writeStream);
                        }
                    }

                    DataFacade.Update(existingFile);
                    DataFacade.Update(fileData);

                    addNewTreeRefresher.PostRefreshMesseges(existingFile.GetDataEntityToken());

                    SelectElement(existingFile.GetDataEntityToken());
                }

                transactionScope.Complete();
            }
        }