public List <DynamicServiceObjectBase> GenerateServiceGraph(StringBuilder serviceData) { if (serviceData == null || serviceData.Length == 0) { throw new ArgumentException("serviceData"); } List <DynamicServiceObjectBase> result = new List <DynamicServiceObjectBase>(); var xe = serviceData.ToXElement(); if (IsSource(serviceData)) { Source src = new Source(); var tmp = src as DynamicServiceObjectBase; ServiceMetaData.ExtractMetaData(xe, ref tmp); var typeOf = xe.AttributeSafe("ResourceType"); enSourceType sourceType; src.Type = !Enum.TryParse(typeOf, out sourceType) ? enSourceType.Unknown : sourceType; src.ConnectionString = xe.AttributeSafe("ConnectionString"); var tmpUri = xe.AttributeSafe("Uri"); if (!string.IsNullOrEmpty(tmpUri)) { src.WebServiceUri = new Uri(tmpUri); } src.AssemblyName = xe.AttributeSafe("AssemblyName"); src.AssemblyLocation = xe.AttributeSafe("AssemblyLocation"); // PBI 6597: TWR - added source ID check var id = ServiceMetaData.SetID(ref xe); src.ID = id; src.ResourceDefinition = serviceData; result.Add(src); } else { DynamicService ds = new DynamicService(); var tmp = ds as DynamicServiceObjectBase; ServiceMetaData.ExtractMetaData(xe, ref tmp); // set the resource def ;) ds.ResourceDefinition = serviceData; var actions = xe.Element("Actions"); XElement action = actions != null?actions.Element("Action") : xe.Element("Action"); if (action != null) { ServiceAction sa = new ServiceAction { Name = action.AttributeSafe("Name"), ResourceDefinition = serviceData }; // Set service action ;) enActionType actionType; var typeOf = action.AttributeSafe("Type"); if (Enum.TryParse(typeOf, out actionType)) { sa.ActionType = actionType; } var element = action.Element("Outputs"); if (element != null) { sa.OutputSpecification = element.Value; } // set name and id ;) sa.ServiceName = ds.Name; var id = ServiceMetaData.SetID(ref xe); ds.ID = id; if (IsWorkflow(serviceData)) { // Convert to StringBuilder var xElement = action.Element("XamlDefinition"); if (xElement != null) { var def = xElement.ToStringBuilder(); def = def.Replace("<XamlDefinition>", "").Replace("</XamlDefinition>", ""); sa.XamlDefinition = def.Unescape(); } var dataList = xe.Element("DataList"); if (dataList != null) { ds.DataListSpecification = dataList.ToStringBuilder(); } } else { if (sa.ActionType == enActionType.InvokeStoredProc) { int timeout; Int32.TryParse(action.AttributeSafe("CommandTimeout"), out timeout); sa.CommandTimeout = timeout; } var xElement = action.Element("OutputDescription"); if (xElement != null) { sa.OutputDescription = xElement.Value; } // process inputs and outputs ;) var inputs = action.Element("Inputs"); if (inputs != null) { var inputCollection = inputs.Elements("Input"); foreach (var inputItem in inputCollection) { bool emptyToNull; bool.TryParse(inputItem.AttributeSafe("EmptyToNull"), out emptyToNull); ServiceActionInput sai = new ServiceActionInput { Name = inputItem.AttributeSafe("Name"), Source = inputItem.AttributeSafe("Source"), DefaultValue = inputItem.AttributeSafe("DefaultValue"), EmptyToNull = emptyToNull, NativeType = inputItem.AttributeSafe("NativeType") }; if (string.IsNullOrEmpty(sai.NativeType)) { sai.NativeType = "object"; } // handle validators ;) var validators = inputItem.Elements("Validator"); foreach (var validator in validators) { Validator v = new Validator(); enValidationType validatorType; v.ValidatorType = !Enum.TryParse(validator.AttributeSafe("Type"), out validatorType) ? enValidationType.Required : validatorType; sai.Validators.Add(v); } sa.ServiceActionInputs.Add(sai); } } } // add the action ds.Actions.Add(sa); result.Add(ds); } } return(result); }
static ServiceAction AddServiceAction(ServiceAction sa, XElement action) { if (sa.ActionType == enActionType.InvokeStoredProc) { Int32.TryParse(action.AttributeSafe("CommandTimeout"), out int timeout); sa.CommandTimeout = timeout; } var xElement = action.Element("OutputDescription"); if (xElement != null) { sa.OutputDescription = xElement.Value; } // process inputs and outputs ;) var inputs = action.Element("Inputs"); if (inputs != null) { var inputCollection = inputs.Elements("Input"); foreach (var inputItem in inputCollection) { bool.TryParse(inputItem.AttributeSafe("EmptyToNull"), out bool emptyToNull); var sai = new ServiceActionInput { Name = inputItem.AttributeSafe("Name"), Source = inputItem.AttributeSafe("Source"), DefaultValue = inputItem.AttributeSafe("DefaultValue"), EmptyToNull = emptyToNull, NativeType = inputItem.AttributeSafe("NativeType") }; if (string.IsNullOrEmpty(sai.NativeType)) { sai.NativeType = "object"; } // handle validators ;) var validators = inputItem.Elements("Validator"); foreach (var validator in validators) { var v = new Validator { ValidatorType = !Enum.TryParse(validator.AttributeSafe("Type"), out enValidationType validatorType) ? enValidationType.Required : validatorType }; sai.Validators.Add(v); } sa.ServiceActionInputs.Add(sai); } } return(sa); } bool IsSource(StringBuilder serviceData) => serviceData.IndexOf("<Source ", 0, false) == 0; bool IsWorkflow(StringBuilder serviceData) { var startIdx = serviceData.IndexOf("<XamlDefinition>", 0, false); if (startIdx >= 0) { var endIdx = serviceData.IndexOf("</XamlDefinition>", startIdx, false); var dif = endIdx - startIdx; // we know a blank wf is larger then our max string size ;) return(startIdx > 0 && dif > GlobalConstants.MAX_SIZE_FOR_STRING - 1024); } return(false); } }