Esempio 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");
        }
Esempio 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));
   }
 }
Esempio 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));
				}
			}
		}
Esempio 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);
                }
            }
        }
Esempio n. 6
0
 protected virtual void OnGetChildren(SerializationInfo info, MobileFormatter formatter)
 { }
Esempio 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));
        }
Esempio 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);
    }
Esempio 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
 }
Esempio 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);
     }
 }
        /// <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));
        }
Esempio 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));
        }
Esempio 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);
            }
        }
Esempio 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);
            }
        }
Esempio 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;
        }
Esempio 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)
 {
 }
Esempio n. 17
0
 void IMobileObject.GetChildren(SerializationInfo info, MobileFormatter formatter)
 {
   //
 }
Esempio 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
 }
Esempio 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();
   }
 }
Esempio 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);
 }
Esempio 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);
 }
Esempio 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);
    }
Esempio 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);
 }
Esempio 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));
        }
Esempio 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);
      }
    }
Esempio 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)
 {
 }
Esempio 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);
    }
Esempio n. 28
0
 void IMobileObject.SetChildren(SerializationInfo info, MobileFormatter formatter)
 {
   OnSetChildren(info, formatter);
 }
Esempio 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);
            }
        }