internal void ConfigureDecisionExpression(Tuple<ModelItem, IEnvironmentModel> wrapper)
{
IEnvironmentModel environment = wrapper.Item2;
ModelItem decisionActivity = wrapper.Item1;
ModelProperty conditionProperty = decisionActivity.Properties[GlobalConstants.ConditionPropertyText];
if (conditionProperty == null) return;
var activity = conditionProperty.Value;
if (activity != null)
{
string val = JsonConvert.SerializeObject(DataListConstants.DefaultStack);
ModelProperty activityExpression = activity.Properties[GlobalConstants.ExpressionPropertyText];
ErrorResultTO errors = new ErrorResultTO();
if (errors.HasErrors()) //BUG 8796, Added this if to handle errors
{
// Bad things happened... Tell the user
PopupProvider.Show(errors.MakeDisplayReady(), GlobalConstants.DecisionWizardErrorHeading, MessageBoxButton.OK, MessageBoxImage.Error);
// Stop configuring!!!
return;
}
// Push the correct data to the server ;)
if (activityExpression != null && activityExpression.Value == null)
{
// Its all new, push the empty model
//compiler.PushSystemModelToDataList(dataListID, DataListConstants.DefaultStack, out errors);
}
else if (activityExpression != null && activityExpression.Value != null)
{
//we got a model, push it in to the Model region ;)
// but first, strip and extract the model data ;)
val = Dev2DecisionStack.ExtractModelFromWorkflowPersistedData(activityExpression.Value.ToString());
if (string.IsNullOrEmpty(val))
{
val = JsonConvert.SerializeObject(DataListConstants.DefaultStack);
}
}
// Now invoke the Wizard ;)
Uri requestUri;
if (Uri.TryCreate((environment.WebServerAddress + GlobalConstants.DecisionWizardLocation), UriKind.Absolute, out requestUri))
{
string uriString = Browser.FormatUrl(requestUri.AbsoluteUri, GlobalConstants.NullDataListID);
_callBackHandler.ModelData = val; // set the model data
//callBackHandler.Owner = new WebPropertyEditorWindow(callBackHandler, uriString);
//callBackHandler.Owner.ShowDialog();
WebSites.ShowWebPageDialog(uriString, _callBackHandler, 824, 508);
WebSites.ShowWebPageDialog(uriString, callBackHandler, 824, 508);
// Wizard finished...
try
{
// Remove naughty chars...
var tmp = callBackHandler.ModelData;
// remove the silly Choose... from the string
tmp = Dev2DecisionStack.RemoveDummyOptionsFromModel(tmp);
// remove [[]], &, !
tmp = Dev2DecisionStack.RemoveNaughtyCharsFromModel(tmp);
Dev2DecisionStack dds = JsonConvert.DeserializeObject<Dev2DecisionStack>(tmp);
if (dds != null)
{
// Empty check the arms ;)
if (string.IsNullOrEmpty(dds.TrueArmText.Trim()))
{
dds.TrueArmText = GlobalConstants.DefaultTrueArmText;
}
if (string.IsNullOrEmpty(dds.FalseArmText.Trim()))
{
dds.FalseArmText = GlobalConstants.DefaultFalseArmText;
}
// Update the decision node on the workflow ;)
string modelData = dds.ToVBPersistableModel();
// build up our injected expression handler ;)
string expressionToInject = string.Join("", GlobalConstants.InjectedDecisionHandler, "(\"", modelData, "\",", GlobalConstants.InjectedDecisionDataListVariable, ")");
if (activityExpression != null)
{
activityExpression.SetValue(expressionToInject);
}
// now set arms ;)
ModelProperty tArm = decisionActivity.Properties[GlobalConstants.TrueArmPropertyText];
if (tArm != null)
{
tArm.SetValue(dds.TrueArmText);
}
ModelProperty fArm = decisionActivity.Properties[GlobalConstants.FalseArmPropertyText];
if (fArm != null)
{
fArm.SetValue(dds.FalseArmText);
}
}
}
catch
{
// Bad things happened... Tell the user
//PopupProvider.Show("", "")
PopupProvider.Buttons = MessageBoxButton.OK;
PopupProvider.Description = GlobalConstants.DecisionWizardErrorString;
PopupProvider.Header = GlobalConstants.DecisionWizardErrorHeading;
PopupProvider.ImageType = MessageBoxImage.Error;
PopupProvider.Show();
}
}
}
}