public static string SaveToFile(string fileType, string fileContent, string saveDirectory, ActWebAPIBase mAct) { string extension = string.Empty; string contentType = string.Empty; string actName = string.Empty; if (fileType == "Request") { contentType = mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType); } else if (fileType == "Response") { contentType = mAct.GetInputParamValue(ActWebAPIRest.Fields.ResponseContentType); } if (contentType == ApplicationAPIUtils.eContentType.XML.ToString()) { extension = "xml"; } else if (contentType == ApplicationAPIUtils.eContentType.JSon.ToString()) { extension = "json"; } else if (contentType == ApplicationAPIUtils.eContentType.PDF.ToString()) { extension = "pdf"; } else { extension = "txt"; } string directoryFullPath = Path.Combine(saveDirectory.Replace("~//", WorkSpace.Instance.Solution.ContainingFolderFullPath), fileType + "s"); if (!Directory.Exists(directoryFullPath)) { Directory.CreateDirectory(directoryFullPath); } string fullFileName = ""; lock (thisObj) { String timeStamp = DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss"); actName = PathHelper.CleanInValidPathChars(mAct.Description); fullFileName = Path.Combine(directoryFullPath, actName + "_" + timeStamp + "_" + fileType + "." + extension); if (contentType != ApplicationAPIUtils.eContentType.PDF.ToString()) { File.WriteAllText(fullFileName, fileContent); } else { byte[] bytes = Encoding.Default.GetBytes(fileContent); File.WriteAllBytes(fullFileName, bytes); } } return(fullFileName); }
//private ObservableList<ActReturnValue> GetAPIModelActionReturnValues(ObservableList<ActReturnValue> modelReturnValues) //{ // ObservableList<ActReturnValue> returnValuesList = new ObservableList<ActReturnValue>(); // foreach (ActReturnValue modelRV in modelReturnValues) // { // ActReturnValue rv = new ActReturnValue(); // rv.AddedAutomatically = true; // rv.Guid = modelRV.Guid; // rv.Active = modelRV.Active; // rv.Param = modelRV.Param; // rv.Path = modelRV.Path; // rv.Expected = modelRV.Expected; // if (!string.IsNullOrEmpty(modelRV.StoreToValue)) // { // rv.StoreTo = ActReturnValue.eStoreTo.ApplicationModelParameter; // rv.StoreToValue = modelRV.StoreToValue; // } // returnValuesList.Add(rv); // } // return returnValuesList; //} /// <summary> /// This method is used to check if the app parameter is already added in the list if not then it will add the parameter /// </summary> /// <param name="aPIModel"></param> /// <param name="act"></param> /// <param name="actApiModel"></param> private Dictionary <System.Tuple <string, string>, List <string> > ParseParametersOptionalValues(ApplicationAPIModel aPIModel, ActWebAPIBase actionToConvert) { Dictionary <System.Tuple <string, string>, List <string> > optionalValuesPerParameterDict = new Dictionary <Tuple <string, string>, List <string> >(); try { string requestBody = null; if (!string.IsNullOrEmpty(actionToConvert.GetInputParamValue(ActWebAPIBase.Fields.TemplateFileNameFileBrowser))) { string fileUri = WorkSpace.Instance.SolutionRepository.ConvertSolutionRelativePath(actionToConvert.GetInputParamValue(ActWebAPIBase.Fields.TemplateFileNameFileBrowser)); if (File.Exists(fileUri)) { requestBody = System.IO.File.ReadAllText(fileUri); } } else if (!string.IsNullOrEmpty(actionToConvert.GetInputParamValue(ActWebAPIBase.Fields.RequestBody))) { requestBody = actionToConvert.GetInputParamValue(ActWebAPIBase.Fields.RequestBody); } if (requestBody != null) { ImportParametersOptionalValues ImportOptionalValues = new ImportParametersOptionalValues(); if (!string.IsNullOrEmpty(requestBody) && requestBody.StartsWith("{")) { ImportOptionalValues.GetJSONAllOptionalValuesFromExamplesFile(requestBody, optionalValuesPerParameterDict); ImportOptionalValues.PopulateJSONOptionalValuesForAPIParameters(aPIModel, optionalValuesPerParameterDict); } else if (!string.IsNullOrEmpty(requestBody) && requestBody.StartsWith("<")) { ImportOptionalValues.GetXMLAllOptionalValuesFromExamplesFile(requestBody, optionalValuesPerParameterDict); ImportOptionalValues.PopulateXMLOptionalValuesForAPIParameters(aPIModel, optionalValuesPerParameterDict); } } return(optionalValuesPerParameterDict); } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Error occurred while parsing the app parameter", ex); return(optionalValuesPerParameterDict); } }
public void SaveRequest(bool RequestSave, string SaveDirectory) { string RequestFileContent = string.Empty; if (RequestSave) { if (mAct.GetType() == typeof(ActWebAPISoap)) { RequestFileContent = BodyString; mAct.AddOrUpdateInputParamValueAndCalculatedValue(ActWebAPIRest.Fields.ContentType, "XML"); } else if (mAct.GetType() == typeof(ActWebAPIRest)) { if (!string.IsNullOrEmpty(BodyString)) { RequestFileContent = BodyString; } else if ((mAct.RequestKeyValues.Count() > 0) && (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == "XwwwFormUrlEncoded")) { HttpContent UrlEncoded = new FormUrlEncodedContent(ConstructURLEncoded((ActWebAPIRest)mAct)); RequestFileContent = UrlEncoded.ToString(); } else if ((mAct.RequestKeyValues.Count() > 0) && (mAct.GetInputParamValue(ActWebAPIRest.Fields.ContentType) == "FormData")) { MultipartFormDataContent FormDataContent = new MultipartFormDataContent(); for (int i = 0; i < mAct.RequestKeyValues.Count(); i++) { FormDataContent.Add(new StringContent(mAct.RequestKeyValues[i].ValueForDriver), mAct.RequestKeyValues[i].ItemName.ToString()); } RequestFileContent = FormDataContent.ToString(); } else { RequestFileContent = RequestMessage.ToString(); } } string FileFullPath = Webserviceplatforminfo.SaveToFile("Request", RequestFileContent, SaveDirectory, mAct); mAct.AddOrUpdateReturnParamActual("Saved Request File Name", Path.GetFileName(FileFullPath)); } }
private void CheckNetworkCredentials() { if (mAct.GetInputParamValue(ActWebAPIBase.Fields.NetworkCredentialsRadioButton) == ApplicationAPIUtils.eNetworkCredentials.Custom.ToString()) { SP_CustomCreds.Visibility = System.Windows.Visibility.Visible; } else { SP_CustomCreds.Visibility = System.Windows.Visibility.Collapsed; } }