/// <summary> /// Invocado pelo Magic xpi Server /// </summary> /// <param name="stepParams"></param> public void invoke(StepGeneralParams stepParams) { try { #region // Propriedades [In] UserProperty httpVerbProperty = stepParams.getUserProperty(enumStr(CUrlInputArgs.httpVerb)); // string UserProperty urlDynAdditionProperty = stepParams.getUserProperty(enumStr(CUrlInputArgs.urlDynAddition)); // string UserProperty headersToSendProperty = stepParams.getUserProperty(enumStr(CUrlInputArgs.headersToSend)); // byte[] UserProperty dataToSendProperty = stepParams.getUserProperty(enumStr(CUrlInputArgs.dataToSend)); // byte[] UserProperty additionalCurlFlagsProperty = stepParams.getUserProperty(enumStr(CUrlInputArgs.additionalCurlFlags)); // string UserProperty keepWorkingFilesProperty = stepParams.getUserProperty(enumStr(CUrlInputArgs.keepWorkingFiles)); // bool // Propriedades [Out] UserProperty finalSiteUrlProperty = stepParams.getUserProperty(enumStr(CUrlOutputArgs.finalSiteUrl)); // ALPHA UserProperty finalCUrlCmdProperty = stepParams.getUserProperty(enumStr(CUrlOutputArgs.finalCUrlCmd)); // ALPHA UserProperty outputHeadersProperty = stepParams.getUserProperty(enumStr(CUrlOutputArgs.outputHeaders)); // BLOB UserProperty outputDataProperty = stepParams.getUserProperty(enumStr(CUrlOutputArgs.outputData)); // BLOB UserProperty httpResultCodeProperty = stepParams.getUserProperty(enumStr(CUrlOutputArgs.httpResultCode)); // NUMERIC UserProperty httpResultTextProperty = stepParams.getUserProperty(enumStr(CUrlOutputArgs.httpResultText)); // ALPHA UserProperty outputCUrlProperty = stepParams.getUserProperty(enumStr(CUrlOutputArgs.outputCUrl)); // BLOB UserProperty exitCodeCUrlProperty = stepParams.getUserProperty(enumStr(CUrlOutputArgs.exitCodeCUrl)); // NUMERIC _randValue = (new Random()).Next(1, Int32.MaxValue); _fsid = stepParams.FSID; _attachedResourceName = stepParams.EnviromentSettings[ENV_RSRCNAME_KEY]; _attachedResourceUrlValue = stepParams.ResourceObject[CURL_RSRC_KEY]; _logFileName = stepParams.EnviromentSettings[ENV_COMPPATH_KEY].Trim() + "\\..\\..\\logs\\CUrl_SDKComponent_" + string.Format("{0:yyyy'-'dd'-'MM}", DateTime.Now) + ".log"; _curlProgram = stepParams.EnviromentSettings[ENV_COMPPATH_KEY].Trim() + "\\program\\bin\\curl.exe"; _magicxpiTempDir = stepParams.EnviromentSettings[ENV_COMPPATH_KEY].Trim() + "\\..\\..\\temp"; string[] dmLines = new string[0]; if (!(stepParams.PayloadOBject == null)) { dmLines = Encoding.UTF8.GetString(stepParams.PayloadOBject).Split(new[] { Environment.NewLine }, StringSplitOptions.None); } // Analisa a 2a linha do FF _debugIsOn = dmLines.Length > 1 && (dmLines[1].ToUpper() == "Y" || dmLines[1].ToUpper() == "S" || dmLines[1].ToUpper() == "1"); #endregion #region // Validar parâmetros de entrada "obrigatórios" // No mínimo um 'GET' de algum site tem de ter if ((httpVerbProperty.getValue() == null) || string.IsNullOrEmpty((string)httpVerbProperty.getValue())) { throw new ArgumentNullException(enumStr(CUrlInputArgs.httpVerb)); } else if (string.IsNullOrEmpty(_attachedResourceName)) { throw new ArgumentNullException("attached resource name"); } else if (string.IsNullOrEmpty(_attachedResourceUrlValue)) { throw new ArgumentNullException("resource [ " + _attachedResourceName.Trim() + " ] value"); } // Extrai os argumentos de entrada string httpVerb = httpVerbProperty.getValue().ToString().Trim().ToUpper(); string urlDynAddition = (urlDynAdditionProperty.getValue() == null) ? string.Empty : urlDynAdditionProperty.getValue().ToString().Trim(); byte[] headersToSend = (headersToSendProperty.getValue() == null) ? null : (byte[])headersToSendProperty.getValue(); byte[] dataToSend = (dataToSendProperty.getValue() == null) ? null : (byte[])dataToSendProperty.getValue(); string additionalCurlFlags = (additionalCurlFlagsProperty.getValue() == null) ? string.Empty : additionalCurlFlagsProperty.getValue().ToString().Trim(); bool keepWorkingFiles = (keepWorkingFilesProperty.getValue() == null) ? false : (bool)keepWorkingFilesProperty.getValue(); // Cria os argumentos de saída string finalSiteUrl = string.Empty; string finalCUrlCmd = string.Empty; byte[] outputHeaders = null; byte[] outputData = null; double httpResultCode = HTTP_DEFAULT_ERROR_CODE; string httpResultText = HTTP_DEFAULT_ERROR_TEXT; byte[] outputCUrl = null; long exitCodeCUrl = 0; #endregion #region /// /// Chama o programa "curl" por linha de comando /// if (_debugIsOn) { appendLogMessage("[CUrl] SDK Component from MagicBR, (C) 2021 -- No warranty or support, of any kind, is provided"); } execCurlCommand(httpVerb, urlDynAddition, headersToSend, dataToSend, additionalCurlFlags, keepWorkingFiles, ref finalSiteUrl, ref finalCUrlCmd, ref outputHeaders, ref outputData, ref httpResultCode, ref httpResultText, ref outputCUrl, ref exitCodeCUrl); #endregion #region // Atualiza as propriedades de saída [Out] finalSiteUrlProperty.setAlpha(finalSiteUrl); finalCUrlCmdProperty.setAlpha(finalCUrlCmd); outputHeadersProperty.setBlob(outputHeaders); outputDataProperty.setBlob(outputData); httpResultCodeProperty.setNumeric(httpResultCode); httpResultTextProperty.setAlpha(httpResultText); outputCUrlProperty.setBlob(outputCUrl); exitCodeCUrlProperty.setNumeric((double)exitCodeCUrl); #endregion } catch (Exception e) { // retorna qqer problema como uma exceção "conhecida", de código "conhecido", para poder ser tratada corretamente pelo Error Handling do Magi xpi throw new XPI_SDK.SDKException(CURL_ERROR_CODE, "[CUrl] SDK Component Error: " + e.GetType().ToString() + ": " + e.Message.Replace(Environment.NewLine, " ")); } }