예제 #1
0
 public void Persist(PluginDescription pluginDescription, byte[] pluginPackage)
 {
     using (var ctx = new DeploymentDataContext()) {
         try {
             using (var transaction = new TransactionScope()) {
                 Plugin pluginEntity = InsertOrUpdatePlugin(ctx, pluginDescription);
                 if (pluginEntity.PluginPackage == null)
                 {
                     // insert
                     pluginEntity.PluginPackage = MakePluginPackage(pluginEntity, pluginPackage);
                 }
                 else
                 {
                     // update
                     pluginEntity.PluginPackage.Data = pluginPackage;
                 }
                 ctx.SubmitChanges();
                 transaction.Complete();
             }
         }
         catch (SqlException ex) {
             throw new ArgumentException("Something went wrong while trying to persist plugin", ex);
         }
         catch (InvalidOperationException ex) {
             throw new ArgumentException("Something went wrong while trying to persist plugin", ex);
         }
     }
 }
예제 #2
0
        private Plugin MakePluginFromDescription(PluginDescription pluginDescription)
        {
            var plugin = new Plugin();

            plugin.Name         = pluginDescription.Name;
            plugin.Version      = pluginDescription.Version.ToString();
            plugin.ContactName  = pluginDescription.ContactName;
            plugin.ContactEmail = pluginDescription.ContactEmail;
            plugin.License      = pluginDescription.LicenseText;
            return(plugin);
        }
예제 #3
0
        private Plugin InsertOrUpdatePlugin(DeploymentDataContext ctx, PluginDescription pluginDescription)
        {
            var pluginEntity = (from p in ctx.Plugins
                                where p.Name == pluginDescription.Name
                                where p.Version == pluginDescription.Version.ToString()
                                select p).FirstOrDefault() ?? MakePluginFromDescription(pluginDescription);

            if (pluginEntity.Id <= 0)
            {
                ctx.Plugins.InsertOnSubmit(pluginEntity);
                ctx.SubmitChanges();
            }

            UpdatePlugin(ctx, pluginEntity, pluginDescription);
            return(pluginEntity);
        }
예제 #4
0
        private PluginDescription MakePluginDescription(DeploymentDataContext ctx, Plugin plugin)
        {
            if (!pluginDescriptions.ContainsKey(plugin.Id))
            {
                // no cached description -> create new
                var desc = new PluginDescription(plugin.Name, new Version(plugin.Version));
                pluginDescriptions[plugin.Id] = desc; // and add to cache

                // fill remaining properties of plugin description
                desc.Dependencies = new List <PluginDescription>(from dep in GetDependencies(ctx, plugin) select MakePluginDescription(ctx, dep));
                desc.ContactEmail = plugin.ContactEmail ?? string.Empty;
                desc.ContactName  = plugin.ContactName ?? string.Empty;
                desc.LicenseText  = plugin.License ?? string.Empty;
            }
            return(pluginDescriptions[plugin.Id]);
        }
예제 #5
0
        private void UpdatePlugin(DeploymentDataContext ctx, Plugin pluginEntity, PluginDescription pluginDescription)
        {
            // update plugin data
            pluginEntity.License      = pluginDescription.LicenseText;
            pluginEntity.ContactName  = pluginDescription.ContactName;
            pluginEntity.ContactEmail = pluginDescription.ContactEmail;

            // delete cached entry
            if (pluginDescriptions.ContainsKey(pluginEntity.Id))
            {
                pluginDescriptions.Remove(pluginEntity.Id);
            }

            DeleteOldDependencies(ctx, pluginEntity);

            foreach (var dependency in pluginDescription.Dependencies)
            {
                var        dependencyEntity = GetExistingPlugin(ctx, dependency.Name, dependency.Version);
                Dependency d = new Dependency();
                d.PluginId     = pluginEntity.Id;
                d.DependencyId = dependencyEntity.Id;
                ctx.Dependencies.InsertOnSubmit(d);
            }
        }
예제 #6
0
 public void Persist(PluginDescription pluginDescription, byte[] pluginPackage) {
   using (var ctx = new DeploymentDataContext()) {
     try {
       using (var transaction = new TransactionScope()) {
         Plugin pluginEntity = InsertOrUpdatePlugin(ctx, pluginDescription);
         if (pluginEntity.PluginPackage == null) {
           // insert
           pluginEntity.PluginPackage = MakePluginPackage(pluginEntity, pluginPackage);
         } else {
           // update
           pluginEntity.PluginPackage.Data = pluginPackage;
         }
         ctx.SubmitChanges();
         transaction.Complete();
       }
     }
     catch (SqlException ex) {
       throw new ArgumentException("Something went wrong while trying to persist plugin", ex);
     }
     catch (InvalidOperationException ex) {
       throw new ArgumentException("Something went wrong while trying to persist plugin", ex);
     }
   }
 }
예제 #7
0
 public void DeployPlugin(PluginDescription plugin, byte[] zipFile) {
   var store = new PluginStore();
   store.Persist(plugin, zipFile);
 }
예제 #8
0
 public byte[] GetPlugin(PluginDescription description) {
   PluginStore store = new PluginStore();
   return store.PluginFile(description);
 }
예제 #9
0
        public void DeployPlugin(PluginDescription plugin, byte[] zipFile)
        {
            var store = new PluginStore();

            store.Persist(plugin, zipFile);
        }
예제 #10
0
        public byte[] GetPlugin(PluginDescription description)
        {
            PluginStore store = new PluginStore();

            return(store.PluginFile(description));
        }
예제 #11
0
 public byte[] PluginFile(PluginDescription pluginDescription)
 {
     using (var ctx = new DeploymentDataContext()) {
         return(GetExistingPlugin(ctx, pluginDescription.Name, pluginDescription.Version).PluginPackage.Data.ToArray());
     }
 }
예제 #12
0
 public byte[] PluginFile(PluginDescription pluginDescription) {
   using (var ctx = new DeploymentDataContext()) {
     return GetExistingPlugin(ctx, pluginDescription.Name, pluginDescription.Version).PluginPackage.Data.ToArray();
   }
 }
예제 #13
0
 private Plugin MakePluginFromDescription(PluginDescription pluginDescription) {
   var plugin = new Plugin();
   plugin.Name = pluginDescription.Name;
   plugin.Version = pluginDescription.Version.ToString();
   plugin.ContactName = pluginDescription.ContactName;
   plugin.ContactEmail = pluginDescription.ContactEmail;
   plugin.License = pluginDescription.LicenseText;
   return plugin;
 }
예제 #14
0
    private PluginDescription MakePluginDescription(DeploymentDataContext ctx, Plugin plugin) {
      if (!pluginDescriptions.ContainsKey(plugin.Id)) {
        // no cached description -> create new
        var desc = new PluginDescription(plugin.Name, new Version(plugin.Version));
        pluginDescriptions[plugin.Id] = desc; // and add to cache

        // fill remaining properties of plugin description
        desc.Dependencies = new List<PluginDescription>(from dep in GetDependencies(ctx, plugin) select MakePluginDescription(ctx, dep));
        desc.ContactEmail = plugin.ContactEmail ?? string.Empty;
        desc.ContactName = plugin.ContactName ?? string.Empty;
        desc.LicenseText = plugin.License ?? string.Empty;
      }
      return pluginDescriptions[plugin.Id];
    }
예제 #15
0
    private void UpdatePlugin(DeploymentDataContext ctx, Plugin pluginEntity, PluginDescription pluginDescription) {
      // update plugin data
      pluginEntity.License = pluginDescription.LicenseText;
      pluginEntity.ContactName = pluginDescription.ContactName;
      pluginEntity.ContactEmail = pluginDescription.ContactEmail;

      // delete cached entry
      if (pluginDescriptions.ContainsKey(pluginEntity.Id)) pluginDescriptions.Remove(pluginEntity.Id);

      DeleteOldDependencies(ctx, pluginEntity);

      foreach (var dependency in pluginDescription.Dependencies) {
        var dependencyEntity = GetExistingPlugin(ctx, dependency.Name, dependency.Version);
        Dependency d = new Dependency();
        d.PluginId = pluginEntity.Id;
        d.DependencyId = dependencyEntity.Id;
        ctx.Dependencies.InsertOnSubmit(d);
      }
    }
예제 #16
0
    private Plugin InsertOrUpdatePlugin(DeploymentDataContext ctx, PluginDescription pluginDescription) {
      var pluginEntity = (from p in ctx.Plugins
                          where p.Name == pluginDescription.Name
                          where p.Version == pluginDescription.Version.ToString()
                          select p).FirstOrDefault() ?? MakePluginFromDescription(pluginDescription);

      if (pluginEntity.Id <= 0) {
        ctx.Plugins.InsertOnSubmit(pluginEntity);
        ctx.SubmitChanges();
      }

      UpdatePlugin(ctx, pluginEntity, pluginDescription);
      return pluginEntity;
    }