Beispiel #1
0
 public void WriteTo(DiagramWriter writer)
 {
     Classifiers.WriteTo(writer);
     if (Note.HasText)
     {
         // we need a separator between the
         // classes and the diagram note
         if (Classifiers.Count > 0)
             writer.AddSeparator();
         writer.WithNote(Note);
     }
 }
        /// <summary>
        /// create the new class diagram
        /// and send it to the webservice.
        /// Receive the result and render it via the web browser.
        /// </summary>
        private async void UpdateDiagram()
        {
            // write classifiers and relations to diagram
            var diagramWriter = new DiagramWriter();
            _diagram.WriteTo(diagramWriter);
            var diagramText = diagramWriter.ToString();

            // skip if diagram did not change
            if (diagramText == _lastDslText)
                return;

            // send diagram data to server
            _lastDslText = diagramText;
            var content = new Dictionary<string, string>
            {
                ["dsl_text"] = diagramText
            };

            // wait for response image URI
            try
            {
                var response = await _yumleHttpConnection.PostAsync(
                _settings.YumlDiagramRequestUri,
                new FormUrlEncodedContent(content));
                // the result is the file name of the cached png,
                // we remove the extension to access the resource
                if (response.IsSuccessStatusCode)
                {
                    var result = await response.Content.ReadAsStringAsync();
                    var uri = $"{_settings.YumlBaseUrl}{GetFileNameWithoutExtension(result)}";
                    UriToDiagram = uri;
                }
                else
                {
                    // TODO: show some error message here (in HTML maybe?)
                }
            }
            catch (HttpRequestException exception)
            {
                // TODO: show correct error message here (in HTML maybe?)
            }
        }
 protected override void Init()
 {
     _diagram = new DiagramWriter();
 }