private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            DeleteTreeRefresher deleteTreeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken);

            DataEntityToken dataEntityToken = (DataEntityToken)this.EntityToken;

            IVisualFunction visualFunction = (IVisualFunction)dataEntityToken.Data;

            DataFacade.Delete <IVisualFunction>(visualFunction);

            int count =
                (from info in DataFacade.GetData <IVisualFunction>()
                 where info.Namespace == visualFunction.Namespace
                 select info).Count();


            if (count == 0)
            {
                RefreshFunctionTree();
            }
            else
            {
                deleteTreeRefresher.PostRefreshMesseges();
            }
        }
        /// <exclude />
        public static XhtmlDocument RenderDataList <T>(IVisualFunction function, XhtmlDocument xhtmlDocument, DataTypeDescriptor typeDescriptor, FunctionContextContainer functionContextContainer, Expression <Func <T, bool> > filter)
            where T : class, IData
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }
            if (xhtmlDocument == null)
            {
                throw new ArgumentNullException("xhtmlDocument");
            }
            if (typeDescriptor == null)
            {
                throw new ArgumentNullException("typeDescriptor");
            }
            if (functionContextContainer == null)
            {
                throw new ArgumentNullException("functionContextContainer");
            }

            Type dataType = typeDescriptor.GetInterfaceType();

            if (dataType == null)
            {
                throw new InvalidOperationException(string.Format("'{0}' is not a known type manager type.", typeDescriptor.TypeManagerTypeName));
            }

            List <T> allData = DataFacade.GetData <T>(filter).ToList();

            List <T> itemsToList;

            if (function.OrderbyFieldName == "(random)")
            {
                int itemsInList  = allData.Count();
                int itemsToFetch = Math.Min(itemsInList, function.MaximumItemsToList);

                itemsToList = new List <T>();

                while (itemsToFetch > 0)
                {
                    int itemToGet = (Math.Abs(Guid.NewGuid().GetHashCode()) % itemsInList); // (new Random()).Next(0, itemsInList);

                    itemsToList.Add(allData[itemToGet]);
                    allData.RemoveAt(itemToGet);

                    itemsToFetch--;
                    itemsInList--;
                }
            }
            else
            {
                IComparer <T> comparer = GenericComparer <T> .Build(typeDescriptor.GetInterfaceType(), function.OrderbyFieldName, function.OrderbyAscending);

                allData.Sort(comparer);

                itemsToList = allData.Take(function.MaximumItemsToList).ToList();
            }

            return(RenderDataListImpl <T>(xhtmlDocument, typeDescriptor, itemsToList, functionContextContainer));
        }
Esempio n. 3
0
 public RuntimeVisualFunction(IVisualFunction function, int maximumItemsToList, string orderbyFieldName, bool orderbyAscending)
 {
     _function           = function;
     _maximumItemsToList = maximumItemsToList;
     _orderbyFieldName   = orderbyFieldName;
     _orderbyAscending   = orderbyAscending;
 }
        private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            DataEntityToken token    = (DataEntityToken)this.EntityToken;
            IVisualFunction function = (IVisualFunction)token.Data;

            this.Bindings.Add("OriginalFullName", string.Format("{0}.{1}", function.Namespace, function.Name));
            this.Bindings.Add("Function", function);
            this.Bindings.Add("XhtmlBody", function.XhtmlTemplate);

            Type interfaceType = TypeManager.GetType(function.TypeManagerName);
            DataTypeDescriptor typeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);

            this.Bindings.Add("EmbedableFieldsTypes", new List <Type> {
                interfaceType
            });
            this.Bindings.Add("SourceTypeFullName", interfaceType.FullName);

            this.Bindings.Add("FieldNameList", FieldNames(typeDescriptor).ToList());

            Dictionary <Guid, string> templateInfos = new Dictionary <Guid, string>();

            foreach (PageTemplateDescriptor pageTemplate in PageTemplateFacade.GetPageTemplates())
            {
                if (pageTemplate.PlaceholderDescriptions.Any())
                {
                    templateInfos.Add(pageTemplate.Id, pageTemplate.Title);
                }
            }

            this.Bindings.Add("PreviewTemplateId", templateInfos.First().Key);
            this.Bindings.Add("TemplateList", templateInfos);
        }
        private static XhtmlDocument RenderCompleteDataListImpl <T>(IVisualFunction function, XhtmlDocument xhtmlDocument, DataTypeDescriptor typeDescriptor, FunctionContextContainer functionContextContainer)
            where T : class, IData
        {
            Expression <Func <T, bool> > filter = f => true;

            return(RenderDataList <T>(function, xhtmlDocument, typeDescriptor, functionContextContainer, filter));
        }
        private static XhtmlDocument BuildDefaultDocument(IVisualFunction newFunction)
        {
            XElement htmlTable = new XElement(Namespaces.Xhtml + "table");

            Type interfaceType = TypeManager.GetType(newFunction.TypeManagerName);
            DataTypeDescriptor typeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);

            foreach (DataFieldDescriptor dataField in typeDescriptor.Fields.OrderBy(f => f.Position))
            {
                if (!typeDescriptor.KeyPropertyNames.Contains(dataField.Name) &&
                    dataField.FormRenderingProfile != null &&
                    !string.IsNullOrEmpty(dataField.FormRenderingProfile.Label))
                {
                    string fieldMarkup = string.Format("<data:fieldreference fieldname=\"{0}\" typemanagername=\"{1}\" xmlns:data=\"{2}\" />", dataField.Name, newFunction.TypeManagerName, Namespaces.DynamicData10);

                    htmlTable.Add(new XElement(Namespaces.Xhtml + "tr",
                                               new XElement(Namespaces.Xhtml + "td",
                                                            dataField.FormRenderingProfile.Label),
                                               new XElement(Namespaces.Xhtml + "td",
                                                            XElement.Parse(fieldMarkup))));
                }
            }
            XhtmlDocument defaultDocument = new XhtmlDocument();

            defaultDocument.Body.Add(htmlTable);
            return(defaultDocument);
        }
        private void CheckFunctionNameIsUnique(object sender, ConditionalEventArgs e)
        {
            IVisualFunction function = this.GetBinding <IVisualFunction>("Function");

            string functionFullName = $"{function.Namespace}.{function.Name}";

            e.Result = !FunctionFacade.FunctionNames.Contains(functionFullName);
        }
Esempio n. 8
0
        /// <exclude />
        public static IVisualFunction GetVisualFunction(RenderingFunctionNames renderingFunctionNames)
        {
            IVisualFunction function =
                (from wrf in DataFacade.GetData <IVisualFunction>()
                 where wrf.Name == renderingFunctionNames.Name &&
                 wrf.Namespace == renderingFunctionNames.Namespace
                 select wrf).FirstOrDefault();

            return(function);
        }
Esempio n. 9
0
 public static IEnumerable <IPackItem> CreateVisual(EntityToken entityToken)
 {
     if (entityToken is DataEntityToken)
     {
         DataEntityToken dataEntityToken = (DataEntityToken)entityToken;
         if (dataEntityToken.Data is IVisualFunction)
         {
             IVisualFunction data = (IVisualFunction)dataEntityToken.Data;
             yield return(new PCFunctions(data.Namespace + "." + data.Name));
         }
     }
 }
        /// <exclude />
        public static XhtmlDocument RenderCompleteDataList(IVisualFunction function, XhtmlDocument xhtmlDocument, DataTypeDescriptor typeDescriptor, FunctionContextContainer functionContextContainer)
        {
            Type typeofClassWithGenericStaticMethod = typeof(RenderingHelper);

            // Grabbing the specific static method
            MethodInfo methodInfo = typeofClassWithGenericStaticMethod.GetMethod("RenderCompleteDataListImpl", System.Reflection.BindingFlags.Static | BindingFlags.NonPublic);

            // Binding the method info to generic arguments
            Type[]     genericArguments  = new Type[] { typeDescriptor.GetInterfaceType() };
            MethodInfo genericMethodInfo = methodInfo.MakeGenericMethod(genericArguments);

            // Simply invoking the method and passing parameters
            // The null parameter is the object to call the method from. Since the method is
            // static, pass null.
            return((XhtmlDocument)genericMethodInfo.Invoke(null, new object[] { function, xhtmlDocument, typeDescriptor, functionContextContainer }));
        }
        private void editPreviewCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                XhtmlDocument templateDocument = GetTemplateDocumentFromBindings();

                IVisualFunction function      = this.GetBinding <IVisualFunction>("Function");
                Type            interfaceType = TypeManager.GetType(function.TypeManagerName);

                DataTypeDescriptor typeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);

                this.LogMessage(Composite.Core.Logging.LogLevel.Info, DataScopeManager.CurrentDataScope.Name);

                FunctionContextContainer fcc = PageRenderer.GetPageRenderFunctionContextContainer();

                XhtmlDocument result = RenderingHelper.RenderCompleteDataList(function, templateDocument, typeDescriptor, fcc);

                IPage previewPage = DataFacade.BuildNew <IPage>();
                previewPage.Id    = GetRootPageId();
                previewPage.Title = function.Name;
                previewPage.DataSourceId.DataScopeIdentifier = DataScopeIdentifier.Administrated;
                previewPage.DataSourceId.LocaleScope         = LocalizationScopeManager.CurrentLocalizationScope;

                previewPage.TemplateId = this.GetBinding <Guid>("PreviewTemplateId");

                var pageTemplate = PageTemplateFacade.GetPageTemplate(previewPage.TemplateId);
                IPagePlaceholderContent placeHolderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                placeHolderContent.Content       = string.Concat((result.Body.Elements().Select(b => b.ToString())).ToArray());
                placeHolderContent.PlaceHolderId = pageTemplate.DefaultPlaceholderId;

                string output = PagePreviewBuilder.RenderPreview(previewPage, new List <IPagePlaceholderContent> {
                    placeHolderContent
                });

                var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);

                var webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>();
                webRenderService.SetNewPageOutput(new LiteralControl(output));
            }
            catch (Exception ex)
            {
                FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
                Control errOutput        = new LiteralControl("<pre>" + ex + "</pre>");
                var     webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>();
                webRenderService.SetNewPageOutput(errOutput);
            }
        }
        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));
        }
        private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            UpdateTreeRefresher updateTreeRefresher = this.CreateUpdateTreeRefresher(this.EntityToken);

            XhtmlDocument templateDocument = GetTemplateDocumentFromBindings();

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

            function.XhtmlTemplate = templateDocument.ToString();

            DataFacade.Update(function);

            string functionFullName = string.Format("{0}.{1}", function.Namespace, function.Name);

            this.UpdateBinding("OriginalFullName", functionFullName);

            updateTreeRefresher.PostRefreshMesseges(function.GetDataEntityToken());

            SetSaveStatus(true);
        }
        private void CheckFunctionReNameIsUnique(object sender, ConditionalEventArgs e)
        {
            IVisualFunction function = this.GetBinding <IVisualFunction>("Function");

            string functionFullName = string.Format("{0}.{1}", function.Namespace, function.Name);
            string originalFullName = this.GetBinding <string>("OriginalFullName");

            if (functionFullName == originalFullName)
            {
                e.Result = true;
                return;
            }

            if (FunctionFacade.FunctionNames.Contains(functionFullName))
            {
                e.Result = false;
            }
            else
            {
                e.Result = true;
            }
        }
 public VisualFunctionTreeBuilderLeafInfo(IVisualFunction function)
 {
     _function = function;
 }
Esempio n. 16
0
 public VisualFunction(IVisualFunction visualFunction)
 {
     _visualFunction = visualFunction;
 }
        private static XhtmlDocument BuildDefaultDocument(IVisualFunction newFunction)
        {
            XElement htmlTable = new XElement(Namespaces.Xhtml + "table");

            Type interfaceType = TypeManager.GetType(newFunction.TypeManagerName);
            DataTypeDescriptor typeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);
            foreach (DataFieldDescriptor dataField in typeDescriptor.Fields.OrderBy(f => f.Position))
            {
                if (!typeDescriptor.KeyPropertyNames.Contains(dataField.Name)
                    && dataField.FormRenderingProfile != null 
                    && !string.IsNullOrEmpty(dataField.FormRenderingProfile.Label))
                {
                    string fieldMarkup = string.Format("<data:fieldreference fieldname=\"{0}\" typemanagername=\"{1}\" xmlns:data=\"{2}\" />", dataField.Name, newFunction.TypeManagerName, Namespaces.DynamicData10);

                    htmlTable.Add(new XElement(Namespaces.Xhtml + "tr",
                        new XElement(Namespaces.Xhtml + "td",
                            dataField.FormRenderingProfile.Label),
                        new XElement(Namespaces.Xhtml + "td",
                            XElement.Parse(fieldMarkup))));
                }
            }
            XhtmlDocument defaultDocument = new XhtmlDocument();
            defaultDocument.Body.Add(htmlTable);
            return defaultDocument;
        }