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);
}
}
}
}
}