Example #1
0
        public void DoubleReferenceCreateOneRemoveAndObjectStillNotGarbageCollected()
        {
            var gc = new GarbageCollector();

            var rootEntry = new StorageEntry(0, "Next", 1);
            var node_1a   = new StorageEntry(1, "Next_A", 2);
            var node_1b   = new StorageEntry(1, "Next_B", 3);
            var node_2    = new StorageEntry(2, "Next", 3);

            var collectables = gc.Collect(
                new List <StorageEntry> {
                rootEntry, node_1a, node_1b, node_2
            },
                Enumerable.Empty <ObjectIdAndKey>()
                ).ToArray();

            collectables.Length.ShouldBe(0);

            collectables = gc.Collect(
                new List <StorageEntry>()
            {
                new StorageEntry(2, "Next", null)
            },
                Enumerable.Empty <ObjectIdAndKey>()
                ).ToArray();

            collectables.Length.ShouldBe(0);
        }
Example #2
0
        private void Test(bool[] rowsToKeep)
        {
            int count = rowsToKeep.Length;

            // Build an identity column
            NumberColumn <int> column = new NumberColumn <int>(-1);

            for (int i = 0; i < rowsToKeep.Length; ++i)
            {
                column[i] = i;
            }

            // Build a RowUpdater and fake mapping to temp to check those results
            TableStub  table   = new TableStub();
            RowUpdater updater = new RowUpdater(table, table);

            int[] rowsToTemp = Enumerable.Range(10, count).ToArray();

            // Request Garbage Collection
            GarbageCollector.Collect <int>(column, null, rowsToKeep, updater, rowsToTemp);

            // Verify correct values were kept
            StringBuilder expected      = new StringBuilder();
            int           expectedCount = 0;

            for (int i = 0; i < count; ++i)
            {
                if (rowsToKeep[i])
                {
                    expectedCount++;

                    if (expected.Length > 0)
                    {
                        expected.Append(", ");
                    }
                    expected.Append(i);
                }
            }

            Assert.Equal(expectedCount, column.Count);
            Assert.Equal(expected.ToString(), String.Join(", ", column.OrderBy((i) => i)));

            // Verify rows removed are reported in the correct indices in temp or swapped in original column
            RowStub stub = new RowStub(table, 0);

            for (int i = 0; i < count; ++i)
            {
                stub.Index = i;
                updater.Update(stub);

                if (!rowsToKeep[i])
                {
                    Assert.Equal(10 + i, stub.Index);
                }
                else
                {
                    Assert.Equal(i, column[stub.Index]);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Generates export file
        /// </summary>
        /// <param name="dt">Data table</param>
        /// <param name="path">Path</param>
        public void GenerateFile(DataTable dt, string path)
        {
            IWorkbook workbook = new HSSFWorkbook();

            ISheet worksheet = workbook.CreateSheet("data");

            GenerateStructure(worksheet, dt.Rows.Count + 1, dt.Columns.Count);
            ICellStyle headerCellStyle = CreateHeaderCellStyle(workbook);
            ICellStyle dataCellStyle   = CreateDataCellStyle(workbook);

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                DataColumn dataColumn = dt.Columns[i];
                worksheet.SetColumnWidth(i, 10000);

                ICell headerCell = GetCell(worksheet, 0, i);
                headerCell.SetCellValue(dataColumn.ColumnName);
                headerCell.CellStyle = headerCellStyle;

                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    ICell cell = GetCell(worksheet, j + 1, i);
                    cell.SetCellValue(dt.Rows[j][i].ToStr());
                    cell.CellStyle = dataCellStyle;
                }
            }

            using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
            {
                workbook.Write(stream);
            }

            GarbageCollector.Collect();
        }
Example #4
0
        /// <summary>
        /// Applies filters
        /// </summary>
        /// <param name="filters">Filters</param>
        public void ApplyFilters(List <Filter> filters)
        {
            try
            {
                // Saving original image
                if (AppliedFilters.Count == 0)
                {
                    OriginalFileName = GenerateOriginalFileName(ImageFileName);
                    File.Copy(ImageFilePath, OriginalFilePath, true);
                }

                // Creating temp image
                if (TempFilePath.IsNullOrEmpty())
                {
                    TempFilePath = Path.Combine(ImageFolderPath, GenerateTempFileName(ImageFileName));
                    File.Copy(ImageFilePath, TempFilePath, true);
                }

                foreach (Filter filter in filters)
                {
                    try
                    {
                        // Applying filter
                        Bitmap original = new Bitmap(TempFilePath);
                        Bitmap bitmap   = new Bitmap(original);
                        original.Dispose();
                        File.Delete(TempFilePath);
                        ApplyFilter(bitmap, filter).Save(TempFilePath, ImageFormat.Jpeg);
                        bitmap.Dispose();
                        GarbageCollector.Collect();

                        AppliedFilters.Add(filter);
                    }
                    catch (Exception e)
                    {
                        LogHelper.Logger.Error(e, $"Unable to apply filter to image. Filter name: {filter.FilterType}");
                    }
                }

                // Create thumbnail for filtered image
                if (TempThumbnailFilePath.IsNullOrEmpty())
                {
                    TempThumbnailFilePath = Path.Combine(ImageFolderPath, GenerateTempThumbnailFileName(ImageFileName));
                }
                else
                if (File.Exists(TempThumbnailFilePath))
                {
                    File.Delete(TempThumbnailFilePath);
                }
                new ImagesConverter(TempFilePath).CreateThumbnail(TempThumbnailFilePath, CommonSettings.ThumbnailWidth, CommonSettings.ThumbnailHeight);
            }
            catch (Exception e)
            {
                LogHelper.Logger.Error(e, "Unable to apply filters to image.");
            }

            GarbageCollector.Collect();
        }
Example #5
0
        public void CorrectEntriesAreCollected()
        {
            var gc = new GarbageCollector();

            var rootEntry = new StorageEntry(0, "Next", 1);
            var node_1    = new StorageEntry(1, "Next", 2);
            var node_2    = new StorageEntry(2, "Next", 3);
            var node_3    = new StorageEntry(3, "Next", 4);

            var gcs = new StorageEntry(10, "SomeKey", "SomeValue");

            var collectables = gc.Collect(
                new List <StorageEntry> {
                rootEntry, node_1, node_2, node_3, gcs
            },
                Enumerable.Empty <ObjectIdAndKey>()
                ).ToArray();

            collectables.Length.ShouldBe(1);
            collectables[0].ShouldBe(10);

            collectables = gc.Collect(
                new List <StorageEntry>()
            {
                new StorageEntry(2, "Next", null)
            },
                Enumerable.Empty <ObjectIdAndKey>()
                ).OrderBy(_ => _).ToArray();

            collectables.Length.ShouldBe(2);
            collectables[0].ShouldBe(3);
            collectables[1].ShouldBe(4);

            collectables = gc.Collect(
                new List <StorageEntry>()
            {
                new StorageEntry(0, "Next", null)
            },
                Enumerable.Empty <ObjectIdAndKey>()
                ).OrderBy(_ => _).ToArray();

            collectables.Length.ShouldBe(2);
            collectables[0].ShouldBe(1);
            collectables[1].ShouldBe(2);
        }
Example #6
0
        /// <summary>
        /// Полное клонирование Bitmap
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="pixelFormat">Формат пикселей</param>
        /// <returns></returns>
        public static Bitmap CloneSmart(this Bitmap bitmap, PixelFormat pixelFormat)
        {
            Bitmap result;

            GarbageCollector.Collect();

            using (Bitmap b = new Bitmap(bitmap))
            {
                b.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);
                result = b.Clone(new Rectangle(Point.Empty, new Size(b.Width, b.Height)), pixelFormat);
            }

            return(result);
        }
Example #7
0
        /// <summary>
        /// Creates the thumbnail.
        /// </summary>
        /// <param name="outputPath">The output path.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public void CreateThumbnail(string outputPath, int width, int height)
        {
            GdPictureImaging image = new GdPictureImaging();
            int imageId            = image.CreateGdPictureImageFromFile(ImagePath);

            if (imageId > 0)
            {
                int thumbnailId = image.CreateThumbnailHQ(imageId, width, height, Color.Black);
                image.SaveAsJPEG(thumbnailId, outputPath);
                image.ReleaseGdPictureImage(imageId);
            }

            GarbageCollector.Collect();
        }
Example #8
0
        public void Trim()
        {
            if (Count == 0)
            {
                return;
            }
            _pairs.Trim();

            // Find Key/Value pairs no longer in any Dictionaries
            BitVector rowsToKeep = new BitVector(false, _keys.Count);

            _pairsInner.ForEach((slice) => IntRemapper.Instance.AddValues(slice, rowsToKeep));

            // Remove those from Keys and Values
            GarbageCollector.Collect <int>(_keys, null, rowsToKeep);
            GarbageCollector.Collect <int>(_values, new [] { _pairsInner }, rowsToKeep);
        }