예제 #1
0
        public object ExecuteTool(string uid, [FromBody] IDictionary parameters = null)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            if (parameters == null)
            {
                parameters = new PythonDictionary();
            }

            Package package;

            try
            {
                package = _packageManagerService.LoadPackage(PackageUid.Parse(uid));
            }
            catch (WirehomePackageNotFoundException)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            try
            {
                var scriptHost = _pythonScriptHostFactoryService.CreateScriptHost(null);
                scriptHost.Compile(package.Script);
                return(scriptHost.InvokeFunction("main", parameters));
            }
            catch (Exception exception)
            {
                return(new ExceptionPythonModel(exception).ConvertToPythonDictionary());
            }
        }
        public IFileInfo GetFileInfo(string subpath)
        {
            if (subpath == null)
            {
                throw new ArgumentNullException(nameof(subpath));
            }

            var fullPath = subpath.Trim(Path.PathSeparator, Path.AltDirectorySeparatorChar);

            if (_defaultFileNames.Contains(fullPath))
            {
                subpath = "index.html";
            }

            var packageUid      = _globalVariablesService.GetValue(_packageUidGlobalVariableUid) as string;
            var packageRootPath = _packageManagerService.GetPackageRootPath(PackageUid.Parse(packageUid));

            fullPath = Path.Combine(packageRootPath, fullPath);

            if (!File.Exists(fullPath))
            {
                return(new NotFoundFileInfo(subpath));
            }

            return(new PhysicalFileInfo(new FileInfo(fullPath)));
        }
        public async Task ForkPackage(string uid, string forkUid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(forkUid));
            }

            var packageUid = PackageUid.Parse(uid);

            if (string.IsNullOrEmpty(packageUid.Version))
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            var packageForkUid = PackageUid.Parse(forkUid);

            if (string.IsNullOrEmpty(packageForkUid.Version))
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            await _packageManagerService.ForkPackageAsync(packageUid, packageForkUid);
        }
        public void DeletePackage(string uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            _packageManagerService.DeletePackage(PackageUid.Parse(uid));
        }
예제 #5
0
    public string get_file_uri(string uid, string filename)
    {
        if (uid == null)
        {
            throw new ArgumentNullException(nameof(uid));
        }

        var packageUid = PackageUid.Parse(uid);

        return($"/packages/{packageUid.Id}/{packageUid.Version}/{filename}");
    }
예제 #6
0
    public void download_package(string uid)
    {
        if (uid == null)
        {
            throw new ArgumentNullException(nameof(uid));
        }

        var packageUid = PackageUid.Parse(uid);

        _packageManagerService.DownloadPackageAsync(packageUid).GetAwaiter().GetResult();
    }
예제 #7
0
    public async Task PostSetup(string appPackageUid = "[email protected]", string configuratorPackageUid = "[email protected]")
    {
        if (!string.IsNullOrWhiteSpace(appPackageUid?.Trim()))
        {
            await _packageManagerService.DownloadPackageAsync(PackageUid.Parse(appPackageUid)).ConfigureAwait(false);
        }

        if (!string.IsNullOrWhiteSpace(configuratorPackageUid?.Trim()))
        {
            await _packageManagerService.DownloadPackageAsync(PackageUid.Parse(configuratorPackageUid)).ConfigureAwait(false);
        }
    }
    string GetLatestVersionPath(string id)
    {
        var packageRootPath = Path.Combine(_rootPath, id);

        if (!Directory.Exists(packageRootPath))
        {
            throw new WirehomePackageNotFoundException(PackageUid.Parse(id));
        }

        var versions = Directory.GetDirectories(packageRootPath).OrderByDescending(d => d.ToLowerInvariant());

        return(versions.First());
    }
        public string GetReleaseNotes(string uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var packageUid = PackageUid.Parse(uid);

            if (string.IsNullOrEmpty(packageUid.Version))
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(null);
            }

            return(_packageManagerService.GetReleaseNotes(packageUid));
        }
예제 #10
0
        public async Task DownloadPackage(string uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var packageUid = PackageUid.Parse(uid);

            if (string.IsNullOrEmpty(packageUid.Version))
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            await _packageManagerService.DownloadPackageAsync(packageUid).ConfigureAwait(false);
        }
예제 #11
0
        public IDirectoryContents GetDirectoryContents(string subpath)
        {
            if (subpath == null)
            {
                throw new ArgumentNullException(nameof(subpath));
            }

            var packageUid      = _globalVariablesService.GetValue(_packageUidGlobalVariableUid) as string;
            var packageRootPath = _packageManagerService.GetPackageRootPath(PackageUid.Parse(packageUid));

            var fullPath = Path.Combine(packageRootPath, subpath.Trim(Path.PathSeparator, Path.AltDirectorySeparatorChar));

            if (!Directory.Exists(fullPath))
            {
                return(new NotFoundDirectoryContents());
            }

            return(new PhysicalDirectoryContents(fullPath));
        }
예제 #12
0
        public async Task PostSetup(
            string appPackageUid          = "[email protected]",
            string configuratorPackageUid = "[email protected]",
            bool fixStartupScripts        = true)
        {
            if (!string.IsNullOrEmpty(appPackageUid.Trim()))
            {
                await _packageManagerService.DownloadPackageAsync(PackageUid.Parse(appPackageUid));
            }

            if (!string.IsNullOrEmpty(configuratorPackageUid.Trim()))
            {
                await _packageManagerService.DownloadPackageAsync(PackageUid.Parse(configuratorPackageUid));
            }

            if (fixStartupScripts)
            {
                FixStartupScripts();
            }
        }
 public void DeletePackage(string uid)
 {
     _packageManagerService.DeletePackage(PackageUid.Parse(uid));
 }