Beispiel #1
0
 /// <summary>
 /// This method used to save accounting journal entry
 /// </summary>
 /// <param name="journalEntryDetails"></param>
 public void SaveAccountingJournalEntry(JournalEntryAc journalEntryDetails)
 {
     try
     {
         foreach (var entryDetails in journalEntryDetails.JournalEntryCollection)
         {
             if (entryDetails.LedgerId != 0 && (entryDetails.DebitAmount != 0 || entryDetails.CreditAmount != 0))
             {
                 var doubleEntry = new DoubleEntry
                 {
                     Debit           = entryDetails.DebitAmount,
                     Credit          = entryDetails.CreditAmount,
                     Description     = entryDetails.Description,
                     LedgerId        = entryDetails.LedgerId,
                     TransactionDate = journalEntryDetails.JournalDate.ToLocalTime(),
                     ActivityName    = StringConstants.JournalEntry,
                     CreatedDateTime = DateTime.UtcNow
                 };
                 _accountEntryContext.Add(doubleEntry);
                 _accountEntryContext.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         _errorLog.LogException(ex);
         throw;
     }
 }
Beispiel #2
0
        public static DoubleEntry[] CreateDoubleChunk(int count, DateTime?start = null, double percentOfFill = 1.0, int ticksIntervalMs = 100)
        {
            var data = new DoubleEntry[(int)(count * percentOfFill)];

            var ticks     = (start ?? DateTime.Now).Ticks;
            var ticksStep = TimeSpan.FromMilliseconds(ticksIntervalMs).Ticks;

            data[0].ticks = ticks;
            data[0].value = random.NextDouble() * 100.0;

            for (int i = 1, j = 1; i < count && j < data.Length; i++)
            {
                ticks += ticksStep;

                if (!(random.NextDouble() + percentOfFill >= 1.0))
                {
                    continue;
                }

                data[j].ticks = ticks;
                data[j].value = random.NextDouble() * 100.0;
                j++;
            }
            return(data);
        }
Beispiel #3
0
        public void RavenNominaleTest()
        {
            const int size  = 16 * Mem.KB;
            var       count = size / sizeof(DoubleEntry);

            var chunk  = Factory.CreateDoubleChunk(count);
            var buffer = new byte[size];
            var result = new DoubleEntry[count];

            fixed(byte *o = buffer)
            {
                int compressedSize;

                fixed(DoubleEntry *i = chunk)
                {
                    var pi = (byte *)i;
                    var po = o;

                    compressedSize = Lz4Raven.Encode64(ref pi, ref po, size, (int)Lz4Raven.MaximumOutputLength(size));
                }

                Console.WriteLine("Compression ratio: x {0}", size / (double)compressedSize);

                fixed(DoubleEntry *r = result)
                Lz4Raven.Decode64(o, compressedSize, (byte *)r, size, true);
            }

            result.Check(chunk);
        }
Beispiel #4
0
        public void NominaleTest()
        {
            const int size  = 16 * Mem.KB;
            var       count = size / sizeof(DoubleEntry);

            var chunk  = Factory.CreateDoubleChunk(count);
            var buffer = new byte[size];
            var result = new DoubleEntry[count];

            fixed(byte *o = buffer)
            {
                int compressedSize;

                fixed(DoubleEntry *i = chunk)
                {
                    var pi = (byte *)i;
                    var po = o;

                    compressedSize = Lz4.LZ4_compress_fast(pi, po, size, (int)Lz4.MaximumOutputLength(size), 1);
                }

                Console.WriteLine("Compression ratio: x {0}", size / (double)compressedSize);

                fixed(DoubleEntry *r = result)
                {
                    var ip = o;
                    var op = (byte *)r;

                    Lz4.LZ4_decompress_fast(ref ip, ref op, compressedSize);
                }
            }

            result.Check(chunk);
        }
Beispiel #5
0
        private static void TestCursor <TEntry, T>(
            Func <DoubleEntry[], TEntry[]> convert,
            Func <TEntry, T> getValue,
            Func <TEntry[], IColumnCursor <T> > factory,
            T defaultValue = default(T))
            where T : struct
        {
            const int iterations = 5;
            var       chunk      = new DoubleEntry[0]
                                   .Add(0, 12.2)
                                   .Add(4, 15.2)
                                   .Add(5, 16.2)
                                   .Add(6, 13.2)
                                   .Add(7, 14.2);

            var convertedChunk = convert(chunk);
            var cursor         = factory(convertedChunk);

            // Test MoveNext
            for (var i = 0; i < iterations; i++)
            {
                Assert.AreEqual(getValue(convertedChunk[0]), cursor.GetNext(0));
                Assert.AreEqual(getValue(convertedChunk[0]), cursor.GetNext(1));
                Assert.AreEqual(getValue(convertedChunk[0]), cursor.GetNext(2));
                Assert.AreEqual(getValue(convertedChunk[1]), cursor.GetNext(4));
                Assert.AreEqual(getValue(convertedChunk[2]), cursor.GetNext(5));
                Assert.AreEqual(getValue(convertedChunk[3]), cursor.GetNext(6));
                Assert.AreEqual(getValue(convertedChunk[4]), cursor.GetNext(7));
                Assert.AreEqual(getValue(convertedChunk[4]), cursor.GetNext(8));
                Assert.AreEqual(getValue(convertedChunk[4]), cursor.GetNext(9));
                cursor.Reset();
            }

            cursor.Dispose();

            chunk.Set(0, 1, 12.2);
            cursor = factory(convert(chunk));
            for (var i = 0; i < iterations; i++)
            {
                Assert.AreEqual(defaultValue, cursor.GetNext(0));
                Assert.AreEqual(getValue(convertedChunk[0]), cursor.GetNext(1));
                Assert.AreEqual(getValue(convertedChunk[3]), cursor.GetNext(6));
                Assert.AreEqual(getValue(convertedChunk[4]), cursor.GetNext(7));
                cursor.Reset();
            }

            cursor.Dispose();
        }
Beispiel #6
0
        public void RavenCompressWithLowerBlockTest()
        {
            const int size           = 16 * Mem.KB;
            const int writeBlockSize = 1 * Mem.KB;
            var       count          = size / sizeof(DoubleEntry);


            var chunk  = Factory.CreateDoubleChunk(count);
            var buffer = new byte[size];
            var result = new DoubleEntry[count];

            fixed(byte *o = buffer)
            {
                var compressedSize = 0;

                fixed(DoubleEntry *i = chunk)
                {
                    var pi   = (byte *)i;
                    var pEnd = pi + size;
                    var po   = o;

                    while (pi < pEnd)
                    {
                        var wrote = Lz4Raven.Encode64(ref pi, ref po, (int)(pEnd - pi), size, writeBlockSize, 1);
                        //Assert.LessOrEqual(wrote, writeBlockSize);
                        compressedSize += wrote;
                    }
                }

                Console.WriteLine("Compression ratio: x {0}", size / (double)compressedSize);

                fixed(DoubleEntry *r = result)
                {
                    var iPtr        = o;
                    var oPtr        = (byte *)r;
                    var inputLength = compressedSize;

                    var wrote = 0;

                    while (wrote < size)
                    {
                        wrote += Lz4Raven.Decode64(ref iPtr, inputLength, ref oPtr, size - wrote, writeBlockSize);
                    }
                }
            }

            result.Check(chunk);
        }
Beispiel #7
0
        public void RavenUncompressWithLowerBlocksTest()
        {
            const int size           = 16 * Mem.KB;
            const int writeBlockSize = 4 * Mem.KB;
            var       count          = size / sizeof(DoubleEntry);


            var chunk  = Factory.CreateDoubleChunk(count);
            var buffer = new byte[size];
            var result = new DoubleEntry[count];

            fixed(byte *o = buffer)
            {
                int compressedSize;

                fixed(DoubleEntry *i = chunk)
                {
                    var pi = (byte *)i;
                    var po = o;

                    compressedSize = Lz4Raven.Encode64(ref pi, ref po, size, (int)Lz4Raven.MaximumOutputLength(size));
                }

                Console.WriteLine("Compression ratio: x {0}", size / (double)compressedSize);

                fixed(DoubleEntry *r = result)
                {
                    var iPtr        = o;
                    var oPtr        = (byte *)r;
                    var inputLength = compressedSize;

                    var wrote = 0;

                    while (wrote < size)
                    {
                        wrote += Lz4Raven.Decode64(ref iPtr, inputLength, ref oPtr, size - wrote, writeBlockSize);
                    }
                }
            }

            result.Check(chunk);
        }
Beispiel #8
0
 public static Int64Entry ToInt64(this DoubleEntry entry)
 {
     return(new Int64Entry {
         ticks = entry.ticks, value = (long)entry.value
     });
 }
Beispiel #9
0
 public static Int32Entry ToInt32(this DoubleEntry entry)
 {
     return(new Int32Entry {
         ticks = entry.ticks, value = (int)entry.value
     });
 }
Beispiel #10
0
 public static FloatEntry ToFloat(this DoubleEntry entry)
 {
     return(new FloatEntry {
         ticks = entry.ticks, value = (float)entry.value
     });
 }
Beispiel #11
0
        public void RavenUncompressComparePerf()
        {
            const int size       = 4 * Mem.KB;
            var       readSizes  = new [] { 1, 2, 4, 8, 16 };
            const int iterations = 10000;
            var       count      = size / sizeof(DoubleEntry);

            var chunk  = Factory.CreateDoubleChunk(count);
            var buffer = new byte[size];
            var result = new DoubleEntry[count];

            fixed(byte *o = buffer)
            {
                int compressedSize;

                fixed(DoubleEntry *i = chunk)
                {
                    var pi = (byte *)i;
                    var po = o;

                    compressedSize = Lz4Raven.Encode64(ref pi, ref po, size, (int)Lz4Raven.MaximumOutputLength(size));
                }

                Console.WriteLine("Compression ratio: x {0}", size / (double)compressedSize);

                fixed(DoubleEntry *r = result)
                {
                    Lz4Raven.Decode64(o, compressedSize, (byte *)r, size, true);

                    // Jitter purpose
                    for (var i = 0; i < 10; i++)
                    {
                        var iPtr           = o;
                        var oPtr           = (byte *)r;
                        var writeBlockSize = readSizes[0] * Mem.KB;
                        var wrote          = 0;
                        while (wrote < size)
                        {
                            wrote += Lz4Raven.Decode64(ref iPtr, compressedSize, ref oPtr, size - wrote, writeBlockSize);
                        }
                    }

                    var sw = Stopwatch.StartNew();

                    for (var i = 0; i < iterations; i++)
                    {
                        Lz4Raven.Decode64(o, compressedSize, (byte *)r, size, true);
                    }
                    sw.Stop();
                    Console.WriteLine("Match: {0} µs", sw.Elapsed.TotalMilliseconds / iterations * 1e3);
                    result.Check(chunk);

                    for (var j = 0; j < readSizes.Length; j++)
                    {
                        var writeBlockSize = readSizes[j] * Mem.KB;

                        sw = Stopwatch.StartNew();
                        for (var i = 0; i < iterations; i++)
                        {
                            var iPtr = o;
                            var oPtr = (byte *)r;

                            var wrote = 0;
                            while (wrote < size)
                            {
                                wrote += Lz4Raven.Decode64(ref iPtr, compressedSize, ref oPtr, size - wrote, writeBlockSize);
                            }
                        }
                        sw.Stop();
                        Console.WriteLine("Size {0} KB: {1} µs", readSizes[j], sw.Elapsed.TotalMilliseconds / iterations * 1e3);
                        result.Check(chunk);
                    }
                }
            }
        }