public int AddResource(Resource resource)
 {
     return Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(this.ConnectString, "SP_AddResource",
         resource.ResourceType,
         resource.FileName,
         resource.FileContent,
         resource.CreateBy);
 }
 public Resource RetrieveResourceByTypeAndFileName(string resourceType,string fileName)
 {
     DataSet dataSet = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(this.ConnectString, "SP_RetrieveResourceByTypeAndFileName", resourceType, fileName);
     Resource resource = new Resource();
     foreach (DataRow item in dataSet.Tables[0].Rows)
     {
         resource.ResourceType = item["ResourceType"] as string;
         resource.FileName = item["FileName"] as string;
         resource.FileContent = item["FileContent"] as byte[];
         resource.CreateBy = item["CreateBy"] as string;
     }
     return resource;
 }
 private bool LoadPluginResourceFile(Resource resource, out System.Reflection.Assembly assembly)
 {
     DictionaryAction dictionaryAction = new DictionaryAction(this.ConnectString);
     string resources = dictionaryAction.RetrieveValueByTypeAndKey("Settings", "Resources");
     string resourcePath = System.IO.Path.Combine(resources, PluginResource);
     if (!Directory.Exists(resourcePath))
     {
         Directory.CreateDirectory(resourcePath);
     }
     string resourceFile = System.IO.Path.Combine(resourcePath, resource.FileName);
     if (!System.IO.File.Exists(resourceFile))
     {
         using (FileStream fileStream = new FileStream(resourceFile, FileMode.CreateNew, FileAccess.Write, FileShare.None))
         {
             fileStream.Write(resource.FileContent, 0, resource.FileContent.Length);
             fileStream.Flush();
             fileStream.Close();
         }
     }
     assembly = System.Reflection.Assembly.LoadFrom(resourceFile);
     return true;
 }
        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);
        }