Exemplo n.º 1
0
 public CompareResult(WorkflowVersion Version1, WorkflowVersion Version2)
 {
     this.version1 = Version1;
     this.version2 = Version2;
     InitializeComponent();
     aux();
 }
        public List <WorkflowVersion> GetWorkflowVersions(string URI, string token)
        {
            Uri uri = new Uri(String.Format(URI));

            // Create the request
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);

            httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "GET";

            // Get the response
            HttpWebResponse httpResponse = null;

            try
            {
                httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error from : " + uri + ": " + ex.Message,
                                "HttpWebResponse exception", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }

            string result = null;

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                result = streamReader.ReadToEnd();
            }

            JsonList subs = new JsonList(result);
            List <WorkflowVersion> res = new List <WorkflowVersion>();

            foreach (var json in subs.subString)
            {
                string          js   = JsonConvert.SerializeObject(json);
                WorkflowVersion temp = new WorkflowVersion(js);
                res.Add(temp);
            }

            return(res);
        }
        public ResultsInfo(JToken version1, JToken version2, WorkflowVersion Version1, WorkflowVersion Version2)
        {
            InitializeComponent();
            v1            = version1;
            v2            = version2;
            this.version1 = Version1;
            this.version2 = Version2;
            //display();
            str1 = v1.ToString();
            str2 = v2.ToString();
            StringBuilder sb      = new StringBuilder();
            var           d       = new Differ();
            var           builder = new InlineDiffBuilder(d);
            var           result  = builder.BuildDiffModel(str1, str2);

            foreach (var line in result.Lines)
            {
                if (line.Type == ChangeType.Inserted)
                {
                    sb.Append("- ");
                    TextRange tr = new TextRange(ver2.Document.ContentEnd, ver2.Document.ContentEnd);
                    tr.Text = "- " + line.Text;
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, System.Windows.Media.Brushes.Red);
                    ver2.AppendText(System.Environment.NewLine);
                    ver2.ScrollToEnd();
                }
                else if (line.Type == ChangeType.Deleted)
                {
                    sb.Append("+ ");
                    TextRange tr = new TextRange(ver1.Document.ContentEnd, ver1.Document.ContentEnd);
                    tr.Text = "+ " + line.Text;
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, System.Windows.Media.Brushes.Green);
                    ver1.AppendText(System.Environment.NewLine);
                    ver1.ScrollToEnd();
                }
                else if (line.Type == ChangeType.Modified)
                {
                    sb.Append("* ");
                }
                else if (line.Type == ChangeType.Imaginary)
                {
                    sb.Append("? ");
                }
                else if (line.Type == ChangeType.Unchanged)
                {
                    sb.Append("  ");
                    TextRange tr = new TextRange(ver1.Document.ContentEnd, ver1.Document.ContentEnd);
                    tr.Text = line.Text;
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, System.Windows.Media.Brushes.Black);
                    ver1.AppendText(System.Environment.NewLine);
                    ver1.ScrollToEnd();

                    TextRange tr1 = new TextRange(ver2.Document.ContentEnd, ver2.Document.ContentEnd);
                    tr1.Text = line.Text;
                    tr1.ApplyPropertyValue(TextElement.ForegroundProperty, System.Windows.Media.Brushes.Black);
                    ver2.AppendText(System.Environment.NewLine);
                    ver2.ScrollToEnd();
                }

                sb.Append(line.Text + "\n");
            }
            // string str = sb.ToString();
            //MessageBox.Show(str);
        }