Example #1
0
 public ReferencesEventArgs(int contextId, ReferencesMessage message)
     : base(contextId)
 {
     _root = message.RootDependency;
     _dependencies = message.Dependencies.Select(kvp => new KeyValuePair<string, Package>(
         kvp.Key, new Package(message.LongFrameworkName, kvp.Value))).ToImmutableDictionary();
 }
        private IWriteHandler CheckBaseTypes(Type type, IEnumerable<Type> baseTypes)
        {
            IDictionary<Type, IWriteHandler> possibles = new Dictionary<Type, IWriteHandler>();

            foreach (Type item in baseTypes)
            {
                // TODO Better way to decide the most appropriate possibility
                if (possibles.Count < 1)
                {
                    IWriteHandler h;
                    if (handlers.TryGetValue(item, out h))
                    {
                        possibles.Add(item, h);
                    }
                }
            }

            switch (possibles.Count)
            {
                case 0: return null;
                case 1:
                    {
                        IWriteHandler h = possibles.First().Value;
                        handlers = handlers.Add(type, h);
                        return h;
                    }
                default:
                    throw new TransitException("More thane one match for " + type);
            }
        }
 public static void Add(RecursiveAsyncLock mutex, Task<IDisposable> key)
 {
     Tuple<int, Task<IDisposable>> value;
     if (!OwnedLocks.TryGetValue(mutex, out value))
         value = Tuple.Create(0, key);
     OwnedLocks = OwnedLocks.SetItem(mutex, Tuple.Create(value.Item1 + 1, value.Item2));
 }
Example #4
0
        protected Statement(IImmutableDictionary<Id, Id> attributes)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            this.attributes = attributes;
        }
Example #5
0
 public Build(string id,
              string number,
              IImmutableDictionary<PackageVersionId, Package> createdPackages,
              IImmutableDictionary<PackageVersionId, Package> dependencies)
 {
     CreatedPackages = createdPackages;
     Dependencies = dependencies;
     Id = id;
     Number = number;
 }
Example #6
0
        public NodeStatement(Id id, IImmutableDictionary<Id, Id> attributes)
            : base(attributes)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            this.id = id;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractParser"/> class.
 /// </summary>
 /// <param name="handlers">The handlers.</param>
 /// <param name="defaultHandler">The default handler.</param>
 /// <param name="dictionaryBuilder">The dictionary builder.</param>
 /// <param name="listBuilder">The list builder.</param>
 protected AbstractParser(IImmutableDictionary<string, IReadHandler> handlers,
     IDefaultReadHandler<object> defaultHandler,
     IDictionaryReader dictionaryBuilder,
     IListReader listBuilder)
 {
     this.handlers = handlers;
     this.defaultHandler = defaultHandler;
     this.dictionaryBuilder = (IDictionaryReader)dictionaryBuilder;
     this.listBuilder = (IListReader)listBuilder;
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonParser"/> class.
 /// </summary>
 /// <param name="jsonTextReader">The json text reader.</param>
 /// <param name="handlers">The handlers.</param>
 /// <param name="defaultHandler">The default handler.</param>
 /// <param name="dictionaryBuilder">The dictionary builder.</param>
 /// <param name="listBuilder">The list builder.</param>
 public JsonParser(
     JsonTextReader jsonTextReader,
     IImmutableDictionary<string, IReadHandler> handlers,
     IDefaultReadHandler<object> defaultHandler,
     IDictionaryReader dictionaryBuilder,
     IListReader listBuilder)
     : base(handlers, defaultHandler, dictionaryBuilder, listBuilder)
 {
     this.jp = jsonTextReader;
 }
 public static void Remove(RecursiveAsyncLock mutex)
 {
     var value = OwnedLocks[mutex];
     if (value.Item1 == 1)
     {
         OwnedLocks = OwnedLocks.Remove(mutex);
         value.Item2.Result.Dispose();
     }
     else
     {
         OwnedLocks = OwnedLocks.SetItem(mutex, Tuple.Create(value.Item1 - 1, value.Item2));
     }
 }
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParReader"/> class based on the specified stream and using ASCII encoding.
        /// </summary>
        /// <param name="output">The output stream.</param>
        /// <param name="leaveOpen">true to leave the stream open after the <see cref="ParWriter"/> object is disposed; otherwise, false.</param>
        public ParWriter(Stream output, bool leaveOpen) : base(output, Encoding.ASCII, leaveOpen)
        {
            var origin = BaseStream.Position;
            BaseStream.Seek(0, SeekOrigin.Begin);

            if (output.CanRead && output.CanSeek)
            {
                using (var reader = new BinaryReader(output, Encoding.ASCII, true))
                {
                    while (BaseStream.Position < BaseStream.Length)
                    {
                        int b;

                        do
                        {
                            b = BaseStream.ReadByte();

                            if (b == 'P')
                            {
                                byte[] buffer = new byte[8];
                                BaseStream.Read(buffer, 1, 7);
                                buffer[0] = (byte)b;

                                if (Encoding.UTF8.GetString(buffer) == "PAR2\0PKT")
                                {
                                    var pos = BaseStream.Position - 8;
                                    var ok = Verify(reader);
                                    var end = BaseStream.Position;

                                    if (ok)
                                    {
                                        BaseStream.Seek(pos + 8, SeekOrigin.Begin);
                                        packets = packets.Add(pos, reader.ReadInt64());
                                        BaseStream.Seek(end, SeekOrigin.Begin);
                                    }
                                    else
                                    {
                                        BaseStream.Seek(pos + 1, SeekOrigin.Begin);
                                    }
                                }
                            }
                        }
                        while (b != 'P');
                    }
                }

                BaseStream.Seek(origin, SeekOrigin.Begin);
            }
        }
Example #11
0
        public EdgeStatement(NodeId fromId, NodeId toId, IImmutableDictionary<Id, Id> attributes)
            : base(attributes)
        {
            if (fromId == null)
            {
                throw new ArgumentNullException("fromId");
            }
            if (toId == null)
            {
                throw new ArgumentNullException("toId");
            }

            this.fromId = fromId;
            this.toId = toId;
        }
Example #12
0
        private IWriteHandler CheckBaseClasses(Type type)
        {
            Type baseType = type.GetTypeInfo().BaseType;
            while (baseType != null && baseType != typeof(object))
            {
                IWriteHandler handler;
                if (handlers.TryGetValue(baseType, out handler))
                {
                    handlers = handlers.Add(type, handler);
                    return handler;
                }

                baseType = baseType.GetTypeInfo().BaseType;
            }

            return null;
        }
Example #13
0
        public Configuration(XContainer xml)
        {
            var settings = xml
                .Descendants("Setting")
                .Select(e =>
                {
                    var keyElement = e.Element("Key");
                    var valueElement = e.Element("Value");
                    if (valueElement != null && keyElement != null)
                    {
                        return new
                        {
                            Key = keyElement.Value,
                            Value = valueElement.Value
                        };
                    }
                    return null;
                })
                .Where(e => e != null)
                .ToImmutableDictionary(e => e.Key, e => e.Value);

            IgnoreHeaderComments = "true".Equals(settings["sonar.cs.ignoreHeaderComments"]);

            Files = xml.Descendants("File").Select(e => e.Value).ToImmutableList();

            AnalyzerIds = xml.Descendants("Rule").Select(e => e.Elements("Key").Single().Value).ToImmutableHashSet();

            var builder = ImmutableDictionary.CreateBuilder<string, List<IImmutableDictionary<string, string>>>();
            foreach (var rule in xml.Descendants("Rule").Where(e => e.Elements("Parameters").Any()))
            {
                var analyzerId = rule.Elements("Key").Single().Value;

                var parameters = rule
                                 .Elements("Parameters").Single()
                                 .Elements("Parameter")
                                 .ToImmutableDictionary(e => e.Elements("Key").Single().Value, e => e.Elements("Value").Single().Value);

                if (!builder.ContainsKey(analyzerId))
                {
                    builder.Add(analyzerId, new List<IImmutableDictionary<string, string>>());
                }
                builder[analyzerId].Add(parameters);
            }
            Parameters = builder.ToImmutable();
        }
Example #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParReader"/> class based on the specified stream and using ASCII encoding, and optionally leaves the stream open.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <param name="leaveOpen">true to leave the stream open after the <see cref="ParReader"/> object is disposed; otherwise, false.</param>
        public ParReader(Stream input, bool leaveOpen) : base(input, Encoding.ASCII, leaveOpen)
        {
            var origin = BaseStream.Position;
            BaseStream.Seek(0, SeekOrigin.Begin);

            while (BaseStream.Position < BaseStream.Length)
            {
                int b;

                do
                {
                    b = BaseStream.ReadByte();

                    if (b == 'P')
                    {
                        byte[] buffer = new byte[8];
                        BaseStream.Read(buffer, 1, 7);
                        buffer[0] = (byte)b;

                        if (Encoding.UTF8.GetString(buffer) == "PAR2\0PKT")
                        {
                            var pos = BaseStream.Position - 8;
                            var ok = Verify();
                            var end = BaseStream.Position;

                            if (ok)
                            {
                                BaseStream.Seek(pos + 48, SeekOrigin.Begin);
                                var type = this.ReadBytes(16);
                                BaseStream.Seek(end, SeekOrigin.Begin);
                                packets = packets.Add(pos, new PacketType(type));
                            }
                            else
                            {
                                BaseStream.Seek(pos + 1, SeekOrigin.Begin);
                            }
                        }
                    }
                }
                while (b != 'P');
            }

            BaseStream.Seek(origin, SeekOrigin.Begin);
        }
        private bool IsNamespaceMatch(Type type) {
            if (!namespaceScratchPad.ContainsKey(type)) {
                var ns = type.Namespace ?? "";
                var match = config.ModelNamespaces.Any(ns.StartsWith);
                namespaceScratchPad = namespaceScratchPad.Add(type, match);
            }

            return namespaceScratchPad[type];
        }
Example #16
0
 public Bucket(Address owner, long version, IImmutableDictionary<string, ValueHolder> content) : this()
 {
     Owner = owner;
     Version = version;
     Content = content;
 }
 public Task ClearAsync()
 {
     _cache = _cache.Clear();
     return Task.FromResult(true);
 }
Example #18
0
 private async Task<long> NextTagSequenceNr(string tag)
 {
     long value;
     if (!_tagSequenceNr.TryGetValue(tag, out value))
     {
         value = await ReadHighestSequenceNrAsync(TagId(tag), 0L);
     }
     value++;
     _tagSequenceNr = _tagSequenceNr.SetItem(tag, value);
     return value;
 }
 public ImmutableInbox(IImmutableDictionary<StuffId, ImmutableStuff> dict)
 {
     _dict = dict;
 }
		/// <summary>
		/// Creates a new instance of the SyntaxTreeGeneratorData class
		/// </summary>
		/// <param name="ilGenerator">The IL generator</param>
		/// <param name="symbolTable">The symbol table</param>
		public SyntaxTreeGeneratorData(ILGenerator ilGenerator, IImmutableDictionary<string, Symbol> symbolTable)
		{
			this.ILGenerator = ilGenerator;
			this.SymbolTable = symbolTable;
		}
 public JsonVerboseEmitter(JsonWriter jsonWriter, IImmutableDictionary<Type, IWriteHandler> handlers)
     : base(jsonWriter, handlers)
 {
 }
Example #22
0
 public JsonEmitter(JsonWriter jsonWriter, IImmutableDictionary<Type, IWriteHandler> handlers)
     : base(handlers)
 {
     this.jsonWriter = jsonWriter;
 }
 internal PackageResolver(IImmutableDictionary<string, ImmutableArray<string>> map)
 {
     _map = map;
 }
 public AbstractEmitter(IImmutableDictionary<Type, IWriteHandler> handlers)
 {
     this.handlers = handlers;
 }
Example #25
0
 public static IChildrenContainer Create(IImmutableDictionary<string, IChildStats> children)
 {
     if (children.Count == 0) return EmptyChildrenContainer.Instance;
     return new NormalChildrenContainer(children);
 }
        /// <summary>
        /// Caches the write.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="asDictionaryKey">if set to <c>true</c> [as dictionary key].</param>
        /// <returns></returns>
        public string CacheWrite(string s, bool asDictionaryKey)
        {
            if (enabled && IsCacheable(s, asDictionaryKey))
            {
                string val;
                if (cache.TryGetValue(s, out val))
                {
                    return val;
                }
                else
                {
                    if (index == MaxCacheEntries)
                    {
                        Init();
                    }

                    cache = cache.SetItem(s, IndexToCode(index++));
                }
            }

            // TODO Either s or val is returned. Weird?!
            return s;
        }
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 /// <returns>The write cache.</returns>
 public WriteCache Init()
 {
     index = 0;
     cache = cache.Clear();
     return this;
 }
Example #28
0
 private NormalChildrenContainer(IImmutableDictionary<string, IChildStats> children)
     : base(children)
 {
 }
Example #29
0
 public AttributeStatement(AttributeKinds attributeKind, IImmutableDictionary<Id, Id> attributes)
     : base(attributes)
 {
     this.attributeKind = attributeKind;
 }
Example #30
0
        /// <summary>
        /// Writes a <see cref="Packet"/> object to the currrent stream.
        /// </summary>
        /// <param name="packet">The <see cref="Packet"/> object.</param>
        public void Write(Packet packet)
        {
            var range = new Range<long>();
            range.Minimum = BaseStream.Position;
            
            packet.Header.CopyTo(BaseStream);
            packet.Body.CopyTo(BaseStream);

            range.Maximum = BaseStream.Position - 1;

            var overwrittenPackets = packets
                .Where(x => range.IsInsideRange(new Range<long>
                {
                    Minimum = x.Key,
                    Maximum = x.Key + x.Value - 1
                }))
                .Select(x => x.Key);

            foreach (var key in overwrittenPackets)
            {
                packets = packets.Remove(key);
            }

            packets = packets.Add(range.Minimum, range.Maximum - range.Minimum + 1);
        }