Exemplo n.º 1
0
        public void SerializeCommand()
        {
            var cmd = new TestCommand();

            cmd.Name = "test data";

            var buffer = new System.IO.MemoryStream();

#if !SILVERLIGHT
            var bf = (TestCommand)Csla.Core.ObjectCloner.Clone(cmd);
            Assert.AreEqual(cmd.Name, bf.Name, "after BinaryFormatter");

            var ndcs = new System.Runtime.Serialization.NetDataContractSerializer();
            ndcs.Serialize(buffer, cmd);
            buffer.Position = 0;
            var n = (TestCommand)ndcs.Deserialize(buffer);
            Assert.AreEqual(cmd.Name, n.Name, "after NDCS");
#endif

            buffer = new System.IO.MemoryStream();
            var mf = new Csla.Serialization.Mobile.MobileFormatter();
            mf.Serialize(buffer, cmd);
            buffer.Position = 0;
            var m = (TestCommand)mf.Deserialize(buffer);
            Assert.AreEqual(cmd.Name, m.Name, "after MobileFormatter");
        }
Exemplo n.º 2
0
 void IMobileObject.SetChildren(SerializationInfo info, MobileFormatter formatter)
 {
   foreach (string key in info.Children.Keys)
   {
     int referenceId = info.Children[key].ReferenceId;
     this.Add(key, formatter.GetObject(referenceId));
   }
 }
Exemplo n.º 3
0
 void IMobileObject.GetChildren(SerializationInfo info, MobileFormatter formatter)
 {
   foreach (string key in this.Keys)
   {
     object value = this[key];
     IMobileObject mobile = value as IMobileObject;
     if (mobile != null)
     {
       SerializationInfo si = formatter.SerializeObject(mobile);
       info.AddChild(key, si.ReferenceId);
     }
   }
 }
		public void EnsureCollectionCanBeSerialized()
		{
			var builder = new ContainerBuilder();
			builder.Register<IEntities>(_ => Mock.Of<IEntities>());

			using (new ObjectActivator(builder.Build()).Bind(() => ApplicationContext.DataPortalActivator))
			{
				var responses = DataPortal.CreateChild<PollSubmissionResponseCollection>(
					PollSubmissionResponseCollectionTests.CreateOptions());
				var formatter = new MobileFormatter();

				using (var stream = new MemoryStream())
				{
					formatter.Serialize(stream, responses);
					stream.Position = 0;
					var newResponses = formatter.Deserialize(stream) as PollSubmissionResponseCollection;
					Assert.AreEqual(1, newResponses.Count, newResponses.GetPropertyName(_ => _.Count));
					Assert.AreEqual(responses[0].OptionText, newResponses[0].OptionText, newResponses.GetPropertyName(_ => _[0].OptionText));
				}
			}
		}
Exemplo n.º 5
0
        /// <summary>
        /// Gets the report data.
        /// </summary>
        /// <param name="reportDocument">The report document.</param>
        public void GetReportData(ICustomReport reportDocument)
        {
            var currentReport = reportDocument.Reports.First();

            var filterDefinition = GetFilterDefinition(currentReport);
            var filter = new FilterList { FilterDescriptor.FromJSON(filterDefinition) };

            SortList sortDescriptors = null;

            var parameter = currentReport.ReportParameters["sorting"].Value.ToString();
            if (!string.IsNullOrEmpty(parameter))
            {
                using (var stream = new MemoryStream(Convert.FromBase64String(parameter)))
                {
                    var mf = new MobileFormatter();
                    sortDescriptors = mf.Deserialize(stream) as SortList;
                }
            }

            var filterString = currentReport.ReportParameters["globalFilter"].Value.ToString();
            //int pageNumber = Convert.ToInt32(currentReport.ReportParameters["pageNumber"].Value);
            //int pageSize = Convert.ToInt32(currentReport.ReportParameters["pageSize"].Value);

            List<dynamic> colItemList = TheDynamicTypeManager.GetList<IInfoList>(_processName, filterString, 0, short.MaxValue, sortDescriptors, filter).Cast<object>().ToList();

            var info = colItemList.FirstOrDefault();
            if (info != null)
            {
                if (!string.IsNullOrEmpty(((IInfoClass)info).AccessDeniedProperties))
                {
                    AccessDeniedList = ((IInfoClass)info).AccessDeniedProperties.Split('|').ToList();
                }
            }

            currentReport.DataSource = colItemList;

            if (!reportDocument.FitToPage)
            {
                //Method RearrangeColumns automatically evaluates the optimal width of each column based on its contents
                var b = new Bitmap(1000, 1000);
                using (var graphics = Graphics.FromImage(b))
                {
                    RearrangeColumns(currentReport, colItemList.Cast<IInfoClass>(), graphics);
                }
            }
        }
Exemplo n.º 6
0
 protected virtual void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
 { }
Exemplo n.º 7
0
        /// <summary>
        /// Serializes an object from a DTO graph
        /// </summary>
        /// <param name="serialized">DTO Graph to deserialize</param>
        /// <returns>Deserialized object</returns>
        public static object DeserializeFromDTO(List <SerializationInfo> serialized)
        {
            var formatter = new MobileFormatter();

            return(formatter.DeserializeAsDTO(serialized));
        }
Exemplo n.º 8
0
    /// <summary>
    /// Override this method to insert your child object
    /// references into the MobileFormatter serialzation stream.
    /// </summary>
    /// <param name="info">
    /// Object containing the data to serialize.
    /// </param>
    /// <param name="formatter">
    /// Reference to MobileFormatter instance. Use this to
    /// convert child references to/from reference id values.
    /// </param>
    protected override void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
    {
      if (_brokenRules != null && _brokenRules.Count > 0)
      {
        SerializationInfo brInfo = formatter.SerializeObject(_brokenRules);
        info.AddChild("_brokenRules", brInfo.ReferenceId);
      }

      base.OnGetChildren(info, formatter);
    }
Exemplo n.º 9
0
 /// <summary>
 /// Method called by MobileFormatter when an object
 /// should deserialize its child references. The data should be
 /// deserialized from the SerializationInfo parameter.
 /// </summary>
 /// <param name="info">
 /// Object containing the serialized data.
 /// </param>
 /// <param name="formatter">
 /// Reference to the formatter performing the deserialization.
 /// </param>
 public void SetChildren(SerializationInfo info, MobileFormatter formatter)
 {
     // Nothing
 }
Exemplo n.º 10
0
 /// <summary>
 /// Method called by MobileFormatter when an object
 /// should serialize its child references. The data should be
 /// serialized into the SerializationInfo parameter.
 /// </summary>
 /// <param name="info">
 /// Object to contain the serialized data.
 /// </param>
 /// <param name="formatter">
 /// Reference to the formatter performing the serialization.
 /// </param>
 protected override void OnGetChildren(Csla.Serialization.Mobile.SerializationInfo info, Csla.Serialization.Mobile.MobileFormatter formatter)
 {
     base.OnGetChildren(info, formatter);
     if (_deletedList != null)
     {
         var fieldManagerInfo = formatter.SerializeObject(_deletedList);
         info.AddChild("_deletedList", fieldManagerInfo.ReferenceId);
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Deserializes a byte stream into an object.
        /// </summary>
        /// <param name="data">
        /// DTO containing the object's serialized
        /// data.
        /// </param>
        /// <returns>
        /// An object containing the data from the
        /// byte stream. The object must implement
        /// IMobileObject to be deserialized.
        /// </returns>
        public static object Deserialize(List <SerializationInfo> data)
        {
            var formatter = new MobileFormatter();

            return(formatter.DeserializeAsDTO(data));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Serializes the object into a DTO.
        /// </summary>
        /// <param name="obj">
        /// The object to be serialized, which must implement
        /// IMobileObject.
        /// </param>
        /// <returns></returns>
        public List <SerializationInfo> SerializeToDTO(object obj)
        {
            var formatter = new MobileFormatter(ApplicationContext);

            return(formatter.SerializeAsDTO(obj));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Method called by MobileFormatter when an object should deserialize its child references. The data should be deserialized from the SerializationInfo parameter.
        /// </summary>
        /// <param name="info">Object containing the serialized data.</param>
        /// <param name="formatter">Reference to the formatter performing the deserialization.</param>
        public void SetChildren(SerializationInfo info, MobileFormatter formatter)
        {
            if (info == null)
                throw new ArgumentNullException("info");

            if (formatter == null)
                throw new ArgumentNullException("formatter");

            if (info.Children.ContainsKey("BuildFailure"))
            {
                var childInfo = info.Children["BuildFailure"];
                BuildFailure = (BuildFailure)formatter.GetObject(childInfo.ReferenceId);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Method called by MobileFormatter when an object should serialize its child references. The data should be serialized into the SerializationInfo parameter.
        /// </summary>
        /// <param name="info">Object to contain the serialized data.</param>
        /// <param name="formatter">Reference to the formatter performing the serialization.</param>
        public void GetChildren(SerializationInfo info, MobileFormatter formatter)
        {
            if (info == null)
                throw new ArgumentNullException("info");

            if (formatter == null)
                throw new ArgumentNullException("formatter");

            if (BuildFailure != null)
            {
                var childInfo = formatter.SerializeObject(BuildFailure);
                info.AddChild("BuildFailure", childInfo.ReferenceId);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the search custom report data.
        /// </summary>
        /// <param name="report">The report.</param>
        public void GetSearchCustomReportData(Telerik.Reporting.Processing.Report report)
        {
            SetIdentity(report);

            var processName = report.Parameters["processName"].Value.ToString();

            FilterList filter = null;
            var filterDefinition = report.Parameters["filterDefinition"].Value;

            if (filterDefinition == null)
            {
                report.Parameters["filterDefinition"].Value = string.Empty; // Stub. Necessarily to be the some value, to build report without exceptions
            }
            else
            {
                filter = new FilterList { FilterDescriptor.FromJSON((string)filterDefinition) };
            }

            SortList sortDescriptors = null;

            var parameter = report.Parameters["sorting"].Value.ToString();
            if (!string.IsNullOrEmpty(parameter))
            {
                using (var stream = new MemoryStream(Convert.FromBase64String(parameter)))
                {
                    var mf = new MobileFormatter();
                    sortDescriptors = mf.Deserialize(stream) as SortList;
                }
            }

            var filterString = report.Parameters["globalFilter"].Value.ToString();

            var itemList = TheDynamicTypeManager.GetList<IInfoList>(processName, filterString, 0, short.MaxValue, sortDescriptors, filter).Cast<object>().ToList();
            report.DataSource = itemList;
        }
Exemplo n.º 16
0
 /// <summary>
 /// Gets child serialization information.
 /// </summary>
 /// <param name="info">Serialization context.</param>
 /// <param name="formatter">Serializer instance.</param>
 public void GetChildren(SerializationInfo info, MobileFormatter formatter)
 {
 }
Exemplo n.º 17
0
 void IMobileObject.GetChildren(SerializationInfo info, MobileFormatter formatter)
 {
   //
 }
Exemplo n.º 18
0
 /// <summary>
 /// Method called by MobileFormatter when an object
 /// should deserialize its child references. The data should be
 /// deserialized from the SerializationInfo parameter.
 /// </summary>
 /// <param name="info">
 /// Object containing the serialized data.
 /// </param>
 /// <param name="formatter">
 /// Reference to the formatter performing the deserialization.
 /// </param>
 public void SetChildren(SerializationInfo info, MobileFormatter formatter)
 {
     // Nothing
 }
Exemplo n.º 19
0
 /// <summary>
 /// Serializes the object into a byte array.
 /// </summary>
 /// <param name="obj">
 /// The object to be serialized, which must implement
 /// IMobileObject.
 /// </param>
 /// <returns></returns>
 public static byte[] Serialize(object obj)
 {
   using (var buffer = new System.IO.MemoryStream())
   {
     var formatter = new MobileFormatter();
     formatter.Serialize(buffer, obj);
     return buffer.ToArray();
   }
 }
Exemplo n.º 20
0
 /// <summary>
 /// Method called by MobileFormatter when an object
 /// should deserialize its child references. The data should be
 /// deserialized from the SerializationInfo parameter.
 /// </summary>
 /// <param name="info">
 /// Object containing the serialized data.
 /// </param>
 /// <param name="formatter">
 /// Reference to the formatter performing the deserialization.
 /// </param>
 protected override void OnSetChildren(Csla.Serialization.Mobile.SerializationInfo info, Csla.Serialization.Mobile.MobileFormatter formatter)
 {
     if (info.Children.ContainsKey("_deletedList"))
     {
         var childData = info.Children["_deletedList"];
         _deletedList = (MobileList <C>)formatter.GetObject(childData.ReferenceId);
     }
     base.OnSetChildren(info, formatter);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Serializes the object into a DTO.
 /// </summary>
 /// <param name="obj">
 /// The object to be serialized, which must implement
 /// IMobileObject.
 /// </param>
 /// <returns></returns>
 public static List<SerializationInfo> SerializeToDTO(object obj)
 {
   var formatter = new MobileFormatter();
   return formatter.SerializeAsDTO(obj);
 }
Exemplo n.º 22
0
    /// <summary>
    /// Override this method to retrieve your child object
    /// references from the MobileFormatter serialzation stream.
    /// </summary>
    /// <param name="info">
    /// Object containing the data to serialize.
    /// </param>
    /// <param name="formatter">
    /// Reference to MobileFormatter instance. Use this to
    /// convert child references to/from reference id values.
    /// </param>
    protected override void OnSetChildren(SerializationInfo info, MobileFormatter formatter)
    {
      if (info.Children.ContainsKey("_brokenRules"))
      {
        int referenceId = info.Children["_brokenRules"].ReferenceId;
        _brokenRules = (BrokenRulesCollection)formatter.GetObject(referenceId);
      }

      base.OnSetChildren(info, formatter);
    }
Exemplo n.º 23
0
 /// <summary>
 /// Serializes an object from a DTO graph
 /// </summary>
 /// <param name="serialized">DTO Graph to deserialize</param>
 /// <returns>Deserialized object</returns>
 public static object DeserializeFromDTO(List<SerializationInfo> serialized)
 {
   var formatter = new MobileFormatter();
   return formatter.DeserializeAsDTO(serialized);
 }
Exemplo n.º 24
0
        /// <summary>
        /// Serializes the object into a DTO.
        /// </summary>
        /// <param name="obj">
        /// The object to be serialized, which must implement
        /// IMobileObject.
        /// </param>
        /// <returns></returns>
        public static List <SerializationInfo> SerializeToDTO(object obj)
        {
            var formatter = new MobileFormatter();

            return(formatter.SerializeAsDTO(obj));
        }
Exemplo n.º 25
0
    /// <summary>
    /// Deserializes a byte stream into an object.
    /// </summary>
    /// <param name="data">
    /// Byte array containing the object's serialized
    /// data.
    /// </param>
    /// <returns>
    /// An object containing the data from the
    /// byte stream. The object must implement
    /// IMobileObject to be deserialized.
    /// </returns>
    public static object Deserialize(byte[] data)
    {
      if (data == null)
        return null;

      using (var buffer = new System.IO.MemoryStream(data))
      {
        var formatter = new MobileFormatter();
        return formatter.Deserialize(buffer);
      }
    }
Exemplo n.º 26
0
 /// <summary>
 /// Method called by MobileFormatter when an object
 /// should serialize its child references. The data should be
 /// serialized into the SerializationInfo parameter.
 /// </summary>
 /// <param name="info">
 /// Object to contain the serialized data.
 /// </param>
 /// <param name="formatter">
 /// Reference to the formatter performing the serialization.
 /// </param>
 public void GetChildren(SerializationInfo info, MobileFormatter formatter)
 {
 }
Exemplo n.º 27
0
    /// <summary>
    /// Deserializes a byte stream into an object.
    /// </summary>
    /// <param name="data">
    /// DTO containing the object's serialized
    /// data.
    /// </param>
    /// <returns>
    /// An object containing the data from the
    /// byte stream. The object must implement
    /// IMobileObject to be deserialized.
    /// </returns>
    public static object Deserialize(List<SerializationInfo> data)
    {
      if (data == null)
        return null;

      var formatter = new MobileFormatter();
      return formatter.DeserializeAsDTO(data);
    }
Exemplo n.º 28
0
 void IMobileObject.SetChildren(SerializationInfo info, MobileFormatter formatter)
 {
   OnSetChildren(info, formatter);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Sorts the list to string.
        /// </summary>
        /// <returns>System.String.</returns>
        private string SortListToString()
        {
            if (SortRule == null)
                return string.Empty;

            using (var ms = new MemoryStream())
            {
                var mf = new MobileFormatter();
                mf.Serialize(ms, SortRule);

                var bytes = ms.ToArray();
                return Convert.ToBase64String(bytes, 0, bytes.Length);
            }
        }