public ReturnDataSet ExecuteStoredProcedure(string name, params object[] args) { bool flag; ReturnDataSet set; DbCommand command = this.Connection.CreateCommand(); command.CommandText = name; command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 0; if (!(flag = this.Connection.State == ConnectionState.Open)) { this.Connection.Open(); } try { SqlCommand proxy = command as SqlCommand; if ((proxy == null) && (command is LINQPadDbCommand)) { proxy = ((LINQPadDbCommand) command).Proxy as SqlCommand; } if (proxy == null) { return new ReturnDataSet(); } SqlCommandBuilder.DeriveParameters(proxy); int num = 1; List<DbParameter> list = new List<DbParameter>(); foreach (object obj2 in args) { if (num == command.Parameters.Count) { break; } object obj3 = obj2; IOptional optional = obj3 as IOptional; if (optional != null) { if (!optional.HasValue) { num++; continue; } obj3 = optional.Value; } if (obj3 is XNode) { obj3 = obj3.ToString(); } else if (obj3 is Binary) { obj3 = ((Binary) obj3).ToArray(); } command.Parameters[num].Value = (obj3 == null) ? DBNull.Value : obj3; num++; } foreach (DbParameter parameter in list) { proxy.Parameters.Remove(parameter); } LINQPadDbController.DbCommandExecuting(proxy); SqlDataAdapter adapter = new SqlDataAdapter(proxy); ReturnDataSet dataSet = new ReturnDataSet(); Stopwatch stopwatch = Stopwatch.StartNew(); adapter.Fill(dataSet); stopwatch.Stop(); if (proxy.Parameters[0].Value is int) { dataSet.ReturnValue = (int) proxy.Parameters[0].Value; } Dictionary<string, object> source = new Dictionary<string, object>(); foreach (SqlParameter parameter2 in proxy.Parameters) { if ((parameter2.Direction == ParameterDirection.InputOutput) || (parameter2.Direction == ParameterDirection.Output)) { source[parameter2.ParameterName] = parameter2.Value; } } if (source.Any<KeyValuePair<string, object>>()) { dataSet.OutputParameters = source; } int num3 = 0; foreach (DataTable table in dataSet.Tables) { table.TableName = "Result Set " + num3++; } LINQPadDbController.DbCommandFinished(stopwatch.Elapsed); set = dataSet; } finally { if (!flag) { this.Connection.Close(); } } return set; }
internal static ObjectNode Create(ObjectNode parent, object item, int maxDepth, DataContextDriver dcDriver) { if (item is ObjectNode) { ObjectNode node = (ObjectNode)item; node.Parent = parent; return(node); } if (item == null) { return(new SimpleNode(parent, null)); } if (((!(item is string) && !(item is int)) && !(item is decimal)) && !(item is DateTime)) { Type type = item.GetType(); if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Nullable <>))) { type = type.GetGenericArguments()[0]; } if (Type.GetTypeCode(type) == TypeCode.Object) { HandleObjectProxies(ref item, parent, dcDriver); } if (item == ObjectGraphInfo.GetDisplayNothingToken()) { return(new EmptyNode()); } if (item == null) { return(new SimpleNode(parent, null)); } } Type type2 = item.GetType(); if ((((item is byte[]) || (item is Binary)) && (parent != null)) && !(parent.ObjectValue is HeadingPresenter)) { string str; byte[] buffer = item as byte[]; if (buffer == null) { buffer = ((Binary)item).ToArray(); } if (buffer.Length <= 20) { StringBuilder builder = new StringBuilder(); foreach (byte num2 in buffer) { if (builder.Length > 0) { builder.Append(" "); } builder.AppendFormat("{0:X2}", num2); } str = builder.ToString(); } else { str = "byte[]"; } return(new SimpleNode(parent, str, "(binary data)", SimpleNodeKind.Metadata)); } if (((((((item is string) || (item is bool)) || ((item is char) || (item is TimeSpan))) || (((item is IFormattable) || (item is XObject)) || ((item is XName) || (item is XNamespace)))) || ((((item is SqlBoolean) || (item is SqlByte)) || ((item is SqlDateTime) || (item is SqlDecimal))) || (((item is SqlDouble) || (item is SqlGuid)) || ((item is SqlInt16) || (item is SqlInt32))))) || (((item is SqlInt64) || (item is SqlMoney)) || (item is SqlSingle))) || (item is SqlString)) { return(new SimpleNode(parent, item.ToString())); } if (item is XmlNode) { return(new SimpleNode(parent, XmlHelper.ToFormattedString((XmlNode)item))); } Type type3 = type2.IsGenericType ? type2.GetGenericTypeDefinition() : null; if (!(((!(type3 == typeof(EntitySet <>)) || (parent == null)) || (parent.IsAnonType || (parent is ListNode))) || (parent.ObjectValue is HeadingPresenter))) { return(new SimpleNode(parent, "EntitySet", type2.FormatTypeName(), SimpleNodeKind.Metadata)); } for (ObjectNode node3 = parent; node3 == null; node3 = node3.Parent) { Label_0305: if (0 == 0) { if ((type3 == typeof(Table <>)) && (node3 != null)) { return(new SimpleNode(parent, "Table", type2.FormatTypeName(), SimpleNodeKind.Metadata)); } if (item is DBNull) { return(new SimpleNode(parent, "null", "DbNull", SimpleNodeKind.Metadata)); } string text = null; ObjectNode payload = null; ReturnDataSet set = item as ReturnDataSet; if (set != null) { text = set.ReturnValue.ToString(); if (set.OutputParameters != null) { foreach (KeyValuePair <string, object> pair in set.OutputParameters) { if (pair.Value != null) { string str3 = text; text = str3 + ", " + pair.Key + "=" + pair.Value.ToString(); } } } payload = new SimpleNode(null, text); } if ((item is DataSet) && (((DataSet)item).Tables.Count == 1)) { item = ((DataSet)item).Tables[0]; } if (item is DataSet) { return(new ListPayloadNode(parent, ((DataSet)item).Tables, maxDepth, dcDriver, "Result Sets", payload, "ReturnValue")); } if (item is DataTable) { return(new ListPayloadNode(parent, ((DataTable)item).Rows, maxDepth, dcDriver, "Result Set", payload, "ReturnValue")); } if (item is DataRow) { return(new DataRowNode(parent, (DataRow)item, maxDepth, dcDriver)); } if (item is IDataReader) { DataReaderNode node5 = new DataReaderNode(parent, (IDataReader)item, maxDepth, dcDriver); if (node5.Items.Count == 1) { return(node5.Items[0]); } return(node5); } if (item is IDataRecord) { return(new DataRecordMemberNode(parent, null, (IDataRecord)item, maxDepth, dcDriver)); } if (type2.GetInterfaces().Any <Type>(t => t.FullName == typeof(ICustomMemberProvider).FullName)) { try { return(new CustomMemberProviderNode(parent, item, maxDepth, dcDriver, false)); } catch (Exception exception) { Log.Write(exception, "CustomMemberProvider"); } } if ((dcDriver != null) && (dcDriver.GetCustomDisplayMemberProvider(item) != null)) { return(new CustomMemberProviderNode(parent, item, maxDepth, dcDriver, true)); } if (item is Type) { for (ObjectNode node6 = parent; node6 != null; node6 = node6.Parent) { node6.HasTypeReferences = true; } } if (!(ExpandTypes || !(item is Type))) { return(new SimpleNode(parent, "typeof (" + ((Type)item).FormatTypeName() + ")", ((Type)item).FormatTypeName(true), SimpleNodeKind.Metadata) { HasTypeReferences = true }); } if (item is Image) { Image image = (Image)item; MemoryStream stream = new MemoryStream(); image.Save(stream, ImageFormat.Png); item = Util.Image(stream.ToArray()); } if (((!type2.IsArray && (item is IList)) && (((IList)item).Count == 1)) && (((IList)item)[0] == item)) { return(new ClrMemberNode(parent, item, maxDepth, dcDriver)); } if (type2.IsArray && (type2.GetArrayRank() == 2)) { Type elementType = type2.GetElementType(); if (elementType.IsGenericType && (elementType.GetGenericTypeDefinition() == typeof(Nullable <>))) { elementType = elementType.GetGenericArguments()[0]; } if (((typeof(IFormattable).IsAssignableFrom(elementType) || (elementType == typeof(bool))) || ((elementType == typeof(char)) || (elementType == typeof(TimeSpan)))) || (elementType == typeof(string))) { return(new MultiDimArrayNode(parent, (Array)item)); } } if (item is IEnumerable) { return(new ListNode(parent, (IEnumerable)item, maxDepth, dcDriver)); } if (item is Exception) { return(new ExceptionNode(parent, (Exception)item, maxDepth)); } if (item is DynamicObject) { return(new DynamicObjectMemberNode(parent, (DynamicObject)item, maxDepth, dcDriver)); } return(new ClrMemberNode(parent, item, maxDepth, dcDriver)); } } goto Label_0305; }