Exemplo n.º 1
0
        public static KinshipRet FindKinship(RelationKind prev, RelationKind cur)
        {
            RelationKind finRel = RelationKind.rkUndefined;
            int          great  = 0;
            int          level  = 0;

            int num = fKinships.Count;

            for (int i = 0; i < num; i++)
            {
                KinshipRec kinship = fKinships[i];

                if (kinship.PrevRels.Contains(prev) && kinship.CurrRels.Contains(cur))
                {
                    RelationKind rel = kinship.FinRel;
                    great = kinship.Great;
                    level = kinship.Level;

                    if (rel == RelationKind.rkSame)
                    {
                        rel = cur;
                    }

                    finRel = rel;
                }
            }

            return(new KinshipRet(finRel, great, level));
        }
 private void DispatchAction(RelationKind work, Action succeeded, Action <Exception> failed)
 {
     this.IsCommunicating = true;
     RequestQueue.EnqueueObservable(_source, new UpdateRelationRequest(_target, work))
     .Finally(() => this.IsCommunicating = false)
     .Subscribe(_ => { }, failed, succeeded);
 }
Exemplo n.º 3
0
        public bool HasChangedRoles(Object derivable, RelationKind relationKind)
        {
            Func <IRoleType, bool> check;

            switch (relationKind)
            {
            case RelationKind.Regular:
                check = (roleType) => !roleType.RelationType.IsDerived && !roleType.RelationType.IsSynced;
                break;

            case RelationKind.Derived:
                check = (roleType) => roleType.RelationType.IsDerived;
                break;

            case RelationKind.Synced:
                check = (roleType) => roleType.RelationType.IsSynced;
                break;

            default:
                check = (roleType) => true;
                break;
            }

            this.RoleTypesByAssociation.TryGetValue(derivable.Id, out var changedRoleTypes);
            if (changedRoleTypes != null)
            {
                if (changedRoleTypes.Any(roleType => check(roleType)))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        private static void SearchKGInt(IBaseContext context, Vertex prevNode, GDMIndividualRecord iRec,
                                        KinshipsGraph graph, RelationKind relation, RelationKind inverseRelation)
        {
            if (iRec == null)
            {
                return;
            }

            Vertex currNode = graph.FindVertex(iRec.XRef);

            if (currNode != null)
            {
                if (prevNode != null)
                {
                    graph.AddRelation(prevNode, currNode, relation, inverseRelation);
                }

                return;
            }
            else
            {
                currNode = graph.AddIndividual(iRec);

                if (prevNode != null)
                {
                    graph.AddRelation(prevNode, currNode, relation, inverseRelation);
                }
            }

            if (iRec.ChildToFamilyLinks.Count > 0)
            {
                GDMFamilyRecord fam = context.Tree.GetParentsFamily(iRec);
                if (fam != null)
                {
                    GDMIndividualRecord father, mother;
                    father = context.Tree.GetPtrValue(fam.Husband);
                    mother = context.Tree.GetPtrValue(fam.Wife);

                    SearchKGInt(context, currNode, father, graph, RelationKind.rkParent, RelationKind.rkChild);
                    SearchKGInt(context, currNode, mother, graph, RelationKind.rkParent, RelationKind.rkChild);
                }
            }

            int num = iRec.SpouseToFamilyLinks.Count;

            for (int i = 0; i < num; i++)
            {
                GDMFamilyRecord     family = context.Tree.GetPtrValue(iRec.SpouseToFamilyLinks[i]);
                GDMIndividualRecord spouse = (iRec.Sex == GDMSex.svMale) ? context.Tree.GetPtrValue(family.Wife) : context.Tree.GetPtrValue(family.Husband);

                SearchKGInt(context, currNode, spouse, graph, RelationKind.rkSpouse, RelationKind.rkSpouse);

                int num2 = family.Children.Count;
                for (int j = 0; j < num2; j++)
                {
                    GDMIndividualRecord child = context.Tree.GetPtrValue(family.Children[j]);
                    SearchKGInt(context, currNode, child, graph, RelationKind.rkChild, RelationKind.rkParent);
                }
            }
        }
Exemplo n.º 5
0
        private static void SearchKGInt(Vertex prevNode, GEDCOMIndividualRecord iRec,
                                        KinshipsGraph graph, RelationKind relation, RelationKind inverseRelation)
        {
            if (iRec == null)
            {
                return;
            }

            Vertex currNode = graph.FindVertex(iRec.XRef);

            if (currNode != null)
            {
                if (prevNode != null)
                {
                    graph.AddRelation(prevNode, currNode, relation, inverseRelation);
                }

                return;
            }
            else
            {
                currNode = graph.AddIndividual(iRec);

                if (prevNode != null)
                {
                    graph.AddRelation(prevNode, currNode, relation, inverseRelation);
                }
            }

            if (iRec.ChildToFamilyLinks.Count > 0)
            {
                GEDCOMFamilyRecord fam = iRec.GetParentsFamily();
                if (fam != null)
                {
                    GEDCOMIndividualRecord father, mother;
                    father = fam.GetHusband();
                    mother = fam.GetWife();

                    SearchKGInt(currNode, father, graph, RelationKind.rkParent, RelationKind.rkChild);
                    SearchKGInt(currNode, mother, graph, RelationKind.rkParent, RelationKind.rkChild);
                }
            }

            int num = iRec.SpouseToFamilyLinks.Count;

            for (int i = 0; i < num; i++)
            {
                GEDCOMFamilyRecord     family = iRec.SpouseToFamilyLinks[i].Family;
                GEDCOMIndividualRecord spouse = ((iRec.Sex == GEDCOMSex.svMale) ? family.GetWife() : family.GetHusband());

                SearchKGInt(currNode, spouse, graph, RelationKind.rkSpouse, RelationKind.rkSpouse);

                int num2 = family.Children.Count;
                for (int j = 0; j < num2; j++)
                {
                    GEDCOMIndividualRecord child = (GEDCOMIndividualRecord)family.Children[j].Value;
                    SearchKGInt(currNode, child, graph, RelationKind.rkChild, RelationKind.rkParent);
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="masterTableMapping">主关联表的映射</param>
 /// <param name="relateTableType">关联类型</param>
 /// <param name="relationName">关联名</param>
 public RelationFieldMapping(DataEntityMapping masterTableMapping, Type relateTableType, string relationName)
 {
     _masterTableMapping = masterTableMapping;
     _relationName       = relationName;
     if (relateTableType.IsArray)
     {
         _relationTableType = relateTableType.GetElementType();
         _relationKind      = RelationKind.OneToMany;
         _resultDataKind    = DataKind.Array;
     }
     else if (relateTableType.IsGenericType)
     {
         Type frameType = relateTableType.GetGenericTypeDefinition();
         if (frameType.FullName != "System.Collections.Generic.IList`1")
         {
             throw new LightDataException(RE.TheRelationTypeNotIList);
         }
         else
         {
             Type[] arguments = relateTableType.GetGenericArguments();
             _relationTableType = arguments [0];
             _relationKind      = RelationKind.OneToMany;
             _resultDataKind    = DataKind.IList;
         }
     }
     else
     {
         _relationTableType = relateTableType;
         _relationKind      = RelationKind.OneToOne;
         _resultDataKind    = DataKind.SingleObject;
     }
 }
Exemplo n.º 7
0
 public KinshipRec(EnumSet <RelationKind> prevRels, EnumSet <RelationKind> currRels, RelationKind finRel, short great, short level)
 {
     PrevRels = prevRels;
     CurrRels = currRels;
     FinRel   = finRel;
     Great    = great;
     Level    = level;
 }
Exemplo n.º 8
0
 public NodeRelation(RelationKind relationKind, Node node1, Node node2)
 {
     this.RelationKind = relationKind;
     this.Node1        = node1;
     this.Node2        = node2;
     if (node1 == node2)
     {
         throw new InvalidOperationException("Node relation cannot have the same node on both sides.");
     }
 }
Exemplo n.º 9
0
 public Relation(string name) : base(name)
 {
     var(kind, relatedEntityType) =
         DetectDependentRelation() ??
         DetectOptionalRelation() ??
         DetectMultipleRelation() ??
         throw new InvalidOperationException($"Unable to determine relation kind for {this}");
     _kind          = kind;
     _relatedEntity = Entity.GetDescriptorFromType(relatedEntityType);
 }
 public RelatedToAttribute(Type left, Type right, RelationKind kind)
 {
     this.Settings = new RelationshipSettings
     {
         LeftModelName  = left.Name,
         RightModelName = right.Name,
         LeftClrName    = left.FullName,
         RightClrName   = right.FullName,
         Kind           = kind
     };
 }
Exemplo n.º 11
0
        private static RelationKind FixLink(GDMIndividualRecord xFrom, GDMIndividualRecord xTo, RelationKind rel)
        {
            RelationKind resRel = rel;

            switch (rel)
            {
            case RelationKind.rkParent:
                switch (xTo.Sex)
                {
                case GDMSex.svMale:
                    resRel = RelationKind.rkFather;
                    break;

                case GDMSex.svFemale:
                    resRel = RelationKind.rkMother;
                    break;
                }
                break;

            case RelationKind.rkSpouse:
                switch (xTo.Sex)
                {
                case GDMSex.svMale:
                    resRel = RelationKind.rkHusband;
                    break;

                case GDMSex.svFemale:
                    resRel = RelationKind.rkWife;
                    break;
                }
                break;

            case RelationKind.rkChild:
                switch (xTo.Sex)
                {
                case GDMSex.svMale:
                    resRel = RelationKind.rkSon;
                    break;

                case GDMSex.svFemale:
                    resRel = RelationKind.rkDaughter;
                    break;
                }
                break;

            default:
                resRel = rel;
                break;
            }

            return(resRel);
        }
Exemplo n.º 12
0
 protected Relation(
     TypeReference source,
     MethodDefinition targetMettod,
     TypeReference target,
     MethodReference sourceMethod,
     Instruction op, int offset, RelationKind kind)
 {
     Source       = source;
     SourceMethod = sourceMethod;
     Target       = target;
     TargetMethod = targetMettod;
     Kind         = kind;
     Op           = op;
     Offset       = offset;
 }
        private void MapRelation(PropertyInfo property, Type relatedResourceType, RelationKind kind)
        {
            var name = property.GetJsonPropertyName();

            if (!_properties.ContainsKey(name))
            {
                throw new ArgumentException($"Property with JSON name {name} not found. Did you call {nameof(IgnoreProperty)} on the property?");
            }

            if (_relations.ContainsKey(name))
            {
                throw new ArgumentException($"Relation property with JSON name {name} already mapped", nameof(property));
            }

            _relations.Add(name, new RelationInfo(property, relatedResourceType, kind));
        }
Exemplo n.º 14
0
        private static string FixRelation(GDMIndividualRecord target, RelationKind rel, int great)
        {
            string tmp = "";

            if (great != 0)
            {
                if (rel == RelationKind.rkUncle || rel == RelationKind.rkAunt)
                {
                    tmp = GKData.Numerals[great] + GKData.NumKinship[(int)target.Sex] + " ";
                    if (rel == RelationKind.rkUncle)
                    {
                        rel = RelationKind.rkGrandfather;
                    }
                    else if (rel == RelationKind.rkAunt)
                    {
                        rel = RelationKind.rkGrandmother;
                    }
                }
                else if (rel == RelationKind.rkNephew || rel == RelationKind.rkNiece)
                {
                    tmp = GKData.Numerals[great] + GKData.NumKinship[(int)target.Sex] + " ";
                    if (rel == RelationKind.rkNephew)
                    {
                        rel = RelationKind.rkBrother;
                    }
                    else if (rel == RelationKind.rkNiece)
                    {
                        rel = RelationKind.rkSister;
                    }
                }
                else
                {
                    if (rel != RelationKind.rkUndefined)
                    {
                        tmp = GetGreat(great);
                    }
                }
            }
            else
            {
                tmp = "";
            }
            return(tmp + LangMan.LS(GKData.RelationKinds[(int)rel]));
        }
Exemplo n.º 15
0
        internal static Relation MethodCall(TypeDefinition type, MethodDefinition method, TypeReference targetType, MethodReference targetMethod)
        {
            var resolvedMethod = targetMethod.SmartResolve();

            RelationKind kind = RelationKind.MethodCall;

            if (resolvedMethod != null)
            {
                if (resolvedMethod.IsConstructor)
                {
                    kind = RelationKind.Construction;
                }
                if (resolvedMethod.IsGetter)
                {
                    kind = RelationKind.MethodCallImmutable;
                }
            }
            return(new Relation(type, method, targetType, targetMethod, null, 0, kind));
        }
Exemplo n.º 16
0
 public PreferenceFileReader(string filename, RelationKind relationKind)
 {
     fileName = filename;
     ClassRelations = new Dictionary<string, HashSet<string>>();
     SetInRelationFunc(relationKind);
 }
Exemplo n.º 17
0
 public RelationInfo(PropertyInfo propertyInfo, Type relatedResourceType, RelationKind kind)
 {
     PropertyInfo = propertyInfo;
     ResourceType = relatedResourceType;
     Kind         = kind;
 }
Exemplo n.º 18
0
 private static void RegisterKinship(RelationSet prevRels, RelationSet currRels, RelationKind finRel, sbyte great, sbyte level)
 {
     fKinships.Add(new KinshipRec(prevRels, currRels, finRel, great, level));
 }
Exemplo n.º 19
0
 internal KinshipRet(RelationKind finRel, int great, int level)
 {
     FinRel = finRel;
     Great  = great;
     Level  = level;
 }
Exemplo n.º 20
0
 public TypeRelation(TypeDefinition usingType, TypeReference usedType, RelationKind kind)
     : base(usingType, null, usedType, null, null, 0, kind)
 {
 }
Exemplo n.º 21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <param name="tsRel">target to source relation (if target is parent of source = Parent)</param>
 /// <param name="stRel">source to target relation (if target is parent of source = Child)</param>
 /// <returns></returns>
 public bool AddRelation(Vertex source, Vertex target, RelationKind tsRel, RelationKind stRel)
 {
     return(fGraph.AddUndirectedEdge(source, target, 1, (int)tsRel, (int)stRel));
 }
Exemplo n.º 22
0
        private string GetRelationPart(GDMIndividualRecord ind1, GDMIndividualRecord ind2, RelationKind xrel, int great)
        {
            if (ind1 == null || ind2 == null)
            {
                return("???");
            }

            string rel   = FixRelation(ind2, xrel, great);
            string name1 = fContext.Culture.GetPossessiveName(ind1);
            string name2 = GKUtils.GetNameString(ind2, true, false);

            rel = string.Format(LangMan.LS(LSID.LSID_RelationshipMask), name2, rel, name1);
            return(rel);
        }
Exemplo n.º 23
0
 private void _addRelation(string name, RelationKind kind, bool isEnabled, bool isInitiallyExpanded, IEnumerable<BplClass> classes) {
    var targetClasses = classes.Where(c => c != Class).ToArray();
    if (targetClasses.Length > 0) {
       Children.Add(new RelationNode(this, name, kind, isEnabled, isInitiallyExpanded, targetClasses));
    }
 }
Exemplo n.º 24
0
 static string RelationKindToArrow(RelationKind relationKind) => relationKind switch
 {
Exemplo n.º 25
0
 public UpdateRelationRequest(long userId, RelationKind kind)
 {
     _userId = userId;
     _kind   = kind;
 }
Exemplo n.º 26
0
 public UpdateRelationRequest(TwitterUser target, RelationKind kind)
     : this(target.Id, kind)
 {
 }
Exemplo n.º 27
0
        public string GetRelationship(GDMIndividualRecord targetRec, bool fullFormat = false)
        {
            if (targetRec == null)
            {
                return("???");
            }
            Vertex target = fGraph.FindVertex(targetRec.XRef);

            if (target == null)
            {
                return("???");
            }

            try {
                IEnumerable <Edge> edgesPath = fGraph.GetPath(target);

                string       tmp     = "";
                RelationKind prevRel = RelationKind.rkNone;
                RelationKind finRel  = RelationKind.rkNone;
                int          great   = 0;

                GDMIndividualRecord src = null, tgt = null, prev_tgt = null;
                string part, fullRel = "";

                foreach (Edge edge in edgesPath)
                {
                    GDMIndividualRecord xFrom  = (GDMIndividualRecord)edge.Source.Value;
                    GDMIndividualRecord xTo    = (GDMIndividualRecord)edge.Target.Value;
                    RelationKind        curRel = FixLink(xFrom, xTo, (RelationKind)((int)edge.Value));

                    if (src == null)
                    {
                        src = xFrom;
                    }
                    prev_tgt = tgt;
                    tgt      = xTo;

                    if (tmp != "")
                    {
                        tmp += ", ";
                    }
                    tmp += xFrom.XRef + ">" + GKData.RelationSigns[(int)curRel] + ">" + xTo.XRef;

                    if (prevRel != RelationKind.rkUndefined)
                    {
                        int g, lev;
                        finRel = KinshipsMan.FindKinship(prevRel, curRel, out g, out lev);
                        great += g;

                        // it's gap
                        if (finRel == RelationKind.rkUndefined && fullFormat)
                        {
                            part    = GetRelationPart(src, prev_tgt, prevRel, great);
                            src     = prev_tgt;
                            great   = 0;
                            prevRel = RelationKind.rkNone;

                            if (fullRel.Length > 0)
                            {
                                fullRel += ", ";
                            }
                            fullRel += part;

                            finRel = KinshipsMan.FindKinship(prevRel, curRel, out g, out lev);
                            great += g;
                        }

                        prevRel = finRel;
                    }
                }

                IndividualsPath = targetRec.XRef + " [" + tmp + "]";

                if (!fullFormat)
                {
                    string relRes = FixRelation(targetRec, finRel, great);
                    return(relRes);
                }
                else
                {
                    part = GetRelationPart(src, tgt, finRel, great);

                    if (fullRel.Length > 0)
                    {
                        fullRel += ", ";
                    }
                    fullRel += part;

                    return(fullRel);
                }
            } catch (Exception ex) {
                Logger.WriteError("KinshipsGraph.GetRelationship()", ex);
                return("");
            }
        }
Exemplo n.º 28
0
 private void _addPrecedents(string name, RelationKind kind, bool isEnabled, bool isInitiallyExpanded, Func<BplProperty, bool> cond) {
    var precedents = Class.UsedBy.Where(p => cond(p)).Select(p => p.Class).Distinct().OrderBy(c => c.Name);
    _addRelation(name, kind, isEnabled, isInitiallyExpanded, precedents);
 }
Exemplo n.º 29
0
         // Constructor
         public RelationNode(SourceNode parent, string name, RelationKind kind, bool isEnabled, bool isInitiallyExpanded, IEnumerable<BplClass> targetClasses) {
            IsEnabled = isEnabled;
            IsInitiallyExpanded = isInitiallyExpanded;
            Kind = kind;
            Name = name;
            Parent = parent;

            Children = new List<TargetNode>();
            foreach (var c in targetClasses) {
               Children.Add(new TargetNode(this, isEnabled, c));
            }
            UpdateSelection(true);
         }
Exemplo n.º 30
0
 private void DispatchAction(RelationKind work, Action succeeded, Action<Exception> failed)
 {
     this.IsCommunicating = true;
     RequestQueue.Enqueue(_source, new UpdateRelationRequest(_target, work))
                 .Finally(() => this.IsCommunicating = false)
                 .Subscribe(_ => { },
                            failed,
                            succeeded);
 }
Exemplo n.º 31
0
 public BaseRelation(Type type, RelationKind kind, Type relationWith)
 {
     Type         = type;
     Kind         = kind;
     RelationWith = relationWith;
 }
Exemplo n.º 32
0
 private void SetInRelationFunc(RelationKind relationKind)
 {
     switch (relationKind)
     {
         case RelationKind.Strict:
             inRelationFunc = AreInStrictRelation;
             break;
         case RelationKind.NonStrict:
             inRelationFunc = AreInNonStrictRelation;
             break;
         case RelationKind.Equal:
             inRelationFunc = AreInEqualRelation;
             break;
         default:
             throw new ArgumentOutOfRangeException("relationKind");
     }
 }
Exemplo n.º 33
0
 private void _addDependents(string name, RelationKind kind, bool isEnabled, bool isInitiallyExpanded, Func<BplProperty, bool> cond) {
    var inherit = Diagram.DisplayOptions.Has(DisplayOptions.DisplayInheritedMembers);
    var properties = (inherit ? Class.Properties : Class.OwnProperties);
    if (Class.Operation != null) {
       var output = Class.Operation.Output;
       if (output != null) {
          properties = properties.Union(inherit ? output.Properties : output.OwnProperties);
       }
    }
    var dependents = properties.Where(p => cond(p)).Select(p => p.ReferencedClass).Distinct().OrderBy(c => c.Name);
    _addRelation(name, kind, isEnabled, isInitiallyExpanded, dependents);
 }
Exemplo n.º 34
0
 public CsvDataFileManager(string fileNameObjects, string separator, int classNameColumnIndex, string fileNameRelations, RelationKind kind)
 {
     csvReader = new CsvFileReader(fileNameObjects, separator, classNameColumnIndex);
     preferenceReader = new PreferenceFileReader(fileNameRelations, kind);
 }