コード例 #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
 public void Persist(ProductDescription productDescription) {
   using (var ctx = new DeploymentDataContext()) {
     try {
       using (var transaction = new TransactionScope()) {
         foreach (var plugin in productDescription.Plugins) {
           var pluginEntity = GetExistingPlugin(ctx, plugin.Name, plugin.Version);
           UpdatePlugin(ctx, pluginEntity, plugin);
         }
         InsertOrUpdateProduct(ctx, productDescription);
         ctx.SubmitChanges();
         transaction.Complete();
       }
     }
     catch (SqlException ex) {
       throw new ArgumentException("Something went wrong while trying to persist product", ex);
     }
     catch (InvalidOperationException ex) {
       throw new ArgumentException("Something went wrong while trying to persist product", ex);
     }
   }
 }
コード例 #3
0
    private void DeleteOldDependencies(DeploymentDataContext ctx, Plugin pluginEntity) {
      var oldDependencies = (from dep in ctx.Dependencies
                             where dep.PluginId == pluginEntity.Id
                             select dep).ToList();

      ctx.Dependencies.DeleteAllOnSubmit(oldDependencies);
      ctx.SubmitChanges();
    }
コード例 #4
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;
    }
コード例 #5
0
 private void DeleteProductPlugins(DeploymentDataContext ctx, Product productEntity) {
   var oldPlugins = (from p in ctx.ProductPlugins
                     where p.ProductId == productEntity.Id
                     select p).ToList();
   ctx.ProductPlugins.DeleteAllOnSubmit(oldPlugins);
   ctx.SubmitChanges();
 }
コード例 #6
0
    private void InsertOrUpdateProduct(DeploymentDataContext ctx, ProductDescription product) {
      var productEntity = (from p in ctx.Products
                           where p.Name == product.Name
                           where p.Version == product.Version.ToString()
                           select p).FirstOrDefault() ?? MakeProductFromDescription(product);

      if (productEntity.Id <= 0) {
        ctx.Products.InsertOnSubmit(productEntity);
        ctx.SubmitChanges();
      }

      DeleteProductPlugins(ctx, productEntity);

      foreach (var plugin in product.Plugins) {
        var existingPlugin = GetExistingPlugin(ctx, plugin.Name, plugin.Version);
        ProductPlugin prodPlugin = new ProductPlugin();
        prodPlugin.PluginId = existingPlugin.Id;
        prodPlugin.ProductId = productEntity.Id;
        ctx.ProductPlugins.InsertOnSubmit(prodPlugin);
      }
    }
コード例 #7
0
    public void Delete(ProductDescription productDescription) {
      using (var ctx = new DeploymentDataContext()) {
        try {
          using (var transaction = new TransactionScope()) {
            var productEntity = GetExistingProduct(ctx, productDescription.Name, productDescription.Version);

            DeleteProductPlugins(ctx, productEntity);
            ctx.Products.DeleteOnSubmit(productEntity);

            ctx.SubmitChanges();
            transaction.Complete();
          }
        }
        catch (SqlException ex) {
          throw new ArgumentException("Something went wrong while trying to delete product", ex);
        }
        catch (InvalidOperationException ex) {
          throw new ArgumentException("Something went wrong while trying to delete product", ex);
        }
      }
    }