public PluginResponse InvokeMetrics(MetricsRequest metricsRequest,string metricsType)
 {
     PluginResourceAction pluginResourceAction = new PluginResourceAction(this.ConnectString);
     List<PluginMap> pluginMaps = pluginResourceAction.RetrievePluginMapByClassAndType(CentralConnectMetrics, metricsType);
     if (pluginMaps.Count != 1)
     {
         return new PluginResponse() { IsSuccess = false, Message = Enum.GetName(typeof(CentralConnectCode), CentralConnectCode.PluginMapNotExist) };
     }
     Logger.Write("PluginMaps", pluginMaps[0]);
     PluginMap pluginMap = pluginMaps[0];
     Resource resource = pluginResourceAction.RetrieveResourceByTypeAndFileName(PluginResource, pluginMap.FileName);
     if(string.IsNullOrEmpty(resource.FileName))
     {
         return new PluginResponse() { IsSuccess = false, Message = Enum.GetName(typeof(CentralConnectCode), CentralConnectCode.ResourceFileNotExist) };
     }
     System.Reflection.Assembly assembly = null;
     if (!LoadPluginResourceFile(resource, out assembly) || assembly == null)
     {
         return new PluginResponse() { IsSuccess = false, Message = Enum.GetName(typeof(CentralConnectCode), CentralConnectCode.LoadResourceFileFail) };
     }
     IMetrics iMetrics = (IMetrics)assembly.CreateInstance(pluginMap.ClassFullName);
     if (iMetrics == null)
     {
         return new PluginResponse() { IsSuccess = false, Message = Enum.GetName(typeof(CentralConnectCode), CentralConnectCode.CreateMetricsInstanceFail) };
     }
     DictionaryAction dictionaryAction = new DictionaryAction(this.ConnectString);
     string workspace = dictionaryAction.RetrieveValueByTypeAndKey("Settings", "Workspace");
     metricsRequest.Workspace = System.IO.Path.Combine(workspace, CentralConnectMetrics);
     return iMetrics.GenerateMetrics(metricsRequest);
 }
        public void TestAddResourceAndPluginMap()
        {
            PluginResourceAction resourceAction = new PluginResourceAction(ConnectString);
            Resource resource = new Resource();
            resource.ResourceType = "Plugin";

            FileStream fileStream = new FileStream(@"D:\Crazywolf\Devops\DevopsSupportCenter\HP.TS.Devops.CentralConnect.Plugin.General\bin\Debug\HP.TS.Devops.CentralConnect.Plugin.General.dll", FileMode.Open, FileAccess.Read, FileShare.None);
            StreamReader streamReader = new StreamReader(fileStream);
            byte[] source = new byte[fileStream.Length];
            fileStream.Read(source, 0, (int)fileStream.Length);
            fileStream.Close();
            resource.ResourceType = "Plugin";
            resource.FileName = @"HP.TS.Devops.CentralConnect.Plugin.General.dll";
            resource.FileContent = source;
            resource.CreateBy = "UnitTest";
            int result = resourceAction.AddResource(resource);
            PluginMap pluginMap = new PluginMap();
            pluginMap.PluginClass = "CentralConnectMetrics";
            pluginMap.PluginType = "MetricsV1";
            pluginMap.Description = "Official Metrics Plugin";
            pluginMap.FileName = resource.FileName;
            pluginMap.ClassFullName = "HP.TS.Devops.CentralConnect.Plugin.General.Metrics.MetricsV1";
            result = resourceAction.AddPluginMap(pluginMap);
        }