Пример #1
0
 private void initKey()
 {
     try
     {
         /**
          * 获取秘钥
          * 没有秘钥则产生一对秘钥,并用非明文方式保存秘钥
          * */
         String strKey = FileReadWrite.Read();
         if (String.IsNullOrEmpty(strKey))
         {
             Key    = AesCryptoHelper.CreateKeyAndIv();
             strKey = SerializationHelper.Serialization(Key);
             strKey = AesCryptoHelper.Encrypt(strKey, keyEncryptorKey);
             FileReadWrite.Write(strKey);
         }
         else
         {
             strKey = AesCryptoHelper.Decrypt(strKey, keyEncryptorKey);
             Key    = SerializationHelper.Deserialization(strKey);
         }
     }
     catch (Exception ex)
     {
         var entity = LogEntityFactory.Create(String.Format("秘钥初始化失败:{0}", ex.ToString()),
                                              LogTypeFacotry.CreateExceptionLogType(),
                                              LogLevelFactory.CreateGravenessLogLevel());
         log.SaveLog(entity);
         throw new Exception("秘钥初始化失败,秘钥文件被破坏!");
     }
 }
Пример #2
0
        private void lvPlugin_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (lvPlugin.SelectedItems.Count > 0)
            {
                try
                {
                    IPlugin plugin = this.lvPlugin.SelectedItems[0].Tag as IPlugin;
                    plugin.StartUp();
                }
                catch (Exception ex)
                {
                    var entity = LogEntityFactory.Create(String.Format("启动工具失败:{0}", ex.ToString()),
                                                         LogTypeFacotry.CreateExceptionLogType(),
                                                         LogLevelFactory.CreateGravenessLogLevel());
                    log.SaveLog(entity);

                    MessageBox.Show(ex.ToString(), "启动工具失败");
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 加载插件
        /// </summary>
        private static void LoadPlugins()
        {
            Plugins = new List <IPlugin>();
            List <String> files = GetFiles(PluginsFolder);

            foreach (String filePath in files)
            {
                string fileName      = Path.GetFileName(filePath);
                string fileExtension = Path.GetExtension(filePath);

                if (fileName.Equals("MyDevTools.Plugin.dll", StringComparison.InvariantCultureIgnoreCase) ||
                    !_pluginExtensions.Contains(fileExtension))
                {
                    continue;
                }

                try
                {
                    Assembly pluginAssembly = Assembly.LoadFrom(filePath);
                    Type[]   exprotedTypes  = pluginAssembly.GetExportedTypes();

                    foreach (Type type in exprotedTypes)
                    {
                        if (!TypeIsIPlugin(type))
                        {
                            continue;
                        }

                        Plugins.Add((IPlugin)Activator.CreateInstance(type));
                    }
                }
                catch (Exception ex)
                {
                    var entity = LogEntityFactory.Create(String.Format("加载插件 {0} 时出现错误:{1}", fileName, ex.ToString()),
                                                         LogTypeFacotry.CreateExceptionLogType(),
                                                         LogLevelFactory.CreateWarningLogLevel());
                    log.SaveLog(entity);
                }
            }
        }