Exemplo n.º 1
0
 public CredentialDependency(RequestNode from, RequestNode to, CredentialType credentialType, long value)
 {
     From           = from;
     To             = to;
     CredentialType = credentialType;
     Value          = value;
 }
 protected virtual bool Visit <T>(RequestNode <T> node)
 {
     IncreaseDepth();
     Visit(node.Output);
     DecreaseDepth();
     return(true);
 }
Exemplo n.º 3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject joe  = JObject.Load(reader);
            var     type = joe["type"].Value <string>();

            Node node;

            if (type == "request")
            {
                node = new RequestNode();
            }
            else if (type == "pack")
            {
                node = new PackNode();
            }
            else if (type == "script")
            {
                node = new ScriptNode();
            }
            else
            {
                throw new ZealotException("Could not deserialize node, unknown type");
            }
            serializer.Populate(joe.CreateReader(), node);
            return(node);
        }
Exemplo n.º 4
0
        static RemoveActivation AddActivation(RoutingEngineConfigurator configurator,
                                              Activation <Request <T> > consumerNode)
        {
            var messageActivation = new RequestNode <T>(consumerNode);

            return(configurator.Add(messageActivation));
        }
Exemplo n.º 5
0
        protected override bool Visit <T>(RequestNode <T> node)
        {
            _current = GetVertex(node.GetHashCode(), () => "P", typeof(RequestNode <>), typeof(T));

            LinkFromParent();

            return(WithVertex(() => base.Visit(node)));
        }
Exemplo n.º 6
0
        private void CreateTree()
        {
            RequestTree = new ObservableCollection <RequestNode>();

            RequestNode node = new RequestNode(typeof(LocationRequestPart), new RequestBuilder(BaseAddress).Locations as RequestPart);

            node.Name = "Locations";
            RequestTree.Add(node);

            node      = new RequestNode(typeof(DirectionsRequestPart), new RequestBuilder(BaseAddress).Directions);
            node.Name = "Directions";
            RequestTree.Add(node);

            //node = new RequestNode(typeof(AdminRequestPart), new RequestBuilder(BaseAddress).Admin);
            //RequestTree.Add(node);
        }
Exemplo n.º 7
0
        public static async Task <RequestGraph> ToRequestGraphAsync(OperationGraph graph, IReadOnlyList <string> sources)
        {
            var maxSourceIndex = graph.Nodes.Max(x => x.Operation.SourceIndex);

            if (maxSourceIndex >= sources.Count)
            {
                throw new ArgumentException($"The max source index in the operation graph is {maxSourceIndex} so at least {maxSourceIndex + 1} sources are required.");
            }

            var operationToRequest = await RequestBuilder.BuildAsync(sources, graph.Nodes.Select(x => x.Operation));

            // Initialize all of the request nodes.
            var requestNodes = new List <RequestNode>();
            var operationNodeToRequestNode = new Dictionary <OperationNode, RequestNode>();

            foreach (var operationNode in graph.Nodes)
            {
                var requestNode = new RequestNode(
                    operationNode.HitIndex,
                    operationToRequest[operationNode.Operation]);

                requestNodes.Add(requestNode);
                operationNodeToRequestNode.Add(operationNode, requestNode);
            }

            // Initialize dependencies.
            foreach (var operationNode in graph.Nodes)
            {
                var requestNode = operationNodeToRequestNode[operationNode];
                foreach (var dependency in operationNode.Dependencies)
                {
                    requestNode.Dependencies.Add(operationNodeToRequestNode[dependency]);
                }
            }

            return(new RequestGraph(requestNodes, sources.ToList()));
        }
Exemplo n.º 8
0
        private void tpForm_Load(object sender, EventArgs e)
        {
            var logCfg = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config");

            XmlConfigurator.ConfigureAndWatch(logCfg);
            var logger = LogManager.GetLogger(typeof(Program));

            try
            {
                using (var db = new dbproductmainEntities())
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(" With Data");
                    sb.AppendLine("           As");
                    sb.AppendLine("       (");
                    sb.AppendLine(" select ta.node_id,ta.node_pid,ta.order_no,ta.node_path,tb.node_name,tb.map_key   from node_net ta inner join site_node tb on ta.node_id=tb.node_id where site_code='13385E2E95FA7FD3' and ta.node_pid='0'");
                    sb.AppendLine("        Union All");
                    sb.AppendLine("        select ta.node_id,ta.node_pid,ta.order_no,ta.node_path,tb.node_name,tb.map_key   from node_net ta inner join site_node tb on ta.node_id=tb.node_id  inner join  Data t on  ta.node_pid=t.node_path  ");
                    sb.AppendLine("        )");
                    sb.AppendLine("    select a.*,b.obj_table from  Data  a left join object_info b on a.map_key=b.obj_name");
                    var         nodeinfos = db.ExecuteStoreQuery <NoteInfo>(sb.ToString());
                    RequestNode req       = new RequestNode();
                    req.isSec = 1;
                    var nodes = nodeinfos.ToArray();
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        var nodeid = nodes[i].node_id;
                        req.Model.Add(new NodeStruct {
                            AutoNo = Convert.ToInt32(nodes[i].node_id), NodeId = Convert.ToInt32(nodeid), NodeName = nodes[i].node_name, ChildNodeIds = nodes.Where(p => p.node_pid == nodes[i].node_path).Select(p => p.node_id).ToArray()
                        });
                        if (!string.IsNullOrWhiteSpace(nodes[i].obj_table))
                        {
                            var sqlsb = new System.Text.StringBuilder();

                            sqlsb.AppendLine("select  " + Convert.ToInt32(nodes[i].node_id) + " as nodeId,* ");
                            sqlsb.AppendLine(" from  {0}  a left join  node_objdata b on a.IDLeaf=b.ID_Leaf  ");
                            sqlsb.AppendLine("  where a.[state]=@state and isnull(b.is_hot,0)=0 and b.node_id={1}");
                            sqlsb.AppendLine("  order by inputtime ");
                            DataTable needPublish = SQLHelper.GetTable(string.Format(sqlsb.ToString(), nodes[i].obj_table, nodeid),
                                                                       new System.Data.SqlClient.SqlParameter[] {
                                new System.Data.SqlClient.SqlParameter("@state", 99)
                            });

                            sqlsb.Clear();

                            sqlsb.AppendLine("select isnull(max(num),0) score from (");
                            sqlsb.AppendLine(" select row_number()over(order by inputtime) as num  from  {0} a left join   ");
                            sqlsb.AppendLine(" node_objdata b on a.IDLeaf=b.ID_Leaf  ");
                            sqlsb.AppendLine(" where a.[state]=@state and b.is_hot=1 and  b.node_id={1}) b");
                            DataTable PublishedMaxScore = SQLHelper.GetTable(string.Format(sqlsb.ToString(), nodes[i].obj_table, nodeid),
                                                                             new System.Data.SqlClient.SqlParameter[] {
                                new System.Data.SqlClient.SqlParameter("@state", 99)
                            });

                            int score = Convert.ToInt32(PublishedMaxScore.Rows[0]["score"]);

                            DataTable fields = SQLHelper.GetTable("select * from dbo.object_dict where obj_table=@table ", new System.Data.SqlClient.SqlParameter[] {
                                new System.Data.SqlClient.SqlParameter("@table", nodes[i].obj_table)
                            });

                            int           pushCount   = 0;
                            var           pushIDLeafs = new List <string>();
                            RequestScript rs          = new RequestScript();
                            rs.isSec = Convert.ToInt32(Convert.ToInt32(nodes[i].node_id));
                            foreach (DataRow row in needPublish.Rows)
                            {
                                pushIDLeafs.Add(Convert.ToString(row["IDLeaf"]));
                                score     = score + 1;
                                pushCount = pushCount + 1;
                                var resultstr = new List <string>();
                                foreach (DataRow r in fields.Rows)
                                {
                                    var    key         = Convert.ToString(r["obj_feild"]);
                                    var    limit       = 30000;
                                    string value       = Convert.ToString(row[key]);
                                    string valueString = string.Empty;
                                    var    num         = (value.Length / limit);
                                    if (value.Length > 32766)
                                    {
                                        for (var k = 0; k <= num; k++)
                                        {
                                            if (k == num)
                                            {
                                                valueString += Uri.EscapeUriString(value.ToString().Substring(limit * k, value.Length - limit * k));
                                            }
                                            else
                                            {
                                                valueString += Uri.EscapeUriString(value.ToString().Substring(limit * k, limit));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        valueString = Uri.EscapeUriString(value);
                                    }

                                    resultstr.Add(String.Format("\"{0}\":\"{1}\"", Uri.EscapeUriString(key), valueString));
                                }
                                resultstr.Add(String.Format("\"{0}\":\"{1}\"", "nodeId", row["nodeId"].ToString()));
                                string str = string.Format("{0}{1}{2}", "{", string.Join(",", resultstr), "}");

                                rs.Model.Add(new Manuscript {
                                    AutoNo = score, content = str
                                });

                                if (pushCount % 100 == 0 && pushCount >= 100)
                                {
                                    PostValue(ConfigurationManager.AppSettings["ScriptUrl"].ToString(), JsonConvert.SerializeObject(rs));
                                    rs = new RequestScript();
                                    string sql = string.Format("update  node_objdata set is_hot=1 where node_id=" + nodeid + " and ID_Leaf in ({0}{1}{2})", "'", string.Join("','", pushIDLeafs), "'");
                                    db.ExecuteStoreCommand(sql);
                                    pushIDLeafs = new List <string>();
                                }
                                else
                                {
                                    if (pushCount == needPublish.Rows.Count)
                                    {
                                        PostValue(ConfigurationManager.AppSettings["ScriptUrl"].ToString(), JsonConvert.SerializeObject(rs));
                                        rs = new RequestScript();
                                        string sql = string.Format("update  node_objdata set is_hot=1 where node_id=" + nodeid + " and ID_Leaf in ({0}{1}{2})", "'", string.Join("','", pushIDLeafs), "'");
                                        db.ExecuteStoreCommand(sql);
                                        pushIDLeafs = new List <string>();
                                    }
                                }
                            }
                        }
                    }
                    PostValue(ConfigurationManager.AppSettings["NodeUrl"].ToString(), JsonConvert.SerializeObject(req));
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error("程序退出");
                Application.Exit();
            }
            logger.Error("程序退出");
            Application.Exit();
        }
Exemplo n.º 9
0
        private static async Task GetRequestTask(
            Dictionary <RequestNode, Task> nodeToTask,
            SemaphoreSlim throttle,
            object consoleLock,
            HttpClient httpClient,
            RequestNode node,
            BackgroundCsvWriter <ReplayRequestRecord> writer)
        {
            if (node.Dependencies.Any())
            {
                await Task.WhenAll(node.Dependencies.Select(n => nodeToTask[n]).ToList());
            }

            await throttle.WaitAsync();

            try
            {
                if (node.StartRequest.Method != "GET")
                {
                    throw new InvalidOperationException("Only GET requests are supported.");
                }

                var       buffer      = new byte[80 * 1024];
                const int maxAttempts = 3;
                for (var i = 0; i < maxAttempts; i++)
                {
                    var stopwatch = Stopwatch.StartNew();
                    try
                    {
                        using (var response = await httpClient.GetAsync(node.StartRequest.Url, HttpCompletionOption.ResponseHeadersRead))
                        {
                            var headerDuration = stopwatch.Elapsed;

                            using (var stream = await response.Content.ReadAsStreamAsync())
                            {
                                int read;
                                do
                                {
                                    read = await stream.ReadAsync(buffer, 0, buffer.Length);
                                }while (read > 0);
                            }

                            writer.Add(new ReplayRequestRecord
                            {
                                Url              = node.StartRequest.Url,
                                StatusCode       = (int)response.StatusCode,
                                HeaderDurationMs = headerDuration.TotalMilliseconds,
                                BodyDurationMs   = (stopwatch.Elapsed - headerDuration).TotalMilliseconds,
                            });

                            if (!response.IsSuccessStatusCode && response.StatusCode != HttpStatusCode.NotFound)
                            {
                                response.EnsureSuccessStatusCode();
                            }

                            break;
                        }
                    }
                    catch (Exception ex) when(i < maxAttempts - 1)
                    {
                        lock (consoleLock)
                        {
                            Console.WriteLine($"  ERROR {node.StartRequest.Url} {stopwatch.ElapsedMilliseconds}ms");
                            Console.WriteLine(ExceptionUtilities.DisplayMessage(ex, indent: true));
                        }
                    }
                }
            }
            finally
            {
                throttle.Release();
            }
        }
Exemplo n.º 10
0
        private static RequestGraph ParseRequestGraph(string logPath, Dictionary <string, string> stringToString)
        {
            var           pendingRequests    = new Dictionary <string, Queue <RequestNode> >();
            var           urlToCount         = new Dictionary <string, int>();
            var           startedRequests    = new List <RequestNode>();
            var           completedRequests  = new HashSet <RequestNode>(CompareByHitIndexAndRequest.Instance);
            var           currentConcurrency = 0;
            var           maxConcurrency     = 0;
            List <string> sources            = null;

            Parse(
                logPath,
                stringToString,
                startRequest =>
            {
                if (!urlToCount.TryGetValue(startRequest.Url, out var count))
                {
                    count = 1;
                    urlToCount.Add(startRequest.Url, count);
                }
                else
                {
                    count++;
                    urlToCount[startRequest.Url] = count;
                }

                var requestNode = new RequestNode(count - 1, startRequest, completedRequests);
                startedRequests.Add(requestNode);

                currentConcurrency++;
                maxConcurrency = Math.Max(currentConcurrency, maxConcurrency);

                if (!pendingRequests.TryGetValue(startRequest.Url, out var pendingNodes))
                {
                    pendingNodes = new Queue <RequestNode>();
                    pendingRequests.Add(startRequest.Url, pendingNodes);
                }

                pendingNodes.Enqueue(requestNode);
            },
                endRequest =>
            {
                // We assume the first response with the matching URL is associated with the first request. This is
                // not necessarily true (A-A-B-B vs. A-B-B-A) but we must make an arbitrary decision since the logs
                // don't have enough information to be certain.
                var nodes              = pendingRequests[endRequest.Url];
                var requestNode        = nodes.Dequeue();
                requestNode.EndRequest = endRequest;

                currentConcurrency--;

                completedRequests.Add(requestNode);

                if (nodes.Count == 0)
                {
                    pendingRequests.Remove(endRequest.Url);
                }
            },
                parsedSources => sources = parsedSources);

            if (sources == null)
            {
                throw new InvalidDataException("No sources were found.");
            }

            return(new RequestGraph(startedRequests, sources));
        }
Exemplo n.º 11
0
        private static List <RequestNode> GetFieldGroups(string query, GraphQLTypeIntrinsic.GQLInterface parentType,
                                                         JObject variables)
        {
            List <RequestNode> groups = new List <RequestNode>();

            while (query.Length > 0)
            {
                query = query.Trim(' ', '\n');
                if (query == "")
                {
                    break;
                }

                var(start, end) = NextBracketSection(query);

                // If non sub group fields are the only ones that remain
                if (end == -1)
                {
                    foreach (var fName in query.Split('\n'))
                    {
                        var(name, args) = ParseArgs(fName, variables);
                        GraphQLType t = null;
                        foreach (var f in parentType.Fields)
                        {
                            if (f.Name == name)
                            {
                                t = f.type;
                                break;
                            }
                        }

                        if (t != null)
                        {
                            RequestNode n = new RequestNode
                            {
                                QueryType = QueryType.FIELD, NodeType = t, Name = name, Args = args
                            };
                            groups.Add(n);
                        }
                    }

                    break;
                }

                var fullGroup = query.Substring(0, end);
                var names     = fullGroup.Split('{')[0];

                // Parse possible fields that are above a sub group
                var fields2 = names.Split('\n');
                for (int i = 0; i < fields2.Length - 1; i++)
                {
                    var(name, args) = ParseArgs(fields2[i], variables);
                    GraphQLType t = null;
                    foreach (var f in parentType.Fields)
                    {
                        if (f.Name == name)
                        {
                            t = f.type;
                            break;
                        }
                    }

                    if (t != null)
                    {
                        RequestNode n = new RequestNode
                        {
                            QueryType = QueryType.FIELD, NodeType = t, Name = name, Args = args
                        };
                        groups.Add(n);
                    }
                }

                // Parse the sub group
                if (fullGroup.Length > 0)
                {
                    var(name, args) = ParseArgs(fields2[fields2.Length - 1], variables);
                    GraphQLType t = null;
                    foreach (var f in parentType.Fields)
                    {
                        if (f.Name == name)
                        {
                            t = f.type;
                            break;
                        }
                    }

                    if (t != null)
                    {
                        List <RequestNode> fields = new List <RequestNode>();
                        if (t is GraphQLTypeIntrinsic.GQLInterface)
                        {
                            fields = GetFieldGroups(query.Substring(start, end - start),
                                                    (GraphQLTypeIntrinsic.GQLInterface)t, variables);
                        }

                        RequestNode n = new RequestNode
                        {
                            QueryType = QueryType.FIELD, NodeType = t, Name = name, Fields = fields,
                            Args      = args
                        };
                        groups.Add(n);
                    }
                }

                query = query.Substring(end);
            }

            return(groups);
        }
Exemplo n.º 12
0
 protected override bool Visit <T>(RequestNode <T> node)
 {
     AppendLine(node.GetType().ToShortTypeName());
     return(base.Visit <T>(node));
 }