/* ------------------------------------------------------------------------ File: Program Module: Vector.ODXStudio.Plugins.SyntaxCheckerPluginExample --------------------------------------------------------------------------- Syntax Checker Plugin Example --------------------------------------------------------------------------- Copyright (c) Vector Informatik GmbH. All rights reserved. ------------------------------------------------------------------------ */ using System; using System.Collections.Generic; using System.IO; using Vector.ODXStudio.PluginInterfaces; #if DEBUG #endif namespace Vector.ODXStudio.Plugins.SyntaxCheckerPluginExample { public class SyntaxCheckerExamplePlugin : MarshalByRefObject, ISyntaxCheckerPlugin { private const string NAME = "Syntax Checker Plugin Example"; private const string DESCRIPTION = "Example implementation of a Syntax Checker Plugin"; private const string AUTHOR = "Vector Informatik GmbH"; private string mLastError = string.Empty; private SyntaxCheckSummary mSummaryData; private List mItemList; #if DEBUG private StreamWriter mStreamWriter; private const string mDumpFile = "SyntaxCheckerExamplePlugin.txt"; #endif #region MarshalByRefObject overrides /// /// Assure an infinite lifetime for the object /// /// null public override object InitializeLifetimeService() { return null; } #endregion #region Implementation of IPlugin /// /// Initialize the Plugin /// /// LanguageCode the ODXStudio GUI is running in ("en-US" or "de-DE"). May be used to synchronize Plugin GUI language with ODXStudio. public void Initialize(string languageCode) { //throw new NotImplementedException(); } /// /// Dispose the Plugin /// public void Dispose() { //throw new NotImplementedException(); } /// /// Retrieves description of the last error occurred /// /// /// Error text /// public string GetLastError() { return mLastError; } /// /// Get name of the Plugin /// public string Name { get { return NAME; } } /// /// Get description of the Plugin /// public string Description { get { return DESCRIPTION; } } /// /// Get author of the Plugin /// public string Author { get { return AUTHOR; } } /// /// Get version of the Plugin /// public string Version { get { Version ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; return string.Format("{0}.{1}.{2}", ver.Major, ver.Minor, ver.Build); } } #endregion #region Implementation of ISyntaxCheckerPlugin /// /// Configures ODXStudio not to fire CheckElement for certain objects when running the plugin /// /// SyntaxCheckDeRegisterInfo of the plugin public void Configure(out SyntaxCheckDeRegisterInfo deRegisterInfo) { deRegisterInfo = new SyntaxCheckDeRegisterInfo(); List list = new List(); #if !DEBUG SyntaxCheckDeRegisterItem item = new SyntaxCheckDeRegisterItem { Type = SyntaxCheckDeRegisterItem.DeRegisterType.ElementType, Value = "SESSION" }; list.Add(item); #endif deRegisterInfo.SyntaxCheckDeRegisterItems = list.ToArray(); // Init the summary data mSummaryData = new SyntaxCheckSummary(); mItemList = new List(); #if DEBUG { string tempDir = Path.GetTempPath(); string filePath = Path.Combine(tempDir, mDumpFile); FileStream fstream = File.Create(filePath); mStreamWriter = new StreamWriter(fstream); mStreamWriter.WriteLine("SyntaxCheckerExamplePlugin Dump {0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); mItemList.Add(new SyntaxCheckSummaryItem { Severity = SyntaxCheckSummaryItem.ItemSeverity.Info, Category = "INFO", Context = "PLUGIN", Summary = string.Format("Dumping all element data to '{0}'", filePath) }); } #endif } /// /// Called for each element not excluded in the Configure step /// /// SyntaxCheckElementData for the element to be checked /// /// True if check has been performed. /// public bool CheckElement(SyntaxCheckElementData elementData) { #if DEBUG { mStreamWriter.WriteLine("{0}", elementData.ElementPath); } #endif // Traverse the name/value pairs for the element to to the checks if (elementData.SyntaxCheckElementProperties.GetLength(0) > 0) { foreach (var elementProperty in elementData.SyntaxCheckElementProperties) { #if DEBUG if (!string.IsNullOrWhiteSpace(elementProperty.Value)) { mStreamWriter.WriteLine(" {0,-20}:{1}", elementProperty.Name, elementProperty.Value); } #endif // Check LONG-NAME if (elementProperty.Name == "LONG-NAME") { if (string.IsNullOrEmpty(elementProperty.Value)) { SyntaxCheckSummaryItem item = new SyntaxCheckSummaryItem { Severity = SyntaxCheckSummaryItem.ItemSeverity.Info, Category = "Rule 1", Context = elementData.ElementPath, Summary = string.Format("Empty LONG-NAME.") }; mItemList.Add(item); } } // Do other checks } } return true; } /// /// Retrieves the summary of the last plugin run /// /// SyntaxCheckSummary data for the last plugin runtrue if checkSummary shall be written to the StatusWindow and Logfile /// /// True if summary could be created /// public bool CheckSummary(out SyntaxCheckSummary checkSummaryData, out bool logCheckResult) { logCheckResult = true; mSummaryData.SyntaxCheckSummaryItems = mItemList.ToArray(); mItemList.Clear(); checkSummaryData = mSummaryData; #if DEBUG { mStreamWriter.Close(); } #endif return true; } #endregion } }