public ProfileController( UserManager <ApplicationUser> userManager, ApplicationDbContext context) { _userManager = userManager; _profileReader = new ProfileReader(context); }
public bool Execute(string methodPath, int batch) { var reader = new ProfileReader(); var serializeOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, ReferenceHandler = ReferenceHandler.Preserve, }; byte[] inputData = File.ReadAllBytes(Input !); var writer = new ProfileWriter(); for (var i = 0; i < batch; i++) { ProfileData data = JsonSerializer.Deserialize <ProfileData>(inputData, serializeOptions) !; var outputPath = Path.Combine(OutputDir, $"trimmed-{i}.profile"); string[] excludedMethods = GenerateRandomExclusions(10, methodPath); using (FileStream outStream = File.Create(outputPath)) { writer.WriteAllData(outStream, data, excludedMethods); } var trackingPath = Path.Combine(OutputDir, $"methods-{i}.txt"); File.WriteAllLines(trackingPath, excludedMethods); } return(true); }
public static List <Structure> LoadXmlFile(string filename) { XmlDocument document = new XmlDocument(); document.Load(filename); ProfileReader reader = new ProfileReader(); return(reader.Read(document)); }
public static void LoadXMLValueSets(this ProfileBuilder builder, string filename) { XmlDocument document = new XmlDocument(); document.Load(filename); ProfileReader reader = new ProfileReader(); List <ValueSet> valuesets = reader.ReadValueSets(document); builder.Add(valuesets); }
private void FrmProfileSelector_Load(object sender, EventArgs e) { if (Process.GetProcessesByName("eurotrucks2").Length == 0) { MessageBox.Show("Run Euro Truck Simulator 2 before opening Euro Tracker!", "ERROR!"); this.Close(); } profile = new ProfileReader(this); listboxProfiles.Items.AddRange(profile.GetProfiles().ToArray()); }
static ProfileData ReadProfileFromPort(ProfileReader reader) { ProfileData pd; if (AdbForward) { var cmdArgs = $"forward tcp:{Port} tcp:{Port}"; if (Verbose) { ColorWriteLine($"Calling 'adb {cmdArgs}'...", ConsoleColor.Yellow); } System.Diagnostics.Process.Start("adb", cmdArgs); } using (var client = new TcpClient("127.0.0.1", Port)) { using (var stream = client.GetStream()) { var msgData = System.Text.Encoding.ASCII.GetBytes("save\n"); stream.Write(msgData, 0, msgData.Length); if (Verbose) { ColorWriteLine($"Reading from '127.0.0.1:{Port}'...", ConsoleColor.Yellow); } using (var memoryStream = new MemoryStream(128 * 1024)) { var data = new byte [4 * 1024]; int len; while ((len = stream.Read(data, 0, data.Length)) > 0) { memoryStream.Write(data, 0, len); if (Verbose) { ColorWrite($"Read {len} bytes...\r", ConsoleColor.Yellow); } } if (Verbose) { ColorWriteLine($"Read total {memoryStream.Length} bytes...", ConsoleColor.Yellow); } memoryStream.Seek(0, SeekOrigin.Begin); pd = reader.ReadAllData(memoryStream); } } } return(pd); }
public void SetUp() { var writer = new DeploymentWriter("clonewars"); var recipeDefinition = writer.RecipeFor("r1"); var host = recipeDefinition.HostFor("h1"); host.AddDirective(new SimpleSettings { One = "one", Two = "two" }); host.AddDirective(new OneSettings() { Name = "Jeremy", Age = 37 }); host.AddReference(new BottleReference() { Name = "bottle1" }); host.AddReference(new BottleReference() { Name = "bottle2" }); recipeDefinition.HostFor("h2").AddProperty <ThreeSettings>(x => x.Direction, "North"); recipeDefinition.HostFor("h3").AddProperty <TwoSettings>(x => x.City, "Austin"); writer.RecipeFor("r2").HostFor("h3").AddProperty <SimpleSettings>(x => x.One, "one"); writer.RecipeFor("r3").HostFor("h3").AddProperty <SimpleSettings>(x => x.Two, "two"); writer.RecipeFor("r4").HostFor("h4").AddProperty <SimpleSettings>(x => x.Two, "ten"); writer.RecipeFor("r4").HostFor("h5").AddProperty <SimpleSettings>(x => x.Two, "ten"); writer.RecipeFor("r4").HostFor("h5").AddProperty <SimpleSettings>(x => x.One, "*{dbName}*"); writer.AddEnvironmentSetting <SimpleSettings>(x => x.Two, "h4", "env-value"); writer.AddEnvironmentSetting("dbName", "blue"); writer.Flush(FlushOptions.Wipeout); var reader = new ProfileReader(new RecipeSorter(), new DeploymentSettings("clonewars"), new FileSystem()); theHosts = reader.Read(); }
public frmEuroTracker(frmProfileSelector profiles) { mainThread = profiles; profile = profiles.GetProfileReader(); InitializeComponent(); data = new DataHandler(); client = new Ets2SdkTelemetry(); save = new SaveReader(profile.GetAutosaveLocation(), profile.GetQuicksaveLocation()); savewriter = new SaveWriter(profile.GetAutosaveLocation(), profile.GetQuicksaveLocation()); maxSpeed = 0; avgFuelConsumption = 0; //Setup Syncing Voids client.Data += UpdateData; client.JobFinished += TelemetryOnJobFinished; client.JobStarted += TelemetryOnJobStarted; }
public bool Execute() { var reader = new ProfileReader(); ProfileData data; using (FileStream stream = File.OpenRead(Input !)) { data = reader.ReadAllData(stream); // ModuleRecord[] modules = data.Modules; var serializeOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, ReferenceHandler = ReferenceHandler.Preserve, IgnoreNullValues = true, WriteIndented = true, }; string s = JsonSerializer.Serialize(data, serializeOptions); File.WriteAllText(Output !, s); } return(true); }
public bool Execute(string methodPath) { var reader = new ProfileReader(); ProfileData profile; string[] methodNames; using (FileStream stream = File.OpenRead(Input)) profile = reader.ReadAllData(stream); if (ExcludeMethods != null) { var newMethods = new List <MethodRecord>(); foreach (MethodRecord method in profile.Methods) { bool isFiltered = ExcludeMethods !.Any(e => method.Name == e); if (!isFiltered) { newMethods.Add(method); } } profile.Methods = newMethods.ToArray(); } if (Dump) { methodNames = DumpMethods(profile); File.WriteAllLines(methodPath, methodNames.ToArray()); } if (Output != null) { var writer = new ProfileWriter(); using (FileStream outStream = File.Create(Output !)) writer.WriteAllData(outStream, profile); } return(true); }
public static void Main(string [] args) { var path = ProcessArguments(args); if (args.Length == 1) { Modules = Types = Methods = true; } var reader = new ProfileReader(); ProfileData pd = null; if (path == null) { if (Port < 0) { Error($"You should specify path or -p PORT to read the profile."); Environment.Exit(4); } else { try { pd = ReadProfileFromPort(reader); } catch (Exception e) { Error($"Unable to read profile through local port: {Port}.\n{e}"); Environment.Exit(5); } } } else if (!File.Exists(path)) { Error($"'{path}' doesn't exist."); Environment.Exit(3); } else { using (var stream = new FileStream(path, FileMode.Open)) { if (Verbose) { ColorWriteLine($"Reading '{path}'...", ConsoleColor.Yellow); } pd = reader.ReadAllData(stream); } } List <MethodRecord> methods = new List <MethodRecord> (pd.Methods); ICollection <TypeRecord> types = new List <TypeRecord> (pd.Types); ICollection <ModuleRecord> modules = new List <ModuleRecord> (pd.Modules); if (FilterMethod != null || FilterType != null || FilterModule != null) { methods = new List <MethodRecord> (); types = new HashSet <TypeRecord> (); modules = new HashSet <ModuleRecord> (); foreach (var method in pd.Methods) { var type = method.Type; var module = type.Module; if (FilterModule != null) { var match = FilterModule.Match(module.ToString()); if (!match.Success) { continue; } } if (FilterType != null) { var match = FilterType.Match(method.Type.ToString()); if (!match.Success) { continue; } } if (FilterMethod != null) { var match = FilterMethod.Match(method.ToString()); if (!match.Success) { continue; } } methods.Add(method); types.Add(type); modules.Add(module); } } if (FilterMethod == null && FilterType != null) { foreach (var type in pd.Types) { if (types.Contains(type)) { continue; } var match = FilterType.Match(type.ToString()); if (!match.Success) { continue; } types.Add(type); } } if (Modules) { ColorWriteLine($"Modules:", ConsoleColor.Green); foreach (var module in modules) { WriteLine($"\t{module.Mvid} {module.ToString ()}"); } } if (Types) { ColorWriteLine($"Types:", ConsoleColor.Green); foreach (var type in types) { WriteLine($"\t{type}"); } } if (Methods) { ColorWriteLine($"Methods:", ConsoleColor.Green); foreach (var method in methods) { WriteLine($"\t{method}"); } } if (Summary) { ColorWriteLine($"Summary:", ConsoleColor.Green); WriteLine($"\tModules: {modules.Count.ToString ("N0"),10}{(modules.Count != pd.Modules.Length ? $" (of {pd.Modules.Length})" : "" )}"); WriteLine($"\tTypes: {types.Count.ToString ("N0"),10}{(types.Count != pd.Types.Length ? $" (of {pd.Types.Length})" : "")}"); WriteLine($"\tMethods: {methods.Count.ToString ("N0"),10}{(methods.Count != pd.Methods.Length ? $" (of {pd.Methods.Length})" : "")}"); } if (!string.IsNullOrEmpty(Output)) { if (Verbose) { ColorWriteLine($"Going to write the profile to '{Output}'", ConsoleColor.Yellow); } var modulesArray = new ModuleRecord [modules.Count]; modules.CopyTo(modulesArray, 0); var typesArray = new TypeRecord [types.Count]; types.CopyTo(typesArray, 0); var updatedPD = new ProfileData(modulesArray, typesArray, methods.ToArray()); using (var stream = new FileStream(Output, FileMode.Create)) { var writer = new ProfileWriter(); writer.WriteAllData(stream, updatedPD); } } }
public static void Main(string [] args) { var path = ProcessArguments(args); if (!File.Exists(path)) { Error($"'{path}' doesn't exist."); Environment.Exit(3); } if (args.Length == 1) { Modules = Types = Methods = true; } var reader = new ProfileReader(); ProfileData pd; using (var stream = new FileStream(path, FileMode.Open)) { if (Verbose) { ColorWriteLine($"Reading '{path}'...", ConsoleColor.Yellow); } pd = reader.Read(stream); } List <MethodRecord> methods = pd.Methods; ICollection <TypeRecord> types = pd.Types; ICollection <ModuleRecord> modules = pd.Modules; if (FilterMethod != null || FilterType != null || FilterModule != null) { methods = new List <MethodRecord> (); types = new HashSet <TypeRecord> (); modules = new HashSet <ModuleRecord> (); foreach (var method in pd.Methods) { var type = method.Type; var module = type.Module; if (FilterModule != null) { var match = FilterModule.Match(module.ToString()); if (!match.Success) { continue; } } if (FilterType != null) { var match = FilterType.Match(method.Type.ToString()); if (!match.Success) { continue; } } if (FilterMethod != null) { var match = FilterMethod.Match(method.ToString()); if (!match.Success) { continue; } } methods.Add(method); types.Add(type); modules.Add(module); } } if (FilterMethod == null && FilterType != null) { foreach (var type in pd.Types) { if (types.Contains(type)) { continue; } var match = FilterType.Match(type.ToString()); if (!match.Success) { continue; } types.Add(type); } } if (Modules) { ColorWriteLine($"Modules:", ConsoleColor.Green); foreach (var module in modules) { WriteLine($"\t{module.Mvid} {module}"); } } if (Types) { ColorWriteLine($"Types:", ConsoleColor.Green); foreach (var type in types) { WriteLine($"\t{type}"); } } if (Methods) { ColorWriteLine($"Methods:", ConsoleColor.Green); foreach (var method in methods) { WriteLine($"\t{method}"); } } if (Summary) { ColorWriteLine($"Summary:", ConsoleColor.Green); WriteLine($"\tModules: {modules.Count.ToString ("N0"),10}{(modules.Count != pd.Modules.Count ? $" (of {pd.Modules.Count})" : "" )}"); WriteLine($"\tTypes: {types.Count.ToString ("N0"),10}{(types.Count != pd.Types.Count ? $" (of {pd.Types.Count})" : "")}"); WriteLine($"\tMethods: {methods.Count.ToString ("N0"),10}{(methods.Count != pd.Methods.Count ? $" (of {pd.Methods.Count})" : "")}"); } if (!string.IsNullOrEmpty(Output)) { if (Verbose) { ColorWriteLine($"Going to write the profile to '{Output}'", ConsoleColor.Yellow); } var updatedPD = new ProfileData(new List <ModuleRecord>(modules), new List <TypeRecord> (types), methods); using (var stream = new FileStream(Output, FileMode.Create)) { var writer = new ProfileWriter(stream, updatedPD); writer.Write(); } } }