/// <summary> /// Creates new instance of WurmApiManager. /// All WurmApi services are thread safe and independent of execution context (i.e. synchronization context, async handling). /// Always call Dispose on the Manager, before closing app or dropping the instance. This will ensure proper cleanup and internal cache consistency. /// Not calling Dispose without terminating hosting process, may result in resource leaks. /// </summary> /// <param name="dataDirPath"> /// Directory path, where this instance of WurmApiManager can store data caches. Defaults to \WurmApi in the library DLL location. /// If relative path is provided, it will also be in relation to DLL location. /// </param> /// <param name="logger"> /// An optional implementation of ILogger, where all WurmApi errors and warnings can be forwarded. /// Defaults to no logging. /// Providing this parameter is highly is recommended. /// </param> /// <param name="eventMarshaller"> /// An optional event marshaller, used to marshal all events in a specific way (for example to GUI thread). /// Defaults to running events on ThreadPool threads. /// Providing this parameter will greatly simplify usage in any application, that has synchronization context. /// </param> /// <param name="installDirectory"> /// An optional Wurm Game Client directory path provider. /// Defaults to autodetection. /// </param> /// <param name="config"> /// Optional extra configuration options. /// </param> /// <returns></returns> public static IWurmApi Create(string dataDirPath = null, ILogger logger = null, IWurmApiEventMarshaller eventMarshaller = null, IWurmInstallDirectory installDirectory = null, WurmApiConfig config = null) { if (dataDirPath == null) { dataDirPath = "WurmApi"; } if (!Path.IsPathRooted(dataDirPath)) { var codebase = typeof(WurmApiFactory).Assembly.GetAssemblyDllDirectoryAbsolutePath(); dataDirPath = Path.Combine(codebase, dataDirPath); } if (logger == null) { logger = new LoggerStub(); } if (installDirectory == null) { installDirectory = new WurmInstallDirectory(); } if (config == null) { config = new WurmApiConfig(); } return new WurmApiManager(new WurmApiDataDirectory(dataDirPath, true), installDirectory, logger, eventMarshaller, config); }
private static Func <Ninject.Activation.IContext, IWurmApi> BuildWurmApiFactory(IKernel kernel) { return(context => { IWurmAssistantConfig config = kernel.Get <IWurmAssistantConfig>(); IWurmApiLoggerFactory loggerFactory = kernel.Get <IWurmApiLoggerFactory>(); IWurmApiEventMarshaller eventMarshaller = kernel.Get <IWurmApiEventMarshaller>(); IWurmAssistantDataDirectory wurmAssistantDataDirectory = kernel.Get <IWurmAssistantDataDirectory>(); if (string.IsNullOrWhiteSpace(config.WurmGameClientInstallDirectory)) { throw new InvalidOperationException("Unknown path to Wurm Game Client installation folder."); } IWurmClientInstallDirectory wurmInstallDirectory = new WurmInstallDirectoryOverride(config.WurmGameClientInstallDirectory); ServerInfoManager serverInfoManager = kernel.Get <ServerInfoManager>(); var wurmApiConfig = new WurmApiConfig { Platform = Platform.Windows, ClearAllCaches = config.DropAllWurmApiCachesToggle, WurmUnlimitedMode = config.WurmUnlimitedMode }; serverInfoManager.UpdateWurmApiConfigDictionary(wurmApiConfig.ServerInfoMap); var wurmApiDataDir = new DirectoryInfo(Path.Combine(wurmAssistantDataDirectory.DirectoryPath, "WurmApi")); var wurmApi = AldursLab.WurmApi.WurmApiFactory.Create( new WurmApiCreationOptions() { DataDirPath = wurmApiDataDir.FullName, WurmApiLogger = loggerFactory.Create(), WurmApiEventMarshaller = eventMarshaller, WurmClientInstallDirectory = wurmInstallDirectory, WurmApiConfig = wurmApiConfig }); config.DropAllWurmApiCachesToggle = false; var validator = new WurmClientValidator(wurmApi, config); if (!validator.SkipOnStart) { var issues = validator.Validate(); if (issues.Any()) { validator.ShowSummaryWindow(issues); } } return wurmApi; }); }
public void Setup() { wurmApiConfig = new WurmApiConfig {Platform = Platform.Linux}; system = new LogFileStreamReaderFactory(wurmApiConfig); ubuntuDir = TempDirectoriesFactory.CreateByUnzippingFile(Path.Combine(TestPaksZippedDirFullPath, "ubuntu-wurm-dir.7z")); sampleLogFilePath = Path.Combine(ubuntuDir.AbsolutePath, "players", "aldur", "logs", "_Event.2015-08.txt"); }
public void Setup() { wurmApiConfig = new WurmApiConfig { Platform = Platform.Linux }; system = new LogFileStreamReaderFactory(wurmApiConfig); ubuntuDir = TempDirectoriesFactory.CreateByUnzippingFile(Path.Combine(TestPaksZippedDirFullPath, "ubuntu-wurm-dir.7z")); sampleLogFilePath = Path.Combine(ubuntuDir.AbsolutePath, "players", "aldur", "logs", "_Event.2015-08.txt"); }
void ConstructWurmApi(IWurmAssistantConfig config, LoggerFactory loggerFactory, IEventMarshaller eventMarshaller) { IWurmInstallDirectory wurmInstallDirectory = null; if (!string.IsNullOrWhiteSpace(config.WurmGameClientInstallDirectory)) { wurmInstallDirectory = new WurmInstallDirectoryOverride() { FullPath = config.WurmGameClientInstallDirectory }; } WurmApiConfig wurmApiConfig = null; if (config.RunningPlatform != Platform.Unknown) { wurmApiConfig = new WurmApiConfig {Platform = config.RunningPlatform}; } wurmApi = WurmApiFactory.Create(Path.Combine(config.DataDirectoryFullPath, "WurmApi"), loggerFactory.CreateWithGuiThreadMarshaller("WurmApi"), eventMarshaller, wurmInstallDirectory, wurmApiConfig); kernel.Bind<IWurmApi>().ToConstant(wurmApi); }