Ejemplo n.º 1
0
        public Type WorkflowType { get; internal set; }     // Requried


        protected override void OnAddAction(Action<ElementAction> actionAdder, EntityToken entityToken, TreeNodeDynamicContext dynamicContext, DynamicValuesHelperReplaceContext dynamicValuesHelperReplaceContext)
        {
            WorkflowActionToken actionToken = new WorkflowActionToken(
                WorkflowFacade.GetWorkflowType(TypeManager.SerializeType(this.WorkflowType)),
                this.PermissionTypes)
            {
                Payload = this.Serialize(),
                ExtraPayload = PiggybagSerializer.Serialize(dynamicContext.Piggybag.PreparePiggybag(dynamicContext.CurrentTreeNode, dynamicContext.CurrentEntityToken)),
                DoIgnoreEntityTokenLocking = true
            };


            actionAdder(new ElementAction(new ActionHandle(actionToken))
            {
                VisualData = CreateActionVisualizedData(dynamicValuesHelperReplaceContext)
            });
        }
Ejemplo n.º 2
0
        /// <exclude />
        protected override void OnAddAction(Action<ElementAction> actionAdder, EntityToken entityToken, TreeNodeDynamicContext dynamicContext, DynamicValuesHelperReplaceContext dynamicValuesHelperReplaceContext)
        {
            StringBuilder payload = new StringBuilder();
            StringConversionServices.SerializeKeyValuePair(payload, "TreeId", this.OwnerNode.Tree.TreeId);
            StringConversionServices.SerializeKeyValuePair(payload, "ActionId", this.Id);

            WorkflowActionToken actionToken = new WorkflowActionToken(
                WorkflowFacade.GetWorkflowType("Composite.C1Console.Trees.Workflows.ReportFunctionActionWorkflow"), 
                this.PermissionTypes)                
            {
                Payload = this.Serialize(),
                ExtraPayload = PiggybagSerializer.Serialize(dynamicContext.Piggybag.PreparePiggybag(dynamicContext.CurrentTreeNode, dynamicContext.CurrentEntityToken)),
                DoIgnoreEntityTokenLocking = true
            };
            

            actionAdder(new ElementAction(new ActionHandle(actionToken))
            {
                VisualData = CreateActionVisualizedData(dynamicValuesHelperReplaceContext)
            });
        }
        /// <exclude />
        public static ActionToken Deserialize(string serializedWorkflowActionToken)
        {
            Dictionary <string, string> dic = ParseKeyValueCollection(serializedWorkflowActionToken);

            if (!dic.ContainsKey("_WorkflowType_") ||
                !dic.ContainsKey("_Payload_") ||
                !dic.ContainsKey("_ExtraPayload_") ||
                !dic.ContainsKey("_Ignore_") ||
                !dic.ContainsKey("_PermissionTypes_"))
            {
                throw new ArgumentException("The serializedWorkflowActionToken is not a serialized WorkflowActionToken", nameof(serializedWorkflowActionToken));
            }

            string serializedType = DeserializeValueString(dic["_WorkflowType_"]);
            Type   type           = TypeManager.GetType(serializedType);

            string permissionTypesString = DeserializeValueString(dic["_PermissionTypes_"]);

            var workflowActionToken = new WorkflowActionToken(type, permissionTypesString.DesrializePermissionTypes());

            string payload = DeserializeValueString(dic["_Payload_"]);

            workflowActionToken.Payload = payload;

            string extraPayload = DeserializeValueString(dic["_ExtraPayload_"]);

            workflowActionToken.ExtraPayload = extraPayload;

            bool ignoreEntityTokenLocking = DeserializeValueBool(dic["_Ignore_"]);

            workflowActionToken.DoIgnoreEntityTokenLocking = ignoreEntityTokenLocking;

            if (dic.ContainsKey("_EventHandleFilterType_"))
            {
                string serializedFilterType = DeserializeValueString(dic["_EventHandleFilterType_"]);
                workflowActionToken.EventHandleFilterType = TypeManager.GetType(serializedFilterType);
            }

            return(workflowActionToken);
        }
        public FlowToken Execute(string serializedEntityToken, string serializedActionToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            WorkflowActionToken workflowActionToken = (WorkflowActionToken)actionToken;

            WorkflowInstance workflowInstance = WorkflowFacade.CreateNewWorkflow(
                workflowActionToken.WorkflowType,
                new Dictionary <string, object> {
                { "SerializedEntityToken", serializedEntityToken },
                { "SerializedActionToken", serializedActionToken },
                { "ParentWorkflowInstanceId", workflowActionToken.ParentWorkflowInstanceId }
            }
                );

            workflowInstance.Start();

            WorkflowFacade.SetFlowControllerServicesContainer(workflowInstance.InstanceId, flowControllerServicesContainer);
            WorkflowFacade.RunWorkflow(workflowInstance);

            WorkflowFacade.SetEventHandlerFilter(workflowInstance.InstanceId, workflowActionToken.EventHandleFilterType);

            return(new WorkflowFlowToken(workflowInstance.InstanceId));
        }
Ejemplo n.º 5
0
        /// <exclude />
        public static ActionToken Deserialize(string serialiedWorkflowActionToken)
        {
            Dictionary<string, string> dic = StringConversionServices.ParseKeyValueCollection(serialiedWorkflowActionToken);

            if ((dic.ContainsKey("_WorkflowType_") == false) ||
                (dic.ContainsKey("_Payload_") == false) ||
                (dic.ContainsKey("_ExtraPayload_") == false) ||
                (dic.ContainsKey("_Ignore_") == false) ||
                (dic.ContainsKey("_PermissionTypes_") == false))
            {
                throw new ArgumentException("The serialiedWorkflowActionToken is not a serialized WorkflowActionToken", "serialiedWorkflowActionToken");
            }

            string serializedType = StringConversionServices.DeserializeValueString(dic["_WorkflowType_"]);
            Type type = TypeManager.GetType(serializedType);

            string permissionTypesString = StringConversionServices.DeserializeValueString(dic["_PermissionTypes_"]);

            WorkflowActionToken workflowActionToken = new WorkflowActionToken(type, permissionTypesString.DesrializePermissionTypes());

            string payload = StringConversionServices.DeserializeValueString(dic["_Payload_"]);
            workflowActionToken.Payload = payload;

            string extraPayload = StringConversionServices.DeserializeValueString(dic["_ExtraPayload_"]);
            workflowActionToken.ExtraPayload = extraPayload;

            bool ignoreEntityTokenLocking = StringConversionServices.DeserializeValueBool(dic["_Ignore_"]);
            workflowActionToken.DoIgnoreEntityTokenLocking = ignoreEntityTokenLocking;

            if (dic.ContainsKey("_EventHandleFilterType_"))
            {
                string serializedFilterType = StringConversionServices.DeserializeValueString(dic["_EventHandleFilterType_"]);
                workflowActionToken.EventHandleFilterType = TypeManager.GetType(serializedFilterType);
            }

            return workflowActionToken;
        }
Ejemplo n.º 6
0
        private Element BuildElement(IData data, 
            DynamicValuesHelperReplaceContext replaceContext,
            TreeNodeDynamicContext dynamicContext,
            bool localizationEnabled,
            List<object> itemKeys,
            ref IEnumerable<object> keysJoinedByParentFilters,
            EntityToken parentEntityToken
            )
        {
            replaceContext.CurrentDataItem = data;
            
            object keyValue = this.KeyPropertyInfo.GetValue(data, null);

            bool itemLocalizationEnabledAndForeign = localizationEnabled && !data.DataSourceId.LocaleScope.Equals(UserSettings.ActiveLocaleCultureInfo);

            if (itemLocalizationEnabledAndForeign && itemKeys.Contains(keyValue)) return null;

            var currentEntityToken = data.GetDataEntityToken();

            var element = new Element(new ElementHandle
            (
                dynamicContext.ElementProviderName,
                currentEntityToken,
                dynamicContext.Piggybag.PreparePiggybag(this.ParentNode, parentEntityToken)
            ));


            bool hasChildren;
            bool isDisabled = false;
            ResourceHandle icon, openedIcon;

            if (itemLocalizationEnabledAndForeign)
            {
                hasChildren = false;
                isDisabled = !data.IsTranslatable();

                if (this.Icon != null)
                {
                    icon = this.Icon;
                    openedIcon = this.OpenedIcon;
                }
                else
                {
                    icon = data.GetForeignIcon();
                    openedIcon = icon;
                }
            }
            else
            {
                if (this.Display != LeafDisplayMode.Auto)
                {
                    hasChildren = ChildNodes.Any();
                }
                else
                {
                    hasChildren = ChildNodes.OfType<SimpleElementTreeNode>().Any();

                    if (!hasChildren)
                    {
                        if (keysJoinedByParentFilters != null)
                        {
                            keysJoinedByParentFilters = keysJoinedByParentFilters.Evaluate();

                            hasChildren = keysJoinedByParentFilters.Contains(keyValue);
                        }
                    }

                    // Checking children filtered by FunctionFilters
                    if (!hasChildren)
                    {
                        foreach (var childNode in this.ChildNodes.OfType<DataElementsTreeNode>()
                            .Where(n => n.FilterNodes.OfType<FunctionFilterNode>().Any()))
                        {
                            var newDynamicContext = new TreeNodeDynamicContext(TreeNodeDynamicContextDirection.Down)
                            {
                                ElementProviderName = dynamicContext.ElementProviderName,
                                Piggybag = dynamicContext.Piggybag.PreparePiggybag(this.ParentNode, parentEntityToken),
                                CurrentEntityToken = currentEntityToken
                            };

                            if (childNode.GetDataset(newDynamicContext, false).DataItems.Any())
                            {
                                hasChildren = true;
                                break;
                            }
                        }
                    }
                }

                if (this.Icon != null)
                {
                    icon = this.Icon;
                    openedIcon = this.OpenedIcon;
                }
                else
                {
                    openedIcon = icon = data.GetIcon();
                }
            }

            string label = this.Label.IsNullOrEmpty()
                            ? data.GetLabel()
                            : this.LabelDynamicValuesHelper.ReplaceValues(replaceContext);

            string toolTip = this.ToolTip.IsNullOrEmpty()
                            ? label
                            : this.ToolTipDynamicValuesHelper.ReplaceValues(replaceContext);

            if (itemLocalizationEnabledAndForeign)
            {
                label = string.Format("{0} ({1})", label, DataLocalizationFacade.GetCultureTitle(UserSettings.ForeignLocaleCultureInfo));

                if (!data.IsTranslatable())
                {
                    toolTip = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeDataWorkflow.DisabledData");
                }
                else
                {
                    toolTip = string.Format("{0} ({1})", toolTip, DataLocalizationFacade.GetCultureTitle(UserSettings.ForeignLocaleCultureInfo));
                }
            }

            element.VisualData = new ElementVisualizedData
            {
                Label = label,
                ToolTip = toolTip,
                HasChildren = hasChildren,
                Icon = icon,
                OpenedIcon = openedIcon,
                IsDisabled = isDisabled
            };


            if (InternalUrls.DataTypeSupported(data.DataSourceId.InterfaceType))
            {
                var dataReference = data.ToDataReference();

                if (DataUrls.CanBuildUrlForData(dataReference))
                {
                    string internalUrl = InternalUrls.TryBuildInternalUrl(dataReference);

                    if (internalUrl != null)
                    {
                        element.PropertyBag.Add("Uri", internalUrl);
                    }
                }
            }


            if (itemLocalizationEnabledAndForeign)
            {
                var actionToken = new WorkflowActionToken(
                    WorkflowFacade.GetWorkflowType("Composite.C1Console.Trees.Workflows.LocalizeDataWorkflow"),
                    LocalizeDataPermissionTypes);

                element.AddAction(new ElementAction(new ActionHandle(actionToken))
                {
                    VisualData = new ActionVisualizedData
                    {
                        Label = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeDataWorkflow.LocalizeDataLabel"),
                        ToolTip = StringResourceSystemFacade.GetString("Composite.C1Console.Trees", "LocalizeDataWorkflow.LocalizeDataToolTip"),
                        Icon = LocalizeDataTypeIcon,
                        Disabled = false,
                        ActionLocation = ActionLocation.OtherPrimaryActionLocation
                    }
                });
            }

            return element;
        }
Ejemplo n.º 7
0
        /// <exclude />
        public static FlowToken ExecuteSecurityViolation(ActionToken actionToken, EntityToken entityToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            EntityToken newEntityToken = new SecurityViolationWorkflowEntityToken();

            WorkflowActionToken newActionToken = new WorkflowActionToken(WorkflowFacade.GetWorkflowType("Composite.C1Console.Actions.Workflows.SecurityViolationWorkflow"));

            return Execute(newEntityToken, newActionToken, flowControllerServicesContainer);
        }
Ejemplo n.º 8
0
        /// <exclude />
        public static FlowToken ExecuteEntityTokenLocked(ActionToken lockedActionToken, EntityToken lockedEntityToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            EntityToken entityToken = new EntityTokenLockedEntityToken(
                    ActionLockingFacade.LockedBy(lockedEntityToken),
                    ActionTokenSerializer.Serialize(lockedActionToken),
                    EntityTokenSerializer.Serialize(lockedEntityToken)
                );

            WorkflowActionToken actionToken = new WorkflowActionToken(WorkflowFacade.GetWorkflowType("Composite.C1Console.Actions.Workflows.EntityTokenLockedWorkflow"));

            return Execute(entityToken, actionToken, flowControllerServicesContainer);
        }