public void Solutions_LevelConverter_Test() { var converter = new LevelConverter(); var solutionByIndex = converter.GetLevelSolutionByIndex(4); var solutionByNumber = converter.GetLevelSolutionByNumber(5); Assert.AreEqual(solutionByIndex, solutionByNumber); Assert.AreEqual(solutionByNumber, "6-1;4-1;3-1;3-3;2-3;0-3"); }
public void Level_LevelConverter_Test() { var converter = new LevelConverter(); var level25ByIndex = converter.GetLevelByIndex(24); var level25ByNumber = converter.GetLevelByNumber(25); Assert.AreEqual(level25ByIndex, level25ByNumber); Assert.AreEqual(level25ByNumber, "6-1;5-1;5-2;5-3;5-4;4-2;4-3;3-0;3-3;2-1;2-4;1-4;1-2;0-3"); }
public void Platforms_LevelConverter_Test() { var converter = new LevelConverter(); var level1ByIndex = converter.GetLevelPlatformsByIndex(0); var level1ByNumber = converter.GetLevelPlatformsByNumber(1); Assert.AreEqual(level1ByIndex, level1ByNumber); Assert.AreEqual(level1ByNumber, "6-1;4-1#4-1;3-1"); }
private static void SetupLogging(UtlzLevel level) { // ReSharper disable once UseDeconstruction var serilogObjects = SetupSerilog(LevelConverter.Convert(level)); LoggerSingleton.Setup( new LoggerFactory(new BackendLoggerFactory(serilogObjects.serilogger)), new LevelController(serilogObjects.levelSwitch)); _logger = LoggerSingleton.Factory.GetLogger <Program>(); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements) { try { m_activeView = commandData.Application.ActiveUIDocument.Document.ActiveView; //// Create a new instance of class DataManager RoofsManager.CS.RoofsManager roofsManager = new RoofsManager.CS.RoofsManager(commandData); LevelConverter.SetStandardValues(roofsManager.Levels); // Create a form to create and edit a roof. DialogResult result = System.Windows.Forms.DialogResult.None; while (result == DialogResult.None || result == DialogResult.Retry) { if (result == DialogResult.Retry) { roofsManager.WindowSelect(); } using (RoofForms.CS.RoofForm mainForm = new RoofForms.CS.RoofForm(roofsManager)) { result = mainForm.ShowDialog(); } } if (result == System.Windows.Forms.DialogResult.OK) { return(Autodesk.Revit.UI.Result.Succeeded); } else { return(Autodesk.Revit.UI.Result.Cancelled); } } catch (Exception ex) { // If there are something wrong, give error information and return failed message = ex.Message; return(Autodesk.Revit.UI.Result.Failed); } }
public LevelGenerator(LevelManager manager) { _manager = manager; _converter = new LevelConverter(); }
private IEnumerable <LogEntry> InternalGetEntries(string dataSource, FilterParams filter) { using (IDbConnection connection = this.CreateConnection(dataSource)) { connection.Open(); using (IDbTransaction transaction = connection.BeginTransaction()) { using (IDbCommand command = connection.CreateCommand()) { command.CommandText = @"select caller, date, level, logger, thread, message, exception from log where date >= @date"; IDbDataParameter parameter = command.CreateParameter(); parameter.ParameterName = "@date"; parameter.Value = filter.Date.HasValue ? filter.Date.Value : MinDateTime; command.Parameters.Add(parameter); switch (filter.Level) { case 1: AddLevelClause(command, "ERROR"); break; case 2: AddLevelClause(command, "INFO"); break; case 3: AddLevelClause(command, "DEBUG"); break; case 4: AddLevelClause(command, "WARN"); break; case 5: AddLevelClause(command, "FATAL"); break; default: break; } AddLoggerClause(command, filter.Logger); AddThreadClause(command, filter.Thread); AddMessageClause(command, filter.Message); AddOrderByClause(command); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string caller = ""; try { reader.GetString(0); } catch { // [FT] catching exception because when using sqlite, caller is empty text // and GetString() method raises an exception. } string[] split = caller.Split(','); const string MachineKey = "{log4jmachinename="; string item0 = Find(split, MachineKey); string machineName = GetValue(item0, MachineKey); const string HostKey = " log4net:HostName="; string item1 = Find(split, HostKey); string hostName = GetValue(item1, HostKey); const string UserKey = " log4net:UserName="******" log4japp="; string item3 = Find(split, AppKey); string app = GetValue(item3, AppKey); DateTime timeStamp = reader.GetDateTime(1); string level = reader.GetString(2); string logger = reader.GetString(3); string thread = reader.GetString(4); string message = reader.GetString(5); string exception = reader.GetString(6); LogEntry entry = new LogEntry { TimeStamp = timeStamp, LevelIndex = LevelConverter.From(level), Thread = thread, Logger = logger, Message = message, Throwable = exception, MachineName = machineName, HostName = hostName, UserName = userName, App = app, }; // TODO: altri filtri yield return(entry); } } } transaction.Commit(); } } }
private void buttonConvert_Click(object sender, EventArgs e) { if (textSourcePath.Text == "") { MessageBox.Show("You did not provide a source path.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (textOutputPath.Text == "") { MessageBox.Show("You did not provide an output path.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (textLevelsXmlPath.Text != "" && !textLevelsXmlPath.Text.EndsWith("levels.xml")) { MessageBox.Show("You picked an invalid path for the levels.xml file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!textSourcePath.Text.EndsWith("\\")) { textSourcePath.Text += "\\"; } if (textSourceFallbackPath.Text != "" && !textSourceFallbackPath.Text.EndsWith("\\")) { textSourceFallbackPath.Text += "\\"; } if (!textOutputPath.Text.EndsWith("\\")) { textOutputPath.Text += "\\"; } var hwPath = textSourceFallbackPath.Text; if (hwPath == "") { hwPath = textSourcePath.Text; } if (!File.Exists(hwPath + "..\\Hammerwatch.exe")) { MessageBox.Show("Your game's base assets path seems to be set to the wrong path. (Couldn't find Hammerwatch.exe in parent directory of source or fallback path)", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Settings.SourcePath = textSourcePath.Text; Settings.SourceFallbackPath = textSourceFallbackPath.Text; Settings.LevelsPath = textLevelsXmlPath.Text; Settings.OutputPath = textOutputPath.Text; Settings.OutputPrefix = textOutputPrefix.Text; Settings.ConvertActors = checkConvertActors.Checked; Settings.ConvertProjectiles = checkConvertProjectiles.Checked; Settings.ConvertDoodads = checkConvertDoodads.Checked; Settings.ConvertTilesets = checkConvertTilesets.Checked; Settings.ConvertItems = checkConvertItems.Checked; Settings.ConvertStrings = checkConvertStrings.Checked; Settings.ConvertSpeechStyles = checkConvertSpeechStyles.Checked; Settings.ConvertFonts = checkConvertFonts.Checked; Settings.ConvertLoot = checkConvertLoot.Checked; Settings.ConvertLevels = checkConvertLevels.Checked; Settings.ConvertSounds = checkConvertSounds.Checked; Settings.HealthScale = trackActorHealthScale.Value / 100.0f; Settings.RangeScale = trackRangeScale.Value / 100.0f; Settings.DamageScale = trackDamageScale.Value / 100.0f; Settings.SpeedScale = trackActorSpeedScale.Value / 100.0f; Settings.ModifyWallCollision = checkModifyWallCollision.Checked; Settings.StringsKeyPrefix = textStringsKeyPrefix.Text; var waiting = new FormWaiting(); var thread = new Thread(() => { int fileCount = 0; var tmStart = DateTime.Now; try { var files = Directory.GetFiles(Settings.SourcePath, "*.xml", SearchOption.AllDirectories); foreach (var fnm in files) { string filename = fnm.Substring(Settings.SourcePath.Length).Replace('\\', '/'); string dir = Path.GetDirectoryName(filename); var xml = XmlFile.FromFile(fnm); var root = xml.Root.Children[0]; if (Settings.ConvertActors && root.Name == "actor") { // Actor units string filenameUnit = Path.ChangeExtension(filename, "unit"); waiting.SetStatus("Actor: " + filenameUnit); fileCount++; Program.Prepare(dir, filenameUnit); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + filenameUnit))) { UnitConverter.Convert(xml, writer, "actor", Path.GetFileNameWithoutExtension(filenameUnit), filenameUnit); } } else if (Settings.ConvertProjectiles && root.Name == "projectile") { // Projectile units string filenameUnit = Path.ChangeExtension(filename, "unit"); waiting.SetStatus("Projectile: " + filenameUnit); fileCount++; Program.Prepare(dir, filenameUnit); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + filenameUnit))) { UnitConverter.Convert(xml, writer, "projectile", Path.GetFileNameWithoutExtension(filenameUnit), filenameUnit); } } else if (Settings.ConvertDoodads && root.Name == "doodad") { // Doodad units string filenameUnit = Path.ChangeExtension(filename, "unit"); waiting.SetStatus("Doodad: " + filenameUnit); fileCount++; Program.Prepare(dir, filenameUnit); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + filenameUnit))) { UnitConverter.Convert(xml, writer, "doodad", Path.GetFileNameWithoutExtension(filenameUnit), filenameUnit); } } else if (Settings.ConvertTilesets && root.Name == "tileset") { // Tilesets string filenameTileset = Path.ChangeExtension(filename, "tileset"); waiting.SetStatus("Tilemap: " + filenameTileset); fileCount++; Program.Prepare(dir, filenameTileset); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + filenameTileset))) { TilesetConverter.Convert(xml, writer); } } else if (Settings.ConvertItems && root.Name == "item") { // Items (actually just units with behaviors) string filenameUnit = Path.ChangeExtension(filename, "unit"); waiting.SetStatus("Item: " + filenameUnit); fileCount++; Program.Prepare(dir, filenameUnit); var slot = ""; var behavior = root.Attributes["behavior"]; switch (behavior) { case "food": case "money": case "key": case "collectable": case "mana": case "life": case "potion": case "present": // uhh case "upgrade": slot = "item"; break; case "breakable": case "door": case "bomb": case "checkpoint": //TODO: This needs a behavior slot = "doodad"; break; default: Console.WriteLine("WARNING: Unknown behavior '{0}'", behavior); continue; } using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + filenameUnit))) { UnitConverter.Convert(xml, writer, slot, "", filenameUnit); } } else if (Settings.ConvertStrings && filename.StartsWith("language\\") && root.Name == "dictionary") { // String files (almost the same format, but we want to append our language prefix) string filenameLang = Path.ChangeExtension(filename, "lang"); waiting.SetStatus("Strings: " + filenameLang); fileCount++; Program.Prepare(dir, filenameLang); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + filenameLang))) { StringConverter.Convert(xml, writer); } } else if (Settings.ConvertSpeechStyles && root.Name == "speech") { // Speech styles string filenameUnit = Path.ChangeExtension(filename, "sval"); waiting.SetStatus("Speech style: " + filenameUnit); fileCount++; Program.Prepare(dir, filenameUnit); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + filenameUnit))) { SpeechStyleConverter.Convert(xml, writer); } } else if (Settings.ConvertFonts && root.Name == "font") { // Fonts string filenameLocal = Path.ChangeExtension(filename, "fnt"); waiting.SetStatus("Font: " + filenameLocal); fileCount++; Program.Prepare(dir, filenameLocal); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + filenameLocal))) { BitmapFontConverter.Convert(xml, writer); } } } if (Settings.ConvertLoot) { if (fileCount == 0) { waiting.SetStatus("WARNING: Can't convert loot if no units are being converted."); } else { string[] slots = LootConverter.GetSlots(); foreach (var slot in slots) { string filenameLocal = slot + ".sval"; waiting.SetStatus("Loot: " + filenameLocal); fileCount++; Program.Prepare("loot", filenameLocal); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + "loot/" + filenameLocal))) { LootConverter.Convert(slot, writer); } } } } var levelsPath = Settings.LevelsPath; if (Settings.ConvertLevels && levelsPath != "" && File.Exists(levelsPath)) { levelsPath = Path.GetDirectoryName(levelsPath) + "\\"; //TODO: Properly convert this into a scenario xml var levelsXml = XmlFile.FromFile(levelsPath + "levels.xml"); var levelsTags = levelsXml.Root.FindTagsByName("level"); foreach (var level in levelsTags) { Program.LevelKeys.Add(level.Attributes["id"], Path.ChangeExtension(level.Attributes["res"], "lvl")); } var levels = Directory.GetFiles(levelsPath + "levels\\", "*.xml", SearchOption.AllDirectories); foreach (var level in levels) { string filenameLocal = Path.ChangeExtension(level.Substring(levelsPath.Length + "levels\\".Length), "lvl"); waiting.SetStatus("Level: " + filenameLocal); fileCount++; Program.Prepare("levels/" + Path.GetDirectoryName(filenameLocal), filenameLocal); XmlFile xmlLevel = XmlFile.FromFile(level); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + "levels/" + filenameLocal))) { LevelConverter.Convert(xmlLevel, writer, filenameLocal); } } } if (Settings.ConvertSounds) { var filesSbnks = Directory.GetFiles(Settings.SourcePath + "/sound", "*.xml", SearchOption.AllDirectories); foreach (var fnm in filesSbnks) { string filename = fnm.Substring(Settings.SourcePath.Length); string dir = Path.GetDirectoryName(filename); var xml = XmlFile.FromFile(fnm); var root = xml.Root.Children[0]; if (root.Name == "soundbank") { // Soundbanks (are the *exact* same format, but we're parsing it anyway, we want to copy the sound files!) string filenameSbnk = Path.ChangeExtension(filename, "sbnk"); waiting.SetStatus("Soundbank: " + filenameSbnk); fileCount++; Program.Prepare(dir, filenameSbnk); using (StreamWriter writer = new StreamWriter(File.Create(Settings.OutputPath + filenameSbnk))) { SoundbankConverter.Convert(xml, writer, Path.GetFileNameWithoutExtension(filenameSbnk)); } } } } } catch (Exception ex) { BeginInvoke(new Action(() => { MessageBox.Show("Conversion has thrown an exception! Conversion will be stopped.\n\n" + ex.ToString(), "Converter", MessageBoxButtons.OK, MessageBoxIcon.Error); Enabled = true; waiting.Close(); })); return; } Invoke(new Action(() => { Enabled = true; waiting.Close(); MessageBox.Show("Done! Processed " + fileCount + " files in " + (DateTime.Now - tmStart).TotalSeconds.ToString("0.000") + " seconds.", "Converter", MessageBoxButtons.OK, MessageBoxIcon.Information); })); }); Enabled = false; waiting.Show(this); thread.Start(); }
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { var levelName = LevelConverter.Convert(logEvent.Level).GetDisplayName() ?? "UNKNOWN"; logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(PropertyName, levelName)); }