public IHttpActionResult GetEmployee(requestData requestData) { string id; string token; try { id = requestData.id; token = requestData.token; if (token == "rZslJnUHOW") { string sql = @"select nv.*, dp.department_name as TenPhongBan from NhanVien nv, Department dp where nv.MaNV = @id1 and nv.MaPhongBan=dp.department_id UNION ALL select *,NULL as TenPhongBan from nhanvien where MaPhongBan is null AND NhanVien.MaNV = @id2"; ; QUANGHANHABCEntities db = new QUANGHANHABCEntities(); var nhanvien = db.Database.SqlQuery <NhanVienResultModel>(sql, new SqlParameter("@id1", id), new SqlParameter("@id2", id)).ToList <NhanVienResultModel>().FirstOrDefault <NhanVienResultModel>(); if (nhanvien == null) { return(Ok(new { success = true, message = "NO RECORDS FOUND!" })); } return(Ok(new { success = true, message = "SUCCESSED!", results = nhanvien })); } else { return(Ok(new { success = false, message = "INVALID TOKEN!" })); } } catch (Exception e) { return(Ok(new { success = false, message = "INVALID REQUEST!" })); } }
public responseData reserves(requestData r) { responseData rd = new responseData(); try { rd.data.AddRange(DataRPC.getReserves(r.yearFrom, r.yearTo)); } catch (Exception ex) { rd.error = ex.Message; } finally { } return(rd); }
public responseData productionByCountry(requestData r) { responseData rd = new responseData(); try { rd.data.AddRange(DataRPC.getProductionCountry(r.by, r.yearFrom, r.yearTo)); } catch (Exception ex) { rd.error = ex.Message; } finally { } return(rd); }
public OperationResult <bool> SendSms(string fromMobileNumber, string toMobileNumber, string smsText) { var data = new requestData { oper = "cmt", payment = new requestDataPayment { id = "", prop = new[] { new requestDataPaymentProp { name = "phone", value = "%2B38" + fromMobileNumber }, new requestDataPaymentProp { name = "phoneto", value = "%2B38" + toMobileNumber }, new requestDataPaymentProp { name = "text", value = smsText } } }, test = 0, wait = 0, }; var dataSerializer = new Serializer <requestData>(); var xmlData = dataSerializer.Serialize(data); xmlData = xmlData.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", string.Empty); xmlData = xmlData.Replace("<requestData>", string.Empty); xmlData = xmlData.Replace("</requestData>", string.Empty); var signature = Md5.GetHashStringAsSha1(xmlData + _password); var req = new request { merchant = new requestMerchant { id = _merchantId, signature = signature }, data = data, version = "1.0" }; var requestSerializer = new Serializer <request>(); var xml = requestSerializer.Serialize(req); //xml = xml.Replace("utf-16", "UTF-8"); var response = _httpManager.PostXml(SmsUrn, xml); return(new OperationResult <bool>()); }
public void Index(requestData text, IClientProxy clientProxy, string randomEndingForFolder) { try { string usng = ""; string context = ""; Tempproj tempproj = null; if (text.serializeAnonProj != null) { tempproj = JsonConvert.DeserializeObject <Tempproj>(text.serializeAnonProj); text.ContextName = tempproj.Data.ContextName; usng = @"using DiplomWork;"; context = @"var db = new " + text.ContextName + "();" + @"; db.GetService<ILoggerFactory>().AddProvider(new MyLoggerProvider());"; } string codeHead = @" using System; using System.Diagnostics; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.EntityFrameworkCore.Infrastructure;" + usng + @" using System.Linq; namespace onfly { public class TestClass { static string log=""""; public class MyLoggerProvider : ILoggerProvider { public ILogger CreateLogger(string categoryName) { return new MyLogger(); } public void Dispose() { } private class MyLogger : ILogger { public IDisposable BeginScope<TState>(TState state) { return null; } public bool IsEnabled(LogLevel logLevel) { return true; } public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) { Console.Error.WriteLine(formatter(state, exception)); } } } public static void Main() { } public static void CodeCompile() {" + context; string sourceCode = codeHead + text.SourceCode + "}}}"; using (var peStream = new MemoryStream()) { Microsoft.CodeAnalysis.Emit.EmitResult result; if (tempproj == null) { result = GenerateCode(sourceCode).Emit(peStream); } else { result = GenerateCode(sourceCode, tempproj).Emit(peStream); } peStream.Seek(0, SeekOrigin.Begin); if (!result.Success) { var failures = result.Diagnostics.Where(diagnostic => diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error); StringBuilder bld = new StringBuilder(); foreach (var diagnostic in failures) { clientProxy.SendAsync("Exception", diagnostic.ToString()); bld.Append(diagnostic);//StringBuilder more efficient than concat } Result result1 = new Result(); result1.resultcode = bld.ToString(); } peStream.Seek(0, SeekOrigin.Begin); string sql = ""; string resultcode = ""; using (var proc = new Process()) { CancellationTokenSource cts = new CancellationTokenSource(); Task <Result> newTask = Task.Run(() => { try { proc.StartInfo.FileName = Environment.CurrentDirectory + @"\CodeExecuter\netcoreapp3.1\CodeExecuter.exe"; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.ErrorDataReceived += new DataReceivedEventHandler((sender, e) => { clientProxy.SendAsync("SQL", e.Data + "\n"); }); proc.OutputDataReceived += new DataReceivedEventHandler((sender, e) => { clientProxy.SendAsync("Result", e.Data + "\n"); }); proc.StartInfo.Arguments = randomEndingForFolder;/*User.Identity?.Name ?? Request.HttpContext.TraceIdentifier;*/ proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; proc.Start(); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); NamedPipeServerStream pipeServer = new NamedPipeServerStream("pipeServer" + randomEndingForFolder, PipeDirection.InOut); pipeServer.WaitForConnection(); var length = BitConverter.GetBytes((int)peStream.Length); pipeServer.Write(length, 0, length.Length); peStream.CopyTo(pipeServer); proc.WaitForExit(15000); proc.Close(); pipeServer.Close(); pipeServer.Dispose(); Result result1 = new Result(); result1.sql = sql; result1.resultcode = resultcode; clientProxy.SendAsync("Result", "True"); return(result1); } catch (Exception ex) { throw ex; } }, cts.Token); newTask.Wait(300000);//Timeout 5 min 300000 if (newTask.IsCompleted) { } else { proc.Kill(); cts.Cancel(); throw new TimeoutException("TimeOut too long operation"); } } } } catch (Exception ex) { Result result = new Result(); result.resultcode = ex.ToString(); clientProxy.SendAsync("Exeption", ex); } }