Exemplo n.º 1
0
        public async Task <ActionResult> DeleteGet(string ns, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = "(default)";
            }
            if (!ModuleIdentifier.TryParse(ns, out var module))
            {
                logger.LogDebug("invalid module");
                return(BadRequest());
            }

            logger.LogDebug($"Delete {ns}:{name}");
            var found = await context.ModuleInstances.FirstOrDefaultAsync(
                m => m.Module == ns.ToLower() && m.Name == name.ToLower()
                );

            if (found == null)
            {
                return(NotFound($"No such module: {ns}/{name}"));
            }
            context.Remove(found);
            await context.SaveChangesAsync();

            return(Ok());
        }
 public static void get_report(Guid applicationId, ModuleIdentifier moduleIdentifier, string reportName,
                               ref DataTable retReport, ref string retActions, ref Dictionary <string, string> columnsDic,
                               List <ReportParameter> parameters)
 {
     DataProvider.GetReport(applicationId,
                            moduleIdentifier, reportName, ref retReport, ref retActions, ref columnsDic, parameters);
 }
 public static ValueTask <BlazorModuleManifest?> GetModuleManifestAsync(
     this IModuleManifestProvider moduleManifestProvider,
     ModuleIdentifier module,
     CancellationToken cancellation = default)
 {
     return(moduleManifestProvider.GetModuleManifestAsync(module, bypassCache: false, cancellation));
 }
Exemplo n.º 4
0
        private async ValueTask <ModuleProperties?> InternalLookupAsync(ModuleIdentifier module, CancellationToken cancellation)
        {
            var maxTries   = 10;
            var timeToWait = new TimeSpan(TimeSpan.TicksPerSecond * 2);

            for (var i = 0; i < maxTries; i++)
            {
                var query       = new ModulePropertiesQuery(module);
                var queryResult = await _messageDispatcher.DispatchAsync(query, cancellation);

                if (queryResult.IsSuccessWithResult <ModuleProperties>(out var moduleProperties))
                {
                    Assert(moduleProperties != null);
                    return(_cache.GetOrAdd(module, moduleProperties !));
                }

                if (!queryResult.IsNotFound())
                {
                    _logger?.LogError($"Unable to lookup end-point for module '{module.Name}' for reason: {(queryResult.IsSuccess ? "Wrong type returned" : queryResult.ToString())}.");
                    break;
                }

                await Task.Delay(timeToWait, cancellation).ConfigureAwait(false);
            }

            return(null);
        }
Exemplo n.º 5
0
        public IList <ModuleIdentifier> GetAvailableModules()
        {
            var dir = optionsMonitor.CurrentValue.Source;

            if (!Directory.Exists(dir))
            {
                logger.LogError("Config catalog directory not found: " + dir);
                throw new ApplicationException("Config catalog directory not found");
            }

            var list = new List <ModuleIdentifier>();

            foreach (var file in Directory.GetFiles(dir))
            {
                if (Path.GetExtension(file).ToLower() != ".json")
                {
                    continue;
                }
                var name = Path.GetFileNameWithoutExtension(file);
                if (ModuleIdentifier.TryParse(name, out var identifier))
                {
                    list.Add(identifier);
                }
            }
            foreach (var file in Directory.GetDirectories(dir))
            {
                var name = Path.GetFileName(file);
                if (ModuleIdentifier.TryParse(name, out var identifier))
                {
                    list.Add(identifier);
                }
            }
            return(list);
        }
Exemplo n.º 6
0
 // TODO: Refactor to own component
 private async ValueTask <Module> GetModuleAsync(ModuleIdentifier module, CancellationToken cancellation)
 {
     using (var scope = _serviceProvider.CreateScope())
     {
         var storageEngine = scope.ServiceProvider.GetRequiredService <IEntityStorageEngine>();
         return(await storageEngine.GetByIdAsync <Module>(module.ToString(), cancellation));
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Costruisce una nuova specifica
 /// </summary>
 /// <param name="moduleIdentifier">Module identifier.</param>
 public static Builder build(ModuleIdentifier moduleIdentifier)
 {
     if (moduleIdentifier == null)
     {
         throw new ArgumentException("ERROR: provide a valid module indentifier");
     }
     return(new BuilderImpl(moduleIdentifier));
 }
Exemplo n.º 8
0
        private static void _parse_logs(ref IDataReader reader, ref List <Log> lstLogs)
        {
            while (reader.Read())
            {
                try
                {
                    Log log = new Log();

                    if (!string.IsNullOrEmpty(reader["LogID"].ToString()))
                    {
                        log.LogID = (long)reader["LogID"];
                    }
                    if (!string.IsNullOrEmpty(reader["UserID"].ToString()))
                    {
                        log.UserID = (Guid)reader["UserID"];
                    }
                    if (!string.IsNullOrEmpty(reader["Date"].ToString()))
                    {
                        log.Date = (DateTime)reader["Date"];
                    }
                    if (!string.IsNullOrEmpty(reader["HostName"].ToString()))
                    {
                        log.HostName = (string)reader["HostName"];
                    }
                    if (!string.IsNullOrEmpty(reader["HostAddress"].ToString()))
                    {
                        log.HostAddress = (string)reader["HostAddress"];
                    }
                    if (!string.IsNullOrEmpty(reader["Info"].ToString()))
                    {
                        log.Info = (string)reader["Info"];
                    }

                    Action acn = Action.None;
                    if (!Enum.TryParse <Action>(reader["Action"].ToString(), out acn))
                    {
                        continue;
                    }

                    ModuleIdentifier mi = ModuleIdentifier.RV;
                    if (!Enum.TryParse <ModuleIdentifier>(reader["ModuleIdentifier"].ToString(), out mi))
                    {
                        continue;
                    }

                    log.Action           = acn;
                    log.ModuleIdentifier = mi;

                    lstLogs.Add(log);
                }
                catch { }
            }

            if (!reader.IsClosed)
            {
                reader.Close();
            }
        }
        public bool ContainsModule(ModuleIdentifier module)
        {
            if (_resolved == null)
            {
                return(false);
            }

            return(_resolved.ContainsKey(module));
        }
Exemplo n.º 10
0
        public UnresolvedInstallationSet SetVersionRange(ModuleIdentifier module, ModuleVersionRange versionRange)
        {
            if (_resolved != null && _resolved.ContainsKey(module))
            {
                throw new InvalidOperationException();
            }

            return(new UnresolvedInstallationSet(_resolved ?? ImmutableDictionary <ModuleIdentifier, ModuleVersion> .Empty,
                                                 (_unresolved ?? ImmutableDictionary <ModuleIdentifier, ModuleVersionRange> .Empty).SetItem(module, versionRange)));
        }
Exemplo n.º 11
0
        public UnresolvedInstallationSet WithUnresolved(ModuleIdentifier module, ModuleVersionRange versionRange)
        {
            if (ContainsModule(module))
            {
                throw new InvalidOperationException();
            }

            return(new UnresolvedInstallationSet(_resolved ?? ImmutableDictionary <ModuleIdentifier, ModuleVersion> .Empty,
                                                 (_unresolved ?? ImmutableDictionary <ModuleIdentifier, ModuleVersionRange> .Empty).Add(module, versionRange)));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Uninstall(ModuleIdentifier id)
        {
            var queryResult = await _messageDispatcher.QueryByIdAsync <ModuleIdentifier, ModuleUninstallModel>(id);

            if (queryResult.IsSuccessWithResult <ModuleUninstallModel>(out var model))
            {
                return(View(model));
            }

            return(GetActionResult(queryResult));
        }
Exemplo n.º 13
0
 public bool HasCompatibleCatalog(ModuleIdentifier module)
 {
     if (catalogCache.ContainsKey(module))
     {
         return(true);
     }
     return(catalogCache.Keys.Any(
                m => string.Compare(m.Name, module.Name,
                                    StringComparison.OrdinalIgnoreCase) == 0 &&
                m.Version.Major == module.Version.Major));
 }
Exemplo n.º 14
0
        private async Task <string> GetNormalizedPrefixAsync(ModuleIdentifier module, CancellationToken cancellation)
        {
            var prefix = await GetPrefixAsync(module, cancellation);

            if (!prefix.StartsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                prefix = "/" + prefix;
            }

            return(prefix);
        }
Exemplo n.º 15
0
        public static Guid?get_report_id(ModuleIdentifier moduleIdentifier, string reportName)
        {
            string name = (moduleIdentifier.ToString() + "_" + reportName).ToLower();
            Guid?  id   = null;

            if (ReportIDs.Any(u => u.Key.ToLower() == name))
            {
                id = ReportIDs.Where(u => u.Key.ToLower() == name).First().Value;
            }
            return(id);
        }
Exemplo n.º 16
0
        public ValueTask <BlazorModuleManifest?> GetModuleManifestAsync(ModuleIdentifier module, bool bypassCache, CancellationToken cancellation)
        {
            _logger?.LogDebug($"Requesting manifest for module {module}.");

            if (!bypassCache && _cache.TryGetValue(module, out var result))
            {
                _logger?.LogTrace($"Successfully loaded manifest for module {module} from cache.");
                return(new ValueTask <BlazorModuleManifest?>(result));
            }

            return(GetModuleManifestCoreAsync(module, cancellation));
        }
Exemplo n.º 17
0
        private static DebugModuleProperties Decode(ReadOnlySpan <byte> memory)
        {
            var reader       = new BinarySpanReader(memory, ByteOrder.LittleEndian);
            var endPoint     = new EndPointAddress(reader.Read().ToArray()); // TODO: This copies
            var module       = new ModuleIdentifier(reader.ReadString());
            var major        = reader.ReadInt32();
            var minor        = reader.ReadInt32();
            var revision     = reader.ReadInt32();
            var isPreRelease = reader.ReadBool();
            var version      = new ModuleVersion(major, minor, revision, isPreRelease);

            return(new DebugModuleProperties(endPoint, module, version));
        }
        public Task ModuleUninstalledAsync(ModuleIdentifier module,
                                           IDependencyResolver dependencyResolver, // TODO: This should be injected via DI
                                           CancellationToken cancellation = default)
        {
            if (module == default)
            {
                throw new ArgumentDefaultException(nameof(module));
            }

            InstalledModules = InstalledModules.WithoutUnresolved(module);

            return(ResolveDependenciesAsync(dependencyResolver, cancellation));
        }
Exemplo n.º 19
0
        public async Task InstallAssemblyAsync(ModuleIdentifier module, string assemblyName, CancellationToken cancellation)
        {
            Console.WriteLine("Loading assembly: " + assemblyName);

            var assemblyUri = GetAssemblyUri(await GetNormalizedPrefixAsync(module, cancellation), assemblyName);

            using (var assemblyStream = await _httpClient.GetStreamAsync(assemblyUri))
                using (var localAssemblyStream = await assemblyStream.ReadToMemoryAsync(cancellation))
                {
                    var assemblyBytes = localAssemblyStream.ToArray();
                    var assembly      = Assembly.Load(assemblyBytes);
                }
        }
        public ModuleVersion?GetResolvedVersion(ModuleIdentifier module)
        {
            if (_resolved == null)
            {
                return(null);
            }

            if (!_resolved.TryGetValue(module, out var result))
            {
                return(null);
            }

            return(result);
        }
Exemplo n.º 21
0
        public ValueTask <ModuleProperties?> LookupAsync(ModuleIdentifier module, CancellationToken cancellation)
        {
            if (module == default)
            {
                throw new ArgumentDefaultException(nameof(module));
            }

            if (_cache.TryGetValue(module, out var moduleProperties))
            {
                return(new ValueTask <ModuleProperties?>(moduleProperties));
            }

            return(InternalLookupAsync(module, cancellation));
        }
        public ValueTask <string> LookupPrefixAsync(ModuleIdentifier module, CancellationToken cancellation)
        {
            if (module == default)
            {
                throw new ArgumentDefaultException(nameof(module));
            }

            if (_prefixCache.TryGetValue(module, out var modulePrefix))
            {
                return(new ValueTask <string>(modulePrefix));
            }

            return(new ValueTask <string>(InternalLookupPrefixAsync(module, cancellation)));
        }
        public ValueTask <EndPointAddress> LookupEndPointAsync(ModuleIdentifier module, CancellationToken cancellation)
        {
            if (module == default)
            {
                throw new ArgumentDefaultException(nameof(module));
            }

            if (_endPointCache.TryGetValue(module, out var endPoint))
            {
                return(new ValueTask <EndPointAddress>(endPoint));
            }

            return(new ValueTask <EndPointAddress>(InternalLookupEndPointAsync(module, cancellation)));
        }
Exemplo n.º 24
0
        public bool ContainsModule(ModuleIdentifier module)
        {
            if (_resolved != null && _resolved.ContainsKey(module))
            {
                return(true);
            }

            if (_unresolved != null && _unresolved.ContainsKey(module))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 25
0
        public ConfigCatalog GetCompatibleCatalog(ModuleIdentifier module)
        {
            if (catalogCache.TryGetValue(module, out var catalog))
            {
                return(catalog);
            }
            var found = catalogCache.Keys
                        .Where(m => string.Compare(m.Name, module.Name,
                                                   StringComparison.OrdinalIgnoreCase) == 0)
                        .OrderByDescending(m => m.Version)
                        .FirstOrDefault(m => m.Version.Major == module.Version.Major);

            return(catalogCache.TryGetValue(found, out catalog) ? catalog : null);
        }
Exemplo n.º 26
0
        public ConfigCatalog LoadCatalogForModule(ModuleIdentifier module)
        {
            var dir     = optionsMonitor.CurrentValue.Source;
            var catalog = new ConfigCatalog()
            {
                ModuleInfo = new ModuleInfo()
                {
                    Identifier = module
                }
            };

            var basename = Path.Combine(dir, module.ToString());

            if (File.Exists(basename + ".json"))
            {
                logger.LogTrace($"load catalog file [{basename}.json]");
                string content = File.ReadAllText(basename + ".json");
                catalog = JsonConvert.DeserializeObject <ConfigCatalog>(content);
            }
            if (Directory.Exists(basename))
            {
                logger.LogTrace($"load catalog dir [{basename}]");
                var sections = new List <ConfigCatalog.Section>();
                foreach (var file in Directory.GetFiles(basename))
                {
                    logger.LogTrace($"-> loading {file}");
                    if (Path.GetExtension(file).ToLower() != ".json")
                    {
                        break;
                    }
                    string content = File.ReadAllText(file);
                    if (Path.GetFileNameWithoutExtension(file) == "moduleinfo")
                    {
                        catalog.ModuleInfo = JsonConvert.DeserializeObject <ModuleInfo>(content);
                    }
                    else
                    {
                        var section = JsonConvert.DeserializeObject <ConfigCatalog.Section>(content);
                        sections.Add(section);
                    }
                }
                catalog.Sections = sections.ToArray();
            }

            return(catalog);
        }
Exemplo n.º 27
0
        // TODO: This should be internal, but we have to split the interface to do this.
        public void Terminated(ModuleIdentifier module)
        {
            bool removed;

            lock (_mutex)
            {
                var modules = _modules;
                _modules = _modules.Remove(module);

                removed = modules != _modules;
            }

            if (removed)
            {
                ModuleTerminated?.InvokeAll(this, module);
            }
        }
Exemplo n.º 28
0
        public async Task <ActionResult <ConfigCatalog> > GetCompatibleCatalog(string ns)
        {
            if (!ModuleIdentifier.TryParse(ns, out var module))
            {
                logger.LogDebug("invalid module");
                return(BadRequest());
            }
            await moduleCatalogManager.LoadModuleCatalogCache();

            var catalog = moduleCatalogManager.GetCompatibleCatalog(module);

            if (catalog == null)
            {
                return(NotFound());
            }
            return(catalog);
        }
Exemplo n.º 29
0
        /// <summary>
        /// crea un alias per il modulo, ossia all'interno del sistema posso riferire
        /// ad uno stesso modulo tramite il suo alias.
        /// </summary>
        /// <returns>The alias.</returns>
        /// <param name="moduleIdentifier">Module identifier.</param>
        /// <param name="aliasTarget">Alias target, ossia il nome dell'alias </param>
        public static AliasBuilder buildAlias(ModuleIdentifier moduleIdentifier,
                                              ModuleIdentifier aliasTarget)
        {
            if (moduleIdentifier == null)
            {
                throw new ArgumentException("[ERROR] - moduleIdentifier is null");
            }

            if (aliasTarget == null)
            {
                throw new ArgumentException("[ERROR] - aliasTarget is null");
            }

            AliasBuilder aliasBuilder = new AliasBuilderImpl();

            aliasBuilder.create(moduleIdentifier, aliasTarget);
            return(aliasBuilder);
        }
        public Task ReleaseRemovedAsync(ModuleIdentifier module,
                                        ModuleVersion version,
                                        IDependencyResolver dependencyResolver, // TODO: This should be injected via DI
                                        CancellationToken cancellation = default)
        {
            if (module == default)
            {
                throw new ArgumentDefaultException(nameof(module));
            }

            // TODO: Is this ok?
            if (!ResolvedModules.ContainsModule(module))
            {
                return(Task.CompletedTask);
            }

            return(ResolveDependenciesAsync(dependencyResolver, cancellation));
        }