/// <summary> /// Adds a conversion, created by the user, to the list of Conversion objects. /// </summary> /// <param name="FromUnit">string</param> /// <param name="ToUnit">string</param> /// <param name="ConversionRatio">double</param> public void AddConversion(string FromUnit, string ToUnit, double ConversionRatio) { if (ConversionRatio != 0) { var MatchFound = false; var TestString = FromUnit + " " + ToUnit; foreach (var ConversionObject in ConvList) { if (string.Equals(ConversionObject.ToShortString(), TestString, StringComparison.CurrentCultureIgnoreCase)) { MatchFound = true; MessageBox.Show("Entry already in list. Nothing added."); break; } else /*doNothing*/ } { } if (MatchFound == false) { var conversion = new Conversion(FromUnit, ToUnit, ConversionRatio); ConvList.Add(conversion); MessageBox.Show(conversion + " was added."); } else /*doNothing*/ } { }
private async void Update() { if (_currentConvert.Count < 3 && _waitingConvert.Count > 0) { ConversionObject nextToConvert = _waitingConvert[0]; _waitingConvert.RemoveAt(0); _currentConvert.Add(nextToConvert); await nextToConvert.ConvertAsync(); } }
/// <summary> /// Add file for conversion /// </summary> /// <param name="filePath">Path of the Beat Saber zip file</param> public void AddFile(string filePath) { GameObject newConversion = Instantiate(_conversionPrefab, _processingRoot.transform); ConversionObject conversionManager = newConversion.GetComponent <ConversionObject>(); if (conversionManager) { conversionManager.ObjectFinished += ConversionFinished; conversionManager.ObjectDeleted += ConversionDeleted; _waitingConvert.Add(conversionManager); conversionManager.Setup(filePath, _selectionManager.OutputPath); } }
public static void GenerateImage(string pBase64File, string pExtension, string pSqlCommand, string pErrorSqlCommand, GenConnection pSqlConnection, int pWitdh = 150, int pHeight = 180, bool DeleteAfter = true) { if (!File.Exists(ExeConversion.Replace("\"", ""))) { throw new Exception("Execonversion nao existe:" + ExeConversion); } var dirbasename = TempDir + "\\" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + Guid.NewGuid().ToString().Substring(0, 5); var fdirThumb = dirbasename + "\\out"; Directory.CreateDirectory(dirbasename); Directory.CreateDirectory(fdirThumb); var fname = dirbasename + "\\" + "arquivo" + pExtension; File.WriteAllBytes(fname, Convert.FromBase64String(pBase64File)); var dosCommArg = ExeConversionParameters.Replace("{INPUT}", fname) .Replace("{OUTPUT}", fdirThumb) .Replace("{WIDTH}", pWitdh.ToString()) .Replace("{HEIGHT}", pHeight.ToString()); var co = new ConversionObject() { DosCommand = ExeConversion, DosCommandArguments = dosCommArg, InputTempDir = dirbasename, OutputTempDir = fdirThumb, sqlCommand = pSqlCommand, errorSqlCommand = pErrorSqlCommand, sqlConnection = pSqlConnection, DeleteInputAfter = DeleteAfter, inputFile = fname, Width = pWitdh, Height = pHeight }; co.RunningThread = new Thread(new ThreadStart(co.Exec)); ConversionThreads.Add(co); co.RunningThread.Start(); }
public ctlModels() { conversionObject = new ConversionObject(); if (this.Value == null) { this.Value = this.conversionObject.SetEnumObjectToString(ctlModelsEnum.status_only); } this.name = "ctlModels"; this.bTypeEnum = tBasicTypeEnum.Enum; this.id = this.type = "ctlModelsEnum"; Array valuesEnumArray = conversionObject.GetValuesEnumToArray(typeof(ctlModelsEnum)); this.EnumVal = new tEnumVal[valuesEnumArray.Length]; for (int x = 0; x < valuesEnumArray.Length; x++) { tEnumVal enumVal = new tEnumVal(); enumVal.ord = ((int)valuesEnumArray.GetValue(x)).ToString(); enumVal.Value = valuesEnumArray.GetValue(x).ToString(); this.EnumVal[x] = enumVal; } }
public multiplier() { conversionObject = new ConversionObject(); if (this.Value == null) { this.Value = this.conversionObject.SetEnumObjectToString(tUnitMultiplierEnum.a); } this.name = "multiplier"; this.bTypeEnum = tBasicTypeEnum.Enum; this.id = this.type = "multiplierEnum"; Array valuesEnumArray = conversionObject.GetValuesEnumToArray(typeof(tUnitMultiplierEnum)); this.EnumVal = new tEnumVal[valuesEnumArray.Length]; for (int x = 0; x < valuesEnumArray.Length; x++) { tEnumVal enumVal = new tEnumVal(); enumVal.ord = ((int)valuesEnumArray.GetValue(x)).ToString(); enumVal.Value = valuesEnumArray.GetValue(x).ToString(); this.EnumVal[x] = enumVal; } }
/// <summary> /// Event handler for ConvertButton_Click. /// </summary> /// <param name="sender">object</param> /// <param name="e">EventArgs</param> private void ConvertButton_Click(object sender, EventArgs e) { if (ConvertToComboBox.Text != string.Empty) { var ConversionText = ConvertToComboBox.SelectedItem.ToString(); var IsValid = double.TryParse(ConvertFromTextBox.Text, out var TryParseResult); if (IsValid) { var LocalConversionRatio = 0.0; var newtext = ConversionText.Split(' '); //Console.WriteLine(newtext[0] + " " + newtext[1]); if (ConversionText != string.Empty) { foreach (var ConversionObject in Conversions.ConvList) { if (newtext[0] == ConversionObject.FromUnit && newtext[1] == ConversionObject.ToUnit) { LocalConversionRatio = ConversionObject.GetType(); } } if (LocalConversionRatio == 0.0) { MessageBox.Show("Oops! Looks like the selected conversion may have been removed."); } else { this.ConvertToTextBox.Text = conversions.PerformConversion(TryParseResult, LocalConversionRatio); } } else /*doNothing*/ } { } else { MessageBox.Show("Invalid Entry! Only double values permitted."); this.ConvertFromTextBox.Clear(); this.ConvertFromTextBox.Focus(); } }
private void RemoveConversion(ConversionObject conversionObject) { _waitingConvert.Remove(conversionObject); _currentConvert.Remove(conversionObject); _finishedConvert.Remove(conversionObject); }
private void ConversionDeleted(ConversionObject conversionObject) { RemoveConversion(conversionObject); Debug.Log("Deleted item with path: " + conversionObject.InputPath); }
private void ConversionFinished(ConversionObject conversionObject) { _currentConvert.Remove(conversionObject); _finishedConvert.Add(conversionObject); }
private BWebServiceResponse OnRequest_Internal(HttpListenerContext _Context, Action <string> _ErrorMessageAction) { _ErrorMessageAction?.Invoke("Trying to get Optimizer Env Vars"); if (_Context.Request.HttpMethod != "GET") { _ErrorMessageAction?.Invoke("Wrong type"); return(BWebResponse.BadRequest($"This service does not accept requests of type : {_Context.Request.HttpMethod}")); } string Url = _Context.Request.RawUrl; int CopyStart = Url.LastIndexOf('/') + 1; string Podname = Url.Substring(CopyStart).TrimEnd('/'); BatchProcessingCreationService.Instance.GetBucketAndFile(Podname, out string _Bucket, out string _Filename); if (!string.IsNullOrWhiteSpace(_Bucket) && !string.IsNullOrWhiteSpace(_Filename)) { string NewConversionID_FromRelativeUrl_UrlEncoded = WebUtility.UrlEncode(_Filename); bool CanProceed = false; bool ProcessError = false; if (DatabaseService.GetItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), FileConversionDBEntry.Properties, out JObject ConversionObject )) { if (ConversionObject != null && ConversionObject.ContainsKey("conversionStatus")) { EInternalProcessStage ExistingStatus = (EInternalProcessStage)(int)ConversionObject["conversionStatus"]; if (ExistingStatus == EInternalProcessStage.ProcessComplete) { CanProceed = true; } else if (ExistingStatus == EInternalProcessStage.ProcessFailed) { ProcessError = true; } } } else { ProcessError = true; } if (CanProceed) { Dictionary <string, string> EnvVars = BatchProcessingCreationService.Instance.GetOptimizerEnvVars(_Bucket, _Filename, Podname, _ErrorMessageAction); if (EnvVars == null) { _ErrorMessageAction?.Invoke("EnvVars null"); return(BWebResponse.InternalError("An error occured trying to generate optimizer parameters")); } return(BWebResponse.StatusOK("success", new JObject() { ["uploadRequestUrl"] = EnvVars["CAD_PROCESS_UPLOAD_REQUEST_URL"], ["downloadHierarchyCfUrl"] = EnvVars["DOWNLOAD_HIERARCHY_CF"], ["downloadGeometryCfUrl"] = EnvVars["DOWNLOAD_GEOMETRY_CF"], ["downloadMetadataCfUrl"] = EnvVars["DOWNLOAD_METADATA_CF"] })); } else if (ProcessError) { _ErrorMessageAction?.Invoke("Cad process Failed"); return(BWebResponse.InternalError("Pixyz process has failed")); } else { _ErrorMessageAction?.Invoke("Not found"); return(BWebResponse.NotFound("Cad process has not completed yet")); } } else { _ErrorMessageAction?.Invoke("General failure"); return(BWebResponse.InternalError("An error occured trying to retreive pod details")); } }
private BWebServiceResponse OnRequest_Internal(HttpListenerContext _Context, Action <string> _ErrorMessageAction) { if (_Context.Request.HttpMethod != "POST") { _ErrorMessageAction?.Invoke("StartProcessRequest: POST methods is accepted. But received request method: " + _Context.Request.HttpMethod); return(BWebResponse.MethodNotAllowed("POST methods is accepted. But received request method: " + _Context.Request.HttpMethod)); } var NewDBEntry = new FileConversionDBEntry() { ConversionStatus = (int)EInternalProcessStage.Queued }; string NewConversionID_FromRelativeUrl_UrlEncoded = null; string BucketName = null; string RelativeFileName = null; string ZipMainAssembly = ""; using (var InputStream = _Context.Request.InputStream) { var NewObjectJson = new JObject(); using (var ResponseReader = new StreamReader(InputStream)) { try { var ParsedBody = JObject.Parse(ResponseReader.ReadToEnd()); if (!ParsedBody.ContainsKey("bucketName") || !ParsedBody.ContainsKey("rawFileRelativeUrl")) { return(BWebResponse.BadRequest("Request body must contain all necessary fields.")); } var BucketNameToken = ParsedBody["bucketName"]; var RawFileRelativeUrlToken = ParsedBody["rawFileRelativeUrl"]; if (BucketNameToken.Type != JTokenType.String || RawFileRelativeUrlToken.Type != JTokenType.String) { return(BWebResponse.BadRequest("Request body contains invalid fields.")); } if (ParsedBody.ContainsKey("zipTypeMainAssemblyFileNameIfAny")) { var ZipMainAssemblyToken = ParsedBody["zipTypeMainAssemblyFileNameIfAny"]; if (ZipMainAssemblyToken.Type != JTokenType.String) { return(BWebResponse.BadRequest("Request body contains invalid fields.")); } ZipMainAssembly = (string)ZipMainAssemblyToken; } NewDBEntry.BucketName = (string)BucketNameToken; NewConversionID_FromRelativeUrl_UrlEncoded = WebUtility.UrlEncode((string)RawFileRelativeUrlToken); BucketName = (string)BucketNameToken; RelativeFileName = (string)RawFileRelativeUrlToken; } catch (Exception e) { _ErrorMessageAction?.Invoke("Read request body stage has failed. Exception: " + e.Message + ", Trace: " + e.StackTrace); return(BWebResponse.BadRequest("Malformed request body. Request must be a valid json form.")); } } } if (BucketName == null || RelativeFileName == null) { return(BWebResponse.InternalError("No BucketName or FileName")); } BDatabaseAttributeCondition UpdateCondition = DatabaseService.BuildAttributeNotExistCondition(FileConversionDBEntry.KEY_NAME_CONVERSION_ID); //If a process was completed (success or failure) then allow reprocessing //Only stop if a process is currently busy processing or already queued if (DatabaseService.GetItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), FileConversionDBEntry.Properties, out JObject ConversionObject )) { if (ConversionObject != null && ConversionObject.ContainsKey("conversionStatus")) { EInternalProcessStage ExistingStatus = (EInternalProcessStage)(int)ConversionObject["conversionStatus"]; if (ExistingStatus == EInternalProcessStage.ProcessFailed || ExistingStatus == EInternalProcessStage.ProcessComplete) { UpdateCondition = null; } } } if (!DatabaseService.UpdateItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), JObject.Parse(JsonConvert.SerializeObject(NewDBEntry)), out JObject _ExistingObject, EBReturnItemBehaviour.DoNotReturn, UpdateCondition, _ErrorMessageAction)) { return(BWebResponse.Conflict("File is already being processed/queued.")); } try { if (BatchProcessingCreationService.Instance.StartBatchProcess(BucketName, RelativeFileName, ZipMainAssembly, out string _PodName, _ErrorMessageAction)) { //Code for initial method of starting optimizer after pixyz completes //return BWebResponse.StatusAccepted("Request has been accepted; process is now being started."); if (BatchProcessingCreationService.Instance.StartFileOptimizer(BucketName, RelativeFileName, _ErrorMessageAction)) { return(BWebResponse.StatusAccepted("Request has been accepted; process is now being started.")); } else { NewDBEntry.ConversionStatus = (int)EInternalProcessStage.ProcessFailed; if (!DatabaseService.UpdateItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), JObject.Parse(JsonConvert.SerializeObject(NewDBEntry)), out JObject _, EBReturnItemBehaviour.DoNotReturn, null, _ErrorMessageAction)) { return(BWebResponse.InternalError("Failed to start the batch process and experienced a Database error")); } //Try kill pixyz pod that we have succeeded in creating if (!BatchProcessingCreationService.Instance.TryKillPod(_PodName, "cip-batch")) { return(BWebResponse.InternalError("Failed to start the unreal optimizer and failed to kill pixyz pod")); } return(BWebResponse.InternalError("Failed to start the batch process and experienced a Database error")); } } else { NewDBEntry.ConversionStatus = (int)EInternalProcessStage.ProcessFailed; if (!DatabaseService.UpdateItem( FileConversionDBEntry.DBSERVICE_FILE_CONVERSIONS_TABLE(), FileConversionDBEntry.KEY_NAME_CONVERSION_ID, new BPrimitiveType(NewConversionID_FromRelativeUrl_UrlEncoded), JObject.Parse(JsonConvert.SerializeObject(NewDBEntry)), out JObject _, EBReturnItemBehaviour.DoNotReturn, null, _ErrorMessageAction)) { return(BWebResponse.InternalError("Failed to start the batch process and experienced a Database error")); } return(BWebResponse.InternalError("Failed to start the batch process")); } }