private ActiveDirectoryHandlerResults CallPlan(string planName, StartPlanEnvelope planEnvelope) { IExecuteController ec = GetExecuteControllerInstance(); StartPlanEnvelope pe = planEnvelope; if (pe == null) { pe = new StartPlanEnvelope() { DynamicParameters = new Dictionary <string, string>() } } ; IEnumerable <KeyValuePair <string, string> > queryString = this.Request.GetQueryNameValuePairs(); foreach (KeyValuePair <string, string> kvp in queryString) { pe.DynamicParameters.Add(kvp.Key, kvp.Value); } object reply = ec.StartPlanSync(pe, planName, setContentType: false); ActiveDirectoryHandlerResults result = null; Type replyType = reply.GetType(); if (replyType == typeof(string)) { try { result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>((string)reply); } catch (Exception e) { try { // Reply was not Json or Yaml. See if Xml XmlDocument doc = new XmlDocument(); doc.LoadXml((string)reply); result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml); } catch (Exception) { throw e; } } } else if (replyType == typeof(Dictionary <object, object>)) { String str = YamlHelpers.Serialize(reply); result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>(str); } else if (replyType == typeof(XmlDocument)) { XmlDocument doc = (XmlDocument)reply; result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml); } return(result); }
public string WhoAmI() { string planName = @"WhoAmI"; IExecuteController ec = GetExecuteControllerInstance(); StartPlanEnvelope pe = new StartPlanEnvelope() { DynamicParameters = new Dictionary <string, string>() }; return((string)ec.StartPlanSync(pe, planName, setContentType: false)); }
public object ExecutePlan(string planname, string url) { string planName = planname; StartPlanEnvelope pe = GetPlanEnvelope(); String body = this.Request.Content?.ReadAsStringAsync().Result; string user = this.User?.Identity?.Name; string requestUri = this.Request.RequestUri.ToString(); if (url != null) { pe.DynamicParameters.Add("url", url); // Split URL into Individual Parts, Pass Into Plan as "url_#" string[] parts = url.Split('\\', '/'); for (int i = 0; i < parts.Length; i++) { pe.DynamicParameters.Add($"url_{i + 1}", parts[i]); } } if (body != null) { pe.DynamicParameters.Add("body", body); try { Dictionary <string, string> bodyDictionary = YamlHelpers.Deserialize <Dictionary <string, string> >(body); foreach (KeyValuePair <string, string> kvp in bodyDictionary) { if (!(pe.DynamicParameters.ContainsKey(kvp.Key))) { pe.DynamicParameters.Add(kvp.Key, kvp.Value); } } } catch { } } pe.DynamicParameters.Add("method", this.Request.Method.ToString()); pe.DynamicParameters.Add("requesturi", requestUri); int queryIndex = requestUri.IndexOf('?'); if (queryIndex > 0) { pe.DynamicParameters.Add("query", requestUri.Substring(queryIndex + 1)); } if (user != null) { pe.DynamicParameters.Add("user", user); } // Add Query String values into Plan Envelope Exactly As Provided IEnumerable <KeyValuePair <string, string> > queryKvp = this.Request.GetQueryNameValuePairs(); foreach (KeyValuePair <string, string> kvp in queryKvp) { if (pe.DynamicParameters.ContainsKey(kvp.Key)) { string value = pe.DynamicParameters[kvp.Key].ToString(); pe.DynamicParameters[kvp.Key] = $"{value},{kvp.Value}"; } else { pe.DynamicParameters.Add(kvp.Key, kvp.Value); } } IExecuteController ec = GetExecuteControllerInstance(); return(ec.StartPlanSync(pe, planName, serializationType: SerializationType.Unspecified, setContentType: true, timeoutSeconds: 3600)); }
private ActiveDirectoryHandlerResults CallPlan(string planName, StartPlanEnvelope planEnvelope) { IExecuteController ec = GetExecuteControllerInstance(); StartPlanEnvelope pe = planEnvelope; if (pe == null) { pe = new StartPlanEnvelope() { DynamicParameters = new Dictionary <string, string>() } } ; // Add Query String values into Plan Envelope Exactly As Provided IEnumerable <KeyValuePair <string, string> > queryString = this.Request.GetQueryNameValuePairs(); foreach (KeyValuePair <string, string> kvp in queryString) { pe.DynamicParameters.Add(kvp.Key, kvp.Value); } object reply = ec.StartPlanSync(pe, planName, setContentType: false); ActiveDirectoryHandlerResults result = null; Type replyType = reply.GetType(); if (replyType == typeof(Dictionary <object, object>)) { String str = YamlHelpers.Serialize(reply); result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>(str); } else if (replyType == typeof(XmlDocument)) { XmlDocument doc = (XmlDocument)reply; result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml); } else { try { result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>(reply.ToString()); } catch (Exception) { try { // Reply was not Json or Yaml. See if Xml XmlDocument doc = new XmlDocument(); doc.LoadXml(reply.ToString()); result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml); } catch (Exception) { // Reply was of unknown type. Put Raw Output In Return Object result = new ActiveDirectoryHandlerResults(); ActiveDirectoryObjectResult error = new ActiveDirectoryObjectResult(); ActiveDirectoryStatus status = new ActiveDirectoryStatus(); status.StatusId = AdStatusType.NotSupported; status.Message = $"Unable To Parse ObjectType [{replyType}]."; status.ActionId = ActionType.None; error.Statuses.Add(status); error.TypeId = AdObjectType.None; error.Object = reply; result.Add(error); } } } return(result); }