public async Task MainAsync() { //idk commands = new Dictionary <string, Command>(); var eee = ReflectiveEnumerator.GetEnumerableOfType <Command>(); foreach (var command in eee) { commands.Add(command.commandname, command); } if (File.Exists(@"test.bin")) { Stream stream = new FileStream(@"test.bin", FileMode.Open, FileAccess.Read); IFormatter formatter = new BinaryFormatter(); #pragma warning disable SYSLIB0011 // Type or member is obsolete db = (DiscordDatabase)formatter.Deserialize(stream); //get f****d ms #pragma warning restore SYSLIB0011 // Type or member is obsolete } else { db = new DiscordDatabase(); db.Servers = new Dictionary <ulong, DiscordServer>(); } _client = new DiscordSocketClient(); _client.Log += Log; _client.MessageReceived += MessageReceivedAsync; String tok = File.ReadAllText("Token.txt"); await _client.LoginAsync(TokenType.Bot, tok); await _client.StartAsync(); // Block this task until the program is closed. await Task.Delay(-1); }
/// <summary> /// Caches the languages /// </summary> private static void CacheLanguages() { if (_cachedLanguages == null || _cachedLanguages.Count == 0) { _cachedLanguages = ReflectiveEnumerator.GetEnumerableOfType <Language>().ToList(); } }
/// <summary> /// Caches the character races /// </summary> private static void CacheRaces() { if (_cachedRaces == null || _cachedRaces.Count == 0) { _cachedRaces = ReflectiveEnumerator.GetEnumerableOfType <RaceBase>().ToList(); } }
public async Task GetChancesAsync(CommandContext ctx) { List <WheelOutcome> wheelOutcomes = ReflectiveEnumerator.GetEnumerableOfType <WheelOutcome>(SlaveReportsExtension.Outcome.Task) .ToList(); DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); builder.WithDescription( "I've compiled the current List of Chances. First, you'll see a List of Modules (Sabrina.Entities.WheelOutcomes.XXX).\n" + "Under the Module Titles for each of these, is a freshly generated example, under that, you'll see the Chance for this to be chosen.\n" + "The Bot will add all Chance Values, and then generate a Random Number, to determine which Module will be chosen.\n\n" + string.Empty + "Under that, you'll see the Chances for what the chosen Module will output at the end.\n" + "If the Module does not have a fitting response (Ban can never end in an o****m for example), it will be ignored."); foreach (var wheelOutcome in wheelOutcomes) { builder.AddField( wheelOutcome.ToString(), "``" + wheelOutcome.Text + "``\n" + wheelOutcome.Chance); } // builder.AddField("Task", OrgasmWheel.TaskChance.ToString(), true); // builder.AddField("Denial", OrgasmWheel.DenialChance.ToString(), true); // builder.AddField("Ruin", OrgasmWheel.RuinChance.ToString(), true); // builder.AddField("O****m", OrgasmWheel.OrgasmChance.ToString(), true); await ctx.RespondAsync(embed : builder.Build()); }
public CommandFactory() { Commands = new List <Command>(); // Check to see if plugins folder exists, then try loading if (Directory.Exists($"{AppDomain.CurrentDomain.BaseDirectory}plugins")) { ConsoleHelper.WriteLine("Plugins folder found, attempting to load..."); var directoryInfo = new DirectoryInfo($"{AppDomain.CurrentDomain.BaseDirectory}plugins"); int pluginCount = 0; foreach (var plugin in directoryInfo.GetFiles("*.dll")) { var DLL = Assembly.LoadFile(plugin.FullName); foreach (Type type in DLL.GetExportedTypes().Where(x => typeof(Command).IsAssignableFrom(x))) { var c = Activator.CreateInstance(type) as Command; Commands.Add(c); } pluginCount++; } ConsoleHelper.WriteLine($"Added {pluginCount} plugin(s)."); } var commandsEnum = ReflectiveEnumerator.GetEnumerableOfType <Command>(); foreach (Command c in commandsEnum) { Commands.Add(c); } ConsoleHelper.WriteLine($"Added {Commands.Count} command(s)."); }
/// <summary> /// Caches the character abilities /// </summary> private static void CacheAbilities() { if (_cachedAbilities == null || _cachedAbilities.Count == 0) { _cachedAbilities = ReflectiveEnumerator.GetEnumerableOfType <AbilityBase>(0).ToList(); } }
static AbstractItemAspect() { var aspects = ReflectiveEnumerator.GetEnumerableOfType <AbstractItemAspect>().ToList(); foreach (var item in aspects) { AvailableAspects.Add(item); } }
public static IEnumerable <IArmouryProtocolKB> Find() { foreach (IArmouryProtocolKB currentKBInstance in ReflectiveEnumerator.GetEnumerableOfType <IArmouryProtocolKB>()) { if (currentKBInstance.DoesExistOnSystem()) { yield return(currentKBInstance); } } }
private async Task <WheelOutcome> GetWheelOutcome(DiscordContext context, Users user, UserSetting.Outcome outcome) { WheelOutcome wheelOutcome = null; var userItems = await WheelItemExtension.GetUserItemsAsync(user.UserId, context); while (wheelOutcome == null) { try { wheelOutcomes = ReflectiveEnumerator.GetEnumerableOfType <WheelOutcome>(outcome, UserSetting.GetAllSettings(user.UserId, context).ToDictionary(setting => (UserSetting.SettingID)setting.SettingId), userItems, _services) .ToList(); } catch (Exception e) { Console.WriteLine(e); } foreach (var wheeloutcome in wheelOutcomes) { await wheeloutcome.BuildAsync(); } wheelOutcomes = wheelOutcomes.Where(e => !e.Outcome.HasFlag(UserSetting.Outcome.NotSet)).ToList(); if (wheelOutcomes.Count < 1) { continue; } // Choose an outcome by summing up the chance values of all possible outcomes and // then generating a random number inside those. var combinedChance = 0; foreach (WheelOutcome currentOutcome in wheelOutcomes) { combinedChance += currentOutcome.Chance; } var chance = 0; var minChance = Helpers.RandomGenerator.RandomInt(0, combinedChance); foreach (WheelOutcome currentOutcome in wheelOutcomes) { chance += currentOutcome.Chance; if (minChance < chance) { wheelOutcome = currentOutcome; break; } } } return(wheelOutcome); }
public SceneManager(Game game) { this._game = game; IEnumerable <Scene> scenes = ReflectiveEnumerator.GetEnumerableOfType <Scene>(); foreach (Scene testt in scenes) { Console.WriteLine(testt.name); } this._scenes = scenes; }
public CommandFactory() { Commands = new List <Command>(); var commandsEnum = ReflectiveEnumerator.GetEnumerableOfType <Command>(); foreach (Command c in commandsEnum) { Commands.Add(c); } }
public SceneManager(Game gamee) { this.game = gamee; IEnumerable <Scene> test = ReflectiveEnumerator.GetEnumerableOfType <Scene>(); foreach (Scene testt in test) { Console.WriteLine(testt.name); } scenes = test; }
public static void Main() { var sabtReqID = 0; var myCase = ReflectiveEnumerator.GetEnumerableOfType <Case>().FirstOrDefault(c => c.Id == sabtReqID); if (myCase != null) { myCase.Todo(); } }
public void ShouldReturnAllTypesWithIncjectedServices() { // arrange var provider = new Mock <IServiceProvider>(); // act var steps = ReflectiveEnumerator.GetEnumerableOfType <IPipelineStep>(provider.Object); // assert Assert.Equal(4, steps.Count()); }
void InitSkills() { List <Skill> skills = ReflectiveEnumerator.GetEnumerableOfType <Skill>().ToList(); RefreshSkillList(AllSkills, skills, s => { InfoContainer.transform.Find("Name").GetComponent <Text>().text = "Name: " + s.Name; InfoContainer.transform.Find("Target").GetComponent <Text>().text = "Targets: " + s.Mode; InfoContainer.transform.Find("Cooldown").GetComponent <Text>().text = "Cooldown: " + s.MaxCooldown; InfoContainer.transform.Find("Description").GetComponent <Text>().text = "Description: " + s.Description; }); }
private static void CatalogAvailableComponents() { ComponentsByPackage = new Dictionary <string, List <Type> >(); ComponentsByQualifiedName = new Dictionary <string, Type>(); QualifedNameByComponentType = new Dictionary <Type, string>(); List <Type> packageList; foreach (Type t in ReflectiveEnumerator.GetEnumerableOfType <NoFlo_Basic.Component>()) { string name = t.GetAttributeValue((ComponentNameAttribute dna) => dna.name); string package = t.GetAttributeValue((ComponentPackageAttribute dna) => dna.name); string qualifiedName = package + "/" + name; if (name == "") { throw new Exception("Component " + t.Name + " does not have valid attribute ComponentName"); } if (package == "") { throw new Exception("Component " + t.Name + " does not have valid attribute ComponentPackage"); } if (ComponentsByQualifiedName.ContainsKey(qualifiedName)) { throw new Exception("TODO"); } ComponentsByQualifiedName.Add(qualifiedName, t); if (!ComponentsByPackage.TryGetValue(package, out packageList)) { packageList = new List <Type>(); ComponentsByPackage.Add(package, packageList); } if (packageList.Contains(t)) { throw new Exception("TODO"); } packageList.Add(t); QualifedNameByComponentType.Add(t, qualifiedName); } isInitialised = true; }
public void preLoadAllCards() { IEnumerable <Card> allCards = ReflectiveEnumerator.GetEnumerableOfType <Card>(); foreach (Card card in allCards) { //card base classes with this class name are not real cards and should be ignored if (card.GetType().Name.Contains("Base_")) { continue; } //this method will call this class to cash all resources the card requires to function card.cacheResorces(); } }
void OnEnable() { List <GameConfiguration> possibleconfig = ReflectiveEnumerator.GetEnumerableOfType <GameConfiguration>(); confignames = new List <string>(); foreach (GameConfiguration g in possibleconfig) { confignames.Add(g.GetType().ToString()); } generateAtRuntime = serializedObject.FindProperty("generateAtRuntime"); configurationname = serializedObject.FindProperty("configurationname"); themepropertyname = serializedObject.FindProperty("ThemePropertyName"); hastheme = serializedObject.FindProperty("hastheme"); allowOnlyCompleteThemes = serializedObject.FindProperty("allowOnlyCompleteThemes"); }
public static bool InstanciateAllDerivedTypes() { //if (IsInitiated) return false; //prevent duplicate parser //InstanciatedParsers.Clear(); var list = ReflectiveEnumerator.GetEnumerableOfType <Scraper>(); InstanciatedScrapers = from scraper in list where scraper.Ignore == false select scraper; IsInitiated = true; return(true); }
private void Awake() { List <AbstractImageEffect> image_effects = ReflectiveEnumerator.GetEnumerableOfType <AbstractImageEffect>().ToList(); for (int i = 0; i < Enum.GetNames(typeof(AbstractImageEffect.ImageEffectEnum)).Length; i++) { images.Add((AbstractImageEffect.ImageEffectEnum)i, image_effects[i]); } List <AbstractTextEffect> text_effects = ReflectiveEnumerator.GetEnumerableOfType <AbstractTextEffect>().ToList(); for (int i = 0; i < Enum.GetNames(typeof(AbstractTextEffect.TextEffectEnum)).Length; i++) { text.Add((AbstractTextEffect.TextEffectEnum)i, text_effects[i]); } }
private void updatePosibleEffectsList() { IEnumerable <Effect> possibleEffectEnumerable = ReflectiveEnumerator.GetEnumerableOfType <Effect>(new object[0]); int possibleEffectsCount = possibleEffectEnumerable.Count(); possibleEffectsListNames = new string[possibleEffectsCount]; possibleEffectsList = new EffectProperties[possibleEffectsCount]; int index = 0; foreach (Effect effect in possibleEffectEnumerable) { EffectProperties properties = effect.getEffectPropertiesStructure(false); possibleEffectsListNames[index] = properties.effectClassName; possibleEffectsList[index++] = properties; } }
private void InitCardSelector() { for (int i = 0; i < transform.childCount; i++) { UnityExtentionMethods.destoryAllChildren(transform.GetChild(i)); } IEnumerable <Card> allCards = ReflectiveEnumerator.GetEnumerableOfType <Card>(); foreach (Card card in allCards) { //card base classes with this class name are not real cards and should be ignored if (card.GetType().Name.Contains("Base_")) { continue; } Instantiate(cardDisplayPrefab, transform).GetComponent <CardDisplayController>().setCardDisplay(card, deckList); } }
public void FillComboBox(int type) { if (type == 0) { abstracktrigger_list = ReflectiveEnumerator.GetEnumerableOfType <AbstractTrigger>(); foreach (var item in abstracktrigger_list) { comboBox.Items.Add(item.GetActionName()); } } if (type == 1) { abstrackaction_list = ReflectiveEnumerator.GetEnumerableOfType <AbstractAction>(); foreach (var item in abstrackaction_list) { comboBox.Items.Add(item.GetActionName()); } } _type = type; }
public async Task SpinNewWheelAsync(CommandContext ctx) { DiscordContext context = new DiscordContext(); Users user = await context.Users.FindAsync(Convert.ToInt64(ctx.Message.Author.Id)); UserSettings userSettings = await context.UserSettings.FindAsync(Convert.ToInt64(ctx.Message.Author.Id)); SabrinaSettings sabrinaSettings = await context.SabrinaSettings.FindAsync(Convert.ToInt64(ctx.Guild.Id)); if (sabrinaSettings == null) { sabrinaSettings = new SabrinaSettings { GuildId = Convert.ToInt64(ctx.Guild.Id), WheelChannel = Convert.ToInt64(ctx.Channel.Id) }; await context.SabrinaSettings.AddAsync(sabrinaSettings); await context.SaveChangesAsync(); } if (sabrinaSettings.WheelChannel == null) { sabrinaSettings.WheelChannel = Convert.ToInt64(ctx.Channel.Id); await context.SaveChangesAsync(); } if (Convert.ToInt64(ctx.Channel.Id) != sabrinaSettings.WheelChannel.Value) { DiscordChannel channel = await ctx.Client.GetChannelAsync(Convert.ToUInt64(sabrinaSettings.WheelChannel)); await ctx.RespondAsync( $"You cannot issue this command from this Channel. Please use {channel.Mention}"); return; } if (user == null) { user = new Users(); } if (userSettings == null) { userSettings = new UserSettings(); } WheelChances chances = await context.WheelChances.FindAsync(userSettings.WheelDifficulty ?? 2); if (user.LockTime != null && user.LockTime > DateTime.Now) { TimeSpan?timeUntilFree = user.LockTime - DateTime.Now; TimeSpan newTimeUntilFree = TimeSpan.FromTicks(timeUntilFree.Value.Ticks * Helpers.RandomGenerator.RandomInt(1, 4)); if (newTimeUntilFree > TimeSpan.FromDays(365)) { await ctx.RespondAsync("F**k off"); return; } if (Helpers.RandomGenerator.RandomInt(0, 4) > 0) { await ctx.RespondAsync( "Oho, it seems like I told you to stay away from spinning the wheel...\n" + $"That means you get some more extra time of no spinning {DiscordEmoji.FromName(ctx.Client, Config.Emojis.Blush)}"); user.LockTime += newTimeUntilFree; await context.SaveChangesAsync(); return; } await ctx.RespondAsync( "I believe i have told you not to spin the wheel.\n" + $"But since i'm awesome, you won't get punishment for it... Today. {DiscordEmoji.FromName(ctx.Client, Config.Emojis.Blush)}"); } var addedChance = 0; var outcomeChanceValue = Helpers.RandomGenerator.RandomInt( 0, chances.Denial + chances.Task + chances.Ruin + chances.O****m); Console.WriteLine("Chance Rolled: " + outcomeChanceValue); Console.WriteLine("Denial Chance: " + chances.Denial); Console.WriteLine("TaskChance Chance: " + chances.Task); Console.WriteLine("RuinChance Chance: " + chances.Ruin); Console.WriteLine("OrgasmChance Chance: " + chances.O****m); Console.WriteLine("addedChance Chance: " + addedChance); SlaveReportsExtension.Outcome outcome = SlaveReportsExtension.Outcome.Task; if (outcomeChanceValue < chances.Denial) { outcome = SlaveReportsExtension.Outcome.Denial; } else if (outcomeChanceValue < chances.Denial + chances.Task) { outcome = SlaveReportsExtension.Outcome.Task; } else if (outcomeChanceValue < chances.Denial + chances.Task + chances.Ruin) { outcome = SlaveReportsExtension.Outcome.Ruin; } else { outcome = SlaveReportsExtension.Outcome.O****m; } if (user.DenialTime != null && user.DenialTime > DateTime.Now) { TimeSpan?timeUntilFree = user.DenialTime - DateTime.Now; if (outcome.HasFlag(SlaveReportsExtension.Outcome.O****m) || outcome.HasFlag(SlaveReportsExtension.Outcome.Ruin)) { await ctx.RespondAsync( "Haha, I would\'ve let you cum this time, but since you\'re still denied, " + $"that won't happen {DiscordEmoji.FromName(ctx.Client, Config.Emojis.Blush)}.\n" + "As a punishment, you\'re gonna do your Task anyways though."); } else { await ctx.RespondAsync( "Well, i told you, that you\'d be denied now.\n" + "You still want to do something? Then here you go." + $"\nAnd as a bonus, if i decide so, you'll get even more denial! {DiscordEmoji.FromName(ctx.Client, Config.Emojis.Blush)}"); } await Task.Delay(1500); outcome = SlaveReportsExtension.Outcome.Denial | SlaveReportsExtension.Outcome.Task; } WheelOutcome wheelOutcome = null; while (wheelOutcome == null) { wheelOutcomes = ReflectiveEnumerator.GetEnumerableOfType <WheelOutcome>(outcome, userSettings, context) .ToList(); wheelOutcomes = wheelOutcomes.Where(e => outcome.HasFlag(e.Outcome)).ToList(); if (wheelOutcomes.Count < 1) { continue; } // Choose an outcome by summing up the chance values of all possible outcomes and then generating a random number inside those. var combinedChance = 0; foreach (WheelOutcome currentOutcome in wheelOutcomes) { combinedChance += currentOutcome.Chance; } var chance = 0; var minChance = Helpers.RandomGenerator.RandomInt(0, combinedChance); foreach (WheelOutcome currentOutcome in wheelOutcomes) { chance += currentOutcome.Chance; if (minChance < chance) { wheelOutcome = currentOutcome; break; } } } if (user.DenialTime == null) { user.DenialTime = DateTime.Now; } if (user.LockTime == null) { user.LockTime = DateTime.Now; } if (user.DenialTime < DateTime.Now) { user.DenialTime = DateTime.Now; } if (user.LockTime < DateTime.Now) { user.LockTime = DateTime.Now; } user.DenialTime += wheelOutcome.DenialTime; user.LockTime += wheelOutcome.WheelLockedTime; await context.SaveChangesAsync(); if (wheelOutcome.Embed != null) { await ctx.RespondAsync(embed : wheelOutcome.Embed); } else { await ctx.RespondAsync(wheelOutcome.Text); } }
public ProcessPipeline(IServiceProvider provider) { _steps = ReflectiveEnumerator.GetEnumerableOfType <IPipelineStep>(provider).OrderBy(x => x.OrderNumber); }
public async Task SetupAsync(CommandContext ctx) { await ctx.RespondAsync("You got Mail! *AOL chime plays*"); using var context = new DiscordContext(); var dm = await ctx.Member.CreateDmChannelAsync(); var userId = Convert.ToInt64(ctx.User.Id); string userName = ctx.Message.Author.Username; string readableUserName = RemoveSpecialCharacters(userName); if (readableUserName.Length > 4) { userName = readableUserName; } await dm.TriggerTypingAsync(); await Task.Delay(1000); await dm.SendMessageAsync($"Hey there {userName}."); await Task.Delay(1000); bool isFirstChange = true; var settings = UserSetting.GetAllSettings(userId, context); if (settings == null || settings.Count() == 0) { // *** First time setup *** if (!await Introduction(dm, ctx)) { return; } await dm.TriggerTypingAsync(); await Task.Delay(1000); await dm.SendMessageAsync($"Splendid! Now that you know how this works, let's start with the Settings!"); if (!await new WheelDifficultyModule(context, dm, ctx, userId).Execute()) { return; } if (!await new WheelTaskPreferenceModule(context, dm, ctx, userId).Execute()) { return; } isFirstChange = false; } // *** User has come back to change settings *** bool exit = false; while (!exit) { await dm.SendMessageAsync($"What{(isFirstChange ? "" : " else")} would you like to change?"); isFirstChange = false; var m = await ctx.Client.GetInteractivity().WaitForMessageAsync( x => x.Channel.Id == dm.Id && x.Author.Id == ctx.Member.Id, TimeSpan.FromSeconds(240)); if (m.TimedOut) { // *** User didn't enter anything *** return; } var text = m.Result.Content; var modules = ReflectiveEnumerator.GetEnumerableOfType <SettingsModule>(context, dm, ctx, userId).OrderByDescending(module => module.GetScore(text)).ToList(); int suggestion = 0; bool isMatch = false; while (suggestion < 2 && !isMatch) { await dm.TriggerTypingAsync(); await Task.Delay(1000); await dm.SendMessageAsync($"Do you want to change your {modules[suggestion].FriendlyName} settings? (Y/N)"); var suggestionReply = await ctx.Client.GetInteractivity().WaitForMessageAsync( x => x.Channel.Id == dm.Id && x.Author.Id == ctx.Member.Id, TimeSpan.FromSeconds(240)); if (suggestionReply.TimedOut) { return; } if (Regex.Match(suggestionReply.Result.Content, YesRegex).Success) { isMatch = true; exit = !await modules[suggestion].Execute(); } else { suggestion++; } } if (suggestion >= 2) { DiscordEmbedBuilder builder = new DiscordEmbedBuilder() { Title = "These are your options" }; foreach (var module in modules) { builder.AddField(module.FriendlyName, "--------", false); } await dm.TriggerTypingAsync(); await Task.Delay(2000); await dm.SendMessageAsync(embed : builder.Build()); await dm.TriggerTypingAsync(); await Task.Delay(1000); await dm.SendMessageAsync("Would you like to change something else? (Y/N)"); var moreChangesResponse = await ctx.Client.GetInteractivity().WaitForMessageAsync( x => x.Channel.Id == dm.Id && x.Author.Id == ctx.Member.Id, TimeSpan.FromSeconds(240)); if (moreChangesResponse.TimedOut) { return; } if (Regex.Match(moreChangesResponse.Result.Content, YesRegex).Success) { exit = false; } else { exit = true; } suggestion = 0; } } await dm.TriggerTypingAsync(); await Task.Delay(1000); await dm.SendMessageAsync($"Alrighty! I'll try to remember that"); await Task.Delay(2000); await dm.TriggerTypingAsync(); await Task.Delay(500); await dm.SendMessageAsync($"..... I'll better write it down..."); await dm.TriggerTypingAsync(); try { await context.SaveChangesAsync(); } catch (Exception ex) { await dm.SendMessageAsync($"**Uhh... something seems to have gone badly wrong...{Environment.NewLine}" + $"If you see Salem around here somewhere, tell him the following:**"); await dm.TriggerTypingAsync(); await Task.Delay(5000); string msgToSend = $"```{ex.Message}```"; while (msgToSend.Length > 1999) { await dm.SendMessageAsync(msgToSend.Substring(0, 1999)); await dm.TriggerTypingAsync(); await Task.Delay(2000); msgToSend = msgToSend.Substring(1999); } await dm.SendMessageAsync(msgToSend); return; } await dm.SendMessageAsync($"Done!"); await dm.TriggerTypingAsync(); await Task.Delay(1000); await dm.SendMessageAsync($"Nice. You can now start using the Wheel with your brand new set of settings \\*-\\*{Environment.NewLine}" + $"These might get more over time. I will remind you to revisit them, when i feel fit."); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.White; if (args.Length != 2) { Console.WriteLine("[ERROR] Converter expected 2 argument while " + args.Length + " was supplied!"); return; } string dataDirectory = args[0]; string outputDirectory = args[1]; Stopwatch totalTime = Stopwatch.StartNew(); // Create all converters IEnumerable <Converters.BaseConverter> converters = ReflectiveEnumerator.GetEnumerableOfType <Converters.BaseConverter>(); foreach (Converters.BaseConverter converter in converters) { converter.Init(); } ScriptEngine pythonEngine = Python.CreateEngine(); // First we search of dataDirectory for all .py files, these files are scripts that will handle conversion string[] pythonFiles = Directory.GetFiles(dataDirectory, "*.py", SearchOption.AllDirectories); foreach (string pythonFile in pythonFiles) { string output = pythonFile; Stopwatch scriptTime = Stopwatch.StartNew(); ScriptScope scope = pythonEngine.CreateScope(); ScriptSource source = pythonEngine.CreateScriptSourceFromFile(pythonFile); CompiledCode compiled = source.Compile(); dynamic result = compiled.Execute(scope); List <string> errors = new List <string>(); bool availableConverter = false; bool wasConverted = false; foreach (Converters.BaseConverter converter in converters) { string error; if (converter.CanConvert(pythonFile, scope, out error)) { errors.Clear(); availableConverter = true; if (converter.Convert(pythonFile, scope, outputDirectory, out error)) { wasConverted = true; } else if (error != "") { errors.Add(error + " (" + converter.GetType().GetTypeInfo().Name + ")"); } } else if (error != "") { errors.Add(error + " (" + converter.GetType().GetTypeInfo().Name + ")"); } } if (!availableConverter) { output += " Could not find a suitable converter"; } else if (!wasConverted) { output += " Could not successfully be converted"; } else { output += " Converted successfully"; } output += " (" + scriptTime.Elapsed.ToString() + ")"; if (availableConverter && wasConverted) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("[SUCCESS]: "); } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("[ERROR]: "); } Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(output); if (!availableConverter || !wasConverted) { foreach (string error in errors) { Console.WriteLine(" [Reason]: " + error); } } } Console.WriteLine("Conversion done in " + totalTime.Elapsed.ToString()); Console.ReadLine(); }
private void PopulateControls(object sender, System.EventArgs e) { TreeViewItem selectedTVI = (TreeViewItem)treeView.SelectedItem; isTreeViewSelected = true; string selectedShape = selectedTVI.Header.ToString(); IEnumerable <sp.Shape> Eshape = ReflectiveEnumerator.GetEnumerableOfType <sp.Shape>(); List <string> shape_str = new List <string>(); foreach (sp.Shape sh in Eshape) { shape_str.Add(sh.GetType().Name); } bool test = selectedTVI.HasItems; string parentName = null; if (selectedTVI.Parent.GetType() == typeof(TreeViewItem)) // verify that parent is TreeViewItem { TreeViewItem parent = (TreeViewItem)selectedTVI.Parent; parentName = parent.Header.ToString(); } if (!test) { if (parentName == "Basic Shapes") { foreach (sp.Shape sh in Eshape) { if (sh.GetType().Name == selectedShape.Replace(" ", string.Empty)) { GetPoints(sh); AddPointsToObservableCollection(); GetProperties(sh); AddPropsToObservableCollection(); _imgdim = ImageUtil.GetBitmapImage(selectedShape.Replace(" ", string.Empty) + "_dim"); _imgpnt = ImageUtil.GetBitmapImage(selectedShape.Replace(" ", string.Empty) + "_pnt"); } } } if (parentName == "Machined Shapes") { foreach (sp.Shape sh in Eshape) { if (sh.GetType().Name == "Machined" + selectedShape.Replace(" ", string.Empty)) { GetPoints(sh); AddPointsToObservableCollection(); GetProperties(sh); AddPropsToObservableCollection(); _imgdim = ImageUtil.GetBitmapImage("Machined" + selectedShape.Replace(" ", string.Empty) + "_dim"); _imgpnt = ImageUtil.GetBitmapImage("Machined" + selectedShape.Replace(" ", string.Empty) + "_pnt"); } } } if (parentName == "Formed Shapes") { foreach (sp.Shape sh in Eshape) { if (sh.GetType().Name == "Formed" + selectedShape.Replace(" ", string.Empty)) { GetPoints(sh); AddPointsToObservableCollection(); GetProperties(sh); AddPropsToObservableCollection(); _imgdim = ImageUtil.GetBitmapImage("Formed" + selectedShape.Replace(" ", string.Empty) + "_dim"); _imgpnt = ImageUtil.GetBitmapImage("Formed" + selectedShape.Replace(" ", string.Empty) + "_pnt"); } } } HelperImage.Source = _imgdim; HelperImage.Stretch = System.Windows.Media.Stretch.Uniform; HelperBorder.Background = Brushes.White; HelperBorder.BorderBrush = Brushes.DarkGray; } }
private void GenerateSidebar(Control parent) { Padding categoryPadding = new Padding(5, 0, 0, 0); Font categoryFont = new Font(parent.Font.FontFamily, 13, FontStyle.Bold); Padding itemPadding = new Padding(25, 0, 0, 0); Font itemFont = new Font(parent.Font.FontFamily, 12); var items = ReflectiveEnumerator.GetEnumerableOfType <AbstractDeckAction>(); List <Control> toAdd = new List <Control>(); foreach (DeckActionCategory enumItem in Enum.GetValues(typeof(DeckActionCategory))) { var enumItems = items.Where(i => i.GetActionCategory() == enumItem && i.IsTool() == false && i.IsPlugin() == false); if (enumItems.Any()) { toAdd.Add(new Label() { Padding = categoryPadding, TextAlign = ContentAlignment.MiddleLeft, Font = categoryFont, Dock = DockStyle.Top, Text = enumItem.ToString(), Tag = "header", Height = TextRenderer.MeasureText(enumItem.ToString(), categoryFont).Height }); foreach (var i2 in enumItems) { Label item = new Label() { Padding = itemPadding, TextAlign = ContentAlignment.MiddleLeft, Font = itemFont, Dock = DockStyle.Top, Text = i2.GetActionName(), Height = TextRenderer.MeasureText(i2.GetActionName(), itemFont).Height, Tag = i2, }; // Debug.WriteLine("TAG VINDO: " + i2); item.MouseDown += (s, ee) => { if (item.Tag is AbstractDeckAction act) { // listBox2.Items.Add(i2.GetActionName()) ; GlobalAbstractDeckAction listbox = new GlobalAbstractDeckAction(); listbox.Text = i2.GetActionName(); listbox.Value = i2; listBox2.Items.Add(listbox); //listBox2.Refresh(); // item.DoDragDrop(new DeckActionHelper(act), DragDropEffects.Copy); } }; toAdd.Add(item); } } } toAdd.AsEnumerable().Reverse().All(m => { parent.Controls.Add(m); return(true); }); }
public Inventory() { consumableItems = new List <ConsumableItemA>(); IEnumCI = ReflectiveEnumerator.GetEnumerableOfType <ConsumableItemA>(); Ui_Inventory.instance.SetInventory(this); }