Exemple #1
0
        public void BeginRead_should_be_callable_indirectly()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                PStream.BeginReadByteArrayInt32Int32AsyncCallbackObject().Body = (@this, _buffer, offset, count, callback, state) =>
                                                                                 IndirectionsContext.ExecuteOriginal(() => @this.BeginRead(_buffer, offset, 42, callback, state));

                var buffer = new byte[256];
                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] = (byte)i;
                }


                using (var ms = new MemoryStream(buffer))
                {
                    // Act
                    var _buffer = new byte[1024];
                    var ar      = ms.BeginRead(_buffer, 0, _buffer.Length, null, null);
                    var actual  = ms.EndRead(ar);

                    // Assert
                    Assert.AreEqual(42, actual);
                }
            }
        }
        public static byte[] ToBytes(this PVCFrame frame)
        {
            IFormatter formatter = new BinaryFormatter();

            //IFormatter formatter = new JsonNetFormatter();
            formatter.SurrogateSelector = PUtil.FrameworkSurrogateSelector;
            MemoryStream stream  = new MemoryStream();
            PStream      pStream = new PStream(stream);

            pStream.WriteObjectTree(formatter, frame);
            return(stream.ToArray());
        }
Exemple #3
0
        /// <summary>
        /// Overridden.  Write this layer and all its children to the given
        /// SerializationInfo.
        /// </summary>
        /// <param name="info">The SerializationInfo to write to.</param>
        /// <param name="context">
        /// The streaming context of this serialization operation.
        /// </param>
        /// <remarks>
        /// Note that the layer writes out any cameras that are viewing it
        /// conditionally, so they will only get written out if someone else
        /// writes them unconditionally.
        /// </remarks>
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            int count = CameraCount;

            for (int i = 0; i < count; i++)
            {
                PStream.WriteConditionalObject(info, "camera" + i, cameras[i]);
            }

            info.AddValue("cameraCount", count);
        }
        /// <summary>
        /// Overridden.  Write this camera and all its children to the given
        /// SerializationInfo.
        /// </summary>
        /// <param name="info">The SerializationInfo to write to.</param>
        /// <param name="context">
        /// The streaming context of this serialization operation.
        /// </param>
        /// <remarks>
        /// Note that the camera's layers are written conditionally, so they will only
        /// get written out if someone else writes them unconditionally.
        /// </remarks>
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);

            int count = LayerCount;

            for (int i = 0; i < count; i++)
            {
                PStream.WriteConditionalObject(info, "layer" + i, layers[i]);
            }

            info.AddValue("layerCount", count);
            PStream.WriteConditionalObject(info, "canvas", canvas);
        }
        public static PVCFrame ToFrame(this byte[] byteArray)
        {
            PVCFrame   frame     = null;
            IFormatter formatter = new BinaryFormatter();

            //IFormatter formatter = new JsonNetFormatter();
            formatter.SurrogateSelector = PUtil.FrameworkSurrogateSelector;
            MemoryStream stream  = new MemoryStream(byteArray);
            PStream      pStream = new PStream(stream);

            frame = (PVCFrame)pStream.ReadObjectTree(formatter);
            stream.Close();
            return(frame);
        }
Exemple #6
0
        private void GenerateReport()
        {
            try
            {
                var projName = SelectedProject.Code;
                var logoPath = System.IO.Directory.GetCurrentDirectory() + "\\logo.png";
                var path     = Path.GetDirectoryName(SelectedProject.Path);
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                //export images
                foreach (var item in SelectedProject.Units)
                {
                    if (item.Image != null)
                    {
                        ((System.Drawing.Image)item.Image).Save(path + "\\" + item.Code + ".png");                     //item.Image.ToImage().Save(path + "\\" + item.Code + ".png");
                    }
                }

                //initialize and detailed report
                var profiles    = new List <Profile>();
                var fillings    = new List <Domain.Models.Filling>();
                var accessories = new List <Accessory>();
                foreach (var item in SelectedProject.Units)
                {
                    if (item.Frame == null) //|| item.Frame.Length == 0)
                    {
                        continue;
                    }
                    byte[] frameByte = item.Frame;
                    if (frameByte == null || frameByte.Length == 0)
                    {
                        continue;
                    }

                    var formatter = new BinaryFormatter();
                    formatter.SurrogateSelector = PUtil.FrameworkSurrogateSelector;
                    var stream  = new MemoryStream(frameByte);
                    var pStream = new PStream(stream);
                    var frame   = (PVCFrame)pStream.ReadObjectTree(formatter);
                    stream.Close();

                    for (int i = 0; i < item.Quantity; i++)
                    {
                        profiles.AddRange(frame.Model.GetProfiles(true, true));
                        fillings.AddRange(frame.Model.GetFillings(true));
                        accessories.AddRange(frame.Model.GetAccessories());
                    }
                }

                var profileTables   = new List <PdfPTable>();
                var fillingTables   = new List <PdfPTable>();
                var accessoryTables = new List <PdfPTable>();
                var tables          = new List <PdfPTable>();

                if (profiles != null && profiles.Count > 0)
                {
                    profileTables = Reporter.ProfilesTable(profiles, includesPrice: true).ToList();
                }
                if (fillings != null && fillings.Count > 0)
                {
                    fillingTables = Reporter.FillingsTable(fillings, includesPrice: true).ToList();
                }
                if (accessories != null && fillings.Count > 0)
                {
                    accessoryTables = Reporter.AccessoriesTable(accessories, includesPrice: true).ToList();
                }

                if (profileTables != null && profileTables.Count > 0)
                {
                    tables.AddRange(profileTables);
                }
                if (fillingTables != null && fillingTables.Count > 0)
                {
                    tables.AddRange(fillingTables);
                }
                if (accessoryTables != null && accessoryTables.Count > 0)
                {
                    tables.AddRange(accessoryTables);
                }

                var fileName = path + "\\" + projName + "-Details.pdf";
                if (tables != null && tables.Count > 0)
                {
                    Reporter.ItemsReport(fileName, tables, projName, logoPath);
                }

                //total report
                tables = new List <PdfPTable>();
                if (profiles != null && profiles.Count > 0)
                {
                    profileTables = Reporter.ProfilesTable(profiles, includesPrice: true, onlyTotal: true).ToList();
                }
                if (fillings != null && fillings.Count > 0)
                {
                    fillingTables = Reporter.FillingsTable(fillings, includesPrice: true, onlyTotal: true).ToList();
                }
                if (accessories != null && fillings.Count > 0)
                {
                    accessoryTables = Reporter.AccessoriesTable(accessories, includesPrice: true, onlyTotal: true).ToList();
                }

                if (profileTables != null && profileTables.Count > 0)
                {
                    tables.AddRange(profileTables);
                }
                if (fillingTables != null && fillingTables.Count > 0)
                {
                    tables.AddRange(fillingTables);
                }
                if (accessoryTables != null && accessoryTables.Count > 0)
                {
                    tables.AddRange(accessoryTables);
                }

                fileName = path + "\\" + projName + "-Total.pdf";
                if (tables != null && tables.Count > 0)
                {
                    Reporter.ItemsReport(fileName, tables, projName, logoPath);
                }

                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
                {
                    FileName = path, UseShellExecute = true, Verb = "open"
                });
            }
            catch (IOException e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }