Пример #1
0
        /// <summary>
        /// Generates the single file code.
        /// </summary>
        /// <returns>Generated C# code</returns>
        private string GenerateSingleFile()
        {
            StringBuilder stringOutput = new StringBuilder();

            System.Threading.ThreadLocal <StringBuilder> stringWriters = new System.Threading.ThreadLocal <StringBuilder>(() => new StringBuilder());
            string[] texts = new string[userTypes.Count];

            Parallel.For(0, userTypes.Count, (i) =>
            {
                var symbolEntry = userTypes[i];
                var output      = stringWriters.Value;

                output.Clear();
                GenerateCodeInSingleFile(codeWriter, output, symbolEntry, userTypeFactory, errorLogger, generationOptions);
                string text = output.ToString();

                if (!string.IsNullOrEmpty(text))
                {
                    texts[i] = text;
                }
            });
            foreach (string text in texts)
            {
                stringOutput.AppendLine(text);
            }
            return(stringOutput.ToString());
        }
Пример #2
0
 /// <summary>
 /// 初始化session驱动
 /// </summary>
 public void InitSessionProvider()
 {
     if (this.currentSessionThreadLocal == null)
     {
         this.currentSessionThreadLocal = new System.Threading.ThreadLocal <ISession>(false);
     }
 }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sqlExecuter"></param>
 /// <param name="currentSessionThreadLocal"></param>
 protected BaseDao(IEasySqlExecuter sqlExecuter, System.Threading.ThreadLocal <ISession> currentSessionThreadLocal)
 {
     this.SqlExecuter = sqlExecuter;
     this.CurrentSessionThreadLocal = currentSessionThreadLocal;
     this.DataSource = new DefaultDataSource()
     {
         ConnectionString = sqlExecuter.ConnectionString,
         ProviderFactory  = sqlExecuter.ProviderFactory,
     };
 }
Пример #4
0
 /// <summary>
 /// Initializes the <see cref="VSDebugger"/> class.
 /// </summary>
 static VSDebuggerProxy()
 {
     initializationForThread = new System.Threading.ThreadLocal <bool>(() =>
     {
         try
         {
             DkmComponentManager.InitializeThread(DkmComponentManager.IdeComponentId);
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     });
 }
Пример #5
0
        public async Task <string> Get()
        {
            var lo = new System.Threading.ThreadLocal <int>();

            lo.Value = 1;
            var c = new AsyncTest();

            c.Current = new testDate();
            var s = c.Current.date.ToString();

            var da = Task.Factory.StartNew(() =>
            {
                System.Threading.Thread.Sleep(10000);
                var aad = new AsyncTest();
                return(aad.Current.date.ToString());
            });

            c = new AsyncTest();
            return(s + ":");
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdbStream"/> class.
        /// </summary>
        /// <param name="stream">PDB symbol stream.</param>
        public TpiStream(PdbStream stream)
        {
            Stream = stream;
            if (stream.Reader.BytesRemaining < TpiStreamHeader.Size)
            {
                throw new Exception("TPI Stream does not contain a header.");
            }
            Header = TpiStreamHeader.Read(stream.Reader);

            if (Header.Version != PdbTpiVersion.V80)
            {
                throw new Exception("Unsupported TPI Version.");
            }

            if (Header.HeaderSize != TpiStreamHeader.Size)
            {
                throw new Exception("Corrupt TPI Header size.");
            }

            if (Header.HashKeySize != 4) // 4 = sizeof(uint)
            {
                throw new Exception("TPI Stream expected 4 byte hash key size.");
            }

            if (Header.HashBucketsCount < MinTpiHashBuckets || Header.HashBucketsCount > MaxTpiHashBuckets)
            {
                throw new Exception("TPI Stream Invalid number of hash buckets.");
            }

            // The actual type records themselves come from this stream
            TypeRecordsSubStream          = Stream.Reader.ReadSubstream(Header.TypeRecordBytes);
            typeRecordsSubStreamPerThread = new System.Threading.ThreadLocal <IBinaryReader>(() => TypeRecordsSubStream.Duplicate());

            IBinaryReader reader = TypeRecordsSubStream;
            long          position = reader.Position, end = reader.Length;

            references = new List <RecordReference>();
            while (position < end)
            {
                RecordPrefix prefix = RecordPrefix.Read(reader);

                if (prefix.RecordLength < 2)
                {
                    throw new Exception("CV corrupt record");
                }

                TypeLeafKind kind    = (TypeLeafKind)prefix.RecordKind;
                ushort       dataLen = prefix.DataLen;

                references.Add(new RecordReference
                {
                    DataOffset = (uint)position + RecordPrefix.Size,
                    Kind       = kind,
                    DataLen    = dataLen,
                });
                position += dataLen + RecordPrefix.Size;
                reader.Move(dataLen);
            }
            typesCache       = new ArrayCache <TypeRecord>(references.Count, true, ReadType);
            typesByKindCache = new DictionaryCache <TypeLeafKind, TypeRecord[]>(GetTypesByKind);

            // Hash indices, hash values, etc come from the hash stream.
            HashSubstream   = Stream.File.GetStream(Header.HashStreamIndex)?.Reader;
            hashValuesCache = SimpleCache.CreateStruct(() =>
            {
                if (HashSubstream != null)
                {
                    // There should be a hash value for every type record, or no hashes at all.
                    uint numHashValues = Header.HashValueBuffer.Length / 4; // 4 = sizeof(uint)
                    if (numHashValues != references.Count && numHashValues != 0)
                    {
                        throw new Exception("TPI hash count does not match with the number of type records.");
                    }

                    HashSubstream.Position = Header.HashValueBuffer.Offset;
                    return(HashSubstream.ReadUintArray(references.Count));
                }
                return(null);
            });
            typeIndexOffsetsCache = SimpleCache.CreateStruct(() =>
            {
                if (HashSubstream != null)
                {
                    HashSubstream.Position             = Header.IndexOffsetBuffer.Offset;
                    uint numTypeIndexOffsets           = Header.IndexOffsetBuffer.Length / TypeIndexOffset.Size;
                    TypeIndexOffset[] typeIndexOffsets = new TypeIndexOffset[numTypeIndexOffsets];
                    for (uint i = 0; i < typeIndexOffsets.Length; i++)
                    {
                        typeIndexOffsets[i] = TypeIndexOffset.Read(HashSubstream);
                    }
                    return(typeIndexOffsets);
                }
                return(null);
            });
            hashAdjustersCache = SimpleCache.CreateStruct(() =>
            {
                if (HashSubstream != null && Header.HashAdjustersBuffer.Length > 0)
                {
                    HashSubstream.Position = Header.HashAdjustersBuffer.Offset;
                    return(new HashTable(HashSubstream));
                }
                return(null);
            });
            hashTableCache = SimpleCache.CreateStruct(() =>
            {
                uint[] hashes = HashValues;

                if (hashes != null)
                {
                    // Construct hash table
                    TypeIndexListItem[] hashTable = new TypeIndexListItem[Header.HashBucketsCount];

                    for (uint ti = Header.TypeIndexBegin, i = 0; ti < Header.TypeIndexEnd; ti++, i++)
                    {
                        uint bucket = hashes[i] % Header.HashBucketsCount;

                        hashTable[bucket] = new TypeIndexListItem(new TypeIndex(ti), hashTable[bucket]);
                    }

                    // Use hash adjusters to improve hash table
                    if (HashAdjusters != null)
                    {
                        var namesMap = Stream.File.InfoStream.NamesMap;

                        foreach (var kvp in HashAdjusters.Dictionary)
                        {
                            uint nameIndex      = kvp.Key;
                            TypeIndex typeIndex = new TypeIndex(kvp.Value);
                            string name         = namesMap.GetString(nameIndex);
                            uint hash           = Windows.HashTable.HashStringV1(name) % (uint)hashTable.Length;

                            // Find type index hash adjusters wants to be head
                            for (TypeIndexListItem item = hashTable[hash], previousItem = null; item != null; previousItem = item, item = item.Next)
                            {
                                if (item.TypeIndex == typeIndex)
                                {
                                    if (previousItem == null)
                                    {
                                        // Our type index is already at the head
                                        break;
                                    }
                                    previousItem.Next = item.Next;
                                    item.Next         = hashTable[hash];
                                    hashTable[hash]   = item;
                                    break;
                                }
                            }
                        }
                    }

                    return(hashTable);
                }
                return(null);
            });
        }
Пример #7
0
 public ThreadLocal(Func <T> factory)
 {
     _threadLocal = new System.Threading.ThreadLocal <T>(factory, true);
 }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdbStream"/> class.
        /// </summary>
        /// <param name="stream">PDB symbol stream.</param>
        public TpiStream(PdbStream stream)
        {
            Stream = stream;
            if (stream.Reader.BytesRemaining < TpiStreamHeader.Size)
            {
                throw new Exception("TPI Stream does not contain a header.");
            }
            Header = TpiStreamHeader.Read(stream.Reader);

            if (Header.Version != PdbTpiVersion.V80)
            {
                throw new Exception("Unsupported TPI Version.");
            }

            if (Header.HeaderSize != TpiStreamHeader.Size)
            {
                throw new Exception("Corrupt TPI Header size.");
            }

            if (Header.HashKeySize != 4) // 4 = sizeof(uint)
            {
                throw new Exception("TPI Stream expected 4 byte hash key size.");
            }

            if (Header.HashBucketsCount < MinTpiHashBuckets || Header.HashBucketsCount > MaxTpiHashBuckets)
            {
                throw new Exception("TPI Stream Invalid number of hash buckets.");
            }

            // The actual type records themselves come from this stream
            TypeRecordsSubStream          = Stream.Reader.ReadSubstream(Header.TypeRecordBytes);
            typeRecordsSubStreamPerThread = new System.Threading.ThreadLocal <IBinaryReader>(() => TypeRecordsSubStream.Duplicate());

            IBinaryReader reader = TypeRecordsSubStream;
            long          position = reader.Position, end = reader.Length;

            references = new List <RecordReference>();
            while (position < end)
            {
                RecordPrefix prefix = RecordPrefix.Read(reader);

                if (prefix.RecordLength < 2)
                {
                    throw new Exception("CV corrupt record");
                }

                TypeLeafKind kind    = (TypeLeafKind)prefix.RecordKind;
                ushort       dataLen = prefix.DataLen;

                references.Add(new RecordReference
                {
                    DataOffset = (uint)position + RecordPrefix.Size,
                    Kind       = kind,
                    DataLen    = dataLen,
                });
                position += dataLen + RecordPrefix.Size;
                reader.ReadFake(dataLen);
            }
            typesCache       = new ArrayCache <TypeRecord>(references.Count, true, ReadType);
            typesByKindCache = new DictionaryCache <TypeLeafKind, TypeRecord[]>(GetTypesByKind);

            // Hash indices, hash values, etc come from the hash stream.
            if (Header.HashStreamIndex != InvalidStreamIndex)
            {
                if (Header.HashStreamIndex >= Stream.File.Streams.Count)
                {
                    throw new Exception("Invalid TPI hash stream index.");
                }

                HashSubstream = Stream.File.Streams[Header.HashStreamIndex].Reader;
            }

            hashValuesCache = SimpleCache.CreateStruct(() =>
            {
                if (HashSubstream != null)
                {
                    // There should be a hash value for every type record, or no hashes at all.
                    uint numHashValues = Header.HashValueBuffer.Length / 4; // 4 = sizeof(uint)
                    if (numHashValues != references.Count && numHashValues != 0)
                    {
                        throw new Exception("TPI hash count does not match with the number of type records.");
                    }

                    HashSubstream.Position = Header.HashValueBuffer.Offset;
                    return(HashSubstream.ReadUintArray(references.Count));
                }
                return(null);
            });
            typeIndexOffsetsCache = SimpleCache.CreateStruct(() =>
            {
                if (HashSubstream != null)
                {
                    HashSubstream.Position             = Header.IndexOffsetBuffer.Offset;
                    uint numTypeIndexOffsets           = Header.IndexOffsetBuffer.Length / TypeIndexOffset.Size;
                    TypeIndexOffset[] typeIndexOffsets = new TypeIndexOffset[numTypeIndexOffsets];
                    for (uint i = 0; i < typeIndexOffsets.Length; i++)
                    {
                        typeIndexOffsets[i] = TypeIndexOffset.Read(HashSubstream);
                    }
                    return(typeIndexOffsets);
                }
                return(null);
            });
            hashAdjustersCache = SimpleCache.CreateStruct(() =>
            {
                if (HashSubstream != null && Header.HashAdjustersBuffer.Length > 0)
                {
                    HashSubstream.Position = Header.HashAdjustersBuffer.Offset;
                    return(new HashTable(HashSubstream));
                }
                return(null);
            });
        }
Пример #9
0
 static SqlFactory()
 {
     s_seed   = System.Environment.TickCount;
     s_random = new System.Threading.ThreadLocal <System.Random>(GetRandom);
 }
Пример #10
0
 private ThreadContextCache(System.Threading.ThreadLocal <Hashtable> threadLocal) : base(threadLocal.Value)
 {
     this.threadLocal = threadLocal;
 }
Пример #11
0
 /// <summary>
 ///
 /// </summary>
 public ThreadLifetimeScopeTracker()
 {
     this.threadLocal = new System.Threading.ThreadLocal <ILifetimeScope>(false);
 }
Пример #12
0
 public ThreadLocal(Func <T> factory)
 {
     _threadLocal = new System.Threading.ThreadLocal <T>(factory);
     _tracking    = new Dictionary <int, T>();
 }
Пример #13
0
 public MyDao(IEasySqlExecuter sqlExecuter, System.Threading.ThreadLocal <ISession> currentSessionThreadLocal) : base(sqlExecuter, currentSessionThreadLocal)
 {
 }