Exemplo n.º 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);
            }
        }
Exemplo n.º 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.";
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        void OnEvaluateAllButtonClick(NEventArgs arg)
        {
            NList <string> tests = new NList <string>();

            INIterator <NNode> it = m_TestsTreeView.GetSubtreeIterator();

            while (it.MoveNext())
            {
                NTreeViewItem item = it.Current as NTreeViewItem;
                if (item == null || item.Tag == null || !(item.Tag is string))
                {
                    continue;
                }

                tests.Add((string)item.Tag);
            }

            NStopwatch stopwatch = new NStopwatch();

            stopwatch.Start();
            int itcount = 10000;

            for (int j = 0; j < itcount; j++)
            {
                for (int i = 0; i < tests.Count; i++)
                {
                    try
                    {
                        m_FormulaEngine.Evaluate(tests[i]);
                    }
                    catch (Exception ex)
                    {
                        m_ResultTextBox.Text = "Failed on test: " + tests[i] + ". Error was: " + ex.Message;
                        m_InputTextBox.Text  = tests[i];
                        return;
                    }
                }
            }
            stopwatch.Stop();

            int ms = stopwatch.ElapsedMilliseconds;

            m_ResultTextBox.Text = tests.Count + " tests performed " + itcount + " times in: " + ms + " milliseconds.";
        }
Exemplo n.º 5
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;
        }