Exemple #1
0
        public static string SerializeMessage(CompileInfo info)
        {
            DataContractJsonSerializer formatter = new DataContractJsonSerializer(typeof(CompileInfo));

            using (MemoryStream stream = new MemoryStream()) {
                formatter.WriteObject(stream, info);
                string result = Encoding.UTF8.GetString(stream.ToArray());
                return(result);
            }
        }
Exemple #2
0
        /// <summary>
        /// 编译代码,返回结果字符串
        /// </summary>
        public static async Task <string> Compile(string lang, string code, string id)
        {
            if (lang.IsNullOrEmpty() || code.IsNullOrEmpty() || id.IsNullOrEmpty())
            {
                return(null);
            }

            var info = new CompileInfo()
            {
                codeLanguage = lang,
                sourceCode   = code,
                codesID      = id
            };

            string serialized = SerializeMessage(info);

            Debug.WriteLine(serialized);
            return(await Task.Run(() => {
                return Post(complieUrl, serialized);
            }));
        }