public override void Execute( string arg) { XConsole.WriteLine($"Creating Entity Framework Database Context.", Swatch.Cyan); using var context = new CoreContext(); XConsole.WriteLine($"Ensuring database is deleted...", Swatch.Cyan); var deleteResult = context.Database.EnsureDeleted(); if (deleteResult) { XConsole.WriteLine($" Database deleted successfully.", Swatch.Teal); } else { XConsole.WriteLine($" Database already does not exist.", Swatch.Teal); } XConsole.WriteLine($"Creating database structure and schema...", Swatch.Cyan); var createResult = context.Database.EnsureCreated(); if (!createResult) { XConsole.WriteLine($" Database creation failed.", Swatch.Red); return; } XConsole .WriteLine($" Database created successfully", Swatch.Teal) .WriteLine($" Database information:", Swatch.LightBlue) .WriteLine($" {context.Database}", Swatch.LightBlue); }
public static async Task Handle(PacketReader _, Presence user) { user.InLobby = false; await Global.Channels["#lobby"].RemoveUser(user); XConsole.Log($"{user} left from lobby", ConsoleColor.Cyan); }
public void Post(IEnumerable <ISite> sites) { List <SiteBinding> siteBindings = new List <SiteBinding>(); foreach (ISite site in sites) { if (site.AppType != "Root") { continue; } IEnumerable <SiteBinding> bindings = site.Bindings(); string xConsoleString = string.Join(",", bindings.Select(x => $"SiteId:{x.SiteId} Host:{x.Host} Port:{x.Port} SSL:{x.IsSSLBound}")); XConsole.WriteLine(xConsoleString); siteBindings.AddRange(bindings); } if (siteBindings.Count > 0) { PackageManager packageManager = PackageManager.GetManager(); IEnumerable packs = packageManager.GetPacks(siteBindings); foreach (IEnumerable <SiteBinding> pack in packs) { WebTransfer.PostSiteBinding(pack); } } }
public static void Run(this IList <Task> tasks) { XConsole.SetDefaultColorSet(ConsoleColorSetGreen.Instance); TaskQueue = TaskQueue ?? new Queue <Task>(); TaskQueue = TaskQueue.Reload(tasks); int taskQ = TaskQueue.Count; while (TaskQueue.Count > 0) { if (ActiveTaskCounter < TASK_LIMIT && TaskQueue.Count > 0) { Task currentOperation = TaskQueue.Dequeue(); XConsole.Progress(string.Empty, taskQ - TaskQueue.Count - ActiveTaskCounter, taskQ); //XConsole.WriteLine("Active Task(s): " + ActiveTaskCounter + ", TaskQueue: " + TaskQueue.Count + ", Current Ops:" + currentOperation.Id); currentOperation.Start(); ActiveTaskCounter++; Thread.Sleep(TimeSpan.FromMilliseconds(100)); } } Task.WaitAll(tasks.ToArray()); //while (ActiveTaskCounter > 0) //{ // XConsole.Progress("Task Progress", taskQ - TaskQueue.Count - ActiveTaskCounter, taskQ); // //XConsole.WriteLine("Remaining Task(s): " + ActiveTaskCounter + ", TaskQueue: Completed"); // Thread.Sleep(TimeSpan.FromSeconds(1)); //} }
public static async Task Handle(PacketReader reader, Presence user) { var message = reader.ReadBanchoObject <BanchoMessage>(); if (message.To == Global.Bot.Name) { if (message.Body.StartsWith(Global.Config.CommandPrefix)) { await CommandHandler.Process(message.Body.Substring(Global.Config.CommandPrefix.Length), user); } return; } var location = Global.OnlineManager.GetByName(message.To); if (location is null) { await user.Notify("Пользователь не в сети."); return; } await location.SendMessage(message.Body, user); if (message.Body.StartsWith(Global.Config.CommandPrefix)) { await CommandHandler.Process(message.Body.Substring(Global.Config.CommandPrefix.Length), user); } XConsole.Log($"{user} -> {location}: {message.Body}"); }
public static int Main(string[] args) { if (args.Length < 1) { return(XConsole.PrintInfo("HookGenerator.CLI - generate API-like osu! methods access assembly\n" + "by exys, 2019\n" + "\n" + "Usage:\n" + "HookGenerator.CLI [clean module]")); } string originalModulePath; if (!File.Exists(originalModulePath = Path.GetFullPath(args[0]))) { return(XConsole.PrintError("Specified module path does not exist!")); } try { _originalModule = ModuleDefMD.Load(originalModulePath); } catch (Exception e) { return(XConsole.PrintError("An error occurred while trying to load module! Details:\n" + e)); } XConsole.PrintInfo($"Loaded module: {_originalModule.Assembly.FullName}."); var assemblyName = $"OsuHooks-{MD5Helper.Compute(originalModulePath).Substring(0, 8)}"; var moduleName = $"{assemblyName}.dll"; var hookModule = new HookGenerator(assemblyName, _originalModule).CreateHookModule(); XConsole.PrintInfo($"Finally writing {moduleName}!"); hookModule.Write(Path.Combine(Path.GetDirectoryName(originalModulePath) ?? throw new Exception("Path to write module to is null unexpectedly"), moduleName)); return(0); }
public Gateway() { int port = _config.GetValue <int>("Host:Port"); string localIpAddr = Core.Ops.Extensions.GetLocalIPAddress(); IList <string> hosts = new List <string> { $"http://localhost:{port}", $"http://{localIpAddr}:{port}" }; _logManager.Write($"Hosts -> {string.Join(", ", hosts)}"); _server = new WebHostBuilder() .UseContentRoot(Directory.GetCurrentDirectory()) .UseUrls(hosts.ToArray()) .UseStartup <Startup>() .UseKestrel(options => { options.AllowSynchronousIO = true; }) .Build(); _server.Run(); XConsole.SetTitle("DSM Gateway"); _logManager.Write($"Gateway RUNNING UP!"); }
public async Task Leave(Presence user) { user.Match = null; await Channel.RemoveUser(user); if (Channel.Users.IsEmpty) { Global.Channels.Remove(Channel.TrueName); Global.Rooms.Remove(Id); await Global.OnlineManager.AddPacketToAllUsers(await FastPackets.DisposeMatch(Id)); XConsole.Log($"Match {ToString()} ended", ConsoleColor.Green); } else { var slot = GetSlot(user.Id); if (slot is null) { return; } slot.User = null; slot.Mods = Mods.NoMod; slot.Team = MatchTeam.Neutral; slot.Status = SlotStatus.Open; if (user.Id == HostId) { Host = Slots.First(x => (x.Status & SlotStatus.HasPlayer) != 0).User; } await Update(); } }
static void Main(string[] args) { XConsole.WriteLine("This is a high level demo of `PowerUp` tools:"); BenchmarkTest(); DecompilationTest(); }
/// <summary> /// Wait until all threads are done. Pretty much hardcoded. /// </summary> private void WaitMakeSure() { int occ = 0; long prevState = 0; while (true) { if (occ < 3 && _inWork == 0) { occ++; } else if (occ >= 3) { break; } else { occ = 0; } Thread.Sleep(100); if (Math.Abs(prevState - _inWork) > 25) { Message(XConsole.Info("Waiting far all threads to finish! In work: " + _inWork)); } prevState = _inWork; } }
public SecureGate() : base(@"DSM.GatewayEngine\SecureGate") { XConsole.SetDefaultColorSet(ConsoleColorSetGreen.Instance); Get(WebOperations.WebMethod.GET_SITES_ALL, new Func <dynamic, object>(GetSiteAll)); Get(WebOperations.WebMethod.GET_MAILS_ALL, new Func <dynamic, object>(GetMails)); Get(WebOperations.WebMethod.GET_MAIL_RECIPIENTS, new Func <dynamic, object>(GetMailRecipients)); Get(WebOperations.WebMethod.GET_SITES_BY_MACHINENAME.WithParamMachineName(), new Func <dynamic, object>(GetSiteByMachineName)); Get(WebOperations.WebMethod.GET_WEB_CONFIGURATION_BY_SITEID.WithParamSiteId(), new Func <dynamic, object>(GetWebConfiguration)); Get(WebOperations.WebMethod.GET_MAIL_FROM_QUEUE_BY_SITEID.WithParamSiteId(), new Func <dynamic, object>(GetMailFromQueue)); Get(WebOperations.WebMethod.GET_SITE_BY_ID.WithParamId(), new Func <dynamic, object>(GetSite)); Get(WebOperations.WebMethod.GET_BINDING_BY_SITEID.WithParamSiteId(), new Func <dynamic, object>(GetBinding)); Get(WebOperations.WebMethod.GET_EVENT_LOG_BY_SITEID.WithParamSiteId(), new Func <dynamic, object>(GetLog)); Post(WebOperations.WebMethod.POST_SITE, new Func <dynamic, object>(PostSite)); Post(WebOperations.WebMethod.POST_BINDING, new Func <dynamic, object>(PostBinding)); Post(WebOperations.WebMethod.POST_EVENT_LOG, new Func <dynamic, object>(PostLog)); Post(WebOperations.WebMethod.POST_PACKAGE, new Func <dynamic, object>(PostPackageVersion)); Post(WebOperations.WebMethod.POST_WEB_CONFIGURATION, new Func <dynamic, object>(PostWebConfiguration)); Post(WebOperations.WebMethod.POST_BINDING_MULTIPLE, new Func <dynamic, object>(PostBindingMulti)); Post(WebOperations.WebMethod.POST_SITE_MULTIPLE, new Func <dynamic, object>(PostSiteMulti)); Post(WebOperations.WebMethod.POST_EVENT_LOG_MULTIPLE, new Func <dynamic, object>(PostEvenLogMulti)); Post(WebOperations.WebMethod.POST_WEB_CONFIGURATION_MULTIPLE, new Func <dynamic, object>(PostWebConfigurationMulti)); Post(WebOperations.WebMethod.POST_PACKAGE_MULTIPLE, new Func <dynamic, object>(PostPackageVersionMulti)); Post(WebOperations.WebMethod.POST_MAIL_TO_QUEUE, new Func <dynamic, object>(PostMailToQueue)); Post(WebOperations.WebMethod.POST_DELETE_MAIL, new Func <dynamic, object>(DeleteMail)); Get(WebOperations.WebMethod.GET_CONFIG_BACKUP_STATUS, new Func <dynamic, object>(GetConfigBackupStatus)); Post(WebOperations.WebMethod.POST_CONFIG_TO_BACKUP, new Func <dynamic, object>(PostConfigToBackup)); }
public PlatformGate() : base(@"DSM.GatewayEngine\PlatformGate") { XConsole.SetDefaultColorSet(ConsoleColorSetGreen.Instance); Get(WebOperations.WebMethod.GET_ADDOMAIN_LIST, new System.Func <dynamic, object>(GetAllDomainUsers)); Get(WebOperations.WebMethod.GET_ADDOMAIN_LIST, new System.Func <dynamic, object>(GetDomains)); Post(WebOperations.WebMethod.POST_ADDOMAIN_USER, new System.Func <dynamic, object>(PostDomainUser)); Post(WebOperations.WebMethod.POST_ADDOMAIN_USER_MULTIPLE, new System.Func <dynamic, object>(PostDomainUserMulti)); }
public static async Task Handle(PacketReader _, Presence user) { if (user.Match is null) { return; } await user.Match.Leave(user); XConsole.Log($"{user} left from multiplayer room {user.Match}", ConsoleColor.Cyan); }
public IISLogGate() : base(@"DSM.GatewayEngine\IISLogGate") { XConsole.SetDefaultColorSet(ConsoleColorSetGreen.Instance); Get(WebOperations.WebMethod.GET_TRANSACTION_LASTLOGDATE_BY_SITEID.WithParamSiteId(), new Func <dynamic, object>(GetLastLogDate)); Get(WebOperations.WebMethod.GET_TRANSACTION_ACTIVATION_STATUS, new Func <dynamic, object>(GetActivationStatus)); Get(WebOperations.WebMethod.GET_TRANSACTIONS_BY_MACHINENAME.WithParamMachineName(), new Func <dynamic, object>(GetTransactions)); Get(WebOperations.WebMethod.GET_TRANSACTION_FILTERS, new Func <dynamic, object>(GetTransactionFilter)); Post(WebOperations.WebMethod.POST_TRANSACTION, new Func <dynamic, object>(PostTransactions)); Post(WebOperations.WebMethod.POST_TRANSACTION_MULTIPLE, new Func <dynamic, object>(PostTransactionsMulti)); }
public BaseRepository(string dbConnectionString) { vault = new DataVault(dbConnectionString); string className = typeof(Class).Name; _consoleTitle = $"[DB - ENGINE]({className})-> "; XConsole.SetDefaultColorSet(DatabaseEngine.ConsoleColor); XConsole.SetTitle(_consoleTitle); }
public static async Task Handle(PacketReader _, Presence user) { user.InLobby = true; await Global.Channels["#lobby"].JoinUser(user); foreach (var(_, match) in Global.Rooms) { user.WaitingPackets.Enqueue(await FastPackets.NewMatch(match.Foreign())); } XConsole.Log($"{user} joined to lobby", ConsoleColor.Cyan); }
/// <summary> /// Gathers Connectionstring object from raw text -> connection string /// </summary> /// <param name="connectionString">Raw String</param> /// <param name="connectionName">Name of the Connection</param> /// <param name="siteId">Foreign Key of between Site and Connectionstring object</param> /// <returns></returns> private static SiteConnectionString GetConnectionString(string connectionString, string connectionName, long siteId) { if (connectionString.Contains(("metadata=res://"))) { try { XConsole.WriteLine("EF BASED CONNECTION STRING DETECTED"); EFConnectionStringBuilder entityConnectionString = new EFConnectionStringBuilder(connectionString); connectionString = entityConnectionString.ProviderConnectionString; XConsole.WriteLine(connectionString); } catch (Exception ex) { ExceptionHandler.Exception(ex); } } try { SqlConnectionStringBuilder sqlConnectionString = new SqlConnectionStringBuilder(connectionString); string serverName = string.Empty; int portInfo = 1433; string[] spDSource = sqlConnectionString.DataSource.Split(','); if (spDSource.Length > 1) { serverName = spDSource[0]; int.TryParse(spDSource[1], out portInfo); } else { serverName = sqlConnectionString.DataSource; } return(new SiteConnectionString { SiteId = siteId, RawConnectionString = connectionString, ServerName = serverName, Port = portInfo, DatabaseName = sqlConnectionString.InitialCatalog, UserName = sqlConnectionString.UserID, Password = sqlConnectionString.Password, IsAvailable = true, LastCheckTime = DateTime.Now, ConnectionName = connectionName }); } catch (Exception ex) { ExceptionHandler.Exception(ex); return(null); } }
public ClientMgrGate() : base(@"DSM.GatewayEngine\ClientMgrGate") { XConsole.SetDefaultColorSet(ConsoleColorSetGreen.Instance); Get(WebOperations.WebMethod.GET_CLIENT_LIST, action: new Func <dynamic, object>(GetClientList)); Get(WebOperations.WebMethod.GET_CLIENT_BY_MACHINE_NAME.WithParamMachineName(), new Func <dynamic, object>(GetClient)); Get(WebOperations.WebMethod.GET_SCHEDULER_BY_CLIENTID_AND_SERVICEID, new Func <dynamic, object>(GetScheduler)); Post(WebOperations.WebMethod.POST_CLIENT, new Func <dynamic, object>(PostClient)); Post(WebOperations.WebMethod.POST_SCHEDULER, new Func <dynamic, object>(SetScheduler)); Post(WebOperations.WebMethod.POST_ENABLE_SCHEDULER, new Func <dynamic, object>(EnableScheduler)); Post(WebOperations.WebMethod.POST_DISABLE_SCHEDULER, new Func <dynamic, object>(DisableScheduler)); }
public static void Main() { try { using var app = new AutoArknights(); app.Run(); } catch (Exception e) { Log.Error(e.Message, withTime: true); Log.Debug(e.StackTrace); XConsole.AnyKey(); } }
public static async Task Handle(PacketReader _, Presence user) { var toSpec = user.Spectating; if (toSpec is null) { XConsole.Log($"{user} failed to stop spectating (not spectating)", ConsoleColor.Yellow); return; } await toSpec.RemoveSpectator(user); XConsole.Log($"{user} stop spectating {toSpec}", ConsoleColor.Magenta); }
//TODO: /web/ public async Task <Presence> GetPresence() { var user = Auth.GetSafeName(Request.Query["u"]); var pwMd5 = (string)Request.Query["h"]; var presence = await Auth.Login(user, pwMd5); if (presence is null || !presence.Online) { XConsole.Log($"{presence?.ToString() ?? user} requested {Request.Path} while not online", ConsoleColor.Yellow); } return(presence); }
public static async Task Handle(PacketReader _, Presence user) { var toSpec = user.Spectating; if (toSpec is null) { XConsole.Log($"{user} sent cant spectate while not spectatinmg", ConsoleColor.Yellow); return; } var packet = await FastPackets.CantSpectate(user.Id); toSpec.WaitingPackets.Enqueue(packet); await toSpec.AddPacketToSpectators(packet); }
public static async Task Handle(PacketReader reader, Presence user) { var channel = reader.ReadString(); if (!Global.Channels.ContainsKey(channel) || channel == "#lobby") { return; } var c = Global.Channels[channel]; await c.RemoveUser(user); XConsole.Log($"{user} left from {channel}", ConsoleColor.Cyan); }
public override async Task StartAsync() { Console.Clear(); var opt = XConsole.PromptLine(Description); if (Tasks.ContainsKey(opt)) { await Tasks[opt](); } XConsole.PromptLine("\nPress enter to exit task"); Console.Clear(); }
public static async Task Handle(PacketReader reader, Presence user) { var id = reader.ReadInt32(); var toSpec = Global.OnlineManager.GetById(id); if (toSpec is null) { XConsole.Log($"{user} failed to spectate <({id})> (offline)", ConsoleColor.Yellow); return; } await toSpec.AddSpectator(user); XConsole.Log($"{user} started spectating {toSpec}", ConsoleColor.Magenta); }
private static RunContext InitializeContext(RunArgs run) { // init DB connection var ctx = new RunContext { DbType = run.DbType, Connection = run.Connection }; if (ctx.Connection != null) { Verbose.WriteLine($"DB type: {ctx.DbType.ToString().ToUpper()}"); Verbose.WriteLine($"DB connection: {ctx.Connection}"); } // choose target path ctx.TargetPath = Environment.CurrentDirectory; if (!String.IsNullOrWhiteSpace(run.CustomPath)) ctx.TargetPath = run.CustomPath; if (!Directory.Exists(ctx.TargetPath)) { XConsole.NewPara().Warning.WriteLine("Cannot locate target path"); XConsole.Write("The following target path was not found: ").Cyan.WriteLine(ctx.TargetPath); XConsole.Write("When you use ").Yellow.Write("-p").Default.WriteLine(" parameter to specify custom path, make sure it points to existing location"); return null; } Verbose.WriteLine($"Target path: {ctx.TargetPath}"); // get log path ctx.LogPath = Path.Combine(ctx.TargetPath, "log"); Verbose.Write($"Log path: {ctx.LogPath}"); if (!Directory.Exists(ctx.LogPath)) { Directory.CreateDirectory(ctx.LogPath); Verbose.Write(" (created)"); } Verbose.WriteLine(); // optionally use "soft" reset ctx.UseSoftReset = run.UseSoftReset; return ctx; }
public void Run() { var cin = new Cin(); var mode = cin.Get <RepeatLevelAction.Mode>("输入模式"); int repeatTime = -1; if (mode == RepeatLevelAction.Mode.SpecifiedTimes || mode == RepeatLevelAction.Mode.SpecTimesWithWait) { repeatTime = cin.Get <int>("输入刷关次数"); } _automation.Actions.Enqueue(new RepeatLevelAction(mode, repeatTime)); _automation.DoAll(); Console.Beep(); XConsole.AnyKey("所有任务完成"); }
private Task AddMigration() { Console.Clear(); var migrationName = XConsole.PromptLine("Migration name: "); if (string.IsNullOrWhiteSpace(migrationName)) { Console.Write("Invalid migration name"); return(Task.CompletedTask); } var solutionFolder = XConsole.PromptLine("Solution folder: "); if (string.IsNullOrWhiteSpace(solutionFolder)) { solutionFolder = DirectoryHelper.GetSolutionFolder(); } var destPrj = XConsole.PromptLine("Destination project: "); if (string.IsNullOrWhiteSpace(destPrj)) { destPrj = DefaultDestinationProject; } var startupPrj = XConsole.PromptLine("Startup project: "); if (string.IsNullOrWhiteSpace(startupPrj)) { startupPrj = DefaultStartupProject; } Process process = new Process().Build(fileName: "cmd.exe", arguments: $"/C dotnet ef migrations add {migrationName} --project={destPrj} --startup-project={startupPrj}", workingDir: solutionFolder); process.Start(); process.WaitForExit(); Console.ReadLine(); Console.Clear(); return(Task.CompletedTask); }
public override async Task StartAsync() { Console.Clear(); var opt = XConsole.PromptLine(Description); switch (opt) { case SimpleValidationOpt: await SimpleValidation(); break; } XConsole.PromptLine("\nPress enter to exit task"); Console.Clear(); }
/// <summary> /// Get Raw endpoints from site /// </summary> /// <param name="site"></param> /// <returns></returns> private static IEnumerable <KeyValuePair <string, string> > GetRawEndpoints(this string xmlContent, string siteName = "") { try { List <KeyValuePair <string, string> > outputs = new List <KeyValuePair <string, string> >(); XmlDocument document = new XmlDocument(); document.LoadXml(xmlContent); XmlNodeList nodes = document.SelectNodes("//client/endpoint"); foreach (XmlNode xmlNode in nodes) { string addr = xmlNode.Attributes["address"].InnerText; string name = xmlNode.Attributes["name"].InnerText; outputs.Add(new KeyValuePair <string, string>(name, addr)); } document.LoadXml(xmlContent); nodes = document.SelectNodes("//appSettings/add"); if (nodes.Count < 1) { return(outputs); } foreach (XmlNode xmlNode1 in nodes) { string addr = xmlNode1.Attributes["value"].InnerText; if (addr.Contains("http")) { string name = xmlNode1.Attributes["key"].InnerText; outputs.Add(new KeyValuePair <string, string>(name, addr)); } } return(outputs); } catch (XmlException ex) { ExceptionHandler.XmlException(ex); XConsole.WriteLine(ex.ToString()); XConsole.WriteLine(siteName, Core.Ops.ConsoleTheming.ConsoleColorSetGreen.Instance); XConsole.WriteLine(xmlContent.Length.ToString(), Core.Ops.ConsoleTheming.ConsoleColorSetGreen.Instance); XConsole.WriteLine(xmlContent, Core.Ops.ConsoleTheming.ConsoleColorSetRed.Instance); return(null); } }