コード例 #1
0
        Task CreateWriter(BlockingCollection <DomainTrust> output)
        {
            return(Task.Factory.StartNew(() =>
            {
                if (options.URI == null)
                {
                    string path = options.GetFilePath("trusts");
                    bool append = false || File.Exists(path);
                    using (StreamWriter writer = new StreamWriter(path, append))
                    {
                        if (!append)
                        {
                            writer.WriteLine("SourceDomain,TargetDomain,TrustDirection,TrustType,Transitive");
                        }
                        writer.AutoFlush = true;
                        foreach (DomainTrust info in output.GetConsumingEnumerable())
                        {
                            writer.WriteLine(info.ToCSV());
                        }
                    }
                }
                else
                {
                    using (WebClient client = new WebClient())
                    {
                        client.Headers.Add("content-type", "application/json");
                        client.Headers.Add("Accept", "application/json; charset=UTF-8");
                        client.Headers.Add("Authorization", options.GetEncodedUserPass());

                        RESTOutput domains = new RESTOutput(Query.Domain);

                        JavaScriptSerializer serializer = new JavaScriptSerializer();

                        foreach (DomainTrust info in output.GetConsumingEnumerable())
                        {
                            domains.props.AddRange(info.ToMultipleParam());
                        }

                        var FinalPost = serializer.Serialize(new
                        {
                            statements = new object[] {
                                domains.GetStatement()
                            }
                        });

                        try
                        {
                            client.UploadData(options.GetURI(), "POST", Encoding.Default.GetBytes(FinalPost));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }
            }));
        }
コード例 #2
0
        Task StartWriter(BlockingCollection <LocalAdminInfo> output, TaskFactory factory)
        {
            return(factory.StartNew(() =>
            {
                if (options.URI == null)
                {
                    string path = options.GetFilePath("local_admins");
                    bool append = false || File.Exists(path);
                    using (StreamWriter writer = new StreamWriter(path, append))
                    {
                        if (!append)
                        {
                            writer.WriteLine("ComputerName,AccountName,AccountType");
                        }
                        int localcount = 0;
                        foreach (LocalAdminInfo info in output.GetConsumingEnumerable())
                        {
                            writer.WriteLine(info.ToCSV());
                            localcount++;
                            if (localcount % 100 == 0)
                            {
                                writer.Flush();
                            }
                        }
                        writer.Flush();
                    }
                }
                else
                {
                    using (WebClient client = new WebClient())
                    {
                        client.Headers.Add("content-type", "application/json");
                        client.Headers.Add("Accept", "application/json; charset=UTF-8");
                        client.Headers.Add("Authorization", options.GetEncodedUserPass());

                        int localcount = 0;

                        RESTOutput groups = new RESTOutput(Query.LocalAdminGroup);
                        RESTOutput computers = new RESTOutput(Query.LocalAdminComputer);
                        RESTOutput users = new RESTOutput(Query.LocalAdminUser);

                        JavaScriptSerializer serializer = new JavaScriptSerializer();

                        foreach (LocalAdminInfo info in output.GetConsumingEnumerable())
                        {
                            switch (info.ObjectType)
                            {
                            case "user":
                                users.props.Add(info.ToParam());
                                break;

                            case "group":
                                groups.props.Add(info.ToParam());
                                break;

                            case "computer":
                                computers.props.Add(info.ToParam());
                                break;
                            }
                            localcount++;
                            if (localcount % 1000 == 0)
                            {
                                var ToPost = serializer.Serialize(new
                                {
                                    statements = new object[] {
                                        users.GetStatement(),
                                        computers.GetStatement(),
                                        groups.GetStatement()
                                    }
                                });

                                users.Reset();
                                computers.Reset();
                                groups.Reset();

                                try
                                {
                                    client.UploadData("http://localhost:7474/db/data/transaction/commit", "POST", Encoding.Default.GetBytes(ToPost));
                                }catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }
                            }
                        }

                        var FinalPost = serializer.Serialize(new
                        {
                            statements = new object[] {
                                users.GetStatement(),
                                computers.GetStatement(),
                                groups.GetStatement()
                            }
                        });

                        try
                        {
                            client.UploadData("http://localhost:7474/db/data/transaction/commit", "POST", Encoding.Default.GetBytes(FinalPost));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }
            }));
        }
コード例 #3
0
        Task StartWriter(BlockingCollection <SessionInfo> output, TaskFactory factory)
        {
            return(factory.StartNew(() =>
            {
                if (options.URI == null)
                {
                    string path = options.GetFilePath("sessions");
                    bool append = false || File.Exists(path);
                    using (StreamWriter writer = new StreamWriter(path, append))
                    {
                        if (!append)
                        {
                            writer.WriteLine("UserName,ComputerName,Weight");
                        }
                        int localcount = 0;
                        foreach (SessionInfo info in output.GetConsumingEnumerable())
                        {
                            writer.WriteLine(info.ToCSV());
                            localcount++;
                            if (localcount % 100 == 0)
                            {
                                writer.Flush();
                            }
                        }
                        writer.Flush();
                    }
                }
                else
                {
                    using (WebClient client = new WebClient())
                    {
                        client.Headers.Add("content-type", "application/json");
                        client.Headers.Add("Accept", "application/json; charset=UTF-8");
                        client.Headers.Add("Authorization", options.GetEncodedUserPass());

                        int localcount = 0;

                        RESTOutput users = new RESTOutput(Query.Sessions);

                        JavaScriptSerializer serializer = new JavaScriptSerializer();

                        foreach (SessionInfo info in output.GetConsumingEnumerable())
                        {
                            users.props.Add(info.ToParam());
                            localcount++;
                            if (localcount % 1000 == 0)
                            {
                                var ToPost = serializer.Serialize(new
                                {
                                    statements = new object[] {
                                        users.GetStatement()
                                    }
                                });

                                users.Reset();

                                try
                                {
                                    client.UploadData(options.GetURI(), "POST", Encoding.Default.GetBytes(ToPost));
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }
                            }
                        }

                        var FinalPost = serializer.Serialize(new
                        {
                            statements = new object[] {
                                users.GetStatement()
                            }
                        });

                        try
                        {
                            client.UploadData(options.GetURI(), "POST", Encoding.Default.GetBytes(FinalPost));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }
            }));
        }