/// <summary> /// Creates a new <see cref="MasterSection"/> instance from the specified scenario /// description file.</summary> /// <param name="path"> /// The file path to the XML scenario description to open.</param> /// <exception cref="ArgumentNullOrEmptyException"> /// <paramref name="path"/> is a null reference or an empty string.</exception> /// <remarks> /// <b>CreateScenario</b> raises the <see cref="TaskEvents.TaskProgress"/> event four times /// with a value of one.</remarks> private void CreateScenario(string path) { if (String.IsNullOrEmpty(path)) { ThrowHelper.ThrowArgumentNullOrEmptyException("path"); } this._threadEvents.OnTaskMessage(this, Global.Strings.StatusScenarioReading); // create scenario instance MasterSection.CreateInstance(); this._threadEvents.OnTaskProgress(this, 1); // load specified XML scenario MasterSection.Instance.Load(path); this._threadEvents.OnTaskProgress(this, 1); // read media files from disk MasterSection.Instance.Images.Load(); this._threadEvents.OnTaskProgress(this, 1); // load associated rule script MasterSection.Instance.Rules.Load(); this._threadEvents.OnTaskProgress(this, 1); }
/// <summary> /// Initializes a new instance of the <see cref="AboutScenario"/> class.</summary> public AboutScenario() { InitializeComponent(); MasterSection scenario = MasterSection.Instance; if (scenario == null) { return; } // show scenario title ScenarioInfo.Text = scenario.Title; // show scenario information ScenarioAuthorInfo.Text = scenario.Information.Author; ScenarioVersionInfo.Text = scenario.Information.Version; ScenarioLegalInfo.Text = scenario.Information.Legal; // show graphics information GraphicsAuthorInfo.Text = scenario.Images.Information.Author; GraphicsVersionInfo.Text = scenario.Images.Information.Version; GraphicsLegalInfo.Text = scenario.Images.Information.Legal; // default to scenario details ShowDetails(false); }
/// <summary> /// Handles the <see cref="Application.DispatcherUnhandledException"/> event for the <see /// cref="EditorApplication"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> sending the event.</param> /// <param name="args"> /// A <see cref="DispatcherUnhandledExceptionEventArgs"/> object containing event data. /// </param> /// <remarks> /// <b>OnUnhandledException</b> handles all uncaught exceptions for the <see /// cref="EditorApplication"/> by gathering all relevant application data and then calling /// <see cref="ApplicationUtility.OnUnhandledException"/> for further processing.</remarks> private void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs args) { // store information about the exception StringBuilder info = new StringBuilder(); info.Append(args.Exception); info.Append(Environment.NewLine); info.Append(Environment.NewLine); MasterSection scenario = MasterSection.Instance; Action <String> saveScenario = null; if (scenario == null) { info.Append("Scenario instance is null. "); info.Append(Environment.NewLine); } else { // delegate to save scenario data saveScenario = scenario.SaveAll; // collect various Hexkit Editor information foreach (ScenarioSection section in SectionUtility.AllSections) { info.AppendFormat("Scenario.Section.{0}: {1} ", section, scenario.SectionPaths.GetPath(section)); info.Append(Environment.NewLine); } } // invoke common exception handler ApplicationUtility.OnUnhandledException(info.ToString(), null, saveScenario, null); }
protected override ILibrary CreateLibrary(InputB input, MasterSection masterSection) { return(new LibraryB { Id = id, InitialRevisionId = input.InitialRevisionId ?? id, MasterSection = masterSection, AirClass = input.AirClass, Revision = 0 }); }
protected override ILibrary CreateLibrary(InputA input, MasterSection masterSection) { new LibraryA { Id = id, InitialRevisionId = input.InitialRevisionId ?? id, MasterSection = masterSection, DirectExhaust = input.DirectExhaust, Revision = 0 }; }
public async Task AddAsync(SectionModel model) { var section = new MasterSection { DepartmentId = model.DepartmentId, SectionName = model.SectionName, SectionCode = model.SectionCode, }; await _repository.AddAsync(section); }
/// <summary> /// Initializes the section-specific controls of the tab page.</summary> /// <remarks> /// <b>Initialize</b> initializes all controls that are specific to the "Master" tab page, /// and also calls <see cref="MainWindow.UpdateTabPage"/> for all subsections to initialize /// their data from the current <see cref="MasterSection"/>. This is necessary because the /// Master section determines the contents (via file path or inlining) of all subsections. /// </remarks> public void Initialize() { // update subsections from file or scenario data foreach (ScenarioSection section in SectionUtility.Subsections) { MainWindow.Instance.UpdateTabPage(section); } // initialize controls on this page MasterSection scenario = MasterSection.Instance; TitleBox.Text = scenario.Title; RulesPathBox.Text = scenario.Rules.Path; }
public Guid UpsertRequest( TInput input, MasterSection masterSection, RequestInput requestInputs, APIDbContext dbContext) { Guid id = Guid.NewGuid(); var library = CreateLibrary(input, masterSection); dbContext.Set <TLibrary>().Add(library); dbContext.SaveChanges(); var request = RequestHelper.CreateRequest(masterSection, library.Id, requestInputs, dbContext); dbContext.Requests.Add(request); dbContext.SaveChanges(); return(request.Id); }
/// <summary> /// Handles the <see cref="Application.DispatcherUnhandledException"/> event for the <see /// cref="GameApplication"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> sending the event.</param> /// <param name="args"> /// A <see cref="DispatcherUnhandledExceptionEventArgs"/> object containing event data. /// </param> /// <remarks> /// <b>OnUnhandledException</b> handles all uncaught exceptions for the <see /// cref="GameApplication"/> by gathering all relevant application data and then calling /// <see cref="ApplicationUtility.OnUnhandledException"/> for further processing.</remarks> private void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs args) { // store information about the exception StringBuilder info = new StringBuilder(); info.Append(args.Exception); info.Append(Environment.NewLine); info.Append(Environment.NewLine); // retrieve current scenario path, if any MasterSection scenario = MasterSection.Instance; string scenarioPath = (scenario == null ? "(no scenario)" : StringUtility.Validate(scenario.Path.RelativePath)); // collect various game information info.AppendFormat("Session.State.{0} ", Session.State); info.Append(Environment.NewLine); info.AppendFormat("Scenario: \"{0}\"", scenarioPath); info.Append(Environment.NewLine); string rulesPath = null; Action <String> saveScenario = null, saveSession = null; // delegates to save scenario and session data if (scenario != null) { rulesPath = scenario.Rules.Path; saveScenario = scenario.SaveAll; if (Session.State != SessionState.Invalid) { saveSession = Session.Instance.SaveDirect; } } // invoke common exception handler ApplicationUtility.OnUnhandledException( info.ToString(), rulesPath, saveScenario, saveSession); }
/// <summary> /// Determines whether the current scenario contains at least one <see cref="TerrainClass"/> /// with at least one background image.</summary> /// <returns> /// <c>true</c> if <see cref="TerrainClass.IsBackground"/> is <c>true</c> for at least one /// <see cref="TerrainClass"/> defined by the current <see cref="EntitySection"/>; /// otherwise, <c>false</c>.</returns> /// <remarks> /// <b>AnyBackgroundTerrain</b> immediately returns <c>false</c> if either the <see /// cref="ImageSection.Collection"/> of the current <see cref="ImageSection"/> or the <see /// cref="EntitySection.Terrains"/> collection of the current <see cref="EntitySection"/> is /// empty.</remarks> private static bool AnyBackgroundTerrain() { MasterSection scenario = MasterSection.Instance; // fail immediately if no images or no terrains if (scenario.Images.Collection.Count == 0 || scenario.Entities.Terrains.Count == 0) { return(false); } // succeed if any terrain is a background terrain foreach (TerrainClass terrain in scenario.Entities.Terrains.Values) { if (terrain != null && terrain.IsBackground) { return(true); } } // no background terrain return(false); }
protected abstract ILibrary CreateLibrary(TInput input, MasterSection masterSection);
public static Guid UpsertRequest( IInput inputg, MasterSection masterSection, RequestInput requestInputs, APIDbContext dbContext
/// <summary> /// Changes or deletes all occurrences of the specified identifier in the specified /// collection or in the entire scenario.</summary> /// <typeparam name="TValue"> /// The type of all values in the specified <paramref name="collection"/>. The type of all /// keys is assumed to be <see cref="String"/>.</typeparam> /// <param name="collection"> /// The <see cref="ICollection{T}"/> whose elements to process. This must be either an <see /// cref="IDictionary{TKey, TValue}"/> or an <see cref="IList{T}"/> holding <see /// cref="KeyValuePair{TKey, TValue}"/> elements.</param> /// <param name="oldId"> /// The identifier to remove from <paramref name="collection"/> or from the current /// scenario.</param> /// <param name="newId"><para> /// The identifier to store with all values of <paramref name="oldId"/> in <paramref /// name="collection"/> or in the current scenario. /// </para><para>-or-</para><para> /// A null reference to delete all elements with <paramref name="oldId"/> from <paramref /// name="collection"/> or from the current scenario.</para></param> /// <returns> /// <c>true</c> if the user confirmed the change; otherwise, <c>false</c>.</returns> /// <exception cref="ArgumentException"> /// <paramref name="collection"/> implements neither <see cref="IDictionary{TKey, TValue}"/> /// nor <see cref="IList{T}"/>.</exception> /// <exception cref="ArgumentNullException"> /// <paramref name="collection"/> is a null reference.</exception> /// <exception cref="ArgumentNullOrEmptyException"> /// <paramref name="oldId"/> is a null reference or an empty string.</exception> /// <remarks><para> /// <b>ProcessAllIdentifiers</b> invokes <see /// cref="MasterSection.ProcessIdentifierBySection"/> to count all occurrences of the /// specified <paramref name="oldId"/> in the current scenario. /// </para><para> /// If any occurrences are found, <b>ProcessAllIdentifiers</b> asks the user if all of them /// should be deleted or changed to the specified <paramref name="newId"/>, or only those in /// the specified <paramref name="collection"/>, or if the entire operation should be /// cancelled. /// </para><para> /// If the user cancels, <b>ProcessAllIdentifiers</b> returns <c>false</c> without changing /// any data. Otherwise, the requested changes are performed using either /// <b>ProcessIdentifierBySection</b> or <see cref="CollectionsUtility.ChangeKey"/>. In the /// first case, the Hexkit Editor tab pages managing the changed scenario sections, if any, /// are also flagged as containing unsaved changes.</para></remarks> public static bool ProcessAllIdentifiers <TValue>( ICollection <KeyValuePair <String, TValue> > collection, string oldId, string newId) { if (collection == null) { ThrowHelper.ThrowArgumentNullException("collection"); } if (String.IsNullOrEmpty(oldId)) { ThrowHelper.ThrowArgumentNullOrEmptyException("oldId"); } // check if required interface is available IDictionary <String, TValue> dictionary = collection as IDictionary <String, TValue>; IList <KeyValuePair <String, TValue> > list = collection as IList <KeyValuePair <String, TValue> >; if (dictionary == null && list == null) { ThrowHelper.ThrowArgumentException("collection", Tektosyne.Strings.ArgumentNotInTypes + "IDictionary, IList"); } // count all occurrences of old key MasterSection scenario = MasterSection.Instance; int[] found = scenario.ProcessIdentifierBySection(oldId, oldId); int totalFound = found[(int)ScenarioSection.Master]; // ask to change those occurrences, if any MessageBoxResult result = MessageBoxResult.No; if (totalFound > 1) { string dialogText = (newId == null ? Global.Strings.DialogIdentifierDelete : Global.Strings.DialogIdentifierChange); result = MessageBox.Show(MainWindow.Instance, String.Format(ApplicationInfo.Culture, dialogText, totalFound - 1), Global.Strings.TitleIdentifierReferenced, MessageBoxButton.YesNoCancel, MessageBoxImage.Question); // process identifiers throughout scenario if (result == MessageBoxResult.Yes) { scenario.ProcessIdentifierBySection(oldId, newId); for (int i = 0; i < found.Length; i++) { if (found[i] == 0) { continue; } ScenarioSection section = (ScenarioSection)i; MainWindow.Instance.GetTabPage(section).DataChanged = true; } } } // process identifiers in specified collection only if (result == MessageBoxResult.No) { if (dictionary != null) { CollectionsUtility.ProcessKey(dictionary, oldId, newId); } else { CollectionsUtility.ProcessKey(list, oldId, newId); } } // allow user to abort if a dialog came up return(result != MessageBoxResult.Cancel); }