Beispiel #1
0
        public override QueryResult Execute(IGraphDB myGraphDB, IGraphQL myGraphQL, GQLPluginManager myPluginManager, String myQuery, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            QueryResult result = new QueryResult(myQuery, SonesGQLConstants.GQL, 0L, ResultType.Failed);

            try
            {
                var stat = myGraphDB.Truncate(mySecurityToken, myTransactionToken, new RequestTruncate(_TypeName), (stats) => stats);

                result = new QueryResult(myQuery, SonesGQLConstants.GQL, Convert.ToUInt64(stat.ExecutionTime.Milliseconds), ResultType.Successful);
            }
            catch(ASonesException e)
            {
                result = new QueryResult(myQuery, SonesGQLConstants.GQL, 0, ResultType.Failed, null, e);
            }

            return result;
        }
Beispiel #2
0
        public override QueryResult Execute(IGraphDB myGraphDB, IGraphQL myGraphQL, GQLPluginManager myPluginManager, String myQuery, SecurityToken mySecurityToken, TransactionToken myTransactionToken)
        {
            QueryResult qresult = null;
            ASonesException error = null;

            try
            {
                var stat = myGraphDB.DropIndex(mySecurityToken, myTransactionToken, new RequestDropIndex(_TypeName, _IndexName, _IndexEdition), (stats) => stats);

                qresult = new QueryResult(myQuery, "sones.gql", Convert.ToUInt64(stat.ExecutionTime.Milliseconds), ResultType.Successful);
            }
            catch (ASonesException e)
            {
                error = e;
            }

            return new QueryResult(myQuery, "sones.gql", qresult.Duration, qresult.TypeOfResult, qresult.Vertices, error);
        }
Beispiel #3
0
        public string GenerateOutputResult(QueryResult myQueryResult, Dictionary<String, String> myParams)
        {
            var result = new SchemaToClassesGenerator.Result();

            result.Version = IOInterfaceCompatibility.MaxVersion.ToString();

            result.Query = new Query() { Duration = myQueryResult.Duration, ResultType = Enum.GetName(typeof(ResultType), myQueryResult.TypeOfResult), Language = myQueryResult.NameOfQuerylanguage, Value = myQueryResult.Query, VerticesCount = myQueryResult.Vertices.LongCount(), Error = myQueryResult.Error == null ? null : HandleQueryExceptions(myQueryResult) };

            List<SchemaToClassesGenerator.VertexView> vertices = new List<SchemaToClassesGenerator.VertexView>();

            foreach (var aVertex in myQueryResult)
            {
                vertices.Add(GenerateVertexView(aVertex));
            }

            result.VertexViews = vertices.ToArray();
            
            var stream = new MemoryStream();

            var writer = new System.Xml.Serialization.XmlSerializer(result.GetType());
            writer.Serialize(stream, result);

            return System.Text.Encoding.UTF8.GetString(stream.ToArray());
        }
Beispiel #4
0
        private QueryResult GenerateResult(double myElapsedTotalMilliseconds, QueryResult myResult, String myAction)
        {
            List<IVertexView> view = new List<IVertexView>();

            if (myResult != null)
            {
                foreach (var item in myResult.Vertices)
                {
                    var dict = new Dictionary<string, object>();

                    if (item.HasProperty("VertexID"))
                        dict.Add("VertexID", item.GetProperty<IComparable>("VertexID"));

                    if (item.HasProperty("VertexTypeID"))
                        dict.Add("VertexTypeID", item.GetProperty<IComparable>("VertexTypeID"));

                    dict.Add("Action", myAction);

                    view.Add(new VertexView(dict, null));
                }
            }

            return new QueryResult(_query, SonesGQLConstants.GQL, Convert.ToUInt64(myElapsedTotalMilliseconds),
                                   ResultType.Successful, view);
        }
Beispiel #5
0
        public override QueryResult Execute(IGraphDB myGraphDB, 
            IGraphQL myGraphQL,
            GQLPluginManager myPluginManager,
            String myQuery,
            SecurityToken mySecurityToken,
            Int64 myTransactionToken)
        {
            _queryString = myQuery;

            QueryResult result;

            try
            {
                result = myGraphDB.Insert<QueryResult>(
                        mySecurityToken,
                        myTransactionToken,
                        CreateRequest(myPluginManager,
                                        myGraphDB,
                                        mySecurityToken,
                                        myTransactionToken),
                        CreateQueryResult);
            }
            catch (ASonesException e)
            {
                result = new QueryResult(_queryString, SonesGQLConstants.GQL, 0, ResultType.Failed, null, e);
            }

            return result;
        }
        public override IQueryResult Execute(IGraphDB myGraphDB, IGraphQL myGraphQL, GQLPluginManager myPluginManager, String myQuery, SecurityToken mySecurityToken, Int64 myTransactionToken)
        {
            _query = myQuery;

            IQueryResult result;

            try
            {
                result = myGraphDB.CreateVertexTypes<IQueryResult>(
                        mySecurityToken,
                        myTransactionToken,
                        new RequestCreateVertexTypes(GenerateVertexTypePredefinitions()),
                        CreateQueryResult);
            }
            catch (ASonesException e)
            {
                result = new QueryResult(_query, SonesGQLConstants.GQL, 0, ResultType.Failed, null, e);
            }

            return result;
        }
Beispiel #7
0
        /// <summary>
        /// Handles query exceptions.
        /// </summary>
        /// <param name="queryresult">The query result.</param>
        /// <returns>The exception string.</returns>
        private String HandleQueryExceptions(QueryResult queryresult)
        {
            StringBuilder SB = new StringBuilder();

            SB.Append(queryresult.Error.ToString());
            if (queryresult.Error.InnerException != null)
                SB.Append(" InnerException: " + queryresult.Error.InnerException.Message);

            return SB.ToString();
        }
Beispiel #8
0
        /// <summary>
        /// generate node list needed for visual graph out of query result
        /// <param name="myQueryResult">The query result.</param>
        /// <param name="Nodes">out parameter returning list of nodes</param>
        /// </summary>
        private void GenerateNodeList(QueryResult myQueryResult, out List<string> Nodes)
        {
            Nodes = new List<string>();

            GenerateNodeList_AnalyzeVertices(myQueryResult, ref Nodes);
        }
Beispiel #9
0
        public string GenerateOutputResult(QueryResult myQueryResult, Dictionary<String, String> myParams)
        {
            StringBuilder Output = new StringBuilder();
            bool bShowEdgeNames = false;

            if (myParams.ContainsKey(_OptionStrings.ShowEdgeNames.name))
            {
                if (StringComparer.InvariantCultureIgnoreCase.Compare(myParams[_OptionStrings.ShowEdgeNames.name], _OptionStrings.ShowEdgeNames.show) == 0)
                {
                    bShowEdgeNames = true;
                }
                else if (StringComparer.InvariantCultureIgnoreCase.Compare(myParams[_OptionStrings.ShowEdgeNames.name], _OptionStrings.ShowEdgeNames.hide) == 0)
                {
                    bShowEdgeNames = false;
                }
            }

            if (myQueryResult.Error != null)
            {
                Output.Append(ConvertString2WebShellOut(HandleQueryExceptions(myQueryResult)));
                return Output.ToString();
            }

            List<string> Nodes;
            List<NodeLink> Links;
            GenerateVisGraph(myQueryResult, out Nodes, out Links);

            if (Nodes.Count == 0)
            {
                Output.Append(ConvertString2WebShellOut("Graph Visualisation Plugin:"));
                Output.Append(ConvertString2WebShellOut("Error: No vertex with property \"node\" found!"));
                Output.Append(ConvertString2WebShellOut("Please change your query string using \"as node\" for returned vertices"));
                Output.Append(ConvertString2WebShellOut("If you use WebShell and want to use another output format plugin,"));
                Output.Append(ConvertString2WebShellOut("enter e.g. format json for JSON output!"));
                return Output.ToString();
            }
            else
            {
                Output.AppendLine("var w = 960,");
                Output.AppendLine("h = 500;");
                Output.AppendLine("var vis = d3.select(\"#output\")");
                Output.AppendLine(".append(\"svg:svg\")");
                Output.AppendLine(".attr(\"width\", w)");
                Output.AppendLine(".attr(\"height\", h);");

                Output.AppendLine("var nodes = new Array();");
                Output.AppendLine("var links = new Array();");

                foreach (var Node in Nodes)
                {
                    Output.AppendLine("var node = new Object();");
                    Output.AppendLine("node.name=\"" + Node + "\";");
                    Output.AppendLine("nodes.push(node);");
                }

                foreach (var Link in Links)
                {
                    Output.AppendLine("var link = new Object();");
                    Output.AppendLine("link.source=" + Link.source + ";");
                    Output.AppendLine("link.target=" + Link.target + ";");
                    Output.AppendLine("link.name=\"" + Link.name + "\";");
                    Output.AppendLine("links.push(link);");
                }

                Output.AppendLine("var force = self.force = d3.layout.force()");
                Output.AppendLine(".nodes(nodes)");
                Output.AppendLine(".links(links)");
                Output.AppendLine(".gravity(.05)");
                Output.AppendLine(".distance(100)");
                Output.AppendLine(".charge(-100)");
                Output.AppendLine(".size([w, h])");
                Output.AppendLine(".start();");

                Output.AppendLine("var linkgroup = vis.selectAll(\"g.link\")");
                Output.AppendLine(".data(links)");
                Output.AppendLine(".enter().append(\"svg:g\");");

                Output.AppendLine("var link = linkgroup.append(\"svg:line\")");
                Output.AppendLine(".attr(\"class\", \"graphlink\");");

                if (bShowEdgeNames)
                {
                    Output.AppendLine("var linkname = linkgroup.append(\"svg:text\")");
                    Output.AppendLine(".attr(\"class\", \"graphlinktext\")");
                    Output.AppendLine(".text(function(d) { return d.name; });");
                }

                Output.AppendLine("var node = vis.selectAll(\"g.node\")");
                Output.AppendLine(".data(nodes)");
                Output.AppendLine(".enter().append(\"svg:g\")");
                Output.AppendLine(".attr(\"class\", \"node\")");
                Output.AppendLine(".call(force.drag);");

                Output.AppendLine("node.append(\"svg:image\")");
                Output.AppendLine(".attr(\"class\", \"circle\")");
                Output.AppendLine(".attr(\"xlink:href\", \"favicon.ico\")");
                Output.AppendLine(".attr(\"x\", \"-8px\")");
                Output.AppendLine(".attr(\"y\", \"-8px\")");
                Output.AppendLine(".attr(\"width\", \"16px\")");
                Output.AppendLine(".attr(\"height\", \"16px\");");

                Output.AppendLine("node.append(\"svg:text\")");
                Output.AppendLine(".attr(\"class\", \"nodetext\")");
                Output.AppendLine(".attr(\"dx\", 12)");
                Output.AppendLine(".attr(\"dy\", \".35em\")");
                Output.AppendLine(".text(function(d) { return d.name });");

                Output.AppendLine("force.on(\"tick\", function() {");
                Output.AppendLine("link.attr(\"x1\", function(d) { return d.source.x; })");
                Output.AppendLine(".attr(\"y1\", function(d) { return d.source.y; })");
                Output.AppendLine(".attr(\"x2\", function(d) { return d.target.x; })");
                Output.AppendLine(".attr(\"y2\", function(d) { return d.target.y; });");
                if (bShowEdgeNames)
                {
                    Output.AppendLine("linkname.attr(\"x\", function(d) { return (d.source.x + d.target.x) / 2; })");
                    Output.AppendLine(".attr(\"y\", function(d) { return (d.source.y + d.target.y) / 2; });");
                }
                Output.AppendLine("node.attr(\"transform\", function(d) { return \"translate(\" + d.x + \",\" + d.y + \")\"; });");
                Output.AppendLine("});");

                return Output.ToString();
            }
        }
Beispiel #10
0
        public string GenerateOutputResult(QueryResult myQueryResult)
        {
            // root element...
            var _Query = new JObject();
            // query --------------------------------
            _Query.Add(new JProperty("Query", myQueryResult.Query));
            // result -------------------------------
            _Query.Add(new JProperty("Result", myQueryResult.TypeOfResult.ToString()));
            // duration -----------------------------
            _Query.Add(new JProperty("Duration", new JArray(myQueryResult.Duration, "ms")));
            // warnings -----------------------------
            // currently not in 2.0
            //_Query.Add(new JProperty("warnings", new JArray(
            //    from _Warning in myQueryResult.Warnings
            //    select new JObject(
            //             new JProperty("code", _Warning.GetType().ToString()),
            //             new JProperty("description", _Warning.ToString())
            //           ))));
            // errors -------------------------------
            if (myQueryResult.Error != null)
            {
                _Query.Add(new JProperty("Errors", new JArray(
                             new JObject(
                             new JProperty("Code", myQueryResult.Error.GetType().ToString()),
                             new JProperty("Description", HandleQueryExceptions(myQueryResult))
                           ))));
            }
            // results ------------------------------
            JArray _resultsArray = new JArray();
            // fill the results array
            if (myQueryResult.Vertices != null)
            {
                foreach (IVertexView _vertex in myQueryResult.Vertices)
                {
                    _resultsArray.Add(GenerateVertexViewJSON(_vertex));
                }
            }
            // add the results to the query....
            _Query.Add(new JProperty("Results", _resultsArray));

            return _Query.ToString();
        }
Beispiel #11
0
        /// <summary>
        /// generate bar chart data dictionary out of query result by searching recursively
        /// </summary>
        /// <param name="myQueryResult">query result</param>
        /// <returns>dictionary containing bar chart data</returns>
        private Dictionary<String, object> GenerateBarChart(QueryResult myQueryResult)
        {
            Dictionary<String, object> barchart = new Dictionary<string, object>();

            foreach (var aVertex in myQueryResult)
            {
                AnalyzeProperties(aVertex.GetAllProperties(), ref barchart);
                AnalyzeEdges(aVertex.GetAllEdges(), ref barchart);
            }

            return barchart;
        }
Beispiel #12
0
        public string GenerateOutputResult(QueryResult myQueryResult, Dictionary<String, String> myParams)
        {
            StringBuilder Output = new StringBuilder();
            Dictionary<String, object> barchart;
            _eOrientation Orientation = _eOrientation.HORIZONTAL;

            if (myParams.ContainsKey(_OptionStrings.Orientation.name))
            {
                if (StringComparer.InvariantCultureIgnoreCase.Compare(myParams[_OptionStrings.Orientation.name], _OptionStrings.Orientation.vertical) == 0)
                {
                    Orientation = _eOrientation.VERTICAL;
                }
                else if (StringComparer.InvariantCultureIgnoreCase.Compare(myParams[_OptionStrings.Orientation.name], _OptionStrings.Orientation.horizontal) == 0)
                {
                    Orientation = _eOrientation.HORIZONTAL;
                }
            }

            if (myQueryResult.Error != null)
            {
                Output.Append(ConvertString2WebShellOut(HandleQueryExceptions(myQueryResult)));
                return Output.ToString();
            }

            barchart = GenerateBarChart(myQueryResult);

            if (barchart.Count == 0)
            {
                Output.Append(ConvertString2WebShellOut("BarChart Visualisation Plugin:"));
                Output.Append(ConvertString2WebShellOut("Error: No Properties with name x and y found!"));
                Output.Append(ConvertString2WebShellOut("Please change your query string using \"as x\" and \"as y\" for returned vertices"));
                Output.Append(ConvertString2WebShellOut("If you use WebShell and want to use another output format plugin,"));
                Output.Append(ConvertString2WebShellOut("enter e.g. format json for JSON output!"));
                return Output.ToString();
            }
            else
            {
                Output.Append("var data = new Array();");
                Output.Append("var names = new Array();");

                foreach (KeyValuePair<string, object> bar in barchart)
                {
                    Output.Append("data.push(" + bar.Value + ");");
                    Output.Append("names.push(\'" + bar.Key.ToString() + "\');");
                }

                switch (Orientation)
                {
                    case _eOrientation.HORIZONTAL:
                        {
                            Output.Append("var w = 430,");
                            Output.Append("h = data.length * 23,");
                            Output.Append("x = d3.scale.linear().domain([0, d3.max(data)]).range([0, w]),");
                            Output.Append("y = d3.scale.ordinal().domain(d3.range(data.length)).rangeBands([0, h], .2);");

                            Output.Append("var vis = d3.select(\"#output\")");
                            Output.Append(".append(\"svg:svg\")");
                            Output.Append(".attr(\"class\",\"twodbarchart\")");
                            Output.Append(".attr(\"width\", w + 200)");
                            Output.Append(".attr(\"height\", h + 20)");
                            Output.Append(".append(\"svg:g\")");
                            Output.Append(".attr(\"transform\", \"translate(20,0)\");");

                            Output.Append("var bars = vis.selectAll(\"g.bar\")");
                            Output.Append(".data(data)");
                            Output.Append(".enter().append(\"svg:g\")");
                            Output.Append(".attr(\"class\", \"bar\")");
                            Output.Append(".attr(\"transform\", function(d, i) { return \"translate(0,\" + y(i) + \")\"; })");
                            Output.Append(".attr(\"id\", function(d, i) { return \"bar\"+i; } );");

                            Output.Append("var rects = bars.append(\"svg:rect\")");
                            Output.Append(".attr(\"class\",\"twodbarchartunselected\")");
                            Output.Append(".attr(\"width\", x)");
                            Output.Append(".attr(\"height\", y.rangeBand());");

                            Output.Append("rects.append(\"svg:set\")");
                            Output.Append(".attr(\"attributeName\", \"class\")");
                            Output.Append(".attr(\"from\", \"twodbarchartunselected\")");
                            Output.Append(".attr(\"to\", \"twodbarchartselected\")");
                            Output.Append(".attr(\"begin\", \"mouseover\")");
                            Output.Append(".attr(\"end\", \"mouseout\");");

                            Output.Append("rects.append(\"svg:set\")");
                            Output.Append(".attr(\"attributeName\", \"class\")");
                            Output.Append(".attr(\"from\", \"twodbarchartunselected\")");
                            Output.Append(".attr(\"to\", \"twodbarchartselected\")");
                            Output.Append(".attr(\"begin\", function(d, i) { return \"val\"+i+\".mouseover\"; } )");
                            Output.Append(".attr(\"end\", function(d, i) { return \"val\"+i+\".mouseout\"; } );");

                            Output.Append("bars.append(\"svg:text\")");
                            Output.Append(".attr(\"x\", x)");
                            Output.Append(".attr(\"y\", y.rangeBand() / 2)");
                            Output.Append(".attr(\"id\", function(d, i) { return \"val\"+i; } )");
                            Output.Append(".attr(\"dx\", -6)");
                            Output.Append(".attr(\"dy\", \".35em\")");
                            Output.Append(".attr(\"fill\", \"white\")");
                            Output.Append(".attr(\"text-anchor\", \"end\")");
                            Output.Append(".text(x.tickFormat(100));");

                            Output.Append("var texts = bars.append(\"svg:text\")");
                            Output.Append(".attr(\"class\",\"twodbarcharttextunselected\")");
                            Output.Append(".attr(\"x\", x)");
                            Output.Append(".attr(\"y\", y.rangeBand() / 2)");
                            Output.Append(".attr(\"dx\", 2)");
                            Output.Append(".attr(\"dy\", \".35em\")");
                            Output.Append(".attr(\"text-anchor\", \"start\")");
                            Output.Append(".text(function(d, i) { return names[i]; });");

                            Output.Append("texts.append(\"svg:set\")");
                            Output.Append(".attr(\"attributeName\", \"class\")");
                            Output.Append(".attr(\"from\", \"twodbarcharttextunselected\")");
                            Output.Append(".attr(\"to\", \"twodbarcharttextselected\")");
                            Output.Append(".attr(\"begin\", function(d, i) { return \"val\"+i+\".mouseover\"; } )");
                            Output.Append(".attr(\"end\", function(d, i) { return \"val\"+i+\".mouseout\"; } );");

                            Output.Append("texts.append(\"svg:set\")");
                            Output.Append(".attr(\"attributeName\", \"class\")");
                            Output.Append(".attr(\"from\", \"twodbarcharttextunselected\")");
                            Output.Append(".attr(\"to\", \"twodbarcharttextselected\")");
                            Output.Append(".attr(\"begin\", function(d, i) { return \"bar\"+i+\".mouseover\"; } )");
                            Output.Append(".attr(\"end\", function(d, i) { return \"bar\"+i+\".mouseout\"; } );");

                            Output.Append("var rules = vis.selectAll(\"g.rule\")");
                            Output.Append(".data(x.ticks(10))");
                            Output.Append(".enter().append(\"svg:g\")");
                            Output.Append(".attr(\"class\", \"rule\")");
                            Output.Append(".attr(\"transform\", function(d) { return \"translate(\" + x(d) + \",0)\"; })");
                            Output.Append(".attr(\"id\", function(d, i) { return \"bar\"+i; } );");

                            Output.Append("rules.append(\"svg:line\")");
                            Output.Append(".attr(\"y1\", h)");
                            Output.Append(".attr(\"y2\", h + 6)");
                            Output.Append(".attr(\"stroke\", \"black\");");

                            Output.Append("rules.append(\"svg:line\")");
                            Output.Append(".attr(\"y1\", 0)");
                            Output.Append(".attr(\"y2\", h)");
                            Output.Append(".attr(\"stroke\", \"white\")");
                            Output.Append(".attr(\"stroke-opacity\", .3);");

                            Output.Append("rules.append(\"svg:text\")");
                            Output.Append(".attr(\"y\", h + 9)");
                            Output.Append(".attr(\"dy\", \".71em\")");
                            Output.Append(".attr(\"text-anchor\", \"middle\")");
                            Output.Append(".text(x.tickFormat(10));");

                            Output.Append("vis.append(\"svg:line\")");
                            Output.Append(".attr(\"y1\", 0)");
                            Output.Append(".attr(\"y2\", h)");
                            Output.Append(".attr(\"stroke\", \"black\");");
                            break;
                        }
                    case _eOrientation.VERTICAL:
                        {
                            Output.Append("var h = 450;");
                            Output.Append("var th = 180;");
                            Output.Append("var bh = h-th;");
                            Output.Append("w = data.length * 23,");
                            Output.Append("y = d3.scale.linear().domain([0, d3.max(data)]).range([0, bh]),");
                            Output.Append("x = d3.scale.ordinal().domain(d3.range(data.length)).rangeBands([0, w], .2);");

                            Output.Append("var vis = d3.select(\"#output\")");
                            Output.Append(".append(\"svg:svg\")");
                            Output.Append(".attr(\"class\",\"twodbarchart\")");

                            Output.Append(".attr(\"height\", h + 20)");
                            Output.Append(".attr(\"width\", w + 200)");
                            Output.Append(".append(\"svg:g\")");
                            Output.Append(".attr(\"transform\", \"translate(20,0)\");");

                            Output.Append("var bars = vis.selectAll(\"g.bar\")");
                            Output.Append(".data(data)");
                            Output.Append(".enter().append(\"svg:g\")");
                            Output.Append(".attr(\"class\", \"bar\")");
                            Output.Append(".attr(\"transform\", function(d, i) { var dy = h - y(d); var dx = x(i) + 10; return \"translate(\" + dx + \", \" + dy + \")\"; });");

                            Output.Append("var rects = bars.append(\"svg:rect\")");
                            Output.Append(".attr(\"class\",\"twodbarchartunselected\")");
                            Output.Append(".attr(\"width\", x.rangeBand())");
                            Output.Append(".attr(\"height\", y)");
                            Output.Append(".attr(\"id\", function(d, i) { return \"bar\"+i; } );");

                            Output.Append("rects.append(\"svg:set\")");
                            Output.Append(".attr(\"attributeName\", \"class\")");
                            Output.Append(".attr(\"from\", \"twodbarchartunselected\")");
                            Output.Append(".attr(\"to\", \"twodbarchartselected\")");
                            Output.Append(".attr(\"begin\", \"mouseover\")");
                            Output.Append(".attr(\"end\", \"mouseout\");");

                            Output.Append("rects.append(\"svg:set\")");
                            Output.Append(".attr(\"attributeName\", \"class\")");
                            Output.Append(".attr(\"from\", \"twodbarchartunselected\")");
                            Output.Append(".attr(\"to\", \"twodbarchartselected\")");
                            Output.Append(".attr(\"begin\", function(d, i) { return \"val\"+i+\".mouseover\"; } )");
                            Output.Append(".attr(\"end\", function(d, i) { return \"val\"+i+\".mouseout\"; } );");

                            Output.Append("bars.append(\"svg:text\")");
                            Output.Append(".attr(\"x\", x.rangeBand() / 2)");
                            Output.Append(".attr(\"y\", -5)");
                            Output.Append(".attr(\"id\", function(d, i) { return \"val\"+i; } )");
                            Output.Append(".attr(\"fill\", \"white\")");
                            Output.Append(".attr(\"text-anchor\", \"start\")");
                            Output.Append(".attr(\"transform\", \"rotate(90)\")");
                            Output.Append(".text(y.tickFormat(100));");

                            Output.Append("var texts = bars.append(\"svg:text\")");
                            Output.Append(".attr(\"class\",\"twodbarcharttextunselected\")");
                            Output.Append(".attr(\"x\", 10 + x.rangeBand() / 2)");
                            Output.Append(".attr(\"y\", 0)");
                            Output.Append(".attr(\"dx\", 2)");
                            Output.Append(".attr(\"dy\", -5)");
                            Output.Append(".attr(\"text-anchor\", \"end\")");
                            Output.Append(".attr(\"transform\", \"rotate(90) translate(-23)\")");
                            Output.Append(".text(function(d, i) { return names[i]; });");

                            Output.Append("texts.append(\"svg:set\")");
                            Output.Append(".attr(\"attributeName\", \"class\")");
                            Output.Append(".attr(\"from\", \"twodbarcharttextunselected\")");
                            Output.Append(".attr(\"to\", \"twodbarcharttextselected\")");
                            Output.Append(".attr(\"begin\", function(d, i) { return \"val\"+i+\".mouseover\"; } )");
                            Output.Append(".attr(\"end\", function(d, i) { return \"val\"+i+\".mouseout\"; } );");

                            Output.Append("texts.append(\"svg:set\")");
                            Output.Append(".attr(\"attributeName\", \"class\")");
                            Output.Append(".attr(\"from\", \"twodbarcharttextunselected\")");
                            Output.Append(".attr(\"to\", \"twodbarcharttextselected\")");
                            Output.Append(".attr(\"begin\", function(d, i) { return \"bar\"+i+\".mouseover\"; } )");
                            Output.Append(".attr(\"end\", function(d, i) { return \"bar\"+i+\".mouseout\"; } );");

                            Output.Append("var rules = vis.append(\"g.rule\")");
                            Output.Append(".data(y.ticks(10))");
                            Output.Append(".enter().append(\"svg:g\")");
                            Output.Append(".attr(\"class\", \"rule\")");
                            Output.Append(".attr(\"transform\", function(d) { var dy = bh - y(d); return \"translate(0,\" + dy + \")\"; });");

                            Output.Append("rules.append(\"svg:line\")");
                            Output.Append(".attr(\"x1\", w + 10)");
                            Output.Append(".attr(\"x2\", w + 16)");
                            Output.Append(".attr(\"y1\", th)");
                            Output.Append(".attr(\"y2\", th)");
                            Output.Append(".attr(\"stroke\", \"black\");");

                            Output.Append("rules.append(\"svg:line\")");
                            Output.Append(".attr(\"x1\", 0)");
                            Output.Append(".attr(\"x2\", w+20)");
                            Output.Append(".attr(\"y1\", th)");
                            Output.Append(".attr(\"y2\", th)");
                            Output.Append(".attr(\"stroke\", \"white\")");
                            Output.Append(".attr(\"stroke-opacity\", .3);");

                            Output.Append("rules.append(\"svg:text\")");
                            Output.Append(".attr(\"y\", th - 3)");
                            Output.Append(".attr(\"x\", w + 18)");
                            Output.Append(".attr(\"text-anchor\", \"right\")");
                            Output.Append(".text(y.tickFormat(10));");

                            Output.Append("vis.append(\"svg:line\")");
                            Output.Append(".attr(\"y1\", h)");
                            Output.Append(".attr(\"y2\", h)");
                            Output.Append(".attr(\"x1\", 15)");
                            Output.Append(".attr(\"x2\", w + 6)");
                            Output.Append(".attr(\"stroke\", \"black\");");
                            break;
                        }
                    default: throw new NotImplementedException();
                }
            }

            return Output.ToString();
        }
Beispiel #13
0
        public StringBuilder HTMLBuilder(QueryResult myQueryResult, StringBuilder Input)
        {
            var _StringBuilder = new StringBuilder();

            _StringBuilder.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            _StringBuilder.AppendLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
            _StringBuilder.AppendLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
            _StringBuilder.AppendLine("<head>");
            _StringBuilder.AppendLine("<title>sones GraphDS</title>");
            _StringBuilder.AppendLine("<link rel=\"stylesheet\" type=\"text/css\" href=\"/resources/WebShell/WebShell.css\" />");
            _StringBuilder.AppendLine("</head>");
            _StringBuilder.AppendLine("<body>");
            _StringBuilder.AppendLine("<h1>sones GraphDS</h1>");
            _StringBuilder.Append("<h2>").Append(EscapeForXMLandHTML(myQueryResult.Query)).AppendLine("</h2>");
            _StringBuilder.AppendLine("<table>");
            _StringBuilder.AppendLine("<tr>");
            _StringBuilder.AppendLine("<td style=\"width: 100px\">&nbsp;</td>");
            _StringBuilder.AppendLine("<td>");

            // paste in the previous StringBuilder Input
            _StringBuilder.AppendLine(Input.ToString());

            _StringBuilder.AppendLine("</td>");
            _StringBuilder.AppendLine("</tr>");
            _StringBuilder.AppendLine("</table>");
            _StringBuilder.AppendLine("</body>").AppendLine("</html>").AppendLine();

            return _StringBuilder;
        }
Beispiel #14
0
        public string GenerateOutputResult(QueryResult myQueryResult, Dictionary<String, String> myParams)
        {
            StringBuilder Output = new StringBuilder();

            Output.Append("<table class=\"gql_table\" border=\"1\"> <!-- MainTable -->");
            Output.Append("<tr><td style=\"width:250px\">query</td><td style=\"width:400px\">").Append(EscapeForXMLandHTML(myQueryResult.Query)).Append("</td></tr>");
            Output.Append("<tr><td style=\"width:250px\">result</td><td style=\"width:400px\">").Append(EscapeForXMLandHTML(myQueryResult.TypeOfResult.ToString())).Append("</td></tr>");
            Output.Append("<tr><td style=\"width:250px\">duration</td><td style=\"width:400px\">").Append(myQueryResult.Duration).Append(" ms</td></tr>");

            if (myQueryResult.Error != null)
            {
                Output.Append("<tr><td style=\"width:250px\">error</td><td style=\"width:400px\">").Append(EscapeForXMLandHTML(myQueryResult.Error.GetType().ToString()+" - "+HandleQueryExceptions(myQueryResult))).Append("</td></tr>");
            }

            if (myQueryResult.Vertices != null)
            {
                Output.Append("<table class=\"gql_table\" border=\"1\"> <!-- Vertices -->");
                Output.Append("<tr><td style=\"width:250px\">result</td><td style=\"width:400px\">");

                foreach (IVertexView _vertex in myQueryResult.Vertices)
                {
                    Output.Append("<table class=\"gql_table\" border=\"1\"> <!-- Vertices-2 -->");
                    Output.Append(GenerateVertexViewHTML(_vertex));
                    Output.Append("</table> <!-- Vertices-2 -->");
                }

                Output.Append("</td></tr>");
                Output.Append("</table> <!-- Vertices -->");
            }

            Output.Append("</table>  <!-- MainTable -->");
            return HTMLBuilder(myQueryResult,Output).ToString();
        }
Beispiel #15
0
        public QueryResult Query(SecurityToken mySecurityToken, 
            Int64 myTransactionToken,
            string myQueryString)
        {
            //tree-like representation of the query-string
            ParseTree aTree;
            //executeable statement
            AStatement statement;
            QueryResult queryResult = new QueryResult(myQueryString,
                                                        SonesGQLConstants.GQL,
                                                        0L,
                                                        ResultType.Failed);

            #region Input exceptions - null or empty query

            if (myQueryString == null)
            {
                #region create error object

                queryResult.Error = new GqlSyntaxException("Error! Query was null!");

                return queryResult;

                #endregion
            }

            if (myQueryString.Length.Equals(0))
            {
                queryResult.Error = new GqlSyntaxException("Error! Query was empty!");

                return queryResult;
            }

            #endregion

            #region Parse query

            lock (_parser)
            {
                aTree = this._parser.Parse(myQueryString);
            }

            #endregion

            #region error handling

            if (aTree == null)
            {
                queryResult.Error = new GqlSyntaxException("Error! Query could not be parsed!");

                return queryResult;
            }

            if (aTree.HasErrors())
            {
                var error = aTree.ParserMessages.First();

                queryResult.Error = new GQLParsingException(error, myQueryString);

                return queryResult;
            }

            #endregion

            #region Execution

            //get the statement from the tree
            statement = (AStatement)aTree.Root.AstNode;

            try
            {
                queryResult = statement.Execute(_IGraphDBInstance,
                                                this,
                                                _GQLPluginManager,
                                                myQueryString,
                                                mySecurityToken,
                                                myTransactionToken);
            }
            catch (ASonesException ee)
            {
                queryResult.Error = ee;
                return queryResult;
            }
            catch (Exception e)
            {
                queryResult.Error = new UnknownException(e);
                return queryResult;
            }

            #endregion

            return queryResult;
        }
Beispiel #16
0
        public void GenerateResultOutput(QueryResult myResult)
        {
            var _ContentType = HttpServer.GetBestMatchingAcceptHeader(GraphDSREST_Constants._HTML, GraphDSREST_Constants._JSON, GraphDSREST_Constants._XML, GraphDSREST_Constants._GEXF, GraphDSREST_Constants._TEXT);

            IOInterface plugin = null;

            if (_Plugins.TryGetValue(_ContentType.MediaType, out plugin))
            {
                var content = plugin.GenerateOutputResult(myResult);
                ExportContent(_ServerID, System.Text.Encoding.UTF8.GetBytes(content), plugin.ContentType);
            }
            else
            {
                _ErrorMsg.Error406_NotAcceptable(String.Format("The server does not support the requested content type {0} ", _ContentType.ToString()));

            }
        }
Beispiel #17
0
        public string GenerateOutputResult(QueryResult myQueryResult)
        {
            StringBuilder Output = new StringBuilder();
            Output.AppendLine("Query:\t\t"+myQueryResult.Query);
            Output.AppendLine("Result:\t\t"+myQueryResult.TypeOfResult.ToString());
            Output.AppendLine("Duration:\t"+myQueryResult.Duration+" ms");

            if (myQueryResult.Error != null)
            {
                Output.AppendLine("Error: \t\t"+myQueryResult.Error.GetType().ToString() + " - " + HandleQueryExceptions(myQueryResult));
            }

            if (myQueryResult.Vertices != null)
            {
                Output.AppendLine("Vertices:");

                foreach (IVertexView _vertex in myQueryResult.Vertices)
                {
                    Output.Append(GenerateVertexViewText("\t\t",_vertex));
                }
            }

            return Output.ToString();
        }
Beispiel #18
0
        private QueryResult ExecuteAsParallel(IEnumerable<String> myLines, IGraphQL myIGraphQL, SecurityToken mySecurityToken, TransactionToken myTransactionToken, VerbosityTypes myVerbosityType, UInt32 myParallelTasks = 1U, IEnumerable<String> comments = null)
        {
            #region data
            QueryResult queryResult = new QueryResult(myLines.ToString(), ImportFormat, 0L, ResultType.Successful);
            Int64 numberOfLine = 0;
            var query = String.Empty;
            var aggregatedResults = new List<IEnumerable<IVertexView>>();
            Stopwatch StopWatchLine = new Stopwatch();
            Stopwatch StopWatchLines = new Stopwatch();
            #endregion

            #region Create parallel options

            var parallelOptions = new ParallelOptions()
            {
                MaxDegreeOfParallelism = (int)myParallelTasks
            };

            #endregion

            #region check lines and execute query

            StopWatchLines.Start();

            Parallel.ForEach(myLines, parallelOptions, (line, state) =>
            {

                if (!IsComment(line, comments))
                {

                    Interlocked.Add(ref numberOfLine, 1L);

                    if (!IsComment(line, comments)) // Skip comments
                    {

                        var qresult = ExecuteQuery(line, myIGraphQL, mySecurityToken, myTransactionToken);

                        #region VerbosityTypes.Full: Add result

                        if (myVerbosityType == VerbosityTypes.Full)
                        {
                            lock (aggregatedResults)
                            {
                                aggregatedResults.Add(qresult.Vertices);
                            }
                        }

                        #endregion

                        #region !VerbosityTypes.Silent: Add errors and break execution

                        if (qresult.TypeOfResult != ResultType.Successful && myVerbosityType != VerbosityTypes.Silent)
                        {
                            queryResult = new QueryResult(line, ImportFormat, Convert.ToUInt64(StopWatchLine.ElapsedMilliseconds), ResultType.Failed, qresult.Vertices, qresult.Error);

                            state.Break();
                        }

                        #endregion

                    }

                }

            });

            StopWatchLines.Stop();

            #endregion

            //add the results of each query into the queryResult
            if (queryResult != null)
                queryResult = new QueryResult(myLines.ToString(), ImportFormat, Convert.ToUInt64(StopWatchLines.ElapsedMilliseconds), queryResult.TypeOfResult, AggregateListOfListOfVertices(aggregatedResults), queryResult.Error);
            else
                queryResult = new QueryResult(myLines.ToString(), ImportFormat, Convert.ToUInt64(StopWatchLines.ElapsedMilliseconds), ResultType.Successful, AggregateListOfListOfVertices(aggregatedResults));

            return queryResult;
        }
Beispiel #19
0
        /// <summary>
        /// generate link list needed for visual graph out of query result
        /// <param name="myQueryResult">The query result.</param>
        /// <param name="Links">out parameter returning list of NodeLink classes</param>
        /// </summary>
        private void GenerateLinkList(QueryResult myQueryResult, List<string> Nodes, out List<NodeLink> Links)
        {
            Links = new List<NodeLink>();

            if (Nodes.Count() <= 0) return;

            GenerateLinkList_AnalyzeVertices(myQueryResult, Nodes, ref Links);
        }
Beispiel #20
0
        private QueryResult ExecuteAsSingleThread(IEnumerable<String> myLines, IGraphQL myIGraphQL, SecurityToken mySecurityToken, TransactionToken myTransactionToken, VerbosityTypes myVerbosityType, IEnumerable<String> comments = null)
        {
            #region data

            QueryResult queryResult = null;
            Int64 numberOfLine = 0;
            var aggregatedResults = new List<IEnumerable<IVertexView>>();
            Stopwatch StopWatchLines = new Stopwatch();

            #endregion

            #region check lines and execute query

            StopWatchLines.Reset();
            StopWatchLines.Start();

            foreach (var _Line in myLines)
            {
                numberOfLine++;

                if (String.IsNullOrWhiteSpace(_Line))
                {
                    continue;
                }

                #region Skip comments

                if (IsComment(_Line, comments))
                    continue;

                #endregion

                #region execute query

                var tempResult = myIGraphQL.Query(mySecurityToken, myTransactionToken, _Line);

                #endregion

                #region Add errors and break execution

                if (tempResult.TypeOfResult == ResultType.Failed)
                {
                    if (tempResult.Error.Message.Equals("Mal-formed  string literal - cannot find termination symbol."))
                        Debug.WriteLine("Query at line [" + numberOfLine + "] [" + _Line + "] failed with " + tempResult.Error.ToString() + " add next line...");

                    if (myVerbosityType == VerbosityTypes.Errors)
                    {
                        queryResult = new QueryResult(_Line, ImportFormat, 0L, ResultType.Failed, tempResult.Vertices, tempResult.Error);

                        break;
                    }
                }

                aggregatedResults.Add(tempResult.Vertices);

                #endregion
            }

            StopWatchLines.Stop();

            #endregion

            //add the results of each query into the queryResult
            if(queryResult != null)
                queryResult = new QueryResult(myLines.ToString(), ImportFormat, Convert.ToUInt64(StopWatchLines.ElapsedMilliseconds), queryResult.TypeOfResult, AggregateListOfListOfVertices(aggregatedResults), queryResult.Error);
            else
                queryResult = new QueryResult(myLines.ToString(), ImportFormat, Convert.ToUInt64(StopWatchLines.ElapsedMilliseconds), ResultType.Successful, AggregateListOfListOfVertices(aggregatedResults));

            return queryResult;
        }
Beispiel #21
0
 /// <summary>
 /// generates information needed for visual graph out of query result
 /// <param name="myQueryResult">The query result.</param>
 /// <param name="Nodes">out parameter returning list of nodes</param>
 /// <param name="Links">out parameter returning list of NodeLink classes</param>
 /// </summary>
 private void GenerateVisGraph(QueryResult myQueryResult, out List<string> Nodes, out List<NodeLink> Links)
 {
     GenerateNodeList(myQueryResult, out Nodes);
     GenerateLinkList(myQueryResult, Nodes, out Links);
 }
Beispiel #22
0
        public QueryResult Import(String myLocation, IGraphDB myGraphDB, IGraphQL myGraphQL, SecurityToken mySecurityToken, TransactionToken myTransactionToken, UInt32 myParallelTasks = 1U, IEnumerable<string> myComments = null, UInt64? myOffset = null, UInt64? myLimit = null, VerbosityTypes myVerbosityType = VerbosityTypes.Silent)
        {
            ASonesException error;
            Stream stream = null;
            QueryResult result;

            #region Read querie lines from location

            try
            {
                #region file
                if (myLocation.ToLower().StartsWith(@"file:\\"))
                {
                    //lines = ReadFile(location.Substring(@"file:\\".Length));
                    stream = GetStreamFromFile(myLocation.Substring(@"file:\\".Length));
                }
                #endregion
                #region http
                else if (myLocation.ToLower().StartsWith("http://"))
                {
                    stream = GetStreamFromHttp(myLocation);
                }
                #endregion
                else
                {
                    error = new InvalidImportLocationException(myLocation, @"file:\\", "http://");
                    result = new QueryResult("", ImportFormat, 0L, ResultType.Failed, null, error);
                    return result;
                }

                #region Start import using the AGraphDBImport implementation and return the result

                return Import(stream, myGraphDB, myGraphQL, mySecurityToken, myTransactionToken, myParallelTasks, myComments, myOffset, myLimit, myVerbosityType);

                #endregion
            }
            catch (Exception ex)
            {
                #region throw new exception
                error = new ImportFailedException(ex);
                result = new QueryResult("", ImportFormat, 0L, ResultType.Failed, null, error);
                return result;
                #endregion
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }

            #endregion
        }
Beispiel #23
0
        /// <summary>
        /// This private method analyses the QueryResult, shows the ResultType and Errors if existing.
        /// </summary>
        /// <param name="myQueryResult">The result of a query.</param>
        private bool CheckResult(QueryResult myQueryResult)
        {
            if (myQueryResult.Error != null)
            {
                if (myQueryResult.Error.InnerException != null)
                    Console.WriteLine(myQueryResult.Error.InnerException.Message);
                else
                    Console.WriteLine(myQueryResult.Error.Message);

                return false;
            }
            else
            {
                Console.WriteLine("Query " + myQueryResult.TypeOfResult);

                return true;
            }
        }
Beispiel #24
0
        public void GenerateResultOutput(QueryResult myResult, Dictionary<String, String> myParams)
        {
            List<ContentType> Types = new List<ContentType>();

            foreach (IOInterface _io_plugin in _Plugins.Values)
            {
                Types.Add(_io_plugin.ContentType);
            }

            var _ContentType = HttpServer.GetBestMatchingAcceptHeader(Types.ToArray());

            IOInterface plugin = null;

            if (_Plugins.TryGetValue(_ContentType.MediaType, out plugin))
            {
                var content = plugin.GenerateOutputResult(myResult, myParams);
                ExportContent(_ServerID, System.Text.Encoding.UTF8.GetBytes(content), plugin.ContentType);
            }
            else
            {
                _ErrorMsg.Error406_NotAcceptable(String.Format("The server does not support the requested content type {0} ", _ContentType.ToString()));

            }
        }