private async Task <string> HandleLuisRoot(string command, string language) { var handler = new RootHandler(_luisConfigurations); var result = await handler.HandleTextAsync(command, language); Console.WriteLine($"It was a {result} thought."); return(result); }
public TelegramService(RootHandler handler, CallbackHandler cbHandler) { _handler = handler; _cbHandler = cbHandler; //init _client = new TelegramBotClient("1679074026:AAHjWMmSNrqdElgxJAHbvAYb69sk7XgQs8Y"); //listeners _client.OnMessage += OnMessageReceived; _client.OnCallbackQuery += OnCallbackReceived; }
public void RootHandlerRunReturnsRootView() { var handler = new RootHandler(); var result = handler.Run(); Assert.AreEqual(typeof(RootView), result.GetType()); var view = (RootView)result; Assert.AreEqual(2, view.Contexts.Count); Assert.AreEqual("ContextTest1", view.Contexts[0].Name); Assert.AreEqual("ContextTest2", view.Contexts[1].Name); }
public override void Work() { EventManager.Trigger_CASCLoadStart(); if (Program.CASCEngine != null) { Program.CASCEngine.Clear(); Program.CASCEngine = null; } try { // Clear existing cache. if (Directory.Exists(Constants.TEMP_DIRECTORY)) { Directory.Delete(Constants.TEMP_DIRECTORY, true); } } catch { Log.Write("Notice: Unable to delete all temporary directories/files. Something has it open."); } try { Directory.CreateDirectory(Constants.TEMP_DIRECTORY); CASCEngine engine = Program.Settings.UseRemote ? CASCEngine.OpenOnlineStorage() : CASCEngine.OpenLocalStorage(); RootHandler handler = engine.RootHandler; handler.LoadListFile(Constants.LIST_FILE); Program.Root = handler.SetFlags(Locale.GetUserLocale().Flags, ContentFlags.None); handler.MergeInstall(engine.Install); Program.CASCEngine = engine; EventManager.Trigger_LoadStepDone(); Done(true); } catch (Exception ex) { Program.CASCEngine = null; Log.Write("Error prevented CASC engine loading: " + ex.Message); Log.Write(ex.StackTrace); Done(false); } }
/// <summary> /// Initializes a new instance of the <see cref="RootCommand"/> class. /// </summary> public RootCommand() : base() { this.Command = new System.CommandLine.RootCommand() { Description = "A multi-platform, command line interface, checksum utility", Handler = CommandHandler.Create( (RootArguments args, IConsole console) => RootHandler.Handle(args, console)), }; this.AddCommandArguments(); this.AddCommandOptions(); this.AddCommandValidators(); }
public static void OpenRoot(LocaleFlags locale, uint minimumid = 0, bool onlineListfile = false) { Logger.LogInformation("Loading Root..."); var rootkey = BuildConfig.GetKey("root"); if (!EncodingHandler.CEKeys.TryGetValue(rootkey, out EncodingCEKeyPageTable enc)) { Logger.LogCritical($"Encoding missing Root {rootkey.ToString()}"); return; } LocalIndexEntry idxInfo = LocalIndexHandler?.GetIndexInfo(enc.EKeys[0]); if (idxInfo != null) { var path = Path.Combine(BasePath, "Data", "data", string.Format("data.{0:D3}", idxInfo.Archive)); RootHandler = new RootHandler(DataHandler.Read(path, idxInfo), locale, minimumid, onlineListfile); } else { string key = enc.EKeys[0].ToString(); string path = Path.Combine(Settings.SystemFilesPath, key); path = Helper.FixOutputPath(path, "data"); if (!File.Exists(path)) { string url = "/data/" + key.Substring(0, 2) + "/" + key.Substring(2, 2) + "/" + key; if (!DataHandler.Download(url, path)) { Logger.LogCritical($"Unable to download Root {key}."); } } RootHandler = new RootHandler(DataHandler.ReadDirect(path), locale, minimumid, onlineListfile); } }
public static void Close() { RootHandler?.NewFiles.Clear(); Settings = null; BuildInfo = null; Versions = null; CDNs = null; BuildConfig = null; CDNConfig = null; LocalIndexHandler = null; CDNIndexHandler = null; DownloadHandler = null; InstallHandler = null; EncodingHandler?.Dispose(); RootHandler?.Dispose(); // force GC GC.Collect(); GC.WaitForPendingFinalizers(); }
/// <summary> /// The default Constructor. /// </summary> /// <param name="path"></param> public WebScriptingServer(string path) { _path = path; _server = new HttpCwsServer(path); _server.Register(); Debug.WriteSuccess("HttpCwsServer", "Started for path: {0}", _path); Debug.WriteInfo("HttpCwsServer", "Base URL: {0}", BaseUrlDns); Debug.WriteInfo("HttpCwsServer", "Base URL: {0}", BaseUrlIp); _server.ReceivedRequestEvent += (sender, args) => { #if DEBUG CrestronConsole.PrintLine("Incoming http request from {0} {1}", args.Context.Request.UserHostAddress, args.Context.Request.UserHostName); CrestronConsole.PrintLine("Request AbsolutePath: {0}", args.Context.Request.Url.AbsolutePath); CrestronConsole.PrintLine("Request AbsoluteUri: {0}", args.Context.Request.Url.AbsoluteUri); CrestronConsole.PrintLine("Request PhysicalPath: {0}", args.Context.Request.PhysicalPath); CrestronConsole.PrintLine("Request PathAndQuery: {0}", args.Context.Request.Url.PathAndQuery); CrestronConsole.PrintLine("Request Query: {0}", args.Context.Request.Url.Query); CrestronConsole.PrintLine("Request Path: {0}", args.Context.Request.Path); CrestronConsole.PrintLine("Request Method: {0}", args.Context.Request.HttpMethod); #endif try { if (args.Context.Request.RouteData != null) { #if DEBUG CrestronConsole.PrintLine("Request handler: {0}", args.Context.Request.RouteData.RouteHandler.GetType()); CrestronConsole.PrintLine("Route URL Pattern: {0}", args.Context.Request.RouteData.Route.Url); #endif } else if (RootHandler == null) { #if DEBUG CrestronConsole.PrintLine("Request has no handler!"); #endif HandleError(args.Context, 404, "Not Found", "The requested resource does not exist"); } else if (args.Context.Request.PhysicalPath != string.Format("\\HTML\\{0}", _path) && args.Context.Request.PhysicalPath != string.Format("\\HTML\\{0}\\", _path)) { #if DEBUG CrestronConsole.PrintLine("Request handler: {0}", RootHandler.GetType()); #endif RootHandler.ProcessRequest(args.Context); } } catch (Exception e) { CloudLog.Exception("Error in ApiServer main request handler", e); HandleError(args.Context, 500, "Server Error", string.Format("{0}<BR>{1}", e.Message, e.StackTrace)); } }; CrestronEnvironment.ProgramStatusEventHandler += type => { if (type == eProgramStatusEventType.Stopping) { _server.Dispose(); } }; }
public static void Save() { Settings.Cache?.Clean(); //Patch exe //Patcher.Run("http://" + CASContainer.Settings.Host); // Entries var entries = SaveEntries().Result; // CDN Archives Settings.Logger.LogInformation("Starting CDN Index."); CDNIndexHandler?.CreateArchive(entries); // Root Settings.Logger.LogInformation("Starting Root."); foreach (var entry in entries) { RootHandler.AddEntry(entry.Path, entry); } entries.Add(RootHandler.Write()); //Add to entry list // Download if (DownloadHandler != null) { Settings.Logger.LogInformation("Starting Download."); foreach (var entry in entries) { DownloadHandler.AddEntry(entry); } entries.Add(DownloadHandler.Write()); //Add to entry list } if (InstallHandler != null) { Settings.Logger.LogInformation("Starting Install."); var installManifest = InstallHandler.Write(entries); if (installManifest != null) { entries.Add(installManifest); //Add to entry list } } // Encoding Settings.Logger.LogInformation("Starting Encoding."); foreach (var entry in entries) { EncodingHandler.AddEntry(entry); } entries.Insert(0, EncodingHandler.Write()); Settings.Logger.LogInformation("Starting Configs."); // CDN Config CDNConfig.Remove("archive-group"); CDNConfig.Remove("patch-archives"); CDNConfig.Remove("patch-archive-group"); // Build Config BuildConfig.Set("patch", ""); BuildConfig.Set("patch-size", "0"); BuildConfig.Set("patch-config", ""); string buildconfig = BuildConfig.Write(); string cdnconfig = CDNConfig.Write(); string version = BuildInfo["Version"]; // Build Info - redundant BuildInfo["Build Key"] = buildconfig; BuildInfo["CDN Key"] = cdnconfig; BuildInfo["CDN Hosts"] = string.Join(" ", Settings.CDNs); BuildInfo.Write(); // CDNs file CDNs["Hosts"] = string.Join(" ", Settings.CDNs); CDNs.Write(); // Versions file Versions["BuildConfig"] = buildconfig; Versions["CDNConfig"] = cdnconfig; Versions["VersionsName"] = version; Versions["BuildId"] = version.Split('.').Last(); Versions.Write(); // Done! Logger.LogInformation("CDN Config: " + cdnconfig); Logger.LogInformation("Build Config: " + buildconfig); // update Cache files Settings.Cache?.Save(); // cleanup entries.Clear(); entries.TrimExcess(); Close(); }
private CASCHandler(CASCConfig config, ProgressReportSlave worker) { Config = config; if (!config.OnlineMode) { Debugger.Log(0, "CASC", "CASCHandler: loading local indices\r\n"); using (PerfCounter _ = new PerfCounter("LocalIndexHandler.Initialize()")) { LocalIndex = LocalIndexHandler.Initialize(config, worker); } Debugger.Log(0, "CASC", $"CASCHandler: loaded {LocalIndex.Count} local indices\r\n"); } else // todo: supposed to do this? { Debugger.Log(0, "CASC", "CASCHandler: loading CDN indices\r\n"); using (PerfCounter _ = new PerfCounter("CDNIndexHandler.Initialize()")) { CDNIndex = CDNIndexHandler.Initialize(config, worker, Cache); } Debugger.Log(0, "CASC", $"CASCHandler: loaded {CDNIndex.Count} CDN indexes\r\n"); } Debugger.Log(0, "CASC", "CASCHandler: loading encoding entries\r\n"); using (PerfCounter _ = new PerfCounter("new EncodingHandler()")) { using (BinaryReader encodingReader = OpenEncodingKeyFile()) { EncodingHandler = new EncodingHandler(encodingReader, worker); } } Debugger.Log(0, "CASC", $"CASCHandler: loaded {EncodingHandler.Count} encoding entries\r\n"); Debugger.Log(0, "CASC", "CASCHandler: loading root data\r\n"); using (PerfCounter _ = new PerfCounter("new RootHandler()")) { using (BinaryReader rootReader = OpenRootKeyFile()) { RootHandler = new RootHandler(rootReader, worker, this); } } //if ((CASCConfig.LoadFlags & LoadFlags.Download) != 0) //{ // Debugger.Log(0, "CASC", "CASCHandler: loading download data\r\n"); // using (var _ = new PerfCounter("new DownloadHandler()")) // { // using (BinaryReader fs = OpenDownloadFile(EncodingHandler)) // DownloadHandler = new DownloadHandler(fs, worker); // } // Debugger.Log(0, "CASC", $"CASCHandler: loaded {EncodingHandler.Count} download data\r\n"); //} //if ((CASCConfig.LoadFlags & LoadFlags.Install) != 0) { // Debugger.Log(0, "CASC", "CASCHandler: loading install data\r\n"); // using (var _ = new PerfCounter("new InstallHandler()")) // { // using (var fs = OpenInstallFile(EncodingHandler)) // InstallHandler = new InstallHandler(fs, worker); // InstallHandler.Print(); // } // Debugger.Log(0, "CASC", $"CASCHandler: loaded {InstallHandler.Count} install data\r\n"); //} }
private static void Main() { AppDomain.CurrentDomain.UnhandledException += ExceptionHandler; Process.GetCurrentProcess().EnableRaisingEvents = true; AppDomain.CurrentDomain.ProcessExit += (sender, @event) => Console.ForegroundColor = ConsoleColor.Gray; Console.CancelKeyPress += (sender, @event) => Console.ForegroundColor = ConsoleColor.Gray; Console.OutputEncoding = Encoding.UTF8; Files = new Dictionary <ulong, ApplicationPackageManifest.Types.PackageRecord>(); TrackedFiles = new Dictionary <ushort, HashSet <ulong> >(); #region Tool Detection HashSet <Type> tools = new HashSet <Type>(); { Assembly asm = typeof(ITool).Assembly; Type t = typeof(ITool); List <Type> types = asm.GetTypes().Where(tt => tt != t && t.IsAssignableFrom(tt)).ToList(); foreach (Type tt in types) { ToolAttribute attrib = tt.GetCustomAttribute <ToolAttribute>(); if (tt.IsInterface || attrib == null) { continue; } tools.Add(tt); if (attrib.TrackTypes == null) { continue; } foreach (ushort type in attrib.TrackTypes) { if (!TrackedFiles.ContainsKey(type)) { TrackedFiles[type] = new HashSet <ulong>(); } } } } #endregion Flags = FlagParser.Parse <ToolFlags>(() => PrintHelp(tools)); if (Flags == null) { return; } //Logger.EXIT = !Flags.GracefulExit; ITool targetTool = null; ICLIFlags targetToolFlags = null; #region Tool Activation foreach (Type type in tools) { ToolAttribute attrib = type.GetCustomAttribute <ToolAttribute>(); if (!string.Equals(attrib.Keyword, Flags.Mode, StringComparison.InvariantCultureIgnoreCase)) { continue; } targetTool = Activator.CreateInstance(type) as ITool; if (attrib.CustomFlags != null) { Type flags = attrib.CustomFlags; if (typeof(ICLIFlags).IsAssignableFrom(flags)) { targetToolFlags = typeof(FlagParser).GetMethod(nameof(FlagParser.Parse), new Type[] { }).MakeGenericMethod(flags).Invoke(null, null) as ICLIFlags; } } break; } #endregion if (targetTool == null) { FlagParser.Help <ToolFlags>(false); PrintHelp(tools); if (Debugger.IsAttached) { Debugger.Break(); } return; } TankLib.Helpers.Logger.Info("Core", $"{Assembly.GetExecutingAssembly().GetName().Name} v{TankLib.Util.GetVersion(typeof(Program).Assembly)}"); TankLib.Helpers.Logger.Info("Core", $"CommandLine: [{string.Join(", ", Environment.GetCommandLineArgs().Skip(1).Select(x => $"\"{x}\""))}]"); #region Initialize CASC if (Flags.Language != null) { TankLib.Helpers.Logger.Info("CASC", $"Set language to {Flags.Language}"); } if (Flags.SpeechLanguage != null) { TankLib.Helpers.Logger.Info("CASC", $"Set speech language to {Flags.SpeechLanguage}"); } CASCHandler.Cache.CacheAPM = Flags.UseCache; CASCHandler.Cache.CacheCDN = Flags.UseCache; CASCHandler.Cache.CacheCDNData = Flags.CacheData; Config = CASCConfig.LoadFromString(Flags.OverwatchDirectory, Flags.SkipKeys); Config.SpeechLanguage = Flags.SpeechLanguage ?? Flags.Language ?? Config.SpeechLanguage; Config.TextLanguage = Flags.Language ?? Config.TextLanguage; if (Config != null) { if (Flags.Language != null && !Config.InstallData.Settings.Languages.Select(x => x.Language).Contains(Flags.Language)) { TankLib.Helpers.Logger.Warn("Core", "Battle.Net Agent reports that language {0} is not installed.", Flags.Language); } if (Config.InstallData.Uid != "prometheus") { TankLib.Helpers.Logger.Warn("Core", $"The branch \"{Config.InstallData.Uid}\" is not supported!. This might result in failure to load. Proceed with caution."); } } #endregion BuildVersion = uint.Parse(Config.BuildVersion.Split('.').Last()); if (BuildVersion < 39028) { TankLib.Helpers.Logger.Error("Core", "DataTool doesn't support Overwatch versions below 1.14. Please use OverTool"); } else if (BuildVersion < 39241) { TankLib.Helpers.Logger.Error("Core", "DataTool doesn't support this 1.14 release as it uses unmangeled hashes"); } else if (BuildVersion < 49154) { TankLib.Helpers.Logger.Error("Core", "This version of DataTool doesn't properly support versions below 1.26. Please downgrade DataTool."); } TankLib.Helpers.Logger.Info("Core", $"Using Overwatch Version {Config.BuildVersion}"); TankLib.Helpers.Logger.Info("CASC", "Initializing..."); CASC = CASCHandler.Open(Config); Root = CASC.RootHandler; //if (Root== null) { // ErrorLog("Not a valid overwatch installation"); // return; //} if (Config.InstallData != null) { } // Fail when trying to extract data from a specified language with 2 or less files found. if (!Root.APMFiles.Any()) { TankLib.Helpers.Logger.Error("Core", "Unable to load APM files for language {0}. Please confirm that you have that language installed.", Flags.Language); return; } TankLib.Helpers.Logger.Info("Core", "Mapping storage"); TrackedFiles[0x90] = new HashSet <ulong>(); IO.MapCMF(); IO.LoadGUIDTable(); Sound.WwiseBank.GetReady(); //foreach (KeyValuePair<ushort, HashSet<ulong>> type in TrackedFiles.OrderBy(x => x.Key)) { // //Console.Out.WriteLine($"Found type: {type.Key:X4} ({type.Value.Count} files)"); // Console.Out.WriteLine($"Found type: {type.Key:X4}"); //} #region Key Detection if (!Flags.SkipKeys) { TankLib.Helpers.Logger.Info("Core", "Checking ResourceKeys"); foreach (ulong key in TrackedFiles[0x90]) { if (!ValidKey(key)) { continue; } using (Stream stream = IO.OpenFile(Files[key])) { if (stream == null) { continue; } STUResourceKey resourceKey = GetInstance <STUResourceKey>(key); if (resourceKey == null || resourceKey.GetKeyID() == 0 || TACTKeyService.Keys.ContainsKey(resourceKey.GetReverseKeyID())) { continue; } TACTKeyService.Keys.Add(resourceKey.GetReverseKeyID(), resourceKey.m_key); TankLib.Helpers.Logger.Info("Core", $"Added ResourceKey {resourceKey.GetKeyIDString()}, Value: {resourceKey.GetKeyValueString()}"); } } } #endregion Stopwatch stopwatch = new Stopwatch(); TankLib.Helpers.Logger.Info("Core", "Tooling..."); var dbPath = Flags.ScratchDBPath; if (Flags.Deduplicate) { TankLib.Helpers.Logger.Warn("ScratchDB", "Will attempt to deduplicate files if extracting..."); if (!string.IsNullOrWhiteSpace(Flags.ScratchDBPath)) { TankLib.Helpers.Logger.Warn("ScratchDB", "Loading deduplication database..."); if (!File.Exists(dbPath)) { dbPath = Path.Combine(Path.GetFullPath(Flags.ScratchDBPath), "Scratch.db"); } SaveLogic.Combo.ScratchDBInstance.Load(dbPath); } } stopwatch.Start(); targetTool.Parse(targetToolFlags); stopwatch.Stop(); TankLib.Helpers.Logger.Success("Core", $"Execution finished in {stopwatch.Elapsed} seconds"); if (Flags.Deduplicate && !string.IsNullOrWhiteSpace(dbPath)) { TankLib.Helpers.Logger.Warn("ScratchDB", "Saving deduplication database..."); SaveLogic.Combo.ScratchDBInstance.Save(dbPath); } if (Debugger.IsAttached) { Debugger.Break(); } }