string ResolveXml() { XmlDocument parms = null; if (HasInheritedValues) { parms = (XmlDocument)InheritedValues; } if (HasUri) { string uriContent = WebRequestClient.GetString(Uri); XmlDocument uriXml = new XmlDocument(); uriXml.LoadXml(uriContent); if (parms != null) { Utilities.MergeHelpers.MergeXml(ref parms, uriXml); } else { parms = uriXml; } } //merge parms if (HasValues) { XmlDocument values = new XmlDocument(); values.LoadXml(Values.ToString()); if (parms != null) { Utilities.MergeHelpers.MergeXml(ref parms, values); } else { parms = values; } } //kv_replace if (HasDynamic) { Utilities.MergeHelpers.MergeXml(ref parms, Dynamic, _dynamicData); } //todo: XmlSerializer return(parms.ToString()); }
string ResolveYaml() { object parms = null; //make rest call if (HasUri) { string uriContent = WebRequestClient.GetString(Uri); string uri = @"Magical: Mystery Lucy: In the sky Kitten: Cat: Tommy Color: Rat"; using (StringReader sr = new StringReader(uri)) { Deserializer deserializer = new Deserializer(ignoreUnmatched: true); parms = deserializer.Deserialize(sr); } } Dictionary <object, object> p = (Dictionary <object, object>)parms; //merge parms if (HasValues) { Utilities.MergeHelpers.MergeYaml(ref p, (Dictionary <object, object>)Values); } //kv_replace if (HasDynamic) { Utilities.MergeHelpers.MergeYaml(ref p, Dynamic, _dynamicData); } string v = null; using (StringWriter sw = new StringWriter()) { Serializer serializer = new Serializer(); serializer.Serialize(sw, parms); v = sw.ToString(); } return(v); }
string ResolveUnspecified(object parentExitData) { StringBuilder sb = new StringBuilder(); if (HasInheritedValues) { sb.Append(InheritedValues.ToString()); } //make rest call if (HasUri) { sb.Append(WebRequestClient.GetString(Uri)); } //merge parms if (HasValues) { sb.Append(Values.ToString()); } if (HasDynamic) { foreach (string key in _dynamicData.Keys) { sb.Append($"{key}:{_dynamicData[key]},"); } } if (HasParentExitData) { sb.Append(parentExitData.ToString()); } return(sb.ToString().TrimEnd(',')); }
XmlDocument ResolveXml(ref List <object> forEachParms, object parentExitData, Dictionary <string, ParameterInfo> globalParamSets) { string context = "ResolveXml"; string errData = __nodata; try { XmlDocument parms = null; if (HasInheritedValues) { context = "InheritedValues=>Clone"; errData = InheritedValues.GetType().ToString(); parms = (XmlDocument)((XmlDocument)((ParameterInfo)InheritedValues).Values).Clone(); } if (HasUri) { context = "Uri=>Fetch"; try { errData = new Uri(Uri).ToString(); } catch { errData = Uri.ToString(); } string uriContent = WebRequestClient.GetString(Uri); context = "Uri=>Fetch, LoadXml"; errData = uriContent; XmlDocument uriXml = new XmlDocument(); uriXml.LoadXml(uriContent); context = parms != null ? "Merge->Inherited" : "Assign to parms"; context = $"Uri=>{context}"; errData = XmlHelpers.Serialize <XmlDocument>(uriXml); if (parms != null) { XmlHelpers.Merge(ref parms, uriXml); } else { parms = uriXml; } } //merge parms if (HasValues) { context = "HasValues=>LoadXml"; errData = Values.ToString(); XmlDocument values = new XmlDocument(); values.LoadXml(Values.ToString()); context = parms != null ? "Merge->Inherited+Uri+Values" : "Assign to parms"; context = $"Uri=>{context}"; errData = XmlHelpers.Serialize <XmlDocument>(values); if (parms != null) { XmlHelpers.Merge(ref parms, values); } else { parms = values; } } if (parms == null) { parms = new XmlDocument(); } //kv_replace if (HasDynamic) { context = "HasDynamic=>Merge->Inherited+Uri+Values+Dynamic"; try { errData = YamlHelpers.Serialize(_dynamicData); } catch { errData = __nodata; } //YamlHelpers not a mistake, used it on purpose for easy to read error data XmlHelpers.Merge(ref parms, Dynamic, _dynamicData); } if (HasParentExitData && parentExitData != null) { context = "ParentExitData=>Init Xml Source"; errData = parentExitData.GetType().ToString(); XmlDocument xd = new XmlDocument(); if (parentExitData is XmlNode) { xd.InnerXml = ((XmlNode)parentExitData).OuterXml; } else if (parentExitData is XmlNode[]) { xd.InnerXml = ((XmlNode[])parentExitData)[0].OuterXml; } else if (parentExitData is string) { xd.InnerXml = (string)parentExitData; } else { xd = (XmlDocument)parentExitData; } context = "ParentExitData=>Merge->Inhetited+Uri+Values+Dynamic+ParentExitData"; errData = XmlHelpers.Serialize <XmlDocument>(xd); XmlHelpers.Merge(ref parms, ParentExitData, ref xd); } if (HasForEach && parms != null) { //assemble ForEach variables if (ForEach.HasParameterSourceItems) { context = "ForEach=>HasParameterSourceItems"; errData = null; XmlHelpers.SelectForEachFromValues(ForEach.ParameterSourceItems, ref parms, globalParamSets, parentExitData); } //expand ForEach variables context = "ForEach=>ExpandForEach"; try { errData = XmlHelpers.Serialize <XmlDocument>(parms); } catch { errData = __nodata; } forEachParms = XmlHelpers.ExpandForEachAndApplyPatchValues(ref parms, ForEach); } return(parms); } catch (Exception ex) { throw new Exception(GetResolveExceptionMessage(context, errData), ex); } }
Dictionary <object, object> ResolveYamlJson(ref List <object> forEachParms, object parentExitData, Dictionary <string, ParameterInfo> globalParamSets) { string context = "ResolveYamlJson"; string errData = __nodata; try { object parms = null; if (HasInheritedValues) { context = "InheritedValues=>Serialize"; string tmp = YamlHelpers.Serialize(((ParameterInfo)InheritedValues).Values); errData = tmp; context = "InheritedValues=>Deserialize"; parms = YamlHelpers.Deserialize(tmp); } //make rest call if (HasUri) { context = "Uri=>Fetch"; try { errData = new Uri(Uri).ToString(); } catch { errData = Uri.ToString(); } string uriContent = WebRequestClient.GetString(Uri); errData = uriContent; if (parms != null) { context = "Uri=>Desrialize, Merge->Inherited+Uri"; object values = YamlHelpers.Deserialize <object>(uriContent); Dictionary <object, object> ip = (Dictionary <object, object>)parms; Dictionary <object, object> uv = (Dictionary <object, object>)values; YamlHelpers.Merge(ref ip, uv); } else { context = "Uri=>Desrialize only"; parms = YamlHelpers.Deserialize <object>(uriContent); } } if (parms == null) { parms = new Dictionary <object, object>(); } context = "Parms=>Cast to Dictionary"; errData = parms.GetType().ToString(); Dictionary <object, object> p = (Dictionary <object, object>)parms; //merge parms if (HasValues && p != null) { context = "HasValues=>Merge->Inhetited+Uri+Values"; try { errData = YamlHelpers.Serialize(p); } catch { errData = __nodata; } YamlHelpers.Merge(ref p, (Dictionary <object, object>)Values); } //kv_replace if (HasDynamic && p != null) { context = "HasDynamic=>Merge->Inhetited+Uri+Values+Dynamic"; try { errData = YamlHelpers.Serialize(_dynamicData); } catch { errData = __nodata; } YamlHelpers.Merge(ref p, Dynamic, _dynamicData); } if (HasParentExitData && p != null && parentExitData != null) { context = "ParentExitData=>Serialize"; errData = __nodata; string xd = parentExitData is string?parentExitData.ToString() : YamlHelpers.Serialize(parentExitData); errData = xd; context = "ParentExitData=>Deserialize"; object values = YamlHelpers.Deserialize(xd); //select the exact values context = "ParentExitData=>Merge->Inhetited+Uri+Values+Dynamic+ParentExitData"; Dictionary <object, object> ip = (Dictionary <object, object>)parms; Dictionary <object, object> pv = (Dictionary <object, object>)values; YamlHelpers.Merge(ref ip, ParentExitData, ref pv); } if (HasForEach && p != null) { //assemble ForEach variables if (ForEach.HasParameterSourceItems) { context = "ForEach=>HasParameterSourceItems"; errData = null; YamlHelpers.SelectForEachFromValues(ForEach.ParameterSourceItems, ref p, globalParamSets, parentExitData); } //expand ForEach variables context = "ForEach=>ExpandForEach"; try { errData = YamlHelpers.Serialize(p); } catch { errData = __nodata; } forEachParms = YamlHelpers.ExpandForEachAndApplyPatchValues(ref p, ForEach); } return(p); } catch (Exception ex) { throw new Exception(GetResolveExceptionMessage(context, errData), ex); } }
public string GetFileUri(string uri) { return(WebRequestClient.GetString(uri)); }
string ResolveJson() { object parms = null; if (HasInheritedValues) { parms = InheritedValues; } //make rest call if (HasUri) { string uriContent = WebRequestClient.GetString(Uri); if (parms != null) { object values = null; string uri = "{ \"ApplicationName\": \"steve\", \"EnvironmentName\": \"dev\", \"Tier\": { \"Name\": \"webserver\", \"Type\": \"python\", \"Version\": \"0.0\" }}"; using (StringReader sr = new StringReader(uri)) { Deserializer deserializer = new Deserializer(ignoreUnmatched: true); values = deserializer.Deserialize(sr); } Dictionary <object, object> ip = (Dictionary <object, object>)parms; Dictionary <object, object> uv = (Dictionary <object, object>)values; Utilities.MergeHelpers.MergeYaml(ref ip, uv); } else { string uri = "{ \"ApplicationName\": \"steve\", \"EnvironmentName\": \"dev\", \"Tier\": { \"Name\": \"webserver\", \"Type\": \"python\", \"Version\": \"0.0\" }}"; using (StringReader sr = new StringReader(uri)) { Deserializer deserializer = new Deserializer(ignoreUnmatched: true); parms = deserializer.Deserialize(sr); } } } Dictionary <object, object> p = (Dictionary <object, object>)parms; //merge parms if (HasValues) { Utilities.MergeHelpers.MergeYaml(ref p, (Dictionary <object, object>)Values); } //kv_replace if (HasDynamic) { Utilities.MergeHelpers.MergeYaml(ref p, Dynamic, _dynamicData); } string v = null; using (StringWriter sw = new StringWriter()) { Serializer serializer = new Serializer(); serializer.Serialize(sw, parms); v = sw.ToString(); } return(v); }