/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void importStageButton_Click(object sender, EventArgs e) { var f = FileIO.OpenFile("YAML (*.yaml)|*.yaml"); if (f != null) { var package = StagePackage.DeserializeFile(f); var stage = package.Stage; // load items if (package.Items != null) { var newItems = new HSD_UShort[package.Items.Count]; for (int i = 0; i < package.Items.Count; i++) { var item = (ushort)Editor.ItemControl.AddMEXItem(package.Items[i]); newItems[i] = new HSD_UShort() { Value = item }; } stage.ItemLookup.Entries = newItems; } // insert new stage stageEditor.AddItem(stage); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void exportStageButton_Click(object sender, EventArgs e) { if (stageEditor.SelectedObject is MEXStageEntry stage) { var f = FileIO.SaveFile("YAML (*.yaml)|*.yaml", Path.GetFileNameWithoutExtension(stage.FileName) + ".yaml"); if (f != null) { StagePackage package = new StagePackage(); package.Stage = stage; // add stage items foreach (var itemIndex in stage.Items) { package.Items.Add(Editor.ItemControl.GetItem(itemIndex.Value)); } package.Serialize(f); } } }
private async Task <HttpResponseMessage> ProcessPackage(Stream stream, string stageOwner, string stageName, string packageOwner) { Uri nupkgLocation = null; Uri nuspecLocation = null; PackageStorageBase storage = null; bool storageSaveSuccess = false; bool tryStorageCleanup = false; HttpResponseMessage response; try { var package = StagePackage.ReadFromStream(stream); if (package.IsValid) { Uri baseAddress = Utils.CreateBaseAddress(Request.RequestUri, "stage/"); //TODO: currently the Location is storage URI to the blob, it might be more flexible to make this the blob name storage = new AzurePackageStorage(); nupkgLocation = await storage.Save(stream, package.GetNupkgName(storage.Root), package.GetNupkgName(string.Empty), "application/octet-stream"); nuspecLocation = await storage.Save(package.NuspecStream, package.GetNuspecName(storage.Root), package.GetNuspecName(string.Empty), "text/xml"); storageSaveSuccess = true; response = await Persistence.CreatePackage(baseAddress, stageOwner, stageName, package.Id, package.Version, packageOwner, nupkgLocation, nuspecLocation); if (response.StatusCode != HttpStatusCode.Created) { tryStorageCleanup = true; } } else { response = Utils.CreateErrorResponse(HttpStatusCode.BadRequest, package.Reason); } } catch (Exception e) { Trace.TraceError(e.Message); tryStorageCleanup = true; response = new HttpResponseMessage(HttpStatusCode.InternalServerError); } if (storageSaveSuccess && tryStorageCleanup) { try { await storage.Delete(nupkgLocation); await storage.Delete(nuspecLocation); } catch (Exception e) { Trace.TraceWarning(e.Message); } } return(response); }