#region License // Copyright (c) 2010, Jasper Yeh. // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither the name of ClearCanvas Inc. nor the names of its contributors // may be used to endorse or promote products derived from this software without // specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY // OF SUCH DAMAGE. #endregion using System; using System.Configuration; using System.Reflection; using System.Xml; using ClearCanvas.Common; using ClearCanvas.Desktop; using ClearCanvas.Desktop.Actions; using ClearCanvas.Desktop.Tools; namespace Nullstack.ClearCanvasEx.DevTools.OtherTools { /// /// A tool for deleting the action model /// [GroupHint("flush", "Nullstack.ClearCanvasEx.DevTools.ActionModel.Delete")] [MenuAction("flush", "global-menus/mnDebug/mnActionModels/mnDelete", "Flush")] [ExtensionOf(typeof (DesktopToolExtensionPoint))] public class ActionModelTool : Tool { private static FieldInfo field; private static object instance; private static string defaultValue; public override void Initialize() { base.Initialize(); // initialization involves finding the internal class ActionModelSettings by reflection and recording the information we find Assembly assembly = Assembly.GetAssembly(typeof (Application)); Type type = assembly.GetType("ClearCanvas.Desktop.Actions.ActionModelSettings"); PropertyInfo propDefault = type.GetProperty("Default"); PropertyInfo propActionModelXml = type.GetProperty("ActionModelsXml"); // do discovery of default value tagged to the property DefaultSettingValueAttribute[] attribs = (DefaultSettingValueAttribute[]) propActionModelXml.GetCustomAttributes(typeof (DefaultSettingValueAttribute), false); if (attribs.Length > 0) { defaultValue = attribs[0].Value; } else { defaultValue = "\r\n"; } // do discovery of the default settings instance instance = propDefault.GetValue(null, null); field = type.GetField("_actionModelXmlDoc", BindingFlags.NonPublic | BindingFlags.Instance); } /// /// Clears the action model. /// public void Flush() { if (Application.ShowMessageBox(SR.msgConfirmDeleteActionModel, MessageBoxActions.YesNo) == DialogBoxAction.No) return; XmlDocument newmodel = new XmlDocument(); newmodel.LoadXml(defaultValue); field.SetValue(instance, newmodel); Application.ShowMessageBox(SR.msgActionModelDeleted, MessageBoxActions.Ok); } } }