private void OnLoadStateButtonClick(NEventArgs arg1)
        {
            if (m_MemoryStream == null)
            {
                return;
            }

            m_MemoryStream.Seek(0, SeekOrigin.Begin);

            try
            {
                NDomNodeDeserializer deserializer = new NDomNodeDeserializer();

                NTestNode root = (NTestNode)deserializer.LoadFromStream(m_MemoryStream, ENPersistencyFormat.Binary)[0];

/*				NDocumentBlock root = (NDocumentBlock)deserializer.LoadFromStream(m_MemoryStream, ENPersistencyFormat.Binary)[0];
 *
 *                              if (root != null)
 *                              {
 *                                      m_RichText.Document = new NRichTextDocument(root);
 *                              }*/
            }
            catch (Exception ex)
            {
                NTrace.WriteLine(ex.Message);
            }
        }
        void OnSaveStateButtonClick(NEventArgs arg1)
        {
            try
            {
                m_MemoryStream = new MemoryStream();

                NSerializer serializer          = new NSerializer();
                PersonInfo  serializationObject = new PersonInfo(
                    m_NameTextBox.Text,
                    m_AddressTextBox.Text,
                    m_MarriedCheckBox.Checked,
                    m_GenderComboBox.SelectedIndex == 0 ? GenderSingleton.Male : GenderSingleton.Female,
                    m_OtherTextBox.Text);
                serializer.SaveToStream(serializationObject, m_MemoryStream, ENPersistencyFormat.Binary);
            }
            catch (Exception ex)
            {
                NTrace.WriteLine(ex.Message);
            }
        }
        private void OnSaveStateButtonClick(NEventArgs arg1)
        {
            try
            {
                m_MemoryStream = new MemoryStream();

                NDomNodeSerializer serializer = new NDomNodeSerializer();

                NTestNode testNode = new NTestNode();

                testNode.SetValue(NTestNode.ExtendedPropertyEx, false);
                serializer.SaveToStream(new NNode[] { testNode }, m_MemoryStream, ENPersistencyFormat.Binary);

//				serializer.SaveToStream(new NNode[] { m_RichText.Content }, m_MemoryStream, ENPersistencyFormat.Binary);

                m_LoadStateButton.Enabled = true;
            }
            catch (Exception ex)
            {
                NTrace.WriteLine(ex.Message);
            }
        }
예제 #4
0
        /// <summary>
        /// Creates the template in the specified document
        /// </summary>
        /// <remarks>
        /// This method will call the CreateTemplate method.
        /// The call will be embraced in a transaction with the specified TransactionDescription
        /// </remarks>
        /// <param name="document">document in which to create the template</param>
        /// <returns>true if the template was successfully created, otherwise false</returns>
        public virtual bool Create(NDrawingDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            document.StartHistoryTransaction(m_sTransactionDescription);

            try
            {
                CreateTemplate(document);
            }
            catch (Exception ex)
            {
                NTrace.WriteLine("Failed to create template. Exception was: " + ex.Message);
                document.RollbackHistoryTransaction();
                return(false);
            }

            document.CommitHistoryTransaction();
            return(true);
        }
예제 #5
0
        protected override NWidget CreateExampleControls()
        {
            NList <NPropertyEditor> editors = NDesigner.GetDesigner(m_MenuBar).CreatePropertyEditors(
                m_MenuBar,
                NMenuBar.OrientationProperty,
                NMenuBar.OpenPopupsOnMouseInProperty,
                NMenuBar.ClosePopupsOnMouseOutProperty
                );

            NStackPanel stack = new NStackPanel();

            stack.FillMode = ENStackFillMode.Last;
            stack.FitMode  = ENStackFitMode.Last;

            for (int i = 0; i < editors.Count; i++)
            {
                stack.Add(editors[i]);
            }

            m_EventsLog = new NExampleEventsLog();
            stack.Add(m_EventsLog);
            NTrace.WriteLine("Create Menu Example Controls");
            return(new NUniSizeBoxGroup(stack));
        }
        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;
        }