Beispiel #1
0
        public Relationship AddToIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value)
        {
            var uriFormat = IsBatchObject(relationship) ? "{{{0}}}" : "/relationship/{0}";

            var body = new JObject
            {
                { "value", JToken.FromObject(value) },
                { "uri", string.Format(uriFormat, relationship.Id) },
                { "key", key }
            };

            var index = _jobs.Count();

            _jobs.Add(new BatchJob
            {
                Method = HttpRest.Method.Post,
                To     = string.Format("/index/relationship/{0}", indexName),
                Id     = index,
                Body   = body
            });

            _jobs[index].GraphObject = new BatchRelationshipStore(this).Initilize(null, index, null);

            return((Relationship)_jobs[index].GraphObject);
        }
Beispiel #2
0
        /// <summary>
        /// Refreshes the configuration of the ServiceConnection.
        /// </summary>
        public override void RefreshConfiguration()
        {
            base.RefreshConfiguration();
            DataAccessSection section           = DataAccessSection.GetSection();
            ConnectionElement connectionElement = section.ConnectionList[this.Name];

            if (connectionElement == null)
            {
                throw new Exception("Could not find connection element '" + this.Name + "' in the configuration file.");
            }
            else
            {
                _affiliateApplication = connectionElement.Affiliate;
                _userId                      = connectionElement.UserId;
                _password                    = connectionElement.Password;
                _connectionTemplate          = connectionElement.ConnectionTemplate;
                _retryConnectionCount        = connectionElement.RetryConnectionCount;
                _retryIntervalInMilliseconds = connectionElement.RetryIntervalInMilliseconds;
                ClassSpecificationElement connectionProvider = connectionElement.DbConnectionProvider;
                _connectionProviderName     = connectionProvider.Name;
                _connectionProviderAssembly = connectionProvider.Assembly;
                _connectionProviderClass    = connectionProvider.Class;
                GetConnectionString();
            }
        }
        public Node GetRootNode(ConnectionElement connection)
        {
            string response;
            var    status = Neo4jRestApi.GetRoot(Connection.GetDatabaseEndpoint(connection.DbUrl).Data, out response);

            if (status != HttpStatusCode.OK)
            {
                throw new Exception(string.Format("Error getting root node (http response:{0})", status));
            }

            JObject jo;

            try
            {
                jo = JObject.Parse(response);
            }
            catch (Exception e)
            {
                throw new Exception("Invalid json", e);
            }

            JToken referenceNode;

            if (!jo.TryGetValue("reference_node", out referenceNode))
            {
                throw new NodeNotFoundException("Reference node not found");
            }

            var graphStore = new RestNodeStore(referenceNode.Value <string>());

            return(new Node(graphStore));
        }
Beispiel #4
0
        private Transitions GetTransitions(PoolElement poolElement)
        {
            Transitions transitions = new Transitions();

            transitions.Transition = new Transition[poolElement.Connections.Count];
            HashSet <Guid> guids = new HashSet <Guid>(poolElement.Elements.Select(item => item.Guid));

            for (int i = 0; i < poolElement.Connections.Count; i++)
            {
                ConnectionElement connectionElement = poolElement.Connections[i];
                bool containsFirst = guids.Contains(connectionElement.SourceElement.Guid);
                if (!containsFirst)
                {
                    _errorList.Add(string.Format("Cannot create transition. Pool does not contains source element: {0}", connectionElement.SourceElement.Guid));
                }
                bool containsSecond = guids.Contains(connectionElement.TargetElement.Guid);
                if (!containsSecond)
                {
                    _errorList.Add(string.Format("Cannot create transition. Pool does not contains target element: {0}", connectionElement.TargetElement.Guid));
                }
                if (containsSecond && containsFirst)
                {
                    Transition transition = new Transition();
                    transition.Id                     = connectionElement.GetId();
                    transition.From                   = connectionElement.SourceElement.GetId();
                    transition.To                     = connectionElement.TargetElement.GetId();
                    transitions.Transition[i]         = transition;
                    transition.ConnectorGraphicsInfos = CreateConnectorGraphicsInfos(connectionElement);
                }
            }
            return(transitions);
        }
Beispiel #5
0
        public Relationship CreateRelationship(ConnectionElement connection, Node startNode, Node endNode, string name, Properties properties)
        {
            var startFormat = IsBatchObject(startNode) ? "{{{0}}}/relationships" : "/node/{0}/relationships";
            var endFormat   = IsBatchObject(endNode) ? "{{{0}}}" : "/node/{0}";

            var body = new JObject
            {
                { "to", string.Format(endFormat, endNode.Id) },
                { "type", name }
            };

            if (properties != null)
            {
                body.Add("data", properties.ToJObject());
            }

            var index = _jobs.Count();

            _jobs.Add(new BatchJob
            {
                Method = HttpRest.Method.Post,
                To     = string.Format(startFormat, startNode.Id),
                Id     = index,
                Body   = body
            });

            _jobs[index].GraphObject = new BatchRelationshipStore(this).Initilize(null, index, properties);

            return((Relationship)_jobs[index].GraphObject);
        }
Beispiel #6
0
        public Relationship CreateUniqueRelationship(ConnectionElement connection, Node startNode, Node endNode, string name, Properties properties, string indexName, string key, object value, IndexUniqueness uniqueness)
        {
            var startFormat = IsBatchObject(endNode) ? "{{{0}}}" : "/node/{0}";
            var endFormat   = IsBatchObject(startNode) ? "{{{0}}}" : "/node/{0}";

            var body = new JObject
            {
                { "value", JToken.FromObject(value) },
                { "properties", properties.ToJObject() },
                { "key", key },
                { "start", string.Format(startFormat, startNode.Id) },
                { "end", string.Format(endFormat, endNode.Id) },
                { "type", name }
            };

            var index = _jobs.Count();

            _jobs.Add(new BatchJob
            {
                Method = HttpRest.Method.Post,
                To     = string.Format("/index/relationship/{0}?uniqueness={1}", indexName, uniqueness),
                Id     = index,
                Body   = body
            });

            _jobs[index].GraphObject = new BatchRelationshipStore(this).Initilize(null, index, null);

            return((Relationship)_jobs[index].GraphObject);
        }
Beispiel #7
0
 private void ReadTransitions(ProcessType processType)
 {
     if (processType.Transitions?.Transition == null)
     {
         return;
     }
     foreach (var transition in processType.Transitions.Transition)
     {
         var         from        = transition.From;
         var         to          = transition.To;
         PoolElement poolElement = null;
         var         guid        = Guid.Parse(processType.Id);
         if (_poolByProcessDictionary.TryGetValue(guid, out poolElement))
         {
             try
             {
                 IBaseElement      fromElement = _elements[Guid.Parse(from)];
                 IBaseElement      toElement   = _elements[Guid.Parse(to)];
                 ConnectionElement connection  = new ConnectionElement(fromElement, toElement);
                 connection.Guid = Guid.Parse(transition.Id);
                 List <Point> points = GetPoints(transition.ConnectorGraphicsInfos);
                 connection.Points = points;
                 poolElement.Connections.Add(connection);
             }
             catch (KeyNotFoundException ex)
             {
                 throw new BaseElementNotFoundException(ex);
             }
         }
     }
 }
 private RestRelationshipStore(ConnectionElement connection, long id, string relationshipJson = null)
 {
     DbUrl = connection.DbUrl;
     Id    = id;
     Self  = string.Concat(Connection.GetServiceRoot(DbUrl).Relationship, "/", Id);
     OriginalRelationshipJson = relationshipJson;
 }
Beispiel #9
0
        /// <summary>
        /// Get missing elements from the settings.
        /// </summary>
        public ConnectionElement GetMissingElements()
        {
            ConnectionElement result = ConnectionElement.None;

            if (string.IsNullOrEmpty(Host))
            {
                result |= ConnectionElement.Host;
            }
            if (Port == 0)
            {
                result |= ConnectionElement.Port;
            }
            if (string.IsNullOrEmpty(Username))
            {
                result |= ConnectionElement.Username;
            }
            if (string.IsNullOrEmpty(Password))
            {
                result |= ConnectionElement.Password;
            }
            if (Workstation == IrbisWorkstation.None)
            {
                result |= ConnectionElement.Workstation;
            }

            return(result);
        }
Beispiel #10
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (!this._dragging)
            {
                return;
            }
            this._dragging = false;
            AnchorElement tempTo;

            if (this._theSelected is AnchorElement element && (tempTo = element).IsDissociative)
            {
                // 检查是否有能够连接上的锚点
                foreach (NodeElement node in this._nodes)
                {
                    // 节点自身上的锚点不能相互连接
                    if (node == this._tempConnection.From.Owner)
                    {
                        continue;
                    }
                    AnchorElement candidate = node.AttachWith(tempTo);
                    if (candidate != null)
                    {
                        // 连接上了,则用候选锚点替换当前连接的tempTo锚点
                        // 释放当前tempTo锚点图像
                        // 将tempConnection加如到画布上上的连接集合
                        this._tempConnection.To = candidate;
                        this._connections.Add(this._tempConnection);
                    }
                }
            }
            // 无论如何都该释放掉临时连接
            this._tempConnection = null;
            this.Invalidate();
        }
 private RestNodeStore(ConnectionElement connection, long id, string nodeJson = null)
 {
     DbUrl            = connection.DbUrl;
     Id               = id;
     Self             = string.Concat(Connection.GetServiceRoot(DbUrl).Node, "/", Id);
     OriginalNodeJson = nodeJson;
 }
Beispiel #12
0
        /// <summary>
        /// adds/creates a connection element with the proper service name/product name and connection string
        /// </summary>
        /// <param name="dataAccessSettings"></param>
        /// <param name="productName"></param>
        /// <param name="serviceName"></param>
        /// <param name="connectionName"></param>
        private static void AddServiceToProduct(DataAccessSettings dataAccessSettings, string productName, string serviceName, string connectionName)
        {
            ConnectionElement connectionElement = null;

            if (dataAccessSettings != null)
            {
                int count = dataAccessSettings.Connections.Count;
                for (int i = 0; i < count; i++)
                {
                    if (dataAccessSettings.Connections[i].ProductName == productName)
                    {
                        connectionElement = dataAccessSettings.Connections[i];
                        connectionElement.ConnectionName = connectionName;
                        break;
                    }
                }
                if (connectionElement == null)
                {
                    connectionElement                = new ConnectionElement();
                    connectionElement.ProductName    = productName;
                    connectionElement.ServiceName    = serviceName;
                    connectionElement.ConnectionName = connectionName;
                    dataAccessSettings.Connections.Add(connectionElement);
                }
                else
                {
                    connectionElement.ServiceName = serviceName;
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// 对于文档中刚加入的元素,还没有加入它对应的连接。
        /// 此方法会添加这些连接。
        /// </summary>
        /// <param name="document"></param>
        private static void TryAddConnectionElements(AddToDocumentArgs args)
        {
            var document = args.Docment;

            var docTypeList = document.EntityTypes
                              .Select(et => args.AllTypes.First(e => e.FullName == et.FullName))
                              .ToArray();

            foreach (var type in docTypeList)
            {
                //添加继承连接线
                var baseType = type.BaseType;
                if (docTypeList.Contains(baseType))
                {
                    var connectionEl = new ConnectionElement(type.FullName, baseType.FullName);
                    connectionEl.ConnectionType = ConnectionType.Inheritance;
                    TryAddConnection(document, connectionEl);
                }

                //添加引用连接线
                foreach (var reference in type.References)
                {
                    switch (reference.ReferenceType)
                    {
                    case ReferenceType.Normal:
                        //如果被引用的实体也在被选择的列表中,则尝试生成相应的连接。
                        if (docTypeList.Contains(reference.RefEntityType))
                        {
                            var connectionEl = new ConnectionElement(type.FullName, reference.RefEntityType.FullName);
                            connectionEl.ConnectionType = reference.Nullable ? ConnectionType.NullableReference : ConnectionType.Reference;
                            connectionEl.Label          = reference.EntityProperty ?? reference.IdProperty;
                            TryAddConnection(document, connectionEl);
                        }
                        break;

                    //暂时忽略
                    //case ReferenceType.Parent:
                    //    break;
                    //case ReferenceType.Child:
                    //    break;
                    default:
                        break;
                    }
                }

                //添加组合连接线
                foreach (var child in type.Children)
                {
                    if (docTypeList.Contains(child.ChildEntityType))
                    {
                        var connectionEl = new ConnectionElement(child.ChildEntityType.FullName, type.FullName);
                        connectionEl.ConnectionType = ConnectionType.Composition;
                        connectionEl.Label          = child.Name;
                        TryAddConnection(document, connectionEl);
                    }
                }
            }
        }
        public bool RemoveFromIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value)
        {
            var status = Neo4jRestApi.RemoveRelationshipFromIndex(connection.DbUrl, relationship.Id, indexName, key, value);

            if (status != HttpStatusCode.NoContent)
            {
                throw new Exception(string.Format("Error remove relationship from index (relationship id:{0} index name:{1} key:{2} http response:{3})", relationship.Id, indexName, key, status));
            }

            return(true);
        }
        public bool RemoveFromIndex(ConnectionElement connection, Node node, string indexName, string key)
        {
            var status = Neo4jRestApi.RemoveNodeFromIndex(connection.DbUrl, node.Id, indexName, key);

            if (status != HttpStatusCode.NoContent)
            {
                throw new Exception(string.Format("Error remove node from index (node id:{0} index name:{1} key:{2} http response:{3})", node.Id, indexName, key, status));
            }

            return(true);
        }
        public HttpStatusCode DeleteRelationship(ConnectionElement connection)
        {
            var status = Neo4jRestApi.DeleteRelationship(connection.DbUrl, Id);

            if (status != HttpStatusCode.NoContent)
            {
                throw new Exception(string.Format("Error deleting relationship (relationship id:{0} http response:{1})", Id, status));
            }

            return(status);
        }
Beispiel #17
0
        private void HoveringMoving(MouseEventArgs e)
        {
            Point currentLocation = e.Location;

            Element.Element currentHovered = null;

            #region 节点Hover检查
            for (int idx = this._nodes.Count - 1; idx >= 0; idx--)
            {
                NodeElement node = this._nodes[idx];
                if (node.CaughtBy(currentLocation))
                {
                    currentHovered = node;
                    break;
                }
                else
                {
                    AnchorElement anchor = node.AnchorCaughtBy(currentLocation);
                    if (anchor != null)
                    {
                        currentHovered = anchor;
                        break;
                    }
                }
            }
            #endregion

            #region 连接Hover检查
            for (int idx = this._connections.Count - 1; idx >= 0; idx--)
            {
                ConnectionElement conn = this._connections[idx];
                if (conn.CaughtBy(currentLocation))
                {
                    currentHovered = conn;
                    break;
                }
            }
            #endregion

            #region 更新Hovered元素
            if (currentHovered != this._theHovered)
            {
                if (currentHovered != null)
                {
                    currentHovered.Hovered = true;
                }
                if (this._theHovered != null)
                {
                    this._theHovered.Hovered = false;
                }
                this._theHovered = currentHovered;
            }
            #endregion
        }
        public IEnumerable <Relationship> GetRelationship(ConnectionElement connection, string indexName, string searchQuery)
        {
            string response;
            var    status = Neo4jRestApi.GetRelationship(connection.DbUrl, indexName, searchQuery, out response);

            if (status != HttpStatusCode.OK)
            {
                throw new Exception(string.Format("Index not found in (index:{0})", indexName));
            }

            return(ParseRelationshipJson(response));
        }
        public Node CreateNode(ConnectionElement connection, Properties properties)
        {
            string response;
            var    status = Neo4jRestApi.CreateNode(connection.DbUrl, properties.ToString(), out response);

            if (status != HttpStatusCode.Created)
            {
                throw new Exception(string.Format("Error creating node (http response:{0})", status));
            }

            return(ParseNodeJson(response).First());
        }
        public Relationship CreateRelationship(ConnectionElement connection, Node startNode, Node endNode, string name, Properties properties)
        {
            string response;
            var    status = Neo4jRestApi.CreateRelationship(connection.DbUrl, startNode.Id, endNode.Id, name, properties.ToString(), out response);

            if (status != HttpStatusCode.Created)
            {
                throw new Exception(string.Format("Error creating relationship (http response:{0})", status));
            }

            return(ParseRelationshipJson(response).First());
        }
        public Node GetNode(ConnectionElement connection, long nodeId)
        {
            string response;
            var    status = Neo4jRestApi.GetNode(connection.DbUrl, nodeId, out response);

            if (status == HttpStatusCode.NotFound)
            {
                throw new NodeNotFoundException(string.Format("Node({0})", nodeId));
            }

            return(CreateNodeFromJson(response));
        }
        public Relationship GetRelationship(ConnectionElement connection, long relationshipId)
        {
            string response;
            var    status = Neo4jRestApi.GetRelationship(connection.DbUrl, relationshipId, out response);

            if (status == HttpStatusCode.NotFound)
            {
                throw new RelationshipNotFoundException(string.Format("Relationship({0})", relationshipId));
            }

            return(CreateRelationshipFromJson(response));
        }
Beispiel #23
0
        private static void TryAddConnection(ODMLDocument document, ConnectionElement connectionEl)
        {
            //目前,暂时不支持自关联的线。
            if (connectionEl.From == connectionEl.To)
            {
                return;
            }

            //要判断是否之前已经添加了这个连接,才继续添加连接。
            if (document.Connections.All(c => c.From != connectionEl.From || c.To != connectionEl.To || c.Label != connectionEl.Label))
            {
                document.Connections.Add(connectionEl);
            }
        }
Beispiel #24
0
        public static Node GetNode(long nodeId, INodeStore nodeStore = null, ConnectionElement connection = null)
        {
            if (nodeStore == null)
            {
                nodeStore = new RestNodeStore();
            }

            if (connection == null)
            {
                connection = DefaultConnection;
            }

            return(nodeStore.GetNode(connection, nodeId));
        }
Beispiel #25
0
        public Relationship GetRelationship(ConnectionElement connection, long relationshipId)
        {
            var index = _jobs.Count();

            _jobs.Add(new BatchJob
            {
                Method = HttpRest.Method.Get,
                To     = string.Concat("/relationship/", relationshipId),
                Id     = index
            });

            _jobs[index].GraphObject = new BatchRelationshipStore(this).Initilize(null, index, null);

            return((Relationship)_jobs[index].GraphObject);
        }
Beispiel #26
0
        public Node GetNode(ConnectionElement connection, long nodeId)
        {
            var index = _jobs.Count();

            _jobs.Add(new BatchJob
            {
                Method = HttpRest.Method.Get,
                To     = string.Concat("/node/", nodeId),
                Id     = index
            });

            _jobs[index].GraphObject = new BatchNodeStore(this).Initilize(null, index, null);

            return((Node)_jobs[index].GraphObject);
        }
Beispiel #27
0
        public Node CreateNode(ConnectionElement connection, Properties properties)
        {
            var index = _jobs.Count();

            _jobs.Add(new BatchJob
            {
                Method = HttpRest.Method.Post,
                To     = "/node",
                Body   = properties == null ? null : properties.ToJObject(),
                Id     = index
            });

            _jobs[index].GraphObject = new BatchNodeStore(this).Initilize(null, index, properties);

            return((Node)_jobs[index].GraphObject);
        }
        public IEnumerable <Node> GetNode(ConnectionElement connection, string indexName, string key, object value)
        {
            string response;
            var    status = Neo4jRestApi.GetNode(connection.DbUrl, indexName, key, value, out response);

            if (status == HttpStatusCode.OK)
            {
                return(ParseNodeJson(response));
            }

            if (status == HttpStatusCode.NotFound)
            {
                return(new List <Node>());
            }

            throw new Exception(string.Format("Index not found in (index:{0})", indexName));
        }
        public Relationship AddToIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value)
        {
            string response;
            var    status = Neo4jRestApi.AddRelationshipToIndex(connection.DbUrl, relationship.Id, indexName, key, value, out response);

            if (status == HttpStatusCode.Created || status == HttpStatusCode.OK)
            {
                return(ParseRelationshipJson(response).First());
            }

            //// Add a relationship to an index but mapping already exists
            //if (unique && status == HttpStatusCode.OK)
            //{
            //	return null;
            //}

            throw new Exception(string.Format("Error adding relationship to index (http response:{0})", status));
        }
        public Relationship CreateUniqueRelationship(ConnectionElement connection, Node startNode, Node endNode, string name, Properties properties, string indexName, string key, object value, IndexUniqueness uniqueness)
        {
            string response;
            var    status = Neo4jRestApi.CreateUniqueRelationship(connection.DbUrl, startNode.Id, endNode.Id, name, properties.ToString(), indexName, key, value, uniqueness, out response);

            if (status == HttpStatusCode.Created)
            {
                return(ParseRelationshipJson(response).First());
            }

            // Create unique relationship but index mapping already exists
            if (status == HttpStatusCode.OK)
            {
                return(null);
            }

            throw new Exception(string.Format("Error creating relationship (http response:{0})", status));
        }
Beispiel #31
0
        internal static ConnectionElementXml ConvertToNode(ConnectionElement model)
        {
            var xml = new ConnectionElementXml();

            xml.From = model.From;
            xml.To = model.To;
            xml.Label = model.Label;
            xml.ConnectionType = model.ConnectionType;
            xml.Hidden = model.Hidden;
            xml.LabelVisible = model.LabelVisible;

            if (model.FromPointPos.HasValue)
            {
                xml.FromPointX = model.FromPointPos.Value.X;
                xml.FromPointY = model.FromPointPos.Value.Y;
            }
            if (model.ToPointPos.HasValue)
            {
                xml.ToPointX = model.ToPointPos.Value.X;
                xml.ToPointY = model.ToPointPos.Value.Y;
            }

            return xml;
        }
Beispiel #32
0
        internal ConnectionElement Restore()
        {
            var model = new ConnectionElement(this.From, this.To);

            model.Label = this.Label;
            model.ConnectionType = this.ConnectionType;
            model.Hidden = this.Hidden;
            model.LabelVisible = this.LabelVisible;

            if (this.FromPointX.HasValue && this.FromPointY.HasValue)
            {
                model.FromPointPos = new Point(this.FromPointX.Value, this.FromPointY.Value);
            }
            if (this.ToPointX.HasValue && this.ToPointY.HasValue)
            {
                model.ToPointPos = new Point(this.ToPointX.Value, this.ToPointY.Value);
            }

            return model;
        }