示例#1
0
        private void OnGoButtonClick(NEventArgs arg1)
        {
            string address = NStringHelpers.SafeTrim(m_NavigationTextBox.Text);

            if (address == null || address.Length == 0)
            {
                return;
            }

            if (NFile.Exists(address))
            {
                // Load from file
                using (Stream stream = NFile.OpenRead(address))
                {
                    LoadSource(stream);
                    LoadHtml(stream, address);
                }

                return;
            }

            // Load from URI
            try
            {
                address     = NormalizeUri(address);
                m_Stopwatch = NStopwatch.StartNew();
                m_PreviewRichText.LoadFromUri(new NUri(address, ENUriKind.RelativeOrAbsolute));
            }
            catch (Exception ex)
            {
                m_Stopwatch.Stop();
                NMessageBox.Show(ex.Message, "Error", ENMessageBoxButtons.OK, ENMessageBoxIcon.Error);
            }
        }
示例#2
0
        private void ExportToHtml()
        {
            m_ElapsedTimeLabel.Text = null;

            NStopwatch stopwatch = NStopwatch.StartNew();

            using (MemoryStream stream = new MemoryStream())
            {
                m_RichText.SaveToStream(stream, new NHtmlTextFormat());
                stopwatch.Stop();

                LoadHtmlSource(stream);
            }

            m_ElapsedTimeLabel.Text = "Export done in: " + stopwatch.ElapsedMilliseconds.ToString() + " ms.";
        }
示例#3
0
        private void LoadHtml(Stream stream, string baseUri)
        {
            m_ElapsedTimeLabel.Text = String.Empty;

            stream.Position = 0;
            m_Stopwatch     = NStopwatch.StartNew();

            NTextLoadSettings settings = null;

            if (baseUri != null)
            {
                settings         = new NTextLoadSettings();
                settings.BaseUri = new NUri(baseUri);
            }

            m_PreviewRichText.LoadFromStream(stream, new NHtmlTextFormat(), settings);
        }
示例#4
0
        private void ExportToHtml()
        {
            m_ElapsedTimeLabel.Text = null;

            NStopwatch stopwatch = NStopwatch.StartNew();

            using (MemoryStream stream = new MemoryStream())
            {
                // Create and configure HTML save settings
                NHtmlSaveSettings saveSettings = new NHtmlSaveSettings();
                saveSettings.InlineStyles = m_InlineStylesCheckBox.Checked;
                saveSettings.MinifyHtml   = m_MinifyHtmlCheckBox.Checked;

                // Save to HTML
                m_RichText.SaveToStream(stream, new NHtmlTextFormat(), saveSettings);
                stopwatch.Stop();

                LoadHtmlSource(stream);
            }

            m_ElapsedTimeLabel.Text = "Export done in: " + stopwatch.ElapsedMilliseconds.ToString() + " ms.";
        }
        private void OnTestSerializationButtonClick(NEventArgs arg)
        {
            ENPersistencyFormat persistencyFormat = (ENPersistencyFormat)arg.TargetNode.Tag;
            NStopwatch          stopwatch;

            try
            {
                Type   nodeType = typeof(NNode);
                Type[] types = nodeType.Assembly.GetTypes();
                int    nodeCount = 0, successfullySerialized = 0;

                stopwatch = NStopwatch.StartNew();
                StringBuilder output = new StringBuilder();
                for (int i = 0, count = types.Length; i < count; i++)
                {
                    Type type = types[i];

                    // not a NNode type, abstract or generic => skip
                    if (!nodeType.IsAssignableFrom(type) || type.IsAbstract || type.IsGenericType)
                    {
                        continue;
                    }

                    NNode node;
                    try
                    {
                        nodeCount++;
                        NNode typeInstance = (NNode)Activator.CreateInstance(type);

                        // Serialize
                        MemoryStream       memoryStream = new MemoryStream();
                        NDomNodeSerializer serializer   = new NDomNodeSerializer();
                        serializer.SerializeDefaultValues = true;
                        serializer.SaveToStream(new NNode[] { typeInstance }, memoryStream, persistencyFormat);

                        // Deserialize to check if the serialization has succeeded
                        NDomNodeDeserializer deserializer = new NDomNodeDeserializer();
                        memoryStream = new MemoryStream(memoryStream.ToArray());
                        node         = deserializer.LoadFromStream(memoryStream, persistencyFormat)[0];

                        output.AppendLine("Sucessfully serialized node type [" + type.Name + "].");
                        successfullySerialized++;
                    }
                    catch (Exception ex)
                    {
                        output.AppendLine("Failed to serialize node type [" + type.Name + "]. Exception was [" + ex.Message + "]");
                    }
                }

                stopwatch.Stop();

                output.AppendLine("==================================================");
                output.AppendLine("Nodes serialized: " + successfullySerialized.ToString() + " of " + nodeCount.ToString());
                output.AppendLine("Time elapsed: " + stopwatch.ElapsedMilliseconds.ToString() + " ms");

                m_TextBox.Text = output.ToString();
                m_TextBox.SetCaretPos(new NTextPosition(m_TextBox.Text.Length, false));
                m_TextBox.EnsureCaretVisible();
            }
            catch (Exception ex)
            {
                NTrace.WriteLine(ex.Message);
            }

            // Restore the default cursor
            this.OwnerWindow.Cursor = null;
        }