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); } } } })); }
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); } } } })); }