private static void ProcessTypes() { m_Factions = new List <Faction>(); m_Towns = new List <Town>(); var asms = AssemblyHandler.Assemblies; for (var i = 0; i < asms.Length; ++i) { var asm = asms[i]; var tc = AssemblyHandler.GetTypeCache(asm); var types = tc.Types; for (var j = 0; j < types.Length; ++j) { var type = types[j]; if (type.IsSubclassOf(typeof(Faction))) { if (Construct(type) is Faction faction) { Faction.Factions.Add(faction); } } else if (type.IsSubclassOf(typeof(Town))) { if (Construct(type) is Town town) { Town.Towns.Add(town); } } } } }
private void Start() { try { label_runStatus.Text = "运行中..."; button_Start.Enabled = false; _clientControl = new ClientControl(10801, 10802); LogUtil.callback += msgCallback; (AssemblyHandler.GetInstance <CloseApp>() as CloseApp).callback += HideWindow; (AssemblyHandler.GetInstance <Uninstall>() as Uninstall).callback += Quit; //(AssemblyHandler.GetInstance<Uninstall>() as Uninstall).localUrl = Application.ExecutablePath; _clientControl.BeginReceive(); //创建自启快捷方式 //ToolForCmd.CreateShortcut(); } catch (Exception e) { LogUtil.Error(e); label_runStatus.Text = "error!!"; Stop(); } }
public static Type[] Match(string match) { var results = new HashSet <Type>(); Type[] types; var asms = AssemblyHandler.Assemblies; for (var i = 0; i < asms.Length; ++i) { types = AssemblyHandler.GetTypeCache(asms[i]).Types; Match(match, types, results); } types = AssemblyHandler.GetTypeCache(Core.Assembly).Types; Match(match, types, results); if (results.Count == 0) { return(Array.Empty <Type>()); } var finalResults = new Type[results.Count]; var index = 0; foreach (var t in results) { finalResults[index++] = t; } Array.Sort(finalResults, TypeNameComparer.Instance); return(finalResults); }
public static void SaveQuest_OnCommand(CommandEventArgs e) { Mobile m = e.Mobile; if (e.Length == 0 || e.Length > 2) { m.SendMessage("Syntax: SaveQuest <id> [saveEnabled=true]"); return; } Type index = AssemblyHandler.FindFirstTypeForName(e.GetString(0)); if (index == null || !Quests.TryGetValue(index, out MLQuest quest)) { m.SendMessage("Invalid quest type name."); return; } bool enable = e.Length == 2 ? e.GetBoolean(1) : true; quest.SaveEnabled = enable; m.SendMessage("Serialization for quest {0} is now {1}.", quest.GetType().Name, enable ? "enabled" : "disabled"); if (AutoGenerateNew && !enable) { m.SendMessage( "Please note that automatic generation of new quests is ON. This quest will be regenerated on the next server start."); } }
/// <summary> /// 根据反射读取协议dll,并生成协议解析源码 /// </summary> /// <param name="assemblyName"></param> public static string AssemblyParseDll(string assemblyName) { AssemblyHandler handler = new AssemblyHandler(); AssemblyResult result = handler.GetClassName(assemblyName); result.AssemblyNameList = new List <string>(); result.AssemblyNameList.Add(assemblyName); string strGenerateCode = GenerateCodeModel.GenerateCode(result.ClassList); //string codeFileName = "Client_Code.cs"; string codeFileName = ConstData.GenrateCodeFileName; try { string codeFileFullName = PathExt.codePath + ConstData.GenrateCodePathName + codeFileName; FileInfo fCodeFileName = new FileInfo(codeFileFullName); StreamWriter wResponseRecv = fCodeFileName.CreateText(); wResponseRecv.WriteLine(strGenerateCode); wResponseRecv.Close(); //codeFileFullName = PathExt.rootPath + ConstData.GenrateCodePathName + codeFileName; //fCodeFileName = new FileInfo(codeFileFullName); //wResponseRecv = fCodeFileName.CreateText(); //wResponseRecv.WriteLine(strGenerateCode); //wResponseRecv.Close(); } catch (System.Exception e) { Log.Error("e {0}", e.Message); } return(strGenerateCode); }
public override void ExecuteList(CommandEventArgs e, List <object> list) { var args = e.Arguments; if (args.Length <= 1) { LogFailure(Usage); return; } if (list.Count == 0) { LogFailure("No matching objects found."); return; } var name = args[0]; var type = AssemblyHandler.FindTypeByName(name); if (!IsEntity(type)) { LogFailure("No type with that name was found."); return; } var argSpan = e.ArgString.AsSpan(name.Length + 1); var setIndex = argSpan.InsensitiveIndexOf("set "); ReadOnlySpan <char> props = null; if (setIndex > -1) { var start = setIndex + 4; props = argSpan[start..];
public CategoryEntry(CategoryEntry parent, CategoryLine[] lines, ref int index) { Parent = parent; string text = lines[index].Text; int start = text.IndexOf('('); if (start < 0) { throw new FormatException($"Input string not correctly formatted ('{text}')"); } Title = text.Substring(0, start).Trim(); int end = text.IndexOf(')', ++start); if (end < start) { throw new FormatException($"Input string not correctly formatted ('{text}')"); } text = text.Substring(start, end - start); string[] split = text.Split(';'); List <Type> list = new List <Type>(); for (int i = 0; i < split.Length; ++i) { Type type = AssemblyHandler.FindTypeByName(split[i].Trim()); if (type == null) { Console.WriteLine("Match type not found ('{0}')", split[i].Trim()); } else { list.Add(type); } } Matches = list.ToArray(); list.Clear(); int ourIndentation = lines[index].Indentation; ++index; List <CategoryEntry> entryList = new List <CategoryEntry>(); while (index < lines.Length && lines[index].Indentation > ourIndentation) { entryList.Add(new CategoryEntry(this, lines, ref index)); } SubCategories = entryList.ToArray(); entryList.Clear(); Matched = new List <CategoryTypeEntry>(); }
public static Spell NewSpell(string name, Mobile caster, Item scroll) { name = name.Replace(" ", ""); for (var i = 0; i < m_CircleNames.Length; ++i) { var t = AssemblyHandler.FindFirstTypeForName($"Server.Spells.{m_CircleNames[i]}.{name}", true) ?? AssemblyHandler.FindFirstTypeForName($"Server.Spells.{m_CircleNames[i]}.{name}Spell", true); if (t?.IsSubclassOf(typeof(SpecialMove)) == false) { m_Params[0] = caster; m_Params[1] = scroll; try { return((Spell)ActivatorUtil.CreateInstance(t, m_Params)); } catch { // ignored } } } return(null); }
public static object ParseValue(Type type, string value) { try { if (IsEnum(type)) { return(Enum.Parse(type, value, true)); } if (IsType(type)) { return(AssemblyHandler.FindTypeByName(value)); } if (IsParsable(type)) { return(ParseParsable(type, value)); } object obj = value; if (value.StartsWithOrdinal("0x")) { if (IsSignedNumeric(type)) { obj = Convert.ToInt64(value[2..], 16);
public override bool ValidateArgs(BaseCommandImplementor impl, CommandEventArgs e) { if (e.Length >= 1) { Type t = AssemblyHandler.FindFirstTypeForName(e.GetString(0)); if (t == null) { e.Mobile.SendMessage("No type with that name was found."); string match = e.GetString(0).Trim(); if (match.Length < 3) { e.Mobile.SendMessage("Invalid search string."); e.Mobile.SendGump(new AddGump(e.Mobile, match, 0, Type.EmptyTypes, false)); } else { e.Mobile.SendGump(new AddGump(e.Mobile, match, 0, AddGump.Match(match).ToArray(), true)); } } else { return(true); } } else { e.Mobile.SendGump(new CategorizedAddGump(e.Mobile)); } return(false); }
public static SmallBulkEntry[] LoadEntries(string path) { path = Path.Combine(Core.BaseDirectory, path); var list = new List <SmallBulkEntry>(); if (File.Exists(path)) { using var ip = new StreamReader(path); string line; while ((line = ip.ReadLine()) != null) { if (line.Length == 0 || line.StartsWith("#")) { continue; } try { var split = line.Split('\t'); if (split.Length >= 2) { var type = AssemblyHandler.FindFirstTypeForName(split[0]); var graphic = Utility.ToInt32(split[^ 1]);
public BOBSmallEntry(IGenericReader reader) { int version = reader.ReadEncodedInt(); switch (version) { case 0: { string type = reader.ReadString(); if (type != null) { ItemType = AssemblyHandler.FindTypeByFullName(type); } RequireExceptional = reader.ReadBool(); DeedType = (BODType)reader.ReadEncodedInt(); Material = (BulkMaterialType)reader.ReadEncodedInt(); AmountCur = reader.ReadEncodedInt(); AmountMax = reader.ReadEncodedInt(); Number = reader.ReadEncodedInt(); Graphic = reader.ReadEncodedInt(); Price = reader.ReadEncodedInt(); break; } } }
public override Type Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType != JsonTokenType.String) { throw new JsonException("The JSON value could not be converted to System.Type"); } return(AssemblyHandler.FindFirstTypeForName(reader.GetString())); }
private IExecutorProvider CreateExecutorProvider(DbToolDatabase database, DbConnection connection, AssemblyHandler handler) { if (handler.HasType <IExecutorProvider>()) { return(handler.CreateInstance <IExecutorProvider>(_config, database, connection, _cSharpExecutor)); } return(new DefaultExecutorProvider(_config, database, connection, _cSharpExecutor)); }
public static void GetAsseblyResult(out AssemblyHandler handler, out AssemblyResult result) { //AssemblyHandler handler = new AssemblyHandler(); handler = new AssemblyHandler(); //AssemblyResult result = handler.GetClassName(ClientMsgDll); result = handler.GetClassName(ConstData.ServerMsgDll); result.AssemblyNameList = new List <string>(); result.AssemblyNameList.Add(ConstData.ServerMsgDll); }
public override IEnchantmentValue Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType != JsonTokenType.StartObject) { throw new JsonException(); } reader.Read(); if (reader.TokenType != JsonTokenType.PropertyName) { throw new JsonException(); } if (reader.GetString() != "Type") { throw new JsonException(); } reader.Read(); if (reader.TokenType != JsonTokenType.String) { throw new JsonException(); } var typeName = reader.GetString(); reader.Read(); if (reader.TokenType != JsonTokenType.PropertyName) { throw new JsonException(); } if (reader.GetString() != "Properties") { throw new JsonException(); } reader.Read(); if (reader.TokenType != JsonTokenType.StartObject) { throw new JsonException(); } var rawText = JsonDocument.ParseValue(ref reader).RootElement.GetRawText(); var obj = MessagePackSerializer.Deserialize( AssemblyHandler.FindTypeByName(typeName), MessagePackSerializer.ConvertFromJson(rawText, MessagePackOptions), MessagePackOptions ); while (reader.Read()) { if (reader.TokenType == JsonTokenType.EndObject) { return(obj as IEnchantmentValue); } } throw new JsonException(); }
private IExecutorProvider CreateExecutorProvider(DbToolDatabase database, DbConnection connection, AssemblyHandler handler) { if (handler.HasType<IExecutorProvider>()) { return handler.CreateInstance<IExecutorProvider>(_config, database, connection); } return new DefaultExecutorProvider(_config, database, connection); }
private static List <MdFileInfo> ScanFolderForAssemblies(string inputFolderPath, IEnumerable <string> filter, IEnumerable <string> referencePaths, SearchOption searchOption) { var allAssembliesFromInputFolder = Directory.GetFiles(inputFolderPath, "*.*", searchOption) .Where(x => x.EndsWith(".dll") || x.EndsWith(".ds")) .Select(x => new FileInfo(x)) .GroupBy(x => x.Name) .Select(x => x.FirstOrDefault()); var referenceDllPaths = new List <string>(); if (referencePaths != null) { referenceDllPaths = referencePaths .SelectMany(p => new DirectoryInfo(p) .EnumerateFiles("*.dll", SearchOption.AllDirectories) .Select(d => d.FullName) .Distinct()).ToList(); } if (filter.Any()) { // Filters the assemblies specified in the filter from allAssembliesFromInputFolder, // the assembly paths left after this filter are the ones that will be scanned for nodes. var assemblyPathsToScan = allAssembliesFromInputFolder .Where(x => filter.Contains(x.Name) || filter.Contains(x.FullName)) .Select(x => x.FullName); // We still need all assemblies in the inputFolderPath for the PathAssemblyResolver // so here we separate the assemblyPathsToScan from allAssembliesFromInputFolder // which gives us the additional assemblies that need to be added to the AssemblyResolveHandler var addtionalPathsToLoad = allAssembliesFromInputFolder .Select(x => x.FullName) .Except(assemblyPathsToScan) .ToList(); // If there are any paths specified in the referencePaths we need to add them // to addtionalPathsToLoad as the AssemblyResolveHandler will need them to resolve types. if (referenceDllPaths.Any()) { addtionalPathsToLoad.AddRange(referenceDllPaths); } return(AssemblyHandler.ScanAssemblies(assemblyPathsToScan, addtionalPathsToLoad)); } // If there are no filters specified we want to scan all assemblies in the inputFolderPath // and still add any referencePaths to the AssemblyResolveHandler return(AssemblyHandler. ScanAssemblies(allAssembliesFromInputFolder.Select(x => x.FullName), referenceDllPaths)); }
public override void ExecuteList(CommandEventArgs e, List <object> list) { var args = e.Arguments; if (args.Length <= 1) { LogFailure(Usage); return; } if (list.Count == 0) { LogFailure("No matching objects found."); return; } var name = args[0]; var type = AssemblyHandler.FindTypeByName(name); if (!Add.IsEntity(type)) { LogFailure("No type with that name was found."); return; } var argSpan = e.ArgString.AsSpan(name.Length + 1); var setIndex = argSpan.InsensitiveIndexOf("set "); ReadOnlySpan <char> props = null; if (setIndex > -1) { var start = setIndex + 4; props = argSpan.Slice(start, argSpan.Length - start); argSpan = argSpan.SliceToLength(setIndex); } var argStr = argSpan.ToString().DefaultIfNullOrEmpty(null); var propsStr = props.ToString().DefaultIfNullOrEmpty(null); e.Mobile.SendMessage("Updating spawners..."); foreach (var obj in list) { if (obj is BaseSpawner spawner) { UpdateSpawner(spawner, name, argStr, propsStr); } } e.Mobile.SendMessage("Update completed."); }
/// <summary> /// 运行指定的计划 /// </summary> /// <param name="schedule">jobId</param> /// <returns></returns> public async Task <QuartzResult> RunScheduleJob(Scheduler schedule) { QuartzResult result; if (!this.Scheduler.Result.IsStarted) { await this.Scheduler.Result.Start(); } var runResult = await Task.Factory.StartNew(async() => { var tempResult = new QuartzResult(); try { string _AssemblyName = AppDomain.CurrentDomain.BaseDirectory + schedule.AssemblyName; var jobType = AssemblyHandler.GetClassType(_AssemblyName, schedule.ClassName); //反射获取任务执行类 IJobDetail job = new JobDetailImpl(schedule.JobName, schedule.JobGroup, jobType); // 定义这个工作,并将其绑定到IJob实现类 ITrigger trigger = CreateCronTrigger(schedule); // 创建触发器 await this.Scheduler.Result.ScheduleJob(job, trigger); // 告诉Quartz使用我们的触发器来安排作业 tempResult.Code = 1000; ScheduleList.Add(schedule); } catch (Exception ex) { tempResult.Code = 1001; tempResult.Msg = ex.Message; } return(tempResult); }); if (runResult.Result.Code == 1000) { await this.Scheduler.Result.ResumeJob(new JobKey(schedule.JobName, schedule.JobGroup)); //用给定的密钥恢复(取消暂停)IJobDetail result = new QuartzResult { Code = 1000, Msg = "启动成功" }; } else { result = new QuartzResult { Code = -1 }; } return(result); }
public static object ParseValue(Type type, string value) { try { if (IsEnum(type)) { return(Enum.Parse(type, value, true)); } if (IsType(type)) { return(AssemblyHandler.FindTypeByName(value)); } if (IsParsable(type)) { return(ParseParsable(type, value)); } object obj = value; if (value.StartsWithOrdinal("0x")) { if (IsSignedNumeric(type)) { obj = Convert.ToInt64(value.Substring(2), 16); } else if (IsUnsignedNumeric(type)) { obj = Convert.ToUInt64(value.Substring(2), 16); } else { obj = Convert.ToInt32(value.Substring(2), 16); } } if (obj == null && !type.IsValueType) { return(null); } return(Convert.ChangeType(obj, type)); } catch { return(null); } }
public static MLQuest ReadQuestRef(IGenericReader reader) { string typeName = reader.ReadString(); if (typeName == null) { return(null); // not serialized } Type questType = AssemblyHandler.FindTypeByFullName(typeName); if (questType == null) { return(null); // no longer a type } return(FindQuest(questType)); }
public LargeBulkEntry(LargeBOD owner, IGenericReader reader) { Owner = owner; m_Amount = reader.ReadInt(); Type realType = null; var type = reader.ReadString(); if (type != null) { realType = AssemblyHandler.FindFirstTypeForName(type); } Details = new SmallBulkEntry(realType, reader.ReadInt(), reader.ReadInt()); }
private void init() { List <IAccept> acs = AssemblyHandler.CreateInstance <IAccept>(); foreach (IAccept ac in acs) { this.receiveMsgCallBack += ac.acceptMessage; } List <IClient> cls = AssemblyHandler.CreateInstance <IClient>(); foreach (IClient cl in cls) { cl.init(this); } }
public override Type Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType != JsonTokenType.String) { throw new JsonException("The JSON value could not be converted to System.Type"); } var typeName = reader.GetString(); var type = AssemblyHandler.FindTypeByName(typeName); if (type == null) { Console.WriteLine("Invalid type {0} deserialized", typeName); } return AssemblyHandler.FindTypeByName(reader.GetString()); }
public override Type Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType != JsonTokenType.String) { throw new JsonException("The JSON value could not be converted to System.Type"); } var typeName = reader.GetString(); var type = AssemblyHandler.FindTypeByName(typeName); if (type == null) { logger.Warning("Attempted to deserialize type {Type} which does not exist.", typeName); } return(type); }
public void CanScanAssemblyFromPath() { // Arrange var assemblyPath = Path.Combine(DynamoCoreNodesDir, CORENODEMODELS_DLL_NAME); var coreNodeModelMdFilesDir = new DirectoryInfo(Path.Combine(toolsTestFilesDirectory, "TestMdOutput_CoreNodeModels")); var coreNodeModelMdFiles = coreNodeModelMdFilesDir.GetFiles(); // Act var mdFileInfos = AssemblyHandler.ScanAssemblies(new List <string> { assemblyPath }); // Assert Assert.IsTrue(coreNodeModelMdFiles.Count() == mdFileInfos.Count); AssertMdFileInfos(mdFileInfos, coreNodeModelMdFiles); }
private static void AddAutoMapper(IProfileRegistry profileRegistry) { var profiles = AssemblyHandler.GetProfileTypes(); var mapperConfiguration = new MapperConfiguration( cfg => { foreach (var profile in profiles) { cfg.AddProfile(profile); } }); var mapper = mapperConfiguration.CreateMapper(); profileRegistry.For <IMapper>().Use(mapper); }
public CAGObject(CAGCategory parent, XmlTextReader xml) { Parent = parent; if (xml.MoveToAttribute("type")) { Type = AssemblyHandler.FindFirstTypeForName(xml.Value, false); } if (xml.MoveToAttribute("gfx")) { ItemID = XmlConvert.ToInt32(xml.Value); } if (xml.MoveToAttribute("hue")) { Hue = XmlConvert.ToInt32(xml.Value); } }
public static string AssemblyParseDll(string assemblyName, out AssemblyResult result) { AssemblyHandler handler = new AssemblyHandler(); result = handler.GetClassName(assemblyName); result.AssemblyNameList = new List <string>(); result.AssemblyNameList.Add(assemblyName); string strGenerateCode = GenerateCodeModel.GenerateCode(result.ClassTypeList); string codeFileName = "GateServer_Code.cs"; string codeFileFullName = @"..\..\Libs\ClientLib\" + codeFileName; FileInfo fCodeFileName = new FileInfo(codeFileFullName); StreamWriter wResponseRecv = fCodeFileName.CreateText(); wResponseRecv.WriteLine(strGenerateCode); wResponseRecv.Close(); return(strGenerateCode); }
private void MainForm_Load(object sender, EventArgs e) { var height = Height; var width = Width; MinimumSize = new Size(width, height); MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, height); AssemblyHandler handler = new AssemblyHandler(); mAssemblyResult = handler.GetClassName(protocolMsgDllName); foreach (var item in mAssemblyResult.ClassTypeList) { if (item.Key.Contains("Protocol") && item.Key.Contains("MSG_C2G")) { comboBox_ProtocolName.Items.Add(item.Value.Name); } } InitApi(); }