internal static IReadOnlyElement GetElement(IReadOnlyResult result) { if (result.Exception != null) { return(GetElement(result.Exception)); } else { var aml = ElementFactory.Local; IReadOnlyElement res; if (result.Items().Any()) { res = new LooseLinkElement(aml, "Result", result.Items().ToArray()); } else { res = aml.Element("Result", result.Value); } var body = aml.Element("SOAP-ENV:Body", res); if (result.Message.Exists) { body.Add(result.Message); } var elem = aml.Element("SOAP-ENV:Envelope", aml.Attribute("xmlns:SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/"), body); return(elem); } }
public IEnumerator <T> GetEnumerator() { foreach (var item in _result.Items()) { if (_projection == null) { yield return((T)item); } else { yield return((T)_projection.DynamicInvoke(item)); } } }
//public static int ColumnWidth(this DataColumn column) //{ // if (column.ExtendedProperties.ContainsKey("column_width")) // return (int)column.ExtendedProperties["column_width"]; // return 100; //} //private static void ColumnWidth(this DataColumn column, int value) //{ // column.ExtendedProperties["column_width"] = value; //} //public static int SortOrder(this DataColumn column) //{ // if (column.ExtendedProperties.ContainsKey("sort_order")) // return (int)column.ExtendedProperties["sort_order"]; // return 999999; //} //public static void SortOrder(this DataColumn column, int value) //{ // column.ExtendedProperties["sort_order"] = value; //} public static DataSet GetItemTable(IReadOnlyResult res, ArasMetadataProvider metadata, string select) { var ds = new DataSet(); string mainType = null; string mainId = null; var selectedCols = SelectNode.FromString(select); List <IReadOnlyItem> items; try { items = res.Items().ToList(); if (items.Count == 1) { mainType = items[0].Type().Value; mainId = items[0].Id(); items.AddRange(items[0].Relationships()); } if (items.Count < 1) { return(ds); } } catch (ServerException) { return(ds); } var types = new TypeProperties(); string type; bool idAdded; bool keyedNameAdded; foreach (var i in items) { type = (i.Type().Exists || i.Property("id").Type().Exists) ? i.Type().AsString(i.Property("id").Type().AsString("")) : string.Empty; if (!string.IsNullOrEmpty(type)) { types.Add(type, AmlTable_TypeName); } if (i.TypeId().Exists || i.Property("itemtype").Exists) { types.Add(type, AmlTable_TypeId); } idAdded = false; keyedNameAdded = false; foreach (var elem in i.Elements().OfType <IReadOnlyProperty>()) { if (elem.Name != "config_id") { if (elem.Type().Exists) { types.Add(type, elem.Name + "/type"); } if (elem.KeyedName().Exists) { types.Add(type, elem.Name + "/keyed_name"); } } types.Add(type, elem.Name); idAdded = idAdded || elem.Name == "id"; keyedNameAdded = keyedNameAdded || elem.Name == "keyed_name"; } if (!string.IsNullOrEmpty(i.Id()) && !idAdded) { types.Add(type, "id"); } if (i.Property("id").KeyedName().Exists&& !keyedNameAdded) { types.Add(type, "keyed_name"); } } ItemType itemType; Property pMeta; DataRow row; string propName; string propAddendum; int split; DataColumn newColumn; var typesEnum = types.Count > 1 && types.AllTypesTheSame() ? Enumerable.Repeat(new KeyValuePair <string, HashSet <string> >(string.Empty, types.First().Value), 1) : types; foreach (var kvp in typesEnum) { var result = new DataTable(kvp.Key); try { result.BeginLoadData(); if (string.IsNullOrEmpty(kvp.Key) || metadata == null || !metadata.ItemTypeByName(kvp.Key, out itemType)) { itemType = null; } else { result.RowChanging += (s, e) => { if (e.Action == DataRowAction.Add) { var newId = Guid.NewGuid().ToString("N").ToUpperInvariant(); e.Row.Table.Columns["id"].DefaultValue = newId; } }; } var allProps = new HashSet <string>(kvp.Value); if (itemType != null) { allProps.UnionWith(metadata.GetProperties(itemType).Wait().Select(p => p.Name)); } foreach (var prop in allProps) { if (prop != AmlTable_TypeName && prop != AmlTable_TypeId && itemType != null) { result.TableName = itemType.TabLabel ?? (itemType.Label ?? itemType.Name); split = prop.IndexOf('/'); propAddendum = string.Empty; propName = prop; if (split > 0) { propName = prop.Substring(0, split); propAddendum = prop.Substring(split); } try { pMeta = metadata.GetProperty(itemType, propName).Wait(); if (string.IsNullOrEmpty(propAddendum)) { switch (pMeta.Type) { case PropertyType.boolean: newColumn = new DataColumn(prop, typeof(bool)); if (pMeta.IsRequired && pMeta.DefaultValue == null) { newColumn.DefaultValue = false; } break; case PropertyType.date: newColumn = new DataColumn(prop, typeof(DateTime)); break; case PropertyType.number: if (string.Equals(pMeta.TypeName, "integer", StringComparison.OrdinalIgnoreCase)) { newColumn = new DataColumn(prop, typeof(int)); } else { newColumn = new DataColumn(prop, typeof(double)); } break; default: newColumn = new DataColumn(prop, typeof(string)); if (pMeta.StoredLength > 0) { newColumn.MaxLength = pMeta.StoredLength; } break; } } else { newColumn = new DataColumn(prop, typeof(string)); } newColumn.Caption = (pMeta.Label ?? pMeta.Name) + propAddendum; if (pMeta.DefaultValue != null) { newColumn.DefaultValue = pMeta.DefaultValue; } if (kvp.Key != mainType && !string.IsNullOrEmpty(mainId) && pMeta.Name == "source_id") { newColumn.DefaultValue = mainId; } newColumn.ReadOnly = pMeta.ReadOnly && pMeta.Name != "related_id" && pMeta.Name != "source_id"; newColumn.AllowDBNull = selectedCols.Any() || !pMeta.IsRequired || !string.IsNullOrEmpty(propAddendum); // Ignore constraints on the following columns switch (pMeta.Name) { case "config_id": case "created_by_id": case "created_on": case "permission_id": newColumn.AllowDBNull = true; break; } if (selectedCols.Any()) { newColumn.IsUiVisible(selectedCols.Any(c => string.Equals(c.Name, propName))); } else { newColumn.IsUiVisible(!string.IsNullOrEmpty(mainType) && itemType.Name != mainType ? (pMeta.Visibility & PropertyVisibility.RelationshipGrid) > 0 : (pMeta.Visibility & PropertyVisibility.MainGrid) > 0); } newColumn.PropMetadata(pMeta); } catch (KeyNotFoundException) { newColumn = new DataColumn(prop, typeof(string)); newColumn.IsUiVisible(string.IsNullOrEmpty(kvp.Key) || metadata == null); } } else { newColumn = new DataColumn(prop, typeof(string)); newColumn.IsUiVisible(string.IsNullOrEmpty(kvp.Key) || metadata == null); if (prop == AmlTable_TypeName && !string.IsNullOrEmpty(kvp.Key)) { newColumn.DefaultValue = kvp.Key; } } result.Columns.Add(newColumn); } foreach (var item in items .Where(i => string.IsNullOrEmpty(kvp.Key) || i.Type().AsString(i.Property("id").Type().Value) == kvp.Key)) { row = result.NewRow(); row.BeginEdit(); foreach (var prop in kvp.Value) { switch (prop) { case "id": row[prop] = item.Id(); break; case "keyed_name": row[prop] = item.KeyedName().AsString(item.Property("id").KeyedName().Value); break; case AmlTable_TypeName: row[prop] = item.Type().AsString(item.Property("id").Type().Value); break; case AmlTable_TypeId: row[prop] = item.TypeId().AsString(item.Property("itemtype").Value); break; default: split = prop.IndexOf('/'); if (split > 0) { row[prop] = item.Property(prop.Substring(0, split)).Attribute(prop.Substring(split + 1)).Value; } else if (item.Property(prop).HasValue()) { newColumn = result.Columns[prop]; if (newColumn.DataType == typeof(bool)) { row[prop] = item.Property(prop).AsBoolean(false); } else if (newColumn.DataType == typeof(DateTime)) { row[prop] = item.Property(prop).AsDateTime(DateTime.MinValue); } else if (newColumn.DataType == typeof(int)) { row[prop] = item.Property(prop).AsInt(int.MinValue); } else if (newColumn.DataType == typeof(double)) { row[prop] = item.Property(prop).AsDouble(double.MinValue); } else { row[prop] = item.Property(prop).Value; } } else { row[prop] = DBNull.Value; } break; } } row.EndEdit(); row.AcceptChanges(); result.Rows.Add(row); } if (result.Rows.Count > 0 && result.Columns.OfType <DataColumn>().Where(c => c.ColumnName == "source_id" || c.ColumnName == "related_id").Count() == 2) { var firstRelated = result.Rows[0]["related_id"]; var firstSource = result.Rows[0]["source_id"]; if (result.Rows.Count > 1 && result.AsEnumerable().All(r => r["related_id"] == firstRelated) && !result.AsEnumerable().All(r => r["source_id"] == firstSource)) { result.Columns["source_id/keyed_name"].IsUiVisible(true); } else { result.Columns["related_id/keyed_name"].IsUiVisible(true); } } } finally { try { result.EndLoadData(); } catch (ConstraintException) { } result.AcceptChanges(); } ds.Tables.Add(result); } return(ds); }
private void loadAML(IReadOnlyResult result) { _content = (object)result.Exception ?? (object)result.Value ?? result.Items().ToList(); }
public PluginResult(IReadOnlyResult result) { Count = result.Items().Count(); _createReader = result.CreateReader; }