A model for the Switch on the workflow designer
Inheritance: IDev2DataModel, IDev2FlowModel
Ejemplo n.º 1
0
        public static void SetSwitchKeyProperty(Dev2Switch ds, ModelItem switchCase)
        {
            if(ds != null)
            {
                ModelProperty keyProperty = switchCase.Properties["Key"];

                if(keyProperty != null)
                {
                    keyProperty.SetValue(ds.SwitchVariable);

                }
            }
        }
Ejemplo n.º 2
0
        public static void InjectExpression(Dev2Switch ds, ModelProperty activityExpression)
        {
            if(ds == null) return;

            // FetchSwitchData
            string expressionToInject = String.Join("", GlobalConstants.InjectedSwitchDataFetch,
                                                    "(\"", ds.SwitchVariable, "\",",
                                                    GlobalConstants.InjectedDecisionDataListVariable,
                                                    ")");
            if(activityExpression != null)
            {
                activityExpression.SetValue(expressionToInject);
            }
        }
        IEnumerable<IDev2Activity> ParseSwitch(FlowSwitch<string> switchFlowSwitch, List<IDev2Activity> seenActivities)
        {
            var activity = switchFlowSwitch.Expression as DsfFlowSwitchActivity;
            if (activity != null)
            {
                if (seenActivities.Contains(activity))
                {
                    return new List<IDev2Activity> { activity };
                }

                var val = new StringBuilder(Dev2DecisionStack.ExtractModelFromWorkflowPersistedData(activity.ExpressionText));
                 Dev2Switch ds = new Dev2Switch { SwitchVariable = val.ToString() };
                 var swi = new DsfSwitch(activity);
                 if (!seenActivities.Contains(activity))
                 {
                     seenActivities.Add(swi);
                 }
                swi.Switches = switchFlowSwitch.Cases.Select(a => new Tuple<string, IDev2Activity>(a.Key, ParseTools(a.Value, seenActivities).FirstOrDefault())).ToDictionary(a => a.Item1, a => a.Item2);
                swi.Default = ParseTools(switchFlowSwitch.Default, seenActivities);
                swi.Switch = ds.SwitchVariable;
                
                
                return new List<IDev2Activity>
                {  swi
                };
            }
            throw new Exception("Invalid activity");
          
        }
        internal void ConfigureSwitchExpression(Tuple<ModelItem, IEnvironmentModel> wrapper)
        {
            IEnvironmentModel environment = wrapper.Item2;
            ModelItem switchActivity = wrapper.Item1;

            ModelProperty switchProperty = switchActivity.Properties[GlobalConstants.SwitchExpressionPropertyText];

            if (switchProperty != null)
            {
                ModelItem activity = switchProperty.Value;

                if (activity != null)
                {
                    IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(environment.DataListChannel);
                    ModelProperty activityExpression =
                        activity.Properties[GlobalConstants.SwitchExpressionTextPropertyText];

                    ErrorResultTO errors = new ErrorResultTO();
                    Guid dataListID = GlobalConstants.NullDataListID;

                    if (errors.HasErrors()) //BUG 8796, Added this if to handle errors
                    {
                        // Bad things happened... Tell the user
                        PopupProvider.Show(errors.MakeDisplayReady(), GlobalConstants.SwitchWizardErrorHeading,
                                           MessageBoxButton.OK, MessageBoxImage.Error);
                        // Stop configuring!!!
                        return;
                    }

                    string webModel = JsonConvert.SerializeObject(DataListConstants.DefaultSwitch);

                    if (activityExpression != null && activityExpression.Value == null)
                    {
                        // Its all new, push the default model
                        //compiler.PushSystemModelToDataList(dataListID, DataListConstants.DefaultSwitch, out errors);
                    }
                    else
                    {
                        if (activityExpression != null)
                        {
                            if (activityExpression.Value != null)
                            {
                                string val = activityExpression.Value.ToString();

                                if (val.IndexOf(GlobalConstants.InjectedSwitchDataFetch, StringComparison.Ordinal) >= 0)
                                {
                                    // Time to extract the data
                                    int start = val.IndexOf("(", StringComparison.Ordinal);
                                    if (start > 0)
                                    {
                                        int end = val.IndexOf(@""",AmbientData", StringComparison.Ordinal);

                                        if (end > start)
                                        {
                                            start += 2;
                                            val = val.Substring(start, (end - start));

                                            // Convert back for usage ;)
                                            val = Dev2DecisionStack.FromVBPersitableModelToJSON(val);

                                            if (!string.IsNullOrEmpty(val))
                                            {

                                                var ds = new Dev2Switch { SwitchVariable = val };
                                                webModel = JsonConvert.SerializeObject(ds);

                                            }

                                        }
                                    }
                                }
                            }
                        }
                    }

                    // now invoke the wizard ;)
                    Uri requestUri;
                    if (Uri.TryCreate((environment.WebServerAddress + GlobalConstants.SwitchDropWizardLocation), UriKind.Absolute, out requestUri))
                    {
                        string uriString = Browser.FormatUrl(requestUri.AbsoluteUri, dataListID);

                        callBackHandler.ModelData = webModel;
                        WebSites.ShowWebPageDialog(uriString, callBackHandler, 470, 285);


                        // Wizard finished...
                        // Now Fetch from DL and push the model data into the workflow
                        try
                        {
                            Dev2Switch ds = JsonConvert.DeserializeObject<Dev2Switch>(_callBackHandler.ModelData);

                            if (ds != null)
                            {
                                // FetchSwitchData
                                string expressionToInject = string.Join("", GlobalConstants.InjectedSwitchDataFetch, "(\"", ds.SwitchVariable, "\",", GlobalConstants.InjectedDecisionDataListVariable, ")");

                                if (activityExpression != null)
                                {
                                    activityExpression.SetValue(expressionToInject);
                                }
                            }
                        }
                        catch
                        {
                            // Bad things happened... Tell the user
                            PopupProvider.Show(GlobalConstants.SwitchWizardErrorString,
                                               GlobalConstants.SwitchWizardErrorHeading, MessageBoxButton.OK,
                                               MessageBoxImage.Error);
                        }
                    }
                }
            }
        }