public override int GetHashCode() => StoryTitle.StringHash256() ^ ChapterTitle.StringHash256() ^ ChapterIndex.StringHash256() ^ Address.StringHash256() ^ LinkedId.StringHash256() ^ LinkTarget.StringHash256();
/// <summary> /// Initializes a new instance of the <see cref="SimpleLink"/> class. /// </summary> /// <param name="target">A value that specifies where/how a linked resource is displayed/experienced.</param> /// <param name="resource">The resource.</param> /// <param name="formatsToApplyWhenActivated">OPTIONAL formatting to apply, in order, when the link is activated (e.g. clicked). DEFAULT is to leave the formatting unchanged.</param> public SimpleLink( LinkTarget target, ILinkedResource resource, IReadOnlyList <RegionFormatBase> formatsToApplyWhenActivated = null) { if (target == LinkTarget.Unknown) { throw new ArgumentOutOfRangeException(Invariant($"{nameof(target)} is {nameof(LinkTarget.Unknown)}.")); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } if (formatsToApplyWhenActivated != null) { if (!formatsToApplyWhenActivated.Any()) { throw new ArgumentException(Invariant($"{nameof(formatsToApplyWhenActivated)} is an empty enumerable.")); } if (formatsToApplyWhenActivated.Any(_ => _ == null)) { throw new ArgumentException(Invariant($"{nameof(formatsToApplyWhenActivated)} contains at least one null element.")); } } this.Target = target; this.Resource = resource; this.FormatsToApplyWhenActivated = formatsToApplyWhenActivated; }
public SimpleLink DeepCloneWithTarget(LinkTarget target) { var result = new SimpleLink( target, this.Resource?.DeepClone(), this.FormatsToApplyWhenActivated?.DeepClone()); return(result); }
public static MvcHtmlString ScriptItemLink(this HtmlHelper html, string onclick, string text, string title = null, LinkTarget target = LinkTarget.Self) { if (!onclick.TrimEnd().EndsWith("return false;")) { onclick += "; return false;"; } return(ItemLink(html, "javascript:void(0)", text, title ?? text, onclick, target)); }
public PSAccount(LinkTarget account) { if (account == null) { throw new ArgumentNullException("account"); } this.AccountName = account.DisplayName; this.Name = account.WorkspaceName; this.CustomerId = new Guid(account.CustomerId); this.Location = account.Location; }
public static MvcHtmlString ItemLink(this HtmlHelper html, string href, string text, string title, string onclick = null, LinkTarget target = LinkTarget.Self) { var htmlText = @"<a href=""{0}"" target=""{1}"" {2}{3}>{4}</a>" .FormatWith(href, target, !string.IsNullOrEmpty(title) ? " title=\"{0}\"".FormatWith(title) : string.Empty, !string.IsNullOrWhiteSpace(onclick) ? " onclick=\"{0}\"".FormatWith(onclick) : string.Empty, text); return(new MvcHtmlString(htmlText)); }
public NativeReferenceMetadata(LinkWithAttribute attribute) { ForceLoad = attribute.ForceLoad; Frameworks = attribute.Frameworks; WeakFrameworks = attribute.WeakFrameworks; LibraryName = attribute.LibraryName; LinkerFlags = attribute.LinkerFlags; LinkTarget = attribute.LinkTarget; NeedsGccExceptionHandling = attribute.NeedsGccExceptionHandling; IsCxx = attribute.IsCxx; SmartLink = attribute.SmartLink; Dlsym = attribute.Dlsym; Attribute = attribute; }
public void TestRestoreLinks() { // load a different scene for this test TestManager.Helpers.OpenSceneFromFile(Path.Combine(TestManager.Helpers.TestDataDir, @"EntityShapeTest\RestoreLink.scene")); EntityShape entity = EditorManager.Scene.FindShapeByName("Entity") as EntityShape; Assert.IsNotNull(entity); // the map has an anim entity which is attached to a path Assert.AreEqual(entity.EntityClass, "AnimEntity_cl"); Assert.AreEqual(entity.LinkSources.Count, 1); Assert.AreEqual(entity.LinkTargets.Count, 0); Assert.AreEqual(entity.LinkBidirections.Count, 0); // verify the link is there LinkSource linkSrc = (LinkSource)entity.LinkSources[0]; Assert.AreEqual(linkSrc.Links.Count, 1); LinkTarget linkTgt = (LinkTarget)linkSrc.Links[0]; PathShape pathShape = linkTgt.OwnerShape as PathShape; Assert.IsNotNull(pathShape); Assert.AreEqual(pathShape.LinkTargets.Count, 1); Assert.AreEqual(pathShape.LinkTargets[0].Links.Count, 1); // setting a new entity class removes the link IAction myAction = SetPropertyAction.CreateSetPropertyAction(entity, "EntityClass", "VisBaseEntity_cl"); myAction.Do(); Assert.AreEqual(entity.LinkSources.Count, 0); Assert.AreEqual(pathShape.LinkTargets.Count, 1); Assert.AreEqual(pathShape.LinkTargets[0].Links.Count, 0); // not conected to entity anymore // now the link should be restored again myAction.Undo(); Assert.AreEqual(entity.LinkSources.Count, 1); Assert.AreEqual(entity.LinkSources[0].Links.Count, 1); Assert.AreEqual(entity.LinkSources[0].Links[0].OwnerShape, pathShape); Assert.AreEqual(pathShape.LinkTargets.Count, 1); Assert.AreEqual(pathShape.LinkTargets[0].Links.Count, 1); }
public void AddHyperlink(XElement e, BlockCollection b) { if (e.DescendantNodes().Count() == 0) { LinkTarget l = new LinkTarget(); l.Name = e.Value.Trim(); //b.Add(l); } else { Hyperlink h = new Hyperlink(); //fd.Blocks.Add(new Hyperlink //Console.Write("<hyperlink>", xelement.Value.Trim()); //foreach (var att in xelement.Attributes()) // Console.Write(att.Name + "=" + att.Value.Trim() + " "); //foreach (var child in xelement.Descendants()) // ParseBody(child); //Console.WriteLine("</hyperlink>", xelement.Value.Trim()); } }
/// <summary> /// Parses a LinkTarget element. /// </summary> LinkTarget ParseLinkTarget() { Debug.Assert(this.reader.Name == ""); bool isEmptyElement = this.reader.IsEmptyElement; LinkTarget linkTarget = new LinkTarget(); while (MoveToNextAttribute()) { switch (this.reader.Name) { case "Name": linkTarget.Name = this.reader.Value; break; default: UnexpectedAttribute(this.reader.Name); break; } } MoveToNextElement(); return(linkTarget); }
private static void GenerateRelScript(SelfRelationTarget rt, StringBuilder script, bool unicodeStrings, RelationDefinitionBase rel) { for (int i = 0; i < rt.FieldName.Length; i++) { script.Append(rt.FieldName[i]).Append(" "); if (rel is SelfRelationDefinition) { SelfRelationDefinition r = rel as SelfRelationDefinition; ScalarPropertyDefinition sp = r.Properties.Skip(i).First(); script.Append(GetType(sp.SourceField, sp.PropertyType, sp.Attributes, unicodeStrings)).Append(" NOT NULL"); } else if (rel is RelationDefinition) { LinkTarget lt = rt as LinkTarget; ScalarPropertyDefinition sp = lt.Properties.Skip(i).First(); script.Append(GetType(sp.SourceField, sp.PropertyType, sp.Attributes, unicodeStrings)).Append(" NOT NULL"); } else { throw new NotSupportedException(rel.GetType().ToString()); } } }
public LinkWithAttribute(string libraryName, LinkTarget target) { LibraryName = libraryName; LinkTarget = target; }
public LinkWithAttribute(string libraryName, LinkTarget target, string linkerFlags) { LibraryName = libraryName; LinkerFlags = linkerFlags; LinkTarget = target; }
public static string RenderActionlLink(String text, String url, String title, LinkTarget target, CommandIcon icon, IconSize size, String cssClass) { String render = "<a href=\"{0}\" title=\"{1}\" class=\"{2} {3} {4}\" target=\"{5}\">{6}</a>"; return(string.Format(render, url, title, HTMLinputClass.Link.GetStringValue(), icon.GetStringValue() + size.GetStringValue(), cssClass, target.ToString(), text)); }
public static string RenderActionlLink(String url, String title, LinkTarget target, CommandIcon icon, IconSize size, String cssClass) { return(RenderActionlLink("", url, title, target, icon, size, cssClass)); }
public LinkWithAttribute (string libraryName, LinkTarget target) { LibraryName = libraryName; LinkTarget = target; }
public LinkWithAttribute (string libraryName, LinkTarget target, string linkerFlags) { LibraryName = libraryName; LinkerFlags = linkerFlags; LinkTarget = target; }
/// <summary>Formats the URL as a hyperlink.</summary> /// <param name="url">The url to link to.</param> /// <param name="text">The display text of the link (null to use the URL).</param> /// <param name="target">The target attribute.</param> public static string ToHyperlink(string url, string text, LinkTarget target) { if (text == null) text = url; if (Script.IsUndefined(target)) target = LinkTarget.Blank; return string.Format("<a href='{0}' target='_{2}'>{1}</a>", url, text, target.ToString()); }
protected void ProcessMany2Many() { foreach (SourceFragmentDefinition sf in SourceView.GetSourceFragments() .Where(item => SourceView.GetSourceFields(item).All(clm => clm.IsFK) && item.Constraints.Count(citem => citem.ConstraintType == SourceConstraint.ForeignKeyConstraintTypeName) == 2)) { List <LinkTarget> targets = new List <LinkTarget>(); foreach (SourceConstraint fk in sf.Constraints.Where(item => item.ConstraintType == SourceConstraint.ForeignKeyConstraintTypeName)) { var rels = SourceView.GetFKRelations(fk); SourceFragmentDefinition m = rels.First().PKField.SourceFragment; EntityDefinition e = Model.GetEntity(GetEntityIdentifier(m.Selector, m.Name)); LinkTarget lt = new LinkTarget( e, rels.Select(item => item.FKField.SourceFieldExpression).ToArray(), rels.Select(item => e.GetPkProperties().Single(p => p.SourceFieldExpression == item.PKField.SourceFieldExpression).PropertyAlias).ToArray(), rels.First().DeleteAction == SourceConstraint.CascadeAction ); targets.Add(lt); } if (targets.Count != 2) { continue; } if (targets[0].Entity.Name == targets[1].Entity.Name) { LinkTarget t = targets[0]; SelfRelationDefinition newRel = new SelfRelationDefinition( t.Entity, t.EntityProperties, targets[0], targets[1], GetSourceFragment(sf), null); if (sf.Constraints.Any(item => item.ConstraintType == SourceConstraint.PrimaryKeyConstraintTypeName)) { newRel.Constraint = RelationConstraint.PrimaryKey; } else if (sf.Constraints.Any(item => item.ConstraintType == SourceConstraint.UniqueConstraintTypeName)) { newRel.Constraint = RelationConstraint.Unique; } if (Model.GetSimilarRelation(newRel) == null) { string postFix = string.Empty; if (string.IsNullOrEmpty(newRel.Left.AccessorName)) { if (newRel.Left.FieldName.Length == 1) { if (newRel.Left.FieldName[0].EndsWith("_id", StringComparison.InvariantCultureIgnoreCase)) { newRel.Left.AccessorName = newRel.Left.FieldName[0] .Substring(0, newRel.Left.FieldName[0].Length - 3); } else if (newRel.Left.FieldName[0].EndsWith("id", StringComparison.InvariantCultureIgnoreCase)) { newRel.Left.AccessorName = newRel.Left.FieldName[0] .Substring(0, newRel.Left.FieldName[0].Length - 2); } } if (string.IsNullOrEmpty(newRel.Left.AccessorName)) { newRel.Left.AccessorName = newRel.Entity.Name; postFix = "1"; } } if (string.IsNullOrEmpty(newRel.Right.AccessorName)) { if (newRel.Left.FieldName.Length == 1) { if (newRel.Right.FieldName[0].EndsWith("_id", StringComparison.InvariantCultureIgnoreCase)) { newRel.Right.AccessorName = newRel.Right.FieldName[0] .Substring(0, newRel.Right.FieldName[0].Length - 3); } else if (newRel.Right.FieldName[0].EndsWith("id", StringComparison.InvariantCultureIgnoreCase)) { newRel.Right.AccessorName = newRel.Right.FieldName[0] .Substring(0, newRel.Right.FieldName[0].Length - 2); } } if (string.IsNullOrEmpty(newRel.Right.AccessorName)) { newRel.Right.AccessorName = newRel.Entity.Name + postFix; } } Model.AddRelation(newRel); } } else { RelationDefinition newRel = new RelationDefinition( targets[0], targets[1], GetSourceFragment(sf), null); if (sf.Constraints.Any(item => item.ConstraintType == SourceConstraint.PrimaryKeyConstraintTypeName)) { newRel.Constraint = RelationConstraint.PrimaryKey; } else if (sf.Constraints.Any(item => item.ConstraintType == SourceConstraint.UniqueConstraintTypeName)) { newRel.Constraint = RelationConstraint.Unique; } if (!Model.GetRelations().OfType <RelationDefinition>().Any(m => m.Equals(newRel))) { if (Model.HasSimilarRelationM2M(newRel)) { if (string.IsNullOrEmpty(newRel.Left.AccessorName) || string.IsNullOrEmpty(newRel.Right.AccessorName)) { var lst = from r in Model.GetRelations().OfType <RelationDefinition>() where !ReferenceEquals(r.Left, newRel.Left) && !ReferenceEquals(r.Right, newRel.Right) && ( ((r.Left.Entity == newRel.Left.Entity && string.IsNullOrEmpty(r.Right.AccessorName)) && (r.Right.Entity == newRel.Right.Entity && string.IsNullOrEmpty(r.Left.AccessorName))) || ((r.Left.Entity == newRel.Right.Entity && string.IsNullOrEmpty(r.Right.AccessorName)) && (r.Right.Entity == newRel.Left.Entity && string.IsNullOrEmpty(r.Left.AccessorName))) ) select r; if (lst.Count() > 0) { foreach (RelationDefinition r in lst) { if (string.IsNullOrEmpty(r.Left.AccessorName)) { r.Left.AccessorName = r.SourceFragment.Name.TrimEnd(']').TrimStart('[') + r.Right.Entity.Name; } if (string.IsNullOrEmpty(r.Right.AccessorName)) { r.Right.AccessorName = r.SourceFragment.Name.TrimEnd(']').TrimStart('[') + r.Left.Entity.Name; } } if (string.IsNullOrEmpty(newRel.Left.AccessorName)) { newRel.Left.AccessorName = newRel.SourceFragment.Name.TrimEnd(']').TrimStart('[') + newRel.Right.Entity.Name; } if (string.IsNullOrEmpty(newRel.Right.AccessorName)) { newRel.Right.AccessorName = newRel.SourceFragment.Name.TrimEnd(']').TrimStart('[') + newRel.Left.Entity.Name; } } } } Model.AddRelation(newRel); } } } foreach (SelfRelationDefinition rdb in Model.GetActiveRelations().OfType <SelfRelationDefinition>()) { NormalizeRelationAccessors(rdb, rdb.Right.AccessorName, rdb.Entity); NormalizeRelationAccessors(rdb, rdb.Left.AccessorName, rdb.Entity); } foreach (RelationDefinition rdb in Model.GetActiveRelations().OfType <RelationDefinition>()) { NormalizeRelationAccessors(rdb, rdb.Right.AccessorName, rdb.Right.Entity); NormalizeRelationAccessors(rdb, rdb.Left.AccessorName, rdb.Left.Entity); } }
protected virtual void OnPupulateM2MRelations() { var relationDescType = new CodeTypeReference(typeof(RelationDescEx)); #region Relation foreach (var relation in _entity.GetM2MRelations(false)) { if (relation.Left.Entity == relation.Right.Entity) { throw new ArgumentException("To realize m2m relation on self use SelfRelation instead."); } LinkTarget link = relation.Left.Entity == _entity ? relation.Right : relation.Left; var accessorName = link.AccessorName; var relatedEntity = link.Entity; if (string.IsNullOrEmpty(accessorName)) { // существуют похожие релейшены, но не имеющие имени акссесора var lst = link.Entity.GetM2MRelations(false).FindAll( r => r.Left != link && r.Right != link && ((r.Left.Entity == _entity && string.IsNullOrEmpty(r.Right.AccessorName)) || (r.Right.Entity == _entity && string.IsNullOrEmpty(r.Left.AccessorName)))); if (lst.Count > 0) { throw new WXMLException( string.Format( "Существуют неоднозначные связи между '{0}' и '{1}'. конкретизируйте их через accessorName.", lst[0].Left.Entity.Name, lst[0].Right.Entity.Name)); } accessorName = relatedEntity.Name; } accessorName = WXMLCodeDomGeneratorNameHelper.GetMultipleForm(accessorName); var entityTypeExpression = Settings.UseTypeInProps ? WXMLCodeDomGeneratorHelper.GetEntityClassTypeReferenceExpression(_settings, relatedEntity, relatedEntity.Namespace != _entity.Namespace) : WXMLCodeDomGeneratorHelper.GetEntityNameReferenceExpression(_settings, relatedEntity, relatedEntity.Namespace != _entity.Namespace); var desc = new CodeObjectCreateExpression( new CodeTypeReference(typeof(M2MRelationDesc)), entityTypeExpression); var staticProperty = new CodeMemberProperty { Name = accessorName + "Relation", HasGet = true, HasSet = false, Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static, Type = relationDescType }; staticProperty.GetStatements.Add(new CodeMethodReturnStatement( new CodeObjectCreateExpression(typeof(RelationDescEx), new CodeObjectCreateExpression(typeof(EntityUnion), WXMLCodeDomGeneratorHelper.GetEntityNameReferenceExpression(_settings, _entity, false) ), desc) )); desc.Parameters.Add(new CodePrimitiveExpression(relation.SourceFragment.Identifier)); Members.Add(staticProperty); GetRelationMethods(relation.SourceFragment.Identifier, staticProperty.Name); var memberProperty = new CodeMemberProperty { Name = accessorName, HasGet = true, HasSet = false, Attributes = MemberAttributes.Public | MemberAttributes.Final, Type = new CodeTypeReference(typeof(RelationCmd)) }; if (!string.IsNullOrEmpty(link.AccessorDescription)) { WXMLCodeDomGenerator.SetMemberDescription(memberProperty, link.AccessorDescription); } memberProperty.GetStatements.Add( new CodeMethodReturnStatement( new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "GetCmd", new CodePropertyReferenceExpression( new CodePropertyReferenceExpression( null, //WXMLCodeDomGeneratorHelper.GetEntityClassReferenceExpression(_settings, _entity, false), staticProperty.Name ), "M2MRel" ) ) ) ); Members.Add(memberProperty); _gen.RaisePropertyCreated(null, this, memberProperty, null); } #endregion #region SelfRelation foreach (var relation in _entity.GetM2MSelfRelations(false)) { var accessorName = relation.Direct.AccessorName; if (!string.IsNullOrEmpty(accessorName)) { var entityTypeExpression = Settings.UseTypeInProps ? WXMLCodeDomGeneratorHelper.GetEntityClassTypeReferenceExpression(_settings, _entity, false) : WXMLCodeDomGeneratorHelper.GetEntityNameReferenceExpression(_settings, _entity, false); var desc = new CodeObjectCreateExpression( new CodeTypeReference(typeof(M2MRelationDesc)), entityTypeExpression); accessorName = WXMLCodeDomGeneratorNameHelper.GetMultipleForm(accessorName); var staticProperty = new CodeMemberProperty { Name = accessorName + "Relation", HasGet = true, HasSet = false, Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static, Type = relationDescType }; staticProperty.GetStatements.Add(new CodeMethodReturnStatement( new CodeObjectCreateExpression(typeof(RelationDescEx), new CodeObjectCreateExpression(typeof(EntityUnion), WXMLCodeDomGeneratorHelper.GetEntityNameReferenceExpression(_settings, _entity, false) ), desc) )); GetRelationMethods(relation.SourceFragment.Identifier, staticProperty.Name); //desc.Parameters.Add(new CodePrimitiveExpression(relation.Direct.FieldName)); //desc.Parameters.Add(new CodeFieldReferenceExpression( // new CodeTypeReferenceExpression(typeof(M2MRelationDesc)),"DirKey") //); desc.Parameters.Add(new CodePrimitiveExpression(relation.SourceFragment.Identifier)); Members.Add(staticProperty); var memberProperty = new CodeMemberProperty { Name = accessorName, HasGet = true, HasSet = false, Attributes = MemberAttributes.Public | MemberAttributes.Final, Type = new CodeTypeReference(typeof(RelationCmd)) }; if (!string.IsNullOrEmpty(relation.Direct.AccessorDescription)) { WXMLCodeDomGenerator.SetMemberDescription(memberProperty, relation.Direct.AccessorDescription); } memberProperty.GetStatements.Add( new CodeMethodReturnStatement( new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "GetCmd", new CodePropertyReferenceExpression( new CodePropertyReferenceExpression( null, //WXMLCodeDomGeneratorHelper.GetEntityClassReferenceExpression(_settings, _entity, false), staticProperty.Name ), "M2MRel" ) ) ) ); Members.Add(memberProperty); _gen.RaisePropertyCreated(null, this, memberProperty, null); } accessorName = relation.Reverse.AccessorName; if (!string.IsNullOrEmpty(accessorName)) { var entityTypeExpression = WXMLCodeDomGeneratorHelper.GetEntityNameReferenceExpression(_settings, _entity, false); var desc = new CodeObjectCreateExpression( new CodeTypeReference(typeof(M2MRelationDesc)), entityTypeExpression); accessorName = WXMLCodeDomGeneratorNameHelper.GetMultipleForm(accessorName); var staticProperty = new CodeMemberProperty { Name = accessorName + "Relation", HasGet = true, HasSet = false, Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static, Type = relationDescType }; staticProperty.GetStatements.Add(new CodeMethodReturnStatement( new CodeObjectCreateExpression(typeof(RelationDescEx), new CodeObjectCreateExpression(typeof(EntityUnion), WXMLCodeDomGeneratorHelper.GetEntityNameReferenceExpression(_settings, _entity, false) ), desc) )); //desc.Parameters.Add(new CodePrimitiveExpression(relation.Reverse.FieldName)); //desc.Parameters.Add(new CodeFieldReferenceExpression( // new CodeTypeReferenceExpression(typeof(M2MRelationDesc)),"RevKey") //); desc.Parameters.Add(new CodePrimitiveExpression(M2MRelationDesc.ReversePrefix + relation.SourceFragment.Identifier)); GetRelationMethods(relation.SourceFragment.Identifier, staticProperty.Name); Members.Add(staticProperty); var memberProperty = new CodeMemberProperty { Name = accessorName, HasGet = true, HasSet = false, Attributes = MemberAttributes.Public | MemberAttributes.Final, Type = new CodeTypeReference(typeof(RelationCmd)) }; if (!string.IsNullOrEmpty(relation.Reverse.AccessorDescription)) { WXMLCodeDomGenerator.SetMemberDescription(memberProperty, relation.Reverse.AccessorDescription); } memberProperty.GetStatements.Add( new CodeMethodReturnStatement( new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "GetCmd", new CodePropertyReferenceExpression( new CodePropertyReferenceExpression( null, //WXMLCodeDomGeneratorHelper.GetEntityClassReferenceExpression(_settings, _entity, false), staticProperty.Name ), "M2MRel" ) ) ) ); Members.Add(memberProperty); _gen.RaisePropertyCreated(null, this, memberProperty, null); } } #endregion }
public static MvcHtmlString ItemLink(this HtmlHelper html, string href, string text, LinkTarget target = LinkTarget.Self) { return(ItemLink(html, href, text, text, null, target)); }
//private readonly LinkTarget _left; //private readonly LinkTarget _right; //private readonly TableDescription _table; //private readonly EntityDescription _underlyingEntity; //private bool _disabled; public RelationDefinition(LinkTarget left, LinkTarget right, SourceFragmentDefinition table, EntityDefinition underlyingEntity) : this(left, right, table, underlyingEntity, false) { }
protected void ProcessM2M(Dictionary <Column, Column> columns, OrmObjectsDef odef) { List <Pair <string> > tables = new List <Pair <string> >(); using (DbConnection conn = GetDBConn(_server, _m, _db, _i, _user, _psw)) { using (DbCommand cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = @"select table_schema,table_name from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_type = 'FOREIGN KEY' group by table_schema,table_name having count(*) = 2" ; conn.Open(); using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { tables.Add(new Pair <string>(reader.GetString(reader.GetOrdinal("table_schema")), reader.GetString(reader.GetOrdinal("table_name")))); } } } } foreach (Pair <string> p in tables) { string underlying = GetEntityName(p.First, p.Second); EntityDescription ued = odef.GetEntity(underlying); using (DbConnection conn = GetDBConn(_server, _m, _db, _i, _user, _psw)) { using (DbCommand cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = @"select cc.table_schema,cc.table_name,cc2.column_name,rc.delete_rule from INFORMATION_SCHEMA.constraint_column_usage cc join INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc on rc.unique_constraint_name = cc.constraint_name join INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc on tc.constraint_name = rc.constraint_name join INFORMATION_SCHEMA.constraint_column_usage cc2 on cc2.constraint_name = tc.constraint_name and cc2.table_schema = tc.table_schema and cc2.table_name = tc.table_name where tc.table_name = @tbl and tc.table_schema = @schema and tc.constraint_type = 'FOREIGN KEY'" ; DbParameter tbl = cmd.CreateParameter(); tbl.ParameterName = "tbl"; tbl.Value = p.Second; cmd.Parameters.Add(tbl); DbParameter schema = cmd.CreateParameter(); schema.ParameterName = "schema"; schema.Value = p.First; cmd.Parameters.Add(schema); conn.Open(); List <LinkTarget> targets = new List <LinkTarget>(); using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { //string ename = reader.GetString(reader.GetOrdinal("table_schema")) + "." + // reader.GetString(reader.GetOrdinal("table_name")); bool deleteCascade = false; switch (reader.GetString(reader.GetOrdinal("delete_rule"))) { case "NO ACTION": break; case "CASCADE": deleteCascade = true; break; default: throw new NotSupportedException("Cascade " + reader.GetString(reader.GetOrdinal("delete_rule")) + " is not supported"); } bool c; LinkTarget lt = new LinkTarget( GetEntity(odef, reader.GetString(reader.GetOrdinal("table_schema")), reader.GetString(reader.GetOrdinal("table_name")), out c), reader.GetString(reader.GetOrdinal("column_name")), deleteCascade); targets.Add(lt); } } RelationDescription rd = odef.GetSimilarRelation( new RelationDescription(targets[0], targets[1], null, null)); if (rd == null) { rd = new RelationDescription(targets[0], targets[1], GetTable(odef, p.First, p.Second), ued); odef.Relations.Add(rd); } } } } }
internal protected void FillRelations() { XmlNodeList relationNodes; #region Relations relationNodes = _ormXmlDocument.DocumentElement.SelectNodes(string.Format("{0}:EntityRelations/{0}:Relation", OrmObjectsDef.NS_PREFIX), _nsMgr); foreach (XmlNode relationNode in relationNodes) { XmlNode leftTargetNode = relationNode.SelectSingleNode(string.Format("{0}:Left", OrmObjectsDef.NS_PREFIX), _nsMgr); XmlNode rightTargetNode = relationNode.SelectSingleNode(string.Format("{0}:Right", OrmObjectsDef.NS_PREFIX), _nsMgr); XmlElement relationElement = (XmlElement)relationNode; string relationTableId = relationElement.GetAttribute("table"); string underlyingEntityId = relationElement.GetAttribute("underlyingEntity"); string disabledValue = relationElement.GetAttribute("disabled"); XmlElement leftTargetElement = (XmlElement)leftTargetNode; string leftLinkTargetEntityId = leftTargetElement.GetAttribute("entity"); XmlElement rightTargetElement = (XmlElement)rightTargetNode; string rightLinkTargetEntityId = rightTargetElement.GetAttribute("entity"); string leftFieldName = leftTargetElement.GetAttribute("fieldName"); string rightFieldName = rightTargetElement.GetAttribute("fieldName"); bool leftCascadeDelete = XmlConvert.ToBoolean(leftTargetElement.GetAttribute("cascadeDelete")); bool rightCascadeDelete = XmlConvert.ToBoolean(rightTargetElement.GetAttribute("cascadeDelete")); TableDescription relationTable = _ormObjectsDef.GetTable(relationTableId); EntityDescription underlyingEntity; if (string.IsNullOrEmpty(underlyingEntityId)) { underlyingEntity = null; } else { underlyingEntity = _ormObjectsDef.GetEntity(underlyingEntityId); } bool disabled; if (string.IsNullOrEmpty(disabledValue)) { disabled = false; } else { disabled = XmlConvert.ToBoolean(disabledValue); } EntityDescription leftLinkTargetEntity = _ormObjectsDef.GetEntity(leftLinkTargetEntityId); EntityDescription rightLinkTargetEntity = _ormObjectsDef.GetEntity(rightLinkTargetEntityId); LinkTarget leftLinkTarget = new LinkTarget(leftLinkTargetEntity, leftFieldName, leftCascadeDelete); LinkTarget rightLinkTarget = new LinkTarget(rightLinkTargetEntity, rightFieldName, rightCascadeDelete); RelationDescription relation = new RelationDescription(leftLinkTarget, rightLinkTarget, relationTable, underlyingEntity, disabled); _ormObjectsDef.Relations.Add(relation); } #endregion #region Relations relationNodes = _ormXmlDocument.DocumentElement.SelectNodes(string.Format("{0}:EntityRelations/{0}:SelfRelation", OrmObjectsDef.NS_PREFIX), _nsMgr); foreach (XmlNode relationNode in relationNodes) { XmlNode directTargetNode = relationNode.SelectSingleNode(string.Format("{0}:Direct", OrmObjectsDef.NS_PREFIX), _nsMgr); XmlNode reverseTargetNode = relationNode.SelectSingleNode(string.Format("{0}:Reverse", OrmObjectsDef.NS_PREFIX), _nsMgr); XmlElement relationElement = (XmlElement)relationNode; string relationTableId = relationElement.GetAttribute("table"); string underlyingEntityId = relationElement.GetAttribute("underlyingEntity"); string disabledValue = relationElement.GetAttribute("disabled"); string entityId = relationElement.GetAttribute("entity"); XmlElement directTargetElement = (XmlElement)directTargetNode; XmlElement reverseTargetElement = (XmlElement)reverseTargetNode; string directFieldName = directTargetElement.GetAttribute("fieldName"); string reverseFieldName = reverseTargetElement.GetAttribute("fieldName"); bool directCascadeDelete = XmlConvert.ToBoolean(directTargetElement.GetAttribute("cascadeDelete")); bool reverseCascadeDelete = XmlConvert.ToBoolean(reverseTargetElement.GetAttribute("cascadeDelete")); TableDescription relationTable = _ormObjectsDef.GetTable(relationTableId); EntityDescription underlyingEntity; if (string.IsNullOrEmpty(underlyingEntityId)) { underlyingEntity = null; } else { underlyingEntity = _ormObjectsDef.GetEntity(underlyingEntityId); } bool disabled; if (string.IsNullOrEmpty(disabledValue)) { disabled = false; } else { disabled = XmlConvert.ToBoolean(disabledValue); } EntityDescription entity = _ormObjectsDef.GetEntity(entityId); SelfRelationTarget directTarget = new SelfRelationTarget(directFieldName, directCascadeDelete); SelfRelationTarget reverseTarget = new SelfRelationTarget(reverseFieldName, reverseCascadeDelete); SelfRelationDescription relation = new SelfRelationDescription(entity, directTarget, reverseTarget, relationTable, underlyingEntity, disabled); _ormObjectsDef.SelfRelations.Add(relation); } #endregion }
public static ComponentBuilder <TConfig, TTag> SetTarget <TConfig, TTag>(this ComponentBuilder <TConfig, TTag> builder, LinkTarget target) where TConfig : BootstrapConfig where TTag : Tag, IHasLinkExtensions { builder.Component.MergeAttribute("target", target.GetDescription()); return(builder); }
public RelationDefinition(LinkTarget left, LinkTarget right, SourceFragmentDefinition table, EntityDefinition underlyingEntity, bool disabled) : base(table, underlyingEntity, left, right, disabled) { //_left = left; //_right = right; }