public ActionResult UploadImageAndOpenIt( string resourceType, string resourceName, string version, [FromQuery] string deps) { PublishDepsInfoContainer depsInfo = PublishDepsInfoContainer.deserialize(deps); using (Stream requestFileStream = Request.Body) { // if (resourceType == "code") return serverDir if (resourceType == "code") { serverDir.addCodeResource(resourceName, version, depsInfo, requestFileStream); } if (resourceType == "data") { serverDir.addDataResource(resourceName, version, depsInfo, requestFileStream); } if (resourceType == "models") { serverDir.addModelResource(resourceName, version, depsInfo, requestFileStream); } } return(Ok()); }
public static void publishResource( string prefix, System.IO.FileStream fileStream, ResourceType resourceType, string resourceName, string version, PublishDepsInfoContainer publishDepsInfo) { System.Collections.Specialized.NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); queryString["deps"] = publishDepsInfo.serialize(); string url = resourcePostUrl(prefix, resourceType, resourceName, version) + "?" + queryString.ToString(); try { using (var fileContent = new System.Net.Http.StreamContent(fileStream)) { fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data") { Name = $"files[{resourceName}]", FileName = resourceName }; fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"); System.Net.Http.HttpResponseMessage statusResult = client.PostAsync(url, fileContent).Result; if (!statusResult.IsSuccessStatusCode) { throw new NetworkUtilsException("Unable to publish: HTTP Error: " + statusResult.StatusCode.ToString()); } } } catch (NetworkUtilsException ex) { throw ex; } catch (System.Exception) { throw new NetworkUtilsException($"Unable to publish {resourceType} resource {resourceName} to server"); } }
public static void publishResource(string prefix, ResourceIdentifier resourceDescription, IEnumerable <ResourceIdentifier> deps) { try { PublishDepsInfoContainer publishDepsInfo = new PublishDepsInfoContainer(); foreach (ResourceIdentifier depDescription in deps) { if (depDescription.version == null) { CLIInterface.logError( "The versions of dependencies must be supplied. For example, " + "\"dependency.csv\" does not include version, \"[email protected]\" does." ); return; } var publishDepDescription = new PublishDepsInfoContainer.PublishDepDescription(depDescription.version); if (depDescription.resourceType == ResourceType.Code) { publishDepsInfo.codeDeps[depDescription.resourceName] = publishDepDescription; } else if (depDescription.resourceType == ResourceType.Data) { publishDepsInfo.dataDeps[depDescription.resourceName] = publishDepDescription; } else if (depDescription.resourceType == ResourceType.Model) { publishDepsInfo.modelDeps[depDescription.resourceName] = publishDepDescription; } } string resourceName = resourceDescription.resourceName; ResourceType resourceType = resourceDescription.resourceType; string publishVersion = resourceDescription.version; // check that user has provided version to publish file as if (publishVersion == null) { publishVersion = "1.0"; CLIInterface.logLine($"Using default version {publishVersion}"); } if (!FSOps.hasNecessaryDirs()) { CLIInterface.logError($"Could not find nyoka resource folders in current directory. Try running {ConstStrings.APPLICATION_ALIAS} {CLIParserNS.InitOptions.description.name}?"); return; } // If a file to publish with the given name can't be found if (!FSOps.resourceFileExists(resourceType, resourceName)) { CLIInterface.logError($"Resource with name {resourceName} not found."); return; } var resourcesOnServer = NetworkUtils.getAvailableResources(prefix, resourceType); // If this resource already exists on server if (resourcesOnServer.resourceDescriptions.ContainsKey(resourceName)) { ResourceVersionsInfoContainer serverVersionsInfo = NetworkUtils.getResourceVersions(prefix, resourceType, resourceName); // If this resource exists with the same version on server if (serverVersionsInfo.versions.ContainsKey(publishVersion)) { bool continueAnyways = CLIInterface.askYesOrNo( $"Version {publishVersion} of {resourceType.ToString()} resource " + $"{resourceName} already exists on server. Overwrite?" ); if (!continueAnyways) { CLIInterface.logLine("Aborting publish."); return; } else { CLIInterface.logLine("Overwriting resource on server."); } } } CLIInterface.logLine("Opening file."); FileStream fileStream = FSOps.readResourceFile(resourceType, resourceName); CLIInterface.logLine("Uploading file."); NetworkUtils.publishResource( prefix, fileStream, resourceType, resourceName, publishVersion, publishDepsInfo ); // create or overwrite version file locally for this resource to be the publishVersion using (var versionFileStream = FSOps.createOrOverwriteResourceVersionFile(resourceType, resourceName)) { versionFileStream.WriteLine(publishVersion); } } catch (FSOps.FSOpsException ex) { CLIInterface.logError($"File System Error: " + ex.Message); } catch (NetworkUtils.NetworkUtilsException ex) { CLIInterface.logError($"Network Error: {ex.Message}"); } }