private static object PromptReplyObjectToObject(object reply, PromptFieldDescription description) { PromptFieldType promptFieldType = description.PromptFieldType; switch (promptFieldType) { case PromptFieldType.String: { if (reply as string != null) { return(reply); } else { throw new ArgumentException("Expected a string", "reply"); } } case PromptFieldType.SecureString: { object[] objArray = reply as object[]; if (objArray != null) { return(PowwaSession.ToSecureString(objArray)); } else { throw new ArgumentException("Expected an object[]", "reply"); } } case PromptFieldType.Credential: { Dictionary <string, object> strs = reply as Dictionary <string, object>; if (strs == null || !strs.ContainsKey("username") || !strs.ContainsKey("password")) { throw new ArgumentException("Expected an object with username and password properties", "reply"); } else { string item = strs["username"] as string; if (item != null) { object[] item1 = strs["password"] as object[]; if (item1 != null) { return(new PSCredential(item, PowwaSession.ToSecureString(item1))); } else { throw new ArgumentException("The password should be an object[]", "reply"); } } else { throw new ArgumentException("The username should be a string", "reply"); } } } } throw new ArgumentException("Unknown reply type", "reply"); }
public override Dictionary <string, PSObject> Prompt(string caption, string message, Collection <FieldDescription> descriptions) { bool flag = false; Dictionary <string, PSObject> reply; PowwaEvents.PowwaEVENT_DEBUG_LOG0("Prompt(): Enter"); try { if (descriptions != null) { if (descriptions.Count != 0) { PromptFieldDescription[] promptFieldDescriptionArray = new PromptFieldDescription[descriptions.Count]; int num = 0; while (num < descriptions.Count) { if (descriptions[num] != null) { Type fieldType = PowwaHostUserInterface.GetFieldType(descriptions[num], out flag); PromptFieldType promptFieldType = PromptFieldType.String; if (fieldType != typeof(SecureString)) { if (fieldType == typeof(PSCredential)) { promptFieldType = PromptFieldType.Credential; } } else { promptFieldType = PromptFieldType.SecureString; } PromptFieldDescription promptFieldDescription = new PromptFieldDescription(); promptFieldDescription.Name = descriptions[num].Name; promptFieldDescription.Label = descriptions[num].Label; promptFieldDescription.HelpMessage = descriptions[num].HelpMessage; promptFieldDescription.PromptFieldType = promptFieldType; promptFieldDescription.PromptFieldTypeIsList = flag; promptFieldDescriptionArray[num] = promptFieldDescription; num++; } else { object[] objArray = new object[1]; objArray[0] = num; string str = string.Format(CultureInfo.InvariantCulture, "descriptions[{0}]", objArray); PowwaEvents.PowwaEVENT_DEBUG_LOG1("Prompt(): Invalid Description", str, "null"); throw new ArgumentNullException(str); } } MessageCreatedEventArgs messageCreatedEventArg = new MessageCreatedEventArgs(new PromptMessage(caption, message, promptFieldDescriptionArray), true); this.OnMessageCreated(messageCreatedEventArg); reply = (Dictionary <string, PSObject>)messageCreatedEventArg.Reply; } else { int count = descriptions.Count; PowwaEvents.PowwaEVENT_DEBUG_LOG1("Prompt(): Invalid Argument", "Descriptions.Count", count.ToString(CultureInfo.InvariantCulture)); throw new ArgumentException("descriptions cannot be an empty array", "descriptions"); } } else { PowwaEvents.PowwaEVENT_DEBUG_LOG1("Prompt(): Invalid Argument", "Descriptions", "null"); throw new ArgumentNullException("descriptions"); } } finally { PowwaEvents.PowwaEVENT_DEBUG_LOG0("Prompt(): Exit"); } return(reply); }