public async Task <JsonResult> ExecuteBatchStepByObserveId(string ObserveId) { ObserverDbContext _db = new ObserverDbContext(); ObservesModel model = _db.Observes .Where(e => e.Id == ObserveId) .FirstOrDefault(); if (model.Users.Id == User.Identity.GetUserId()) { List <StepsModel> listModel = _db.Observes.Where(e => e.Id == ObserveId).FirstOrDefault().List_Steps.Where(e => e.Deleted == false).OrderBy(e => e.Order).ToList(); List <StepExecutionInputModel> inputList = new List <StepExecutionInputModel>(); PCMethodsModel pcMethodsModel = null; foreach (StepsModel item in listModel) { string PC1 = null; string PC2 = null; int PCMethod = 0; if (item.PC_Method != null) { pcMethodsModel = PCMethodServiceManager.GetPCMethodById(item.PC_Method.Id); PC1 = pcMethodsModel.PC1; PC2 = pcMethodsModel.PC2; PCMethod = int.Parse(item.PC_Method.Id); } StepExecutionInputModel input = new StepExecutionInputModel() { Order = item.Order.GetValueOrDefault(), Uri = item.Url, Method = item.Method.GetValueOrDefault(), PC_Method = PCMethod, PC1 = item.PC1, PC2 = item.PC2, PC2Secret = item.PC2Secret, CustomHeader = item.PredefinedHeader, UseHeader = item.SetHeader.GetValueOrDefault(), LabelPC1 = PC1, LabelPC2 = PC2 }; inputList.Add(input); } return(Json(await StepServiceManager.ExecuteBatchStepReturningResult(inputList))); } else { StepExecutionOutputModel input = new StepExecutionOutputModel() { Status = "Unauthorized" }; return(Json(input)); } }
public int ResubmitStep(StepResubmitInputModel model) { if (model.Url == null) { return(1); } else if (model.Method != 1 && model.Method != 2) { return(2); } else { ObserverDbContext _db = new ObserverDbContext(); byte[] encrypt = null; byte[] encryptSecret = null; string encrypted = null; string encryptedSecret = null; if (model.PC2 != null) { byte[] secretKey = Convert.FromBase64String(_db._AESSecretKeyS); using (AesManaged myAes = new AesManaged()) { encrypt = EncryptionAlgorithmServiceManager.EncryptStringToBytes_Aes(model.PC2, secretKey, myAes.IV); encryptSecret = myAes.IV; } } if (encrypt != null) { encrypted = Convert.ToBase64String(encrypt); encryptedSecret = Convert.ToBase64String(encryptSecret); } PCMethodsModel pcMethodsModel = PCMethodServiceManager.GetPCMethodById(model.PC_Method.ToString()); StepsModel stepsModel = new StepsModel() { Id = model.StepId, Url = model.Url, Method = model.Method, SetHeader = model.Header, Deleted = false, PredefinedHeader = model.PredefinedHeader, PC1 = model.PC1, PC2 = encrypted, PC2Secret = encryptedSecret }; StepServiceManager.UpdateStep(stepsModel, model.PC_Method.ToString()); return(4); } }
public JsonResult GetPCMethod() { List <PCMethodsModel> model = PCMethodServiceManager.GetPCMethodList().OrderBy(e => e.Name).ToList(); List <PCMethodOutputModel> output = new List <PCMethodOutputModel>(); foreach (PCMethodsModel item in model) { PCMethodOutputModel newModel = new PCMethodOutputModel() { Id = item.Id, Name = item.Name }; output.Add(newModel); } return(Json(output)); }
public ActionResult Modify(string id) { if (Request.Browser.IsMobileDevice) { return(RedirectToAction("ModifyM")); } ObservesModel model = ObserveServiceManager.GetObserveById(id); List <StepsModel> oriList = StepServiceManager.GetStepListByObserveId(id); List <PCMethodsModel> methodList = PCMethodServiceManager.GetPCMethodList().OrderBy(e => e.Name).ToList(); List <StepListOutputModel> newList = new List <StepListOutputModel>(); List <PCMethodOutputModel> PCMethodOutput = new List <PCMethodOutputModel>(); foreach (StepsModel item in oriList) { string StringMethod = null; string StringSetHeader = null; if (item.Method == 1) { StringMethod = "GET"; } else if (item.Method >= 2) { StringMethod = "POST"; } if (item.SetHeader == 1) { StringSetHeader = "Yes"; } else if (item.SetHeader == 0) { StringSetHeader = "No"; } else if (item.SetHeader == 2) { StringSetHeader = "Pre"; } StepListOutputModel newModel = new StepListOutputModel() { Id = item.Id, Priority = item.Order.GetValueOrDefault(), Url = item.Url, Method = StringMethod, SetHeader = StringSetHeader }; newList.Add(newModel); } foreach (PCMethodsModel item in methodList) { PCMethodOutputModel newModel = new PCMethodOutputModel() { Id = item.Id, Name = item.Name }; PCMethodOutput.Add(newModel); } try { ObserveOutputModel output = new ObserveOutputModel() { Id = model.Id, Name = model.Name, Status = model.Status.GetValueOrDefault(), Interval = model.Interval.GetValueOrDefault(), StepList = newList, PCMethod = PCMethodOutput }; return(View(output)); } catch (NullReferenceException e) { return(RedirectToAction("Index", "Observe")); } }