/* ------------------------------------------------------------------------ File: FlashPlugin.cs Module: Vector.ODXStudio.Plugins.FlashPluginExample --------------------------------------------------------------------------- Example Flash Plugin --------------------------------------------------------------------------- Copyright (c) Vector Informatik GmbH. All rights reserved. ------------------------------------------------------------------------ */ using System; using System.Collections.Generic; using System.IO; using System.Text; using Vector.ODXStudio.PluginInterfaces; namespace Vector.ODXStudio.Plugins.FlashPluginExample { public class ExampleFlashPlugin : MarshalByRefObject, ISecurityEncryptionCompressionPlugin { private const string NAME = "Flash Plugin Example"; private const string DESCRIPTION = "Example flash plugin that illustrates the usage of the ISecurityEncryptionCompressionPlugin interface"; private const string AUTHOR = "Vector Informatik GmbH"; private string mLastError = string.Empty; private IDataExtractionPluginHost mHost; private List> mDataList; #region MarshalByRefObject overrides /// /// Assure an infinite lifetime for the object /// /// null public override object InitializeLifetimeService() { return null; } #endregion #region ISecurityEncryptionCompressionPlugin public void Initialize(string languageCode) { if (mDataList == null) mDataList = new List>(); } public void Dispose() { mDataList.Clear(); } public string GetLastError() { return mLastError; } public string Name { get { return NAME; } } public string Description { get { return DESCRIPTION; } } public string Author { get { return AUTHOR; } } public string Version { get { Version ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; return string.Format("{0}.{1}.{2}", ver.Major, ver.Minor, ver.Build); } } public int GetNumDataIdentifiers() { return mDataList.Count; } public string GetDataIdentifier(int idx) { return idx < mDataList.Count ? mDataList[idx].Key : null; } public string GetDataValue(int idx) { return idx < mDataList.Count ? mDataList[idx].Value : null; } public IDataExtractionPluginHost Host { get { return mHost; } set { mHost = value; } } public bool SupportsFlashProcess(string flashProcessName) { return flashProcessName == "Vector"; } public bool ProcessData(string flashDataFilePathIn, string dataFormat, string securityPluginSegmentInfo, string secMethod, string secKey, string encryptCompressMethod, string encKey, string encIv, string tempDir, ref string flashDataFilePathOut, string dataFormatOut, bool crcOnCompressedData, bool silent) { mDataList.Clear(); mLastError = "This operation is not supported by " + NAME; return false; } public bool ProcessDataBatch(int flashwareIndex, string flashDataFilePathIn, string dataFormat, string securityPluginSegmentInfo, string secMethod, string secKey, string encryptCompressMethod, string tempDir, ref string flashDataFilePathOut, string dataFormatOut) { mDataList.Clear(); string currentProjectDir = string.Empty; string pluginConfigDir = string.Empty; int identifiersFound = 0; // Look for 2 identifiers that may be provided by ODXStudio for (int idx = 0; idx < Host.GetNumDataIdentifiers() && identifiersFound < 2; ++idx) { switch (Host.GetDataIdentifier(idx)) { case "ODXStudio.CurrentProjectDirectory": currentProjectDir = Host.GetDataValue(idx); ++identifiersFound; break; case "ODXStudio.PluginConfigurationDirectory": pluginConfigDir = Host.GetDataValue(idx); ++identifiersFound; break; } } // Import flashware file as is flashDataFilePathOut = flashDataFilePathIn; // Look for a file flashDataFilePathIn.crc containing the CRC and provide CRC to ODXStudio var crcValue = new StringBuilder(); string crcFile = Path.Combine(Path.GetDirectoryName(flashDataFilePathIn), Path.GetFileNameWithoutExtension(flashDataFilePathIn) + ".crc"); if (File.Exists(crcFile)) { try { string crcFileContent = File.ReadAllText(crcFile); // we expect a crc format of "0xAB,0xCD,0xEF;..." string[] crcBytes = crcFileContent.Split(','); foreach (string crcByte in crcBytes) { crcValue.Append(crcByte.Trim().Replace("0x", string.Empty)); } // Provide CRC for current flashware extracted from the .crc file string crc = string.Format(@"FW-CHECKSUM-TYPE-BYTE=""{0}""", crcValue); mDataList.Add(new KeyValuePair("DATABLOCK-SECURITY", crc)); } catch (Exception e) { mLastError = string.Format("Error extracting CRC from file {0}. Message: {1}", crcFile, e.Message); return false; } } return true; } #endregion } }