Exemple #1
0
        /// <summary>
        /// Returns a list of relations, that are known in RelationCosmos and pointing to
        /// the relation provided.
        /// </summary>
        /// <param name="relation">The object implementing RelationBase</param>
        /// <param name="excludeRelations">List of relations,
        /// that should be excluded in that check</param>
        /// <returns>RelationList</returns>
        public RelationList GetIncoming(RelationBase relation, IList excludeRelations)
        {
            if (relation == null || relation.HRef == null)
            {
                return(RelationCosmos.emptyRelationList);
            }

            lock (syncRoot) {
                try {
                    if (excludeRelations == null)
                    {
                        excludeRelations = (IList)RelationCosmos.emptyRelationList;
                    }

                    // check incoming:
                    RelationList list = registeredIncomingRelations[relation.HRef];
                    if (list != null && list.Count > 0)
                    {
                        RelationList returnList = new RelationList(list.Count);
                        foreach (RelationBase r in list)
                        {
                            if (r != relation && !excludeRelations.Contains(r))
                            {
                                returnList.Add(r);
                            }
                        }
                        return(returnList);
                    }
                } catch (Exception ex) {
                    System.Diagnostics.Trace.WriteLine("RelationCosmos.GetIncoming() exception: " + ex.Message);
                }

                return(RelationCosmos.emptyRelationList);
            }
        }
Exemple #2
0
        public void AddExistRelation(IDesignRelation idr)//添加关联,自行判断是否有关联控件存在
        {
            if (idr == null)
            {
                return;
            }
            if (NodeList.Count == 0)
            {
                return;
            }
            idr.designCanvas = this;
            IDesignNode sdn = null, tdn = null;

            if (idr.SourceID != null)
            {
                List <IDesignNode> rl = NodeList.Where(n => n.ObjectID == idr.SourceID).ToList();
                if (rl.Count > 0)
                {
                    sdn = rl[0];
                }
            }
            if (idr.TargetID != null)
            {
                List <IDesignNode> rl = NodeList.Where(n => n.ObjectID == idr.SourceID).ToList();
                if (rl.Count > 0)
                {
                    tdn = rl[0];
                }
            }
            if (sdn != null)
            {
                idr.StartAnchorPoint = sdn.getDefaultAnchorPoint();
                idr.StartPoint       = idr.StartAnchorPoint.getDesignCanvasPoint();
            }
            else
            {
                idr.StartAnchorPoint = null;
                idr.StartPoint       = new Point(DeseignCanvas.Width / 2 - (new Random()).Next(50), DeseignCanvas.Height / 2 - (new Random()).Next(50));
            }
            if (tdn != null)
            {
                idr.EndAnchorPoint = tdn.getDefaultAnchorPoint();
                idr.EndPoint       = idr.EndAnchorPoint.getDesignCanvasPoint();
            }
            else
            {
                idr.EndAnchorPoint = null;
                idr.EndPoint       = new Point(DeseignCanvas.Width / 2 + (new Random()).Next(150), DeseignCanvas.Height / 2 + (new Random()).Next(150));
            }
            FrameworkElement fe = idr.getControl();

            DeseignCanvas.Children.Add(fe);

            idr.DrawRelationLine(idr.StartPoint, idr.EndPoint);
            sendObjectOperationEvent(idr, DesignOperationFlag.CreateRelation);//提示设计图增加了节点对象
            RelationList.Add(idr);
        }
Exemple #3
0
        private static void AddToRelationList(string key, RelationBase relation, RelationLists toRelations)
        {
            RelationList list = GetRelationList(key, toRelations);

            if (!list.Contains(relation))
            {
                list.Add(relation);
            }
        }
Exemple #4
0
        private void BuildDomFromSchema(JsonData data, string tableName, JsonSchema schema = null)
        {
            // first, create a new table instance for the data
            JsonSchemaTable table = new JsonSchemaTable(tableName, data, this, schema);

            TableList.Add(table);

            JsonData objectToParse;

            if (data != null && data.IsArray)
            {
                objectToParse = data.Count > 0 ? data[0] : null;
            }
            else
            {
                objectToParse = data;
            }

            //enumerate all schema
            foreach (var property in schema.Properties)
            {
                string   propertyName = property.Key;
                JsonData objectData   = null;
                if (objectToParse != null && objectToParse.ContainsKey(propertyName))
                {
                    objectData = objectToParse[propertyName];
                }

                if (property.Value.Type == JsonObjectType.Object)
                {
                    if (IsFlattableR(property.Value))
                    {
                        continue;
                    }
                    else
                    {
                        string            newTableName = GetUniqueTableName(propertyName);
                        JsonTableRelation relation     = new JsonTableRelation(GetUniqueRelationName(tableName, newTableName), tableName, newTableName);
                        RelationList.Add(relation);
                        BuildDomFromSchema(objectData, newTableName, schema.Properties[propertyName]);
                    }
                }
                // schema.Properties[propertyName].Item may be null if schema has no other definitions for the array ("Item": { "type": "array" }) => we wont add this array since it will always be an empty array with no columns
                else if (property.Value.Type == JsonObjectType.Array && schema.Properties[propertyName].Item != null)
                {
                    // need to add a table anyway, either for a true object or just a fake table using "ArrayValue" as field name
                    string            newTableName = GetUniqueTableName(propertyName);
                    JsonTableRelation relation     = new JsonTableRelation(GetUniqueRelationName(tableName, newTableName), tableName, newTableName);
                    RelationList.Add(relation);

                    // see if there is an object underneath
                    BuildDomFromSchema(objectData, newTableName, schema.Properties[propertyName].Item);
                }
            }
        }
Exemple #5
0
        void DeseignCanvas_DesignPointerReleased(object sender, PointerRoutedEventArgs e)
        {
            HideDesignLine();

            DeseignCanvas.PointerMoved    -= new PointerEventHandler(DeseignCanvas_DesignPointerMoved);
            DeseignCanvas.PointerReleased -= new PointerEventHandler(DeseignCanvas_DesignPointerReleased);


            IDesignRelation l = null;

            if ((StartAnchor != null) && (EndAnchor != null) && (EndAnchor != StartAnchor))
            {
                l = null;
                if (!getNewRelationControlByID.Equals(null))//新建关联
                {
                    l = getNewRelationControl(null, null);
                }
                if (l == null)//新建失败使用默认关联
                {
                    l             = new LynxConnectLine();
                    l.IsErrorData = true;
                }
                if (l != null)
                {
                    l.designCanvas = this;

                    l.StartAnchorPoint = StartAnchor;
                    l.EndAnchorPoint   = EndAnchor;
                    StartAnchor.OutRelationList.Add(l);
                    EndAnchor.InRelationList.Add(l);
                    l.SourceID = StartAnchor.ParentConnectControl.ObjectID;
                    l.TargetID = EndAnchor.ParentConnectControl.ObjectID;
                }
            }

            if (l == null)
            {
                return;
            }                                                                //没有能够创立链接
            sendObjectOperationEvent(l, DesignOperationFlag.CreateRelation); //建立新的连接
            l.ReadFromObject();

            DeActiveAll();

            l.DrawRelationLine(StartPoint.Value, e.GetCurrentPoint(getCanvas()).Position);
            RelationList.Add(l);
            ActiveDesignObject(l);
            EndAnchor           = null;
            StartAnchor         = null;
            CurrentConnectPoint = null;
        }
Exemple #6
0
        public void AddExistRelation(IDesignRelation idr, IDesignNode sdn, IDesignNode tdn)//在指定的起始节点和终止节点之间添加一个关联控件
        {
            if (idr == null)
            {
                return;
            }
            if (NodeList.Count == 0)
            {
                return;
            }
            idr.designCanvas = this;
            if (sdn != null)
            {
                idr.StartAnchorPoint = sdn.getDefaultAnchorPoint();
                idr.StartPoint       = idr.StartAnchorPoint.getDesignCanvasPoint();
            }
            else
            {
                idr.StartAnchorPoint = null;
                idr.StartPoint       = new Point(DeseignCanvas.Width / 2 - (new Random()).Next(50), DeseignCanvas.Height / 2 - (new Random()).Next(50));
            }
            if (tdn != null)
            {
                idr.EndAnchorPoint = tdn.getDefaultAnchorPoint();
                idr.EndPoint       = idr.EndAnchorPoint.getDesignCanvasPoint();
            }
            else
            {
                idr.EndAnchorPoint = null;
                idr.EndPoint       = new Point(DeseignCanvas.Width / 2 + (new Random()).Next(150), DeseignCanvas.Height / 2 + (new Random()).Next(150));
            }
            FrameworkElement fe = idr.getControl();

            DeseignCanvas.Children.Add(fe);

            idr.DrawRelationLine(idr.StartPoint, idr.EndPoint);
            sendObjectOperationEvent(idr, DesignOperationFlag.CreateRelation);//提示设计图增加了节点对象
            RelationList.Add(idr);
        }
Exemple #7
0
        public void CreateControl(IDesignObject idn, Point p)
        {
            idn.designCanvas = this;
            FrameworkElement fe = idn.getControl();

            Canvas.SetLeft(fe, p.X);
            Canvas.SetTop(fe, p.Y);
            DeseignCanvas.Children.Add(fe);
            //DesignObjectList.Add(idn);

            if (idn is IDesignNode)
            {
                NodeList.Add(idn as IDesignNode);
                sendObjectOperationEvent(idn, DesignOperationFlag.CreateObject);//提示设计图增加了节点对象
            }
            if (idn is IDesignRelation)
            {
                RelationList.Add(idn as IDesignRelation);
                (idn as IDesignRelation).DrawRelationLine(p, new Point(p.X + 100, p.Y + 100));
                sendObjectOperationEvent(idn, DesignOperationFlag.CreateRelation);//提示设计图增加了节点对象
            }
        }
Exemple #8
0
        /// <summary>
        /// Returns a list of relations, that are known in RelationCosmos and that
        /// the relation provided points to.
        /// </summary>
        /// <param name="relation">The object implementing RelationBase</param>
        /// <param name="excludeRelations">List of relations,
        /// that should be excluded in that check</param>
        /// <returns>RelationList</returns>
        public RelationList GetOutgoing(RelationBase relation, IList excludeRelations)
        {
            if (relation == null || relation.HRef == null)
            {
                return(RelationCosmos.emptyRelationList);
            }

            lock (syncRoot) {
                try {
                    if (excludeRelations == null)
                    {
                        excludeRelations = (IList)RelationCosmos.emptyRelationList;
                    }

                    // check incoming:
                    RelationHRefList list = relation.OutgoingRelations;
                    if (list != null && list.Count > 0)
                    {
                        RelationList returnList = new RelationList(list.Count);
                        foreach (string hrefOut in list)
                        {
                            if (hrefOut != relation.HRef && !RelationListContainsHRef(excludeRelations, hrefOut) &&
                                registeredRelations.Contains(hrefOut))
                            {
                                returnList.Add(registeredRelations[hrefOut]);
                            }
                        }
                        return(returnList);
                    }
                } catch (Exception ex) {
                    System.Diagnostics.Trace.WriteLine("RelationCosmos.GetOutgoing() exception: " + ex.Message);
                }

                return(RelationCosmos.emptyRelationList);
            }
        }