Exemplo n.º 1
0
        /// <summary>
        /// Serializes the object using specified etalon.
        /// </summary>
        /// <param name="obj">The object to serialize.</param>
        /// <param name="diff">The etalon object.</param>
        public void Write(IFRSerializable obj, object diff)
        {
            if (obj == null)
            {
                return;
            }
            XmlItem       saveCurItem       = FCurItem;
            XmlItem       saveCurRoot       = FCurRoot;
            StringBuilder saveText          = FText;
            object        saveDiffObject    = FDiffObject;
            bool          destroyDiffObject = false;

            try
            {
                FText       = new StringBuilder();
                FCurItem    = FCurItem == null ? FRoot : FCurItem.Add();
                FCurRoot    = FCurItem;
                FDiffObject = diff;
                if (obj is Base && SerializeTo == SerializeTo.Preview)
                {
                    FDiffObject   = (obj as Base).OriginalComponent;
                    FCurItem.Name = FDiffObject != null ? (obj as Base).Alias : (obj as Base).ClassName;
                }
                if (GetDiff != null)
                {
                    DiffEventArgs e = new DiffEventArgs();
                    e.Object = obj;
                    GetDiff(this, e);
                    FDiffObject = e.DiffObject;
                }
                if (FDiffObject == null)
                {
                    try
                    {
                        FDiffObject       = Activator.CreateInstance(obj.GetType());
                        destroyDiffObject = true;
                    }
                    catch
                    {
                    }
                }
                obj.Serialize(this);
            }
            finally
            {
                if (FText.Length > 0)
                {
                    FText.Remove(FText.Length - 1, 1);
                }
                FCurRoot.Text = FText.ToString();
                FText         = saveText;
                FCurItem      = saveCurItem;
                FCurRoot      = saveCurRoot;
                if (destroyDiffObject && FDiffObject is IDisposable)
                {
                    (FDiffObject as IDisposable).Dispose();
                }
                FDiffObject = saveDiffObject;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads an object from current xml node.
        /// </summary>
        /// <returns>The object.</returns>
        /// <remarks>
        /// This method creates an instance of object described by the current xml node, then invokes
        /// its <b>Deserialize</b> method.
        /// </remarks>
        /// <example>This example demonstrates the use of <b>ReadProperties</b>, <b>ReadChildren</b>,
        /// <b>NextItem</b>, <b>Read</b> methods.
        /// <code>
        /// public void Deserialize(FRReader reader)
        /// {
        ///   // read simple properties like "Text", complex properties like "Border.Lines"
        ///   reader.ReadProperties(this);
        ///
        ///   // moves the current reader item
        ///   while (reader.NextItem())
        ///   {
        ///     // read the "Styles" collection
        ///     if (String.Compare(reader.ItemName, "Styles", true) == 0)
        ///       reader.Read(Styles);
        ///     else if (reader.ReadChildren)
        ///     {
        ///       // if read of children is enabled, read them
        ///       Base obj = reader.Read();
        ///       if (obj != null)
        ///          obj.Parent = this;
        ///     }
        ///   }
        /// }
        /// </code>
        /// </example>
        public IFRSerializable Read()
        {
            XmlItem saveCurItem = curItem;
            XmlItem saveCurRoot = curRoot;

            XmlProperty[]   saveProps = props;
            IFRSerializable result    = null;

            try
            {
                if (curItem == null)
                {
                    curItem = root;
                }
                curRoot = curItem;
                GetProps();

                if (report != null && report.IsAncestor)
                {
                    result = report.FindObject(ReadStr("Name"));
                }
                if (result == null && curItem.Name != "inherited")
                {
                    Type type = RegisteredObjects.FindType(curItem.Name);
                    if (type != null)
                    {
                        result = Activator.CreateInstance(type) as IFRSerializable;
                        if (result is Report)
                        {
                            report = result as Report;
                        }
                    }
                    else
                    {
                        if (!Config.WebMode)
                        {
                            MessageBox.Show(Res.Get("Messages,CantFindObject") + " " + curItem.Name);
                        }
                        else
                        {
                            throw new ClassException(curItem.Name);
                        }
                    }
                }
                if (result != null)
                {
                    result.Deserialize(this);
                }
            }
            finally
            {
                curItem = saveCurItem;
                curRoot = saveCurRoot;
                props   = saveProps;
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Serializes the object using specified etalon.
        /// </summary>
        /// <param name="obj">The object to serialize.</param>
        /// <param name="diff">The etalon object.</param>
        public void Write(IFRSerializable obj, object diff)
        {
            if (obj == null)
            {
                return;
            }
            XmlItem saveCurItem = curItem;
            XmlItem saveCurRoot = curRoot;
            //StringBuilder saveText = FText;
            object saveDiffObject = diffObject;

            try
            {
                //FText = new StringBuilder();
                curItem    = curItem == null ? root : curItem.Add();
                curRoot    = curItem;
                diffObject = diff;
                if (obj is Base && SerializeTo == SerializeTo.Preview)
                {
                    diffObject   = (obj as Base).OriginalComponent;
                    curItem.Name = diffObject != null ? (obj as Base).Alias : (obj as Base).ClassName;
                }
                if (GetDiff != null)
                {
                    DiffEventArgs e = new DiffEventArgs();
                    e.Object = obj;
                    GetDiff(this, e);
                    diffObject = e.DiffObject;
                }
                if (diffObject == null)
                {
                    try
                    {
                        Type objType = obj.GetType();
                        if (!diffObjects.Contains(objType))
                        {
                            diffObjects[objType] = Activator.CreateInstance(objType);
                        }
                        diffObject = diffObjects[objType];
                    }
                    catch
                    {
                    }
                }
                obj.Serialize(this);
            }
            finally
            {
                //if (FText.Length > 0)
                //          FText.Remove(FText.Length - 1, 1);
                //FCurRoot.Text = FText.ToString();
                //FText = saveText;
                curItem    = saveCurItem;
                curRoot    = saveCurRoot;
                diffObject = saveDiffObject;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reads an object from current xml node.
        /// </summary>
        /// <returns>The object.</returns>
        /// <remarks>
        /// This method creates an instance of object described by the current xml node, then invokes
        /// its <b>Deserialize</b> method.
        /// </remarks>
        /// <example>This example demonstrates the use of <b>ReadProperties</b>, <b>ReadChildren</b>,
        /// <b>NextItem</b>, <b>Read</b> methods.
        /// <code>
        /// public void Deserialize(FRReader reader)
        /// {
        ///   // read simple properties like "Text", complex properties like "Border.Lines"
        ///   reader.ReadProperties(this);
        ///
        ///   // moves the current reader item
        ///   while (reader.NextItem())
        ///   {
        ///     // read the "Styles" collection
        ///     if (String.Compare(reader.ItemName, "Styles", true) == 0)
        ///       reader.Read(Styles);
        ///     else if (reader.ReadChildren)
        ///     {
        ///       // if read of children is enabled, read them
        ///       Base obj = reader.Read();
        ///       if (obj != null)
        ///          obj.Parent = this;
        ///     }
        ///   }
        /// }
        /// </code>
        /// </example>
        public IFRSerializable Read()
        {
            XmlItem         saveCurItem = FCurItem;
            XmlItem         saveCurRoot = FCurRoot;
            List <PropInfo> saveProps   = FProps;
            IFRSerializable result      = null;

            try
            {
                if (FCurItem == null)
                {
                    FCurItem = FRoot;
                }
                FCurRoot = FCurItem;
                GetProps();

                if (FReport != null && FReport.IsAncestor)
                {
                    result = FReport.FindObject(ReadStr("Name"));
                }
                if (result == null && FCurItem.Name != "inherited")
                {
                    Type type = RegisteredObjects.FindType(FCurItem.Name);
                    if (type != null)
                    {
                        result = Activator.CreateInstance(type) as IFRSerializable;
                        if (result is Report)
                        {
                            FReport = result as Report;
                        }
                    }
                    else
                    {
                        throw new ClassException(FCurItem.Name);
                    }
                }
                if (result != null)
                {
                    result.Deserialize(this);
                }
            }
            finally
            {
                FCurItem = saveCurItem;
                FCurRoot = saveCurRoot;
                FProps   = saveProps;
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads the specified object.
        /// </summary>
        /// <param name="obj">The object to read.</param>
        /// <remarks>
        /// The object must implement the <see cref="IFRSerializable"/> interface. This method
        /// invokes the <b>Deserialize</b> method of the object.
        /// </remarks>
        /// <example>This example demonstrates the use of <b>ReadProperties</b>, <b>ReadChildren</b>,
        /// <b>NextItem</b>, <b>Read</b> methods.
        /// <code>
        /// public void Deserialize(FRReader reader)
        /// {
        ///   // read simple properties like "Text", complex properties like "Border.Lines"
        ///   reader.ReadProperties(this);
        ///
        ///   // moves the current reader item
        ///   while (reader.NextItem())
        ///   {
        ///     // read the "Styles" collection
        ///     if (String.Compare(reader.ItemName, "Styles", true) == 0)
        ///       reader.Read(Styles);
        ///     else if (reader.ReadChildren)
        ///     {
        ///       // if read of children is enabled, read them
        ///       Base obj = reader.Read();
        ///       if (obj != null)
        ///          obj.Parent = this;
        ///     }
        ///   }
        /// }
        /// </code>
        /// </example>
        public void Read(IFRSerializable obj)
        {
            XmlItem saveCurItem = curItem;
            XmlItem saveCurRoot = curRoot;

            XmlProperty[] saveProps = props;
            try
            {
                if (curItem == null)
                {
                    curItem = root;
                }
                curRoot = curItem;
                GetProps();
                obj.Deserialize(this);
            }
            finally
            {
                curItem = saveCurItem;
                curRoot = saveCurRoot;
                props   = saveProps;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Reads the specified object.
        /// </summary>
        /// <param name="obj">The object to read.</param>
        /// <remarks>
        /// The object must implement the <see cref="IFRSerializable"/> interface. This method
        /// invokes the <b>Deserialize</b> method of the object.
        /// </remarks>
        /// <example>This example demonstrates the use of <b>ReadProperties</b>, <b>ReadChildren</b>,
        /// <b>NextItem</b>, <b>Read</b> methods.
        /// <code>
        /// public void Deserialize(FRReader reader)
        /// {
        ///   // read simple properties like "Text", complex properties like "Border.Lines"
        ///   reader.ReadProperties(this);
        ///
        ///   // moves the current reader item
        ///   while (reader.NextItem())
        ///   {
        ///     // read the "Styles" collection
        ///     if (String.Compare(reader.ItemName, "Styles", true) == 0)
        ///       reader.Read(Styles);
        ///     else if (reader.ReadChildren)
        ///     {
        ///       // if read of children is enabled, read them
        ///       Base obj = reader.Read();
        ///       if (obj != null)
        ///          obj.Parent = this;
        ///     }
        ///   }
        /// }
        /// </code>
        /// </example>
        public void Read(IFRSerializable obj)
        {
            XmlItem         saveCurItem = FCurItem;
            XmlItem         saveCurRoot = FCurRoot;
            List <PropInfo> saveProps   = FProps;

            try
            {
                if (FCurItem == null)
                {
                    FCurItem = FRoot;
                }
                FCurRoot = FCurItem;
                GetProps();
                obj.Deserialize(this);
            }
            finally
            {
                FCurItem = saveCurItem;
                FCurRoot = saveCurRoot;
                FProps   = saveProps;
            }
        }
Exemplo n.º 7
0
 internal void Read(IFRSerializable obj, XmlItem Root)
 {
     curItem = Root;
     Read(obj);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Serializes the specified object.
 /// </summary>
 /// <param name="obj">The object to serialize.</param>
 /// <remarks>
 /// The object must implement the <see cref="IFRSerializable"/> interface. This method
 /// invokes the <b>Serialize</b> method of the object.
 /// </remarks>
 /// <example>This example demonstrates the use of writer.
 /// <code>
 /// public void Serialize(FRWriter writer)
 /// {
 ///   // get the etalon object. It will be used to write changed properties only.
 ///   Base c = writer.DiffObject as Base;
 ///
 ///   // write the type name
 ///   writer.ItemName = ClassName;
 ///
 ///   // write properties
 ///   if (Name != "")
 ///     writer.WriteStr("Name", Name);
 ///   if (Restrictions != c.Restrictions)
 ///     writer.WriteValue("Restrictions", Restrictions);
 ///
 ///   // write child objects if allowed
 ///   if (writer.SaveChildren)
 ///   {
 ///     foreach (Base child in ChildObjects)
 ///     {
 ///       writer.Write(child);
 ///     }
 ///   }
 /// }
 /// </code>
 /// </example>
 public void Write(IFRSerializable obj)
 {
     Write(obj, null);
 }