Ejemplo n.º 1
0
        public string GetDiffHtml(string CodeGuid, string LeftGuid, string RightGuid)
        {
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            var left = Model.GetCode(LeftGuid, false);
            var right = Model.GetCode(RightGuid, false);

            if (left == null || right == null)
            {
                throw new HttpException(404, "not found");
            }
            Service.LinuxService ser = new Service.LinuxService();
            var res = ser.GetDiff(left.Program, right.Program);
            if (res.IsError)
                return json.Serialize(new JsonData() { Errors = true });
            else
            {
                if (!string.IsNullOrEmpty(res.Result))
                {
                    int startIndex = res.Result.IndexOf("<table");
                    if (startIndex != -1)
                        res.Result = res.Result.Substring(startIndex);
                    int endIndex = res.Result.LastIndexOf("</body");
                    if (endIndex != -1)
                        res.Result = res.Result.Substring(0, endIndex);
                }
                return json.Serialize(new JsonData() { Result = res.Result });
            }
        }
Ejemplo n.º 2
0
        public string Diff(string left, string right)
        {
            int maxLength = 200000;
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            if (!string.IsNullOrEmpty(left) && left.Length > maxLength)
            {
                return json.Serialize(new JsonData() { IsError = true, Errors = string.Format("Left input is too long (max is {0} characters).\n", maxLength) });
            }

            if (!string.IsNullOrEmpty(right) && right.Length > maxLength)
            {
                return json.Serialize(new JsonData() { IsError = true, Errors = string.Format("Right input is too long (max is {0} characters).\n", maxLength) });
            }

            Service.LinuxService ser = new Service.LinuxService();
            var res = ser.GetDiff(left, right);
            if (res.IsError)
                return json.Serialize(new JsonData() { IsError = true });
            else
            {
                if (!string.IsNullOrEmpty(res.Result))
                {
                    int startIndex = res.Result.IndexOf("<table");
                    if (startIndex != -1)
                        res.Result = res.Result.Substring(startIndex);
                    int endIndex = res.Result.LastIndexOf("</body");
                    if (endIndex != -1)
                        res.Result = res.Result.Substring(0, endIndex);
                }
                return json.Serialize(new JsonData() { Result = res.Result });
            }
        }
Ejemplo n.º 3
0
        public string Diff(string left, string right)
        {
            int maxLength = 200000;

            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            if (!string.IsNullOrEmpty(left) && left.Length > maxLength)
            {
                return(json.Serialize(new JsonData()
                {
                    IsError = true, Errors = string.Format("Left input is too long (max is {0} characters).\n", maxLength)
                }));
            }

            if (!string.IsNullOrEmpty(right) && right.Length > maxLength)
            {
                return(json.Serialize(new JsonData()
                {
                    IsError = true, Errors = string.Format("Right input is too long (max is {0} characters).\n", maxLength)
                }));
            }

            Service.LinuxService ser = new Service.LinuxService();
            var res = ser.GetDiff(left, right);

            if (res.IsError)
            {
                return(json.Serialize(new JsonData()
                {
                    IsError = true
                }));
            }
            else
            {
                if (!string.IsNullOrEmpty(res.Result))
                {
                    int startIndex = res.Result.IndexOf("<table");
                    if (startIndex != -1)
                    {
                        res.Result = res.Result.Substring(startIndex);
                    }
                    int endIndex = res.Result.LastIndexOf("</body");
                    if (endIndex != -1)
                    {
                        res.Result = res.Result.Substring(0, endIndex);
                    }
                }
                return(json.Serialize(new JsonData()
                {
                    Result = res.Result
                }));
            }
        }
        public string GetDiffHtml(string CodeGuid, string LeftGuid, string RightGuid)
        {
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            var left  = Model.GetCode(LeftGuid, false);
            var right = Model.GetCode(RightGuid, false);

            if (left == null || right == null)
            {
                throw new HttpException(404, "not found");
            }
            Service.LinuxService ser = new Service.LinuxService();
            var res = ser.GetDiff(left.Program, right.Program);

            if (res.IsError)
            {
                return(json.Serialize(new JsonData()
                {
                    Errors = true
                }));
            }
            else
            {
                if (!string.IsNullOrEmpty(res.Result))
                {
                    int startIndex = res.Result.IndexOf("<table");
                    if (startIndex != -1)
                    {
                        res.Result = res.Result.Substring(startIndex);
                    }
                    int endIndex = res.Result.LastIndexOf("</body");
                    if (endIndex != -1)
                    {
                        res.Result = res.Result.Substring(0, endIndex);
                    }
                }
                return(json.Serialize(new JsonData()
                {
                    Result = res.Result
                }));
            }
        }