-
Notifications
You must be signed in to change notification settings - Fork 0
/
Service1.svc.cs
83 lines (73 loc) · 2.7 KB
/
Service1.svc.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace csharp_compiler
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public string DoCompilation(string code, string name)
{
CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");
ICodeCompiler compiler = provider.CreateCompiler();
CompilerParameters parameters = new CompilerParameters();
parameters.OutputAssembly = @name;
parameters.GenerateExecutable = true;
CompilerResults results = compiler.CompileAssemblyFromSource(parameters, code);
System.Threading.Thread.Sleep(10000);
if (results.Output.Count == 0)
{
return "success";
}
else
{
CompilerErrorCollection CErros = results.Errors;
foreach (CompilerError err in CErros)
{
string msg = string.Format("Erro:{0} on line{1} file name:{2}", err.Line, err.ErrorText, err.FileName);
return msg;
}
}
return "not working";
}
public string DoExecute(string filename)
{
// ProcessStartInfo pi = filename;
try
{
ProcessStartInfo start = new ProcessStartInfo();
start.Arguments = null;
start.FileName = filename;
int exitCode;
using (Process proc = Process.Start(start))
{
}
return "success";
}
catch (Exception e) { return e.ToString(); }
}
}
}