public async Task SetProductsActionAsync(List <Product> products, ProductAction productAction)
        {
            // Get all products for this client
            List <ProductOnClient> productsOnClient = await GetAllAsync().ConfigureAwait(false);

            // Get all products that aren't already created for this client
            List <Product> notCreatedProducts = products.Where(product => productsOnClient.All(productOnClient => productOnClient.ProductId != product.Id)).ToList();

            // Create objects if any need to be created
            foreach (var product in notCreatedProducts)
            {
                await CreateProductAsync(product).ConfigureAwait(false);
            }

            // Update productsOnClient only if there are new products for this client
            if (notCreatedProducts.Any())
            {
                productsOnClient = await GetAllAsync().ConfigureAwait(false);
            }

            // Get all Products On Client that should be applied
            productsOnClient = productsOnClient.Where(productOnClient => products.Any(product => product.Id == productOnClient.ProductId)).ToList();

            // Set Action for all products
            productsOnClient.ForEach(productOnClient => productOnClient.ActionRequest = productAction.ToOpsiName());

            await OpsiHttpClient.ExecuteAsync <List <string> >(new Request(GetFullMethodName("updateObjects")).AddParametersAsJArray(productsOnClient)).ConfigureAwait(false);
        }
예제 #2
0
 /// <summary>
 /// Installs an opsi package.
 /// This method returns as soon as the installation is fully completed
 /// </summary>
 /// <param name="absoluteFilePath"></param>
 /// <param name="timeout">The timeout to wait until the product is installed. We don't have any status update only if an error appears. Another solution would be to use the SSH Command or check the logs</param>
 /// <returns>Nothing if successful otherwise an exception</returns>
 public Task InstallPackageAsync(string absoluteFilePath, int timeout = 180)
 {
     return(OpsiHttpClient.ExecuteAsync <string>(
                new Request(GetFullMethodName("installPackage")).AddParameter(absoluteFilePath),
                timeout
                ));
 }
        /// <summary>
        /// Creates a new product for this client
        /// Runs only if the product isn't already created for this client. Otherwise an exception will be thrown
        /// </summary>
        /// <returns></returns>
        public async Task CreateProductAsync(Product product)
        {
            if (await IsProductCreatedAsync(product).ConfigureAwait(false))
            {
                throw new OpsiProductAlreadyExistsException($"The product {product.Id} is already defined for this client {ClientId}");
            }

            // Create the product definition for this client
            await OpsiHttpClient.ExecuteAsync <List <string> >(new Request(GetFullMethodName("create")).AddParameters(product.Id, product.Type, ClientId)).ConfigureAwait(false);
        }
예제 #4
0
 public DepotInterface(OpsiHttpClient opsiHttpClient) : base(opsiHttpClient)
 {
 }
예제 #5
0
 /// <summary>
 /// Uninstalls an opsi package
 /// </summary>
 /// <param name="productId">The product id which should be uninstalled</param>
 /// <param name="timeout">The timeout to wait until the product is uninstalled. We don't have any status update only if an error appears. Another solution would be to use the SSH Command or check the logs</param>
 /// <returns>Nothing if successful otherwise an exception</returns>
 public Task UninstallPackageAsync(string productId, int timeout = 180)
 {
     return(OpsiHttpClient.ExecuteAsync <string>(
                new Request(GetFullMethodName("uninstallPackage")).AddParameter(productId)
                ));
 }
예제 #6
0
 /// <summary>
 /// Returns a md5 sum of a file in the depot
 /// </summary>
 /// <param name="absoluteFilePath">The absolute file path to the file. Usually /var/lib/opsi/repository</param>
 /// <returns>The md5Sum of the file</returns>
 public Task <string> GetMd5SumAsync(string absoluteFilePath)
 {
     return(OpsiHttpClient.ExecuteAsync <string>(
                new Request(GetFullMethodName("getMD5Sum")).AddParameter(absoluteFilePath)
                ));
 }
예제 #7
0
 /// <summary>
 /// Retrieve general opsi information of the backend
 /// </summary>
 public Task <BackendInfo> InfoAsync() => OpsiHttpClient.ExecuteAsync <BackendInfo>(new Request(GetFullMethodName("info")));
예제 #8
0
 public BackendInterface(OpsiHttpClient opsiHttpClient) : base(opsiHttpClient)
 {
 }
예제 #9
0
 internal RpcInterface(OpsiHttpClient opsiHttpClient)
 {
     OpsiHttpClient = opsiHttpClient;
 }
 internal ProductsOnClientInterface(OpsiHttpClient opsiHttpClient, Host host) : base(opsiHttpClient)
 {
     ClientId = host.Id;
 }
 internal ProductsOnClientInterface(OpsiHttpClient opsiHttpClient, string clientId) : base(opsiHttpClient)
 {
     ClientId = clientId;
 }
예제 #12
0
 internal HostInterface(OpsiHttpClient opsiHttpClient) : base(opsiHttpClient)
 {
 }
 internal ProductsInterface(OpsiHttpClient opsiHttpClient) : base(opsiHttpClient)
 {
 }