Пример #1
0
        public void Set(int address, int value)
        {
            var page = (address & 0xF000) >> 12;

            _mem[_mapper[page]][address & 0xFFF] = value & 0xFF;
            Written?.Invoke(this, new AddressWrittenEventArgs(address, 1, value & 0xFF));
        }
Пример #2
0
        public void DecryptFile(string inputFile, string outputFile)
        {
            try
            {
                FSIn  = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
                FSOut = new FileStream(outputFile, FileMode.Create);
                var decryptor = RMCrypto.CreateDecryptor(keyBytes, VIKey);
                CStream = new CryptoStream(FSIn, decryptor, CryptoStreamMode.Read);

                int data;
                while ((data = CStream.ReadByte()) != -1)
                {
                    FSOut.WriteByte((byte)data);
                }
                CStream.Dispose();
                FSIn.Dispose();
                FSOut.Dispose();
                Written?.Invoke();
            } catch (Exception e)
            {
                FSIn?.Dispose();
                FSOut?.Dispose();
                File.Delete(outputFile);
                Error?.Invoke(e);
            }
        }
Пример #3
0
        public void NotifySubscribers(IEnumerable <DurableEvent> events, Func <IActorRef, bool> predicate = null)
        {
            foreach (var e in events)
            {
                var written = new Written(e);

                // in any case, notify all default subscribers
                // for which condition evaluates to true
                foreach (var subscriber in DefaultRegistry)
                {
                    if (predicate is null || predicate(subscriber))
                    {
                        subscriber.Tell(written);
                    }
                }

                // notify subscribers with matching aggregate id
                foreach (var aggregateId in e.DestinationAggregateIds)
                {
                    foreach (var aggregate in AggregateRegistry[aggregateId])
                    {
                        if (predicate is null || predicate(aggregate))
                        {
                            aggregate.Tell(written);
                        }
                    }
                }
            }
        }
Пример #4
0
        public void PushWriteSuccess(IEnumerable <DurableEvent> events, IActorRef initiator, IActorRef requestor, int instanceId)
        {
            foreach (var durableEvent in events)
            {
                requestor.Tell(new WriteSuccess(durableEvent, instanceId));
                var written = new Written(durableEvent);

                foreach (var actorRef in DefaultRegistry)
                {
                    if (!Equals(actorRef, requestor))
                    {
                        actorRef.Tell(written);
                    }
                }

                foreach (var aggregateId in durableEvent.DestinationAggregateId)
                {
                    foreach (var aggregate in AggregateRegistry[aggregateId])
                    {
                        if (!Equals(aggregate, requestor))
                        {
                            aggregate.Tell(written);
                        }
                    }
                }
            }
        }
Пример #5
0
        public void Edit(string erased, string replacement)
        {
            int index = Written.LastIndexOf(erased);

            Erase(erased);

            if (string.IsNullOrWhiteSpace(Written.Substring(index, erased.Length)))
            {
                if (replacement.Length == erased.Length)
                {
                    Written = Written.Remove(index, erased.Length).Insert(index, replacement);
                }
                else if (replacement.Length != erased.Length)
                {
                    var sb = new StringBuilder(Written);
                    foreach (char c in replacement)
                    {
                        int i = index + replacement.IndexOf(c);
                        if (char.IsWhiteSpace(Written, i))
                        {
                            sb.Remove(i, 1).Insert(i, c);
                        }
                        else
                        {
                            sb.Remove(i, 1).Insert(i, '@');
                        }
                    }

                    Written = sb.ToString();
                }
            }
        }
Пример #6
0
            public void Write(string category, string summary, JSONValue content)
            {
                var item = new LogItem(category, summary, content);

                Entries.Add(item);

                Written?.Invoke(this, item);
            }
Пример #7
0
        public string GetDay()
        {
            if (Written != null)
            {
                return(Written.ToString("dd"));
            }

            return(string.Empty);
        }
Пример #8
0
        public string GetYear()
        {
            if (Written != null)
            {
                return(Written.ToString("yyyy"));
            }

            return(string.Empty);
        }
Пример #9
0
        public string GetMonth()
        {
            if (Written != null)
            {
                CultureInfo info = new CultureInfo("de-DE");
                return(Written.ToString("MMMM", info));
            }

            return(string.Empty);
        }
Пример #10
0
        public void Jira_cat()
        {
            // arrange
            var testName = TestNameBasedOnCurrentTestMethod;

            // act
            Addin.TestStarted(testName);

            // assert
            Written
            .ShouldBeEquivalentTo(new[] { "Related JIRA Issue: CRT-123" });
        }
Пример #11
0
        public void No_categories()
        {
            // arrange
            var testName = TestNameBasedOnCurrentTestMethod;

            // act
            Addin.TestStarted(testName);

            // assert
            Written
            .ShouldBeEquivalentTo(new[] { "Test Category: fixture level cat" });
        }
Пример #12
0
        internal static void RemoveAll()
        {
            if (Written != null)
            {
                foreach (Delegate d in Written.GetInvocationList())
                {
                    Written -= (LogWriteHandler)d;
                }

                Written = null;
            }
        }
        internal void WriteIfDifferent(string filePath, CppTypeContext context)
        {
            if (!Written.Add(Path.GetFullPath(filePath)))
            {
                throw new InvalidOperationException($"Was about to overwrite existing file: {filePath} with context: {context.LocalType.This}");
            }

            if (WriteIfDifferent(filePath, rawWriter.BaseStream))
            {
                NumChangedFiles++;
            }
        }
Пример #14
0
        public void Other_cat()
        {
            // arrange
            var testName = TestNameBasedOnCurrentTestMethod;

            // act
            Addin.TestStarted(testName);

            // assert
            Written
            .ShouldBeEquivalentTo(new[] { "Test Category: some other stuff" });
        }
Пример #15
0
        public void Single_jira_category()
        {
            // arrange
            var testName = TestNameBasedOnCurrentTestMethod;

            // act
            Addin.TestStarted(testName);

            // assert
            Written
            .ShouldBeEquivalentTo(new[] { "Test Category: fixture level cat", "Related JIRA Issue: CRT-123" });
        }
Пример #16
0
        public void Suite_leval_cat_written_with_each_test()
        {
            // arrange
            var testName = TestNameBasedOnCurrentTestMethod;

            // act
            Addin.TestStarted(testName);
            Addin.TestStarted(testName);

            // assert
            Written
            .ShouldBeEquivalentTo(new[] { "Related JIRA Issue: CRT-123", "Related JIRA Issue: CRT-123" });
        }
Пример #17
0
        public void No_cat()
        {
            // arrange
            var testName = TestNameBasedOnCurrentTestMethod;

            // act
            Addin.TestStarted(testName);

            // assert
            Written
            .Should()
            .BeEmpty();
        }
Пример #18
0
        public static void Write(int mask, string format, params object[] args)
        {
            if ((EnableMask & mask) != mask)
            {
                return;
            }

            if (args.Count() > 0)
            {
                Written?.Invoke(mask, string.Format(format, args));
            }
            else
            {
                Written?.Invoke(mask, format);
            }
        }
Пример #19
0
        public void Erase(string erased)
        {
            int    index             = Written.LastIndexOf(erased);
            string replacementString = "";

            if (EraserDurability >= erased.Length)
            {
                replacementString = replacementString.PadRight(erased.Length);
                Written           = Written.Remove(index, erased.Length).Insert(index, replacementString);
                EraserDurability -= erased.Length;
            }
            else
            {
                string erasedNew = erased.Substring(0, erased.Length - EraserDurability);
                replacementString = erasedNew + replacementString.PadRight(EraserDurability);
                Written           = Written.Remove(index, erased.Length).Insert(index, replacementString);
                EraserDurability  = 0;
            }
        }
Пример #20
0
        public void PushReplicateSuccess(IEnumerable <DurableEvent> events)
        {
            foreach (var durableEvent in events)
            {
                var written = new Written(durableEvent);
                foreach (var actorRef in DefaultRegistry)
                {
                    actorRef.Tell(written);
                }

                foreach (var aggregateId in durableEvent.DestinationAggregateId)
                {
                    foreach (var aggregate in AggregateRegistry[aggregateId])
                    {
                        aggregate.Tell(written);
                    }
                }
            }
        }
        public void Write(BinaryWriter writer,Written written)
        {
            var startPosition	= writer.BaseStream.Position;

            writer.Write((ushort)0);
            writer.Write(ValueLength);
            writer.Write(Type);
            writer.WriteUnicode(Name);

            //Padding
            while((writer.BaseStream.Position % 4) != 0)
                writer.Write((byte)0);

            written(writer);

            var endPosition	= writer.BaseStream.Position;
            writer.Seek((int)startPosition,SeekOrigin.Begin);
            writer.Write((ushort)(endPosition - startPosition));

            writer.Seek((int)endPosition,SeekOrigin.Begin);
        }
        public static void Write(BinaryWriter writer,string name,bool isStringValue,byte[] value,Written written)
        {
            var startPosition	= writer.BaseStream.Position;
            var valueLenght	= (ushort)(value == null ? 0 : value.Length);

            writer.Write((ushort)0);
            writer.Write(valueLenght);
            writer.Write((ushort)(isStringValue ? 1 : 0));
            writer.WriteUnicode(name);

            //Padding
            while((writer.BaseStream.Position % 4) != 0)
                writer.Write((byte)0);

            written(writer);

            var endPosition	= writer.BaseStream.Position;
            writer.Seek((int)startPosition,SeekOrigin.Begin);
            writer.Write((ushort)(endPosition - startPosition));

            writer.Seek((int)endPosition,SeekOrigin.Begin);
        }
Пример #23
0
        private void Resize(int desiredBufferSize = 0)
        {
            if (Enlarge == null)
            {
                throw new BufferTooSmallException();
            }
            // double the size; add one to ensure that an empty buffer still resizes
            if (desiredBufferSize <= 0)
            {
                desiredBufferSize = _buffer.Length * 2 + 1;
            }
            else if (desiredBufferSize < _buffer.Length + 1)
            {
                throw new ArgumentOutOfRangeException(nameof(desiredBufferSize));
            }
            var newBuffer = Enlarge(desiredBufferSize).Span;

            if (newBuffer.Length <= _buffer.Length)
            {
                throw new Exception("Enlarge delegate created too small buffer");
            }
            Written.CopyTo(newBuffer);
            _buffer = newBuffer;
        }
Пример #24
0
 internal static void InvokeWritten(FileInfo handle)
 {
     Written?.Invoke(handle);
 }
Пример #25
0
 internal void NotifyWritten() =>
 Written?.Invoke();
Пример #26
0
 /// <summary>
 /// Updates component with the latest file data.
 /// </summary>
 /// <param name="fileEntry">Currently processed file entry.</param>
 /// <param name="position">The current position of this stream.</param>
 /// <param name="data">Curerntly read data.</param>
 /// <returns>A task that represents the asynchronous operation.</returns>
 internal Task UpdateFileWrittenAsync(IFileEntry fileEntry, long position, byte[] data)
 {
     return(Written.InvokeAsync(new FileWrittenEventArgs(fileEntry, position, data)));
 }
Пример #27
0
 public void Write16(int address, int value)
 {
     WriteCore(address, value >> 8);
     WriteCore(address + 1, value & 0xFF);
     Written?.Invoke(this, new AddressWrittenEventArgs(address, 2, value & 0xFFFF));
 }
Пример #28
0
 /// <summary>
 /// Called when console was written.
 /// </summary>
 /// <param name="entry">The entry.</param>
 protected virtual void OnWritten(string entry)
 {
     Written?.Invoke(sender: this, e: entry);
 }