Example #1
0
        public JsonResult MostFunnyUsers()
        {
            using (GagsDbContext model = new GagsDbContext())
            {
                var allGags = model.Gags.Include("Owner");
                ConcurrentDictionary<Guid, int> counters = new ConcurrentDictionary<Guid, int>();
                foreach (var gag in allGags)
                {
                    if (!counters.ContainsKey(gag.Owner.Id))
                        counters[gag.Owner.Id] = 0;
                    counters[gag.Owner.Id]++;
                }
                var top10 = counters.OrderByDescending(x => x.Value).Take(10);
                var context = new List<StatsModel>(10);
                foreach (var user in top10)
                {
                    context.Add(new StatsModel()
                    {
                        Name = model.Users.Where(x => x.Id == user.Key).First().Nickname,
                        Value = user.Value
                    });
                }
                JsonResult result = new JsonResult() { Data = context, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                return  result;

            }
        }
        public void TestLockFreeDictionary()
        {
            IDictionary<int, Guid> dict = new ConcurrentDictionary<int, Guid>();

            KeyValuePair<int, Guid> test = new KeyValuePair<int, Guid>(-64, Guid.NewGuid());

            dict.Add(42, Guid.NewGuid());
            dict.Add(22, Guid.NewGuid());
            dict.Add(test);
            dict.Add(55, Guid.NewGuid());

            Assert.IsTrue(dict.ContainsKey(-64));
            Assert.IsTrue(dict.Contains(test));
            Assert.IsFalse(dict.Contains(new KeyValuePair<int, Guid>(-64, new Guid())));

            dict[-64] = Guid.NewGuid();
            Assert.IsFalse(dict.Contains(test));

            Guid newID = Guid.NewGuid();
            dict[12] = newID;
            Guid id = dict[12];

            Assert.IsTrue(newID == id);

            Assert.IsTrue(dict.Count == 5);

            dict.Remove(-64);
            Assert.IsTrue(dict.Count == 4);

        }
        public static Task<string> GetOrAdd(string title, string language, string uri)
        {
            Lazy<Task<string>> lazyTask = new Lazy<Task<string>>(
                () =>
                    {
                        var uriSubCache = new ConcurrentDictionary<string, Task<string>>();
                        var languageSubCache = new ConcurrentDictionary<string, ConcurrentDictionary<string, Task<string>>>();

                        if (!uriSubCache.ContainsKey(uri))
                        {
                            uriSubCache.TryAdd(uri, GetInfoAsync(uri));
                        }

                        if (!languageSubCache.ContainsKey(language))
                        {
                            languageSubCache.TryAdd(language, uriSubCache);
                        }

                        var returnTask = Cache.GetOrAdd(title, languageSubCache)
                                                .GetOrAdd(language, uriSubCache)
                                                .GetOrAdd(uri, GetInfoAsync(uri));

                        return returnTask;
                    }
                    , LazyThreadSafetyMode.PublicationOnly
            );

            return lazyTask.Value;
        }
Example #4
0
        public void Queue_WithHighThreadCount_WorksCorrectly(int threads, int enqueues, int dequeues)
        {
            //The elements we insert are unique and sentinel value is -1
            int initialValue = -1;
            int currentValue = initialValue;
            ConcurrentDictionary<int, int> table = new ConcurrentDictionary<int, int>();
            Core.Queue.Queue<int> queue = new Core.Queue.Queue<int>(initialValue);

            ThreadBuilder
                .Empty()
                .AddThreads(() =>
                {
                    for (int i = 0; i < enqueues; i++)
                    {
                        int value = Interlocked.Increment(ref currentValue);
                        queue.Enqueue(value);
                    }
                }, threads)
                .AddThreads(() =>
                {
                    for (int i = 0; i < dequeues; i++)
                    {
                        int value = queue.Dequeue();
                        table.AddOrUpdate(value, x => 1, (k, v) => v + 1);
                    }
                }, threads)
                .Start();

            //The sentinel value can be returned more than once if queue is empty at the time of a pop
            int expectedPops = table.Keys.Count + (table.ContainsKey(initialValue) ? -1 : 0);
            int actualPops = table.Count(x => x.Key != initialValue && x.Value == 1);

            Assert.AreEqual(expectedPops, actualPops);
        }
            public void ShouldBeAbleToPullExistingInfoFromCache()
            {
                var monitorConfig = new MonitorConfig { Name = "Test" };
                var reduceLevels = new List<ReduceLevel>();

                var connection = new Mock<IDbConnection>();
                var connectionInstance = connection.Object;

                var storageCommands = new Mock<IStorageCommands>();
                storageCommands.Setup(x => x.CreateConfigAndReduceLevels(monitorConfig, reduceLevels, connectionInstance));

                var setupSystemTables = new Mock<ISetupSystemTables>();
                setupSystemTables.Setup(x => x.ValidateAndCreateDataTables(connectionInstance)).Verifiable();

                var monitorConfigsDictionary = new ConcurrentDictionary<string, MonitorConfig>();

                var cache = new Mock<IDataCache>();
                cache.SetupGet(x => x.MonitorConfigs).Returns(monitorConfigsDictionary).Verifiable();

                var storageFactory = new Mock<IStorageFactory>();
                storageFactory.Setup(x => x.CreateConnection()).Returns(connectionInstance).Verifiable();

                var settings = BuildSettings();

                var defaults = new SetupMonitorConfig(storageCommands.Object, setupSystemTables.Object, cache.Object, storageFactory.Object, settings.Object);
                defaults.CreateDefaultReduceLevels(monitorConfig, reduceLevels);

                Assert.Equal(1, monitorConfigsDictionary.Count);
                Assert.True(monitorConfigsDictionary.ContainsKey("Test"));

                storageCommands.VerifyAll();
                setupSystemTables.VerifyAll();
                storageFactory.VerifyAll();
                cache.VerifyAll();
            }
Example #6
0
        public void AddStatements(ConcurrentQueue<CoveredStatement> coveredStatements, ConcurrentDictionary<int, string> objectNameCache)
        {
            while (!coveredStatements.IsEmpty)
            {
                CoveredStatement statement;
                
                if (coveredStatements.TryDequeue(out statement))
                {
                    if (!objectNameCache.ContainsKey(statement.ObjectId))
                        continue;
                    
                    var name = objectNameCache[statement.ObjectId].ToLowerInvariant();

                    if (!_statements.ContainsKey(name))
                    {
                        _statements[name] = new List<CoveredStatement>();
                    }

                    var statments = _statements[name];

                    if (statments.All(p => p.Offset != statement.Offset))
                    {
                        statments.Add(statement);
                    }
                    else
                    {
                        statments.Remove(statments.First(p => p.Offset == statement.Offset));
                        statments.Add(statement);
                    }
                }

            }
        }
Example #7
0
 public double?GetPageScore(string category)
 {
     if (pageScores?.ContainsKey(category) ?? false)
     {
         return(pageScores[category]);
     }
     return(null);
 }
        public void ContainsKey_ReturnsFalseWhenKeyIsNotPresent()
        {
            // Arrange
            ConcurrentDictionary<int, int> dictionary = new ConcurrentDictionary<int, int>();

            // Act & Assert
            Assert.False(dictionary.ContainsKey(3));
        }
        public void DeserializeEnum_WithCache_EnumsAddedToCache()
        {
            const int YourvalueInt = 123;
            const int MyValueInt = 99;

            var cache = new ConcurrentDictionary<string, FakeTestingEnum>();

            FakeTestingEnum yourvalueEnum =
                PrettyEnumHelpers<FakeTestingEnum>.DeserializeEnum(YourvalueInt.ToString(), cache);
            FakeTestingEnum myvalueEnum = PrettyEnumHelpers<FakeTestingEnum>.DeserializeEnum(
                MyValueInt.ToString(), cache);

            Assert.Equal(FakeTestingEnum.YourValue, yourvalueEnum);
            Assert.Equal(FakeTestingEnum.MyValue, myvalueEnum);
            Assert.Equal(2, cache.Count);
            Assert.True(cache.ContainsKey(YourvalueInt.ToString()));
            Assert.True(cache.ContainsKey(MyValueInt.ToString()));
        }
Example #10
0
        public bool IsSaslMechanismSupported(string mechanism)
        {
            // Registered Mechanisms always take precedence over the default
            if (_saslClientFactories?.ContainsKey(mechanism) == true)
            {
                return(true);
            }

            return(DefaultSaslClientFactory.IsSaslMechanismSupported(mechanism));
        }
        public void DeserializeEnum_WithCacheAndEmptyString_DefaultEnumAndAddedToCache()
        {
            var cache = new ConcurrentDictionary<string, FakeTestingEnum>();
            FakeTestingEnum deserializedEnum = PrettyEnumHelpers<FakeTestingEnum>.DeserializeEnum(
                string.Empty, cache);

            Assert.Equal(default(FakeTestingEnum), deserializedEnum);
            Assert.Equal(1, cache.Count);
            Assert.True(cache.ContainsKey(string.Empty));
        }
        public void DeserializeEnum_WithCacheAndWhiteSpaceString_DefaultEnumAndAddedToCache()
        {
            const string Whitespace = "  \r  \t  ";

            var cache = new ConcurrentDictionary<string, FakeTestingEnum>();
            FakeTestingEnum deserializedEnum = PrettyEnumHelpers<FakeTestingEnum>.DeserializeEnum(Whitespace, cache);

            Assert.Equal(default(FakeTestingEnum), deserializedEnum);
            Assert.Equal(1, cache.Count);
            Assert.True(cache.ContainsKey(Whitespace));
        }
        public override ConfusionMatrix Execute()
        {
            var richTesting = testSet;

            ConcurrentDictionary<double, ActivationNetwork> networks = new ConcurrentDictionary<double, ActivationNetwork>();

            Parallel.For(0, 2000, (int i) =>
            {
                //Create an activation network
                ThreadLocal<ActivationNetwork> network = new ThreadLocal<ActivationNetwork>(() =>
                {
                    return new ActivationNetwork(new SigmoidFunction(2), 2, 2, 1);
                });

                ThreadLocal<ResilientBackpropagationLearning> teachear = new ThreadLocal<ResilientBackpropagationLearning>(() =>
                {
                    return new ResilientBackpropagationLearning(network.Value);
                });

                ThreadLocal<int> iter = new ThreadLocal<int>(() => { return 0; });
                ThreadLocal<double> error = new ThreadLocal<double>(() => { return 0; });

                while (networks.IsEmpty)
                {
                    error.Value = teachear.Value.RunEpoch(trainingSet, trainingOutput);
                    iter.Value++;
                    if (iter.Value == 1000) break;
                }
                if (!networks.ContainsKey(error.Value)) networks.TryAdd(error.Value, network.Value);
            }
            );

            Dictionary<ConfusionMatrix, ActivationNetwork> cms = new Dictionary<ConfusionMatrix, ActivationNetwork>();
            foreach (var keyv in networks)
            {
                var p = richTesting
                   .Select(x => keyv.Value.Compute(x))
                   .Select(x => Convert.ToInt32(x[0]))
                   .ToArray();

                ConfusionMatrix cm = new ConfusionMatrix(p, expected, POSITIVE, NEGATIVE);
                cms.Add(cm, keyv.Value);
            }

            var kv = (from x in cms
                      orderby x.Key.Accuracy descending
                      select x).First();

            var neurons = from neuron in kv.Value.Layers[0].Neurons
                          select neuron as ActivationNeuron;

            OnAlgorithmEnded(neurons, kv.Key);
            return kv.Key;
        }
        public void ContainsKey_KeyDoesntExist_Int64()
        {
            var dictionary = new ConcurrentDictionary<long, long>(Enumerable.Range(0, Iterations).Select(x => (long)x).ToDictionary(x => x));

            var stopwatch = Stopwatch.StartNew();
            for (long i = -1; i >= -Iterations; i--)
            {
                dictionary.ContainsKey(-1);
            }
            stopwatch.StopAndLog(Iterations);
        }
Example #15
0
        protected static async Task Cache(string url, ConcurrentDictionary<string, Page> cache)
        {
            if (!cache.ContainsKey(url))
            {
                Page page = await Downloader.DownloadAsync(url);
                cache.TryAdd(url, page);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Downloaded: {0}", url);
            }
        }
        public void ContainsKey_ReturnsTrueWhenKeyIsPresent()
        {
            // Arrange
            ConcurrentDictionary<int, int> dictionary = new ConcurrentDictionary<int, int>();

            // Act
            dictionary.TryAdd(1, 2);            

            // Assert
            Assert.True(dictionary.ContainsKey(1));
        }
        public void ContainsKey_KeyDoesntExist_Int32()
        {
            var dictionary = new ConcurrentDictionary<int, int>(Enumerable.Range(0, Iterations).ToDictionary(x => x));

            var stopwatch = Stopwatch.StartNew();
            for (var i = -1; i >= -Iterations; i--)
            {
                dictionary.ContainsKey(-1);
            }
            stopwatch.StopAndLog(Iterations);
        }
Example #18
0
        public void List_WithHighThreadCount_WorksCorrectly(int threads, int adds, int removes)
        {
            //The elements we insert are unique and sentinel value is -1
            int initialValue = -1;
            int currentValue = initialValue;
            ConcurrentDictionary<int, int> table = new ConcurrentDictionary<int, int>();
            Core.List.List<int> list = new Core.List.List<int>(initialValue);
            Random random = new Random();

            ThreadBuilder
                .Empty()
                .AddThreads(() =>
                {
                    for (int i = 0; i < adds; i++)
                    {
                        int value = Interlocked.Increment(ref currentValue);
                        list.Add(value);
                    }
                }, threads)
                .AddThreads(() =>
                {
                    for (int i = 0; i < removes; i++)
                    {
                        int element = random.Next(currentValue);

                        if (table.ContainsKey(element))
                        {
                            list.Remove(element);
                            table.AddOrUpdate(element, x => 1, (k, v) => v + 1);
                        }
                    }
                }, threads)
                .Start();

            //The sentinel value can be returned more than once if queue is empty at the time of a dequeue
            int expectedAdds = table.Keys.Count + (table.ContainsKey(initialValue) ? -1 : 0);
            int actualRemoves = table.Count(x => x.Key != initialValue && x.Value == 1);

            Assert.AreEqual(expectedAdds, actualRemoves);
        }
Example #19
0
        /// <summary>
        /// 특정 수형의 필드 정보를 조회합니다.
        /// </summary>
        /// <param name="targetType"></param>
        /// <returns></returns>
        public static IDictionary<string, FieldInfo> RetriveFieldMap(this Type targetType) {
            if(IsDebugEnabled)
                log.Debug("형식[{0}]의 필드 정보를 조회합니다...", targetType.FullName);

            var fieldMap = new ConcurrentDictionary<string, FieldInfo>();

            foreach(var fieldInfo in targetType.Fields()) {
                var fi = fieldInfo;
                if(fieldMap.ContainsKey(fi.Name) == false)
                    fieldMap.AddOrUpdate(fi.Name, fi, (k, v) => fi);
            }

            return fieldMap;
        }
Example #20
0
        /// <summary>
        /// 특정 수형의 속성 정보를 조회합니다.
        /// </summary>
        /// <param name="targetType"></param>
        /// <returns></returns>
        public static IDictionary<string, PropertyInfo> RetrievePropertyMap(this Type targetType) {
            if(IsDebugEnabled)
                log.Debug("형식[{0}]의 속성 정보를 조회합니다...", targetType.FullName);

            var propertyMap = new ConcurrentDictionary<string, PropertyInfo>();

            foreach(var propertyInfo in targetType.Properties()) {
                var pi = propertyInfo;
                if(propertyMap.ContainsKey(pi.Name) == false)
                    propertyMap.AddOrUpdate(pi.Name, pi, (k, v) => pi);
            }

            return propertyMap;
        }
        public void Preprocess(string outputDirPath)
        {
            ConcurrentDictionary<string, int> wordCount = new ConcurrentDictionary<string, int>();
            ConcurrentDictionary<string, int> wordPageCount = new ConcurrentDictionary<string, int>();

            WikiDataProvider wdp = new WikiDataProvider();
            EngTokenizer tokenizer = new EngTokenizer();
            EngMorphology morph = new EngMorphology();

            Stopwatch timer = Stopwatch.StartNew();

            Parallel.For(0, 13000, i => {
            //for(int i = 0; i < 5 /*1300*/; i++)
            //{
                Console.WriteLine("Thread taking iteration: " + i);
                Console.WriteLine("Loading 1K pages from DB");
                var pages = wdp.GetPageByIDInRange(i * 1000, (i+1)*1000);
                pages.ForEach(page => {
                    if (page.Language == "en")
                    {
                        if (page.PageID % 100 == 0) Console.WriteLine("Processing page: " + page.PageID);
                        var tokens = tokenizer.Annotate(page.Text).Select(x => ((TokenAnnotation)x)).ToList();

                        var distWords = tokens.Select(x => x.Text.Trim()).Distinct().ToList();
                        distWords.ForEach(dw => {
                            if (!wordPageCount.ContainsKey(dw)) wordPageCount.TryAdd(dw, 0);
                            wordPageCount[dw] += 1;
                        });

                        tokens.ForEach(t =>
                        {
                            if (!string.IsNullOrEmpty(t.Text))
                            {
                                if (!wordCount.ContainsKey(t.Text.ToLower())) wordCount.TryAdd(t.Text.ToLower(), 0);
                                wordCount[t.Text.ToLower()]++;
                            }
                        });
                    }
                });
            });

            timer.Stop();
            Console.WriteLine("Processing finished in: " + timer.Elapsed.ToString());

            Console.WriteLine("Finished processing, writing freqs...");
            TakeLab.Utilities.IO.StringWriter<string>.WriteDictionary<int>(wordCount.OrderByDescending(x => x.Value).ToList(), outputDirPath + "\\wikipedia-english-word-freq.txt");

            Console.WriteLine("Finished processing, writing page freqs...");
            TakeLab.Utilities.IO.StringWriter<string>.WriteDictionary<int>(wordPageCount.OrderByDescending(x => x.Value).ToList(), outputDirPath + "\\wikipedia-english-word-page-freq.txt");
        }
        public static IDictionary<string, string> BuildPropertyDictionaryConcurrently(IEnumerable<property> properties)
        {
            ConcurrentDictionary<string, string> propertyDictionary = new ConcurrentDictionary<string, string>();
            Parallel.ForEach(properties, (p) =>
            {
                if (p != null && !propertyDictionary.ContainsKey(p.name))
                {
                    // Don't ToLower it - it causes problems when we try to get the column name out again.
                    //propertyDictionaryField.Add(p.name.ToLower(), p.value);

                    propertyDictionary[p.name] = p.value;
                }
            });
            return propertyDictionary;
        }
Example #23
0
 static ConcurrentDictionary<char, int> AccumulateLettersInformation(ConcurrentDictionary<char, int> taskTotal , string item)
 {
     foreach (var c in item)
     {
         if (taskTotal.ContainsKey(c))
         {
             taskTotal[c] = taskTotal[c] + 1;
         }
         else
         {
             taskTotal[c] = 1;
         }
     }
     Console.WriteLine("{0} type was aggregated on a thread id {1}",
             item, Thread.CurrentThread.ManagedThreadId);
     return taskTotal;
 }
Example #24
0
        private static IDictionary<IDependency, ICollection<IInstantiationPoint>> GetPointsGroupedByDependency(IInstantiationPoint[] instantiationPoints)
        {
            var pointsGroupedByDependency = new ConcurrentDictionary<IDependency, ICollection<IInstantiationPoint>>();
            foreach (var point in instantiationPoints)
            {
                var dependencies = point.GetRequiredDependencies().ToArray();
                var nonPrimitiveDependencies = dependencies.Where(dependency => !dependency.DependencyType.IsPrimitive);
                foreach (var dependency in nonPrimitiveDependencies)
                {
                    if (!pointsGroupedByDependency.ContainsKey(dependency))
                        pointsGroupedByDependency[dependency] = new List<IInstantiationPoint>();

                    pointsGroupedByDependency[dependency].Add(point);
                }
            }
            return pointsGroupedByDependency;
        }
Example #25
0
 static ConcurrentDictionary<char, int> MergeAccumulators(ConcurrentDictionary<char, int> total, ConcurrentDictionary<char, int> taskTotal)
 {
     foreach (var key in taskTotal.Keys)
     {
         if (total.ContainsKey(key))
         {
             total[key] = total[key] + taskTotal[key];
         }
         else
         {
             total[key] = taskTotal[key];
         }
     }
     Console.WriteLine("---");
     Console.WriteLine("Total aggregate value was calculated on a thread id {0}",
             Thread.CurrentThread.ManagedThreadId);
     return total;
 }
Example #26
0
        public override void DoLayout()
        {
            ConcurrentDictionary<int, int> nodesPerLevel = new ConcurrentDictionary<int, int>(System.Environment.ProcessorCount, 100);
            ConcurrentDictionary<int, int> countPerLevel = new ConcurrentDictionary<int, int>(System.Environment.ProcessorCount, 100);
            ConcurrentDictionary<int, double> startPosPerLevel = new ConcurrentDictionary<int, double>(System.Environment.ProcessorCount, 0);

            double n = (double) Network.VertexCount;
            int maxLevel = 0;

            //assign levels
            Parallel.ForEach(Network.Vertices.ToArray(), v =>
            {
                int level = (int)Math.Round(Math.Log(n / 2, exp_base) - Math.Log(Math.Max((double)v.Degree, 7d), exp_base));
                if (level < 0)
                    level = (int)Math.Round(Math.Log(n / 2, exp_base) - Math.Log(1d, exp_base));
                maxLevel = Math.Max(level, maxLevel);
                if (!nodesPerLevel.ContainsKey(level))
                {
                    nodesPerLevel[level] = 1;
                    if (!startPosPerLevel.ContainsKey(level))
                        startPosPerLevel[level] = Network.NextRandomDouble() * Math.PI * 2d;
                }
                else
                    nodesPerLevel[level]++;
            });

            // assign positions
            Parallel.ForEach(Network.Vertices.ToArray(), v =>
            {
                int level = (int)Math.Round(Math.Log(n / 2, exp_base) - Math.Log(Math.Max((double)v.Degree, 7d), exp_base));
                if (level < 0)
                    level = (int)Math.Round(Math.Log(n / 2, exp_base) - Math.Log(1d, exp_base));
                if (!countPerLevel.ContainsKey(level))
                    countPerLevel[level] = 1;
                else
                    countPerLevel[level]++;
                double radius = ((double)Width / 2d) / ((double)maxLevel + 1);
                double angle = startPosPerLevel[level] + ((double)countPerLevel[level] / (double)nodesPerLevel[level]) * Math.PI * 2d;

               _vertexPositions[v] = getPosition(Width, Height, angle, level, radius);

            //     v.VertexSize = Math.Max((int)(5 + (((double)v.Degree) / (double)(n / 2)) * 20d), 1);
            });
        }
        static void Main(string[] args)
        {
            ConcurrentDictionary<int, double> numberSquareRoots = new ConcurrentDictionary<int, double>();
            LoadSquareRootsLookupTableAsync("corrupt-squareRootLookupTable.txt", numberSquareRoots);

            while (true)
            {
                int number = int.Parse(Console.ReadLine());
                if (numberSquareRoots.ContainsKey(number))
                {
                    var squareRoot = numberSquareRoots[number];
                    Console.WriteLine("Square root of " + number + " = " + squareRoot);
                }
                else
                {
                    Console.WriteLine("Not yet loaded, please try again later");
                }
            }
        }
Example #28
0
        public void CheckCollisionsParallelTest()
        {
            var values = new ConcurrentDictionary<string, bool>();
            var date = DateTimeOffset.Now;
            var actions = new List<Action>(500000);
            for (var i = 0; i < 500000; i++)
            {
                Action a = () =>
                {
                    //The node id and clock id should be pseudo random
                    var id = TimeUuid.NewId(date).ToString();
                    Assert.False(values.ContainsKey(id), "TimeUuid collided");
                    values.AddOrUpdate(id, true, (k, o) => true);
                };
                actions.Add(a);
            }

            Parallel.Invoke(actions.ToArray());
        }
 public static void Main()
 {
     IDictionary<int, double> numberSquareRoots = new ConcurrentDictionary<int, double>();
     LoadSquareRootsLookupTableAsync(500, numberSquareRoots);
     while (true)
     {
         // Note: the table loads pretty fast, to make it easier to see the asynchronous load, uncomment this lines (and comment the console read)
         // number++;
         var number = int.Parse(Console.ReadLine());
         if (numberSquareRoots.ContainsKey(number))
         {
             var squareRoot = numberSquareRoots[number];
             Console.WriteLine("Square root of " + number + " = " + squareRoot);
         }
         else
         {
             Console.WriteLine("Not yet loaded, please try again later");
         }
     }
 }
Example #30
0
        private void FilterRequestHeaderData(HttpRequestBase request)
        {
            if (_headerLogFilters?.ContainsKey("") == true)
            {
                RequestHeaders = new NameValueCollection();
            }
            else
            {
                RequestHeaders = new NameValueCollection(request.Headers.Count);
                foreach (var header in request.Headers.AllKeys)
                {
                    // Cookies are handled above, no need to repeat
                    if (string.Compare(header, "Cookie", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        continue;
                    }

                    if (request.Headers[header] != null)
                    {
                        string val = null;
                        if (!(_headerLogFilters?.TryGetValue(header, out val) ?? false)) // No match by name
                        {
                            var regexMatch = _headerRegexLogFilters.Where(r => Regex.IsMatch(header, r.Key, RegexOptions.IgnoreCase | RegexOptions.Singleline))
                                             .Select(r => new { Key = r.Key, Value = r.Value })
                                             .FirstOrDefault();

                            val = regexMatch?.Value;
                        }

                        if (val == "")
                        {
                            continue;            // Discard header value
                        }
                        else
                        {
                            RequestHeaders[header] = val ?? request.Headers[header];
                        }
                    }
                }
            }
        }
Example #31
0
        private void FilterCookies(HttpRequestBase request)
        {
            try
            {
                if (_cookieLogFilters?.ContainsKey("") == true)
                {
                    Cookies = new NameValueCollection();
                }
                else
                {
                    Cookies = new NameValueCollection(request.Cookies.Count);

                    for (var i = 0; i < request.Cookies.Count; i++)
                    {
                        var    name = request.Cookies[i].Name;
                        string val  = null;
                        if (!(_cookieLogFilters?.TryGetValue(name, out val) ?? false)) // No match by name
                        {
                            var regexMatch = _cookieRegexLogFilters.Where(r => Regex.IsMatch(name, r.Key, RegexOptions.IgnoreCase | RegexOptions.Singleline))
                                             .Select(r => new { Key = r.Key, Value = r.Value })
                                             .FirstOrDefault();

                            val = regexMatch?.Value;
                        }

                        if (val == "")
                        {
                            Cookies.Remove(name);             // Discard cookie value
                        }
                        else
                        {
                            Cookies.Add(name, val ?? request.Cookies[i].Value);
                        }
                    }
                }
            }
            catch (HttpRequestValidationException e)
            {
                Trace.WriteLine("Error parsing cookie collection: " + e.Message);
            }
        }
Example #32
0
        private void SetContextProperties(HttpContextBase context)
        {
            if (context == null)
            {
                return;
            }

            var request = context.Request;

            Func <Func <HttpRequestBase, NameValueCollection>, NameValueCollection> tryGetCollection = getter =>
            {
                try
                {
                    return(new NameValueCollection(getter(request)));
                }
                catch (HttpRequestValidationException e)
                {
                    Trace.WriteLine("Error parsing collection: " + e.Message);
                    return(new NameValueCollection {
                        { CollectionErrorKey, e.Message }
                    });
                }
            };

            StatusCode  = context.Response?.StatusCode;
            _httpMethod = context.Request.HttpMethod;

            ServerVariables = _serverVarLogFilters?.ContainsKey("") == true
                ? new NameValueCollection()
                : tryGetCollection(r => r.ServerVariables);

            QueryString = tryGetCollection(r => r.QueryString);
            Form        = _formLogFilters?.ContainsKey("") == true ? new NameValueCollection()
                : tryGetCollection(r => r.Form);

            FilterServerVariables();
            FilterFormData();
            FilterCookies(request);
            FilterRequestHeaderData(request);
        }
        /// <summary>
        /// This function checks if there is a framework assembly of assemblyName and of version > availableVersion
        /// in targetFramework. NOTE that this function is only applicable for .NETFramework and returns false for 
        /// all the other targetFrameworks
        /// </summary>
        internal static bool IsHigherAssemblyVersionInFramework(string simpleAssemblyName,
            Version availableVersion,
            FrameworkName targetFrameworkName,
            Func<FrameworkName, IList<string>> getPathToReferenceAssembliesFunc,
            ConcurrentDictionary<string, List<AssemblyName>> frameworkAssembliesDictionary)
        {
            if (!String.Equals(targetFrameworkName.Identifier, NETFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
            {
                return false;
            }

            string dotNetFrameworkVersion = targetFrameworkName.Version + targetFrameworkName.Profile;

            if (!frameworkAssembliesDictionary.ContainsKey(dotNetFrameworkVersion))
            {
                IList<string> frameworkListFiles = getPathToReferenceAssembliesFunc(targetFrameworkName);
                List<AssemblyName> frameworkAssemblies = GetFrameworkAssemblies(frameworkListFiles);
                frameworkAssembliesDictionary.AddOrUpdate(dotNetFrameworkVersion, frameworkAssemblies, (d, f) => frameworkAssemblies);
            }

            // Find a frameworkAssembly with the same name as assemblyName. If one exists, see if its version is greater than that of the availableversion
            return frameworkAssembliesDictionary[dotNetFrameworkVersion].Any(p => (String.Equals(p.Name, simpleAssemblyName, StringComparison.OrdinalIgnoreCase) && p.Version > availableVersion));
        }
Example #34
0
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            List<IConfigSection> sections = new List<IConfigSection>();

            ConcurrentDictionary<string, Type> sectionTypes = new ConcurrentDictionary<string, Type>();
            GetSectionTypes("*.dll", sectionTypes);
            GetSectionTypes("*.exe", sectionTypes);
            XmlElement sectionElement = section.FirstChild as XmlElement;
            while (sectionElement != null)
            {
                if (sectionTypes.ContainsKey(sectionElement.Name))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer( sectionTypes[sectionElement.Name]);
                    IConfigSection confSection  = (IConfigSection)xmlSerializer.Deserialize(new XmlNodeReader(sectionElement));
                    confSection.SectionName     = sectionElement.Name;
                    sections.Add(confSection );
                }

                sectionElement = sectionElement.NextSibling as XmlElement;
            }

            return sections;
        }
Example #35
0
        public ImbleWatcher()
        {
            this.watcher = new BluetoothLEAdvertisementWatcher();
            this.watcher.ScanningMode = BluetoothLEScanningMode.Active;     // We have to perform active scanning to check scan responses from devices.
            this.resetSubject = new Subject<Unit>().AddTo(this.disposables);
            
            var candidateAddresses = new ConcurrentDictionary<ulong, ulong>();
            var resetObservable = this.resetSubject
                .Do(_ => candidateAddresses.Clear());

            var receivedObservable = Observable.FromEvent<TypedEventHandler<BluetoothLEAdvertisementWatcher, BluetoothLEAdvertisementReceivedEventArgs>, BluetoothLEAdvertisementReceivedEventArgs>(
                handler => (sender, args) => handler(args),
                handler => this.watcher.Received += handler,
                handler => this.watcher.Received -= handler)
                .Publish();

            // Check scan responses and add their address to the candidate device list if they contains the target service UUID as Service Solicitation data.
            receivedObservable
                .Where(args => args.AdvertisementType.HasFlag(BluetoothLEAdvertisementType.ScanResponse))
                .Where(args => args.Advertisement.DataSections.Any(section => MatchSolicitationServiceLong(section, ImbleDevice.ServiceUuid)))
                .Subscribe(args => candidateAddresses.TryAdd(args.BluetoothAddress, args.BluetoothAddress))
                .AddTo(this.disposables);

            // Check advertisement data 
            this.UnconnectedDevices = receivedObservable
                .Where(args => !args.AdvertisementType.HasFlag(BluetoothLEAdvertisementType.ScanResponse))
                .Where(args => candidateAddresses.ContainsKey(args.BluetoothAddress))
                .Distinct(args => args.BluetoothAddress)
                .Select(args => new UnconnectedImbleDevice(args.BluetoothAddress, args.Advertisement, args.RawSignalStrengthInDBm))
                .ToReadOnlyReactiveCollection(resetObservable)
                .AddTo(this.disposables);

            receivedObservable.Connect().AddTo(this.disposables);

            this.watcher.Start();
        }
Example #36
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public override bool ContainsKey(string key)
 {
     return(_cacheStruct.ContainsKey(key));
 }
Example #37
0
 public bool IsNewThisSession(IndexDefinition definition)
 {
     return(newDefinitionsThisSession.ContainsKey(definition.IndexId));
 }
        /// <summary>
        /// Runs this instance.
        /// </summary>
        /// <returns></returns>
        public bool Run()
        {
            var startTime = DateTime.UtcNow;
            var success = true;
            Log.Trace($"CoarseUniverseGeneratorProgram.ProcessDailyFolder(): Processing: {_dailyDataFolder.FullName}");

            var symbolsProcessed = 0;
            var filesRead = 0;
            var dailyFilesNotFound = 0;
            var coarseFilesGenerated = 0;

            var mapFileResolver = _mapFileProvider.Get(_market);

            var blackListedTickers = new HashSet<string>();
            if (_blackListedTickersFile.Exists)
            {
                blackListedTickers = File.ReadAllLines(_blackListedTickersFile.FullName).ToHashSet();
            }

            var marketFolder = _dailyDataFolder.Parent;
            var fineFundamentalFolder = new DirectoryInfo(Path.Combine(marketFolder.FullName, "fundamental", "fine"));
            if (!fineFundamentalFolder.Exists)
            {
                Log.Error($"CoarseUniverseGenerator.Run(): FAIL, Fine Fundamental folder not found at {fineFundamentalFolder}! ");
                return false;
            }

            var securityIdentifierContexts = PopulateSidContex(mapFileResolver, blackListedTickers);
            var dailyPricesByTicker = new ConcurrentDictionary<string, List<TradeBar>>();
            var outputCoarseContent = new ConcurrentDictionary<DateTime, List<string>>();

            var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount / 2 };

            try
            {
                Parallel.ForEach(securityIdentifierContexts, parallelOptions, sidContext =>
                {
                    var symbol = new Symbol(sidContext.SID, sidContext.LastTicker);
                    var symbolCount = Interlocked.Increment(ref symbolsProcessed);
                    Log.Debug($"CoarseUniverseGeneratorProgram.Run(): Processing {symbol}");
                    var factorFile = _factorFileProvider.Get(symbol);

                    // Populate dailyPricesByTicker with all daily data by ticker for all tickers of this security.
                    foreach (var ticker in sidContext.Tickers)
                    {
                        var dailyFile = new FileInfo(Path.Combine(_dailyDataFolder.FullName, $"{ticker}.zip"));
                        if (!dailyFile.Exists)
                        {
                            Log.Error($"CoarseUniverseGeneratorProgram.Run(): {dailyFile} not found!");
                            Interlocked.Increment(ref dailyFilesNotFound);
                            continue;
                        }

                        if (!dailyPricesByTicker.ContainsKey(ticker))
                        {
                            dailyPricesByTicker.AddOrUpdate(ticker, ParseDailyFile(dailyFile));
                            Interlocked.Increment(ref filesRead);
                        }
                    }

                    // Look for daily data for each ticker of the actual security
                    for (int mapFileRowIndex = sidContext.MapFileRows.Length - 1; mapFileRowIndex >= 1; mapFileRowIndex--)
                    {
                        var ticker = sidContext.MapFileRows[mapFileRowIndex].Item2.ToLowerInvariant();
                        var endDate = sidContext.MapFileRows[mapFileRowIndex].Item1;
                        var startDate = sidContext.MapFileRows[mapFileRowIndex - 1].Item1;
                        List<TradeBar> tickerDailyData;
                        if (!dailyPricesByTicker.TryGetValue(ticker, out tickerDailyData))
                        {
                            Log.Error($"CoarseUniverseGeneratorProgram.Run(): Daily data for ticker {ticker.ToUpperInvariant()} not found!");
                            continue;
                        }

                        var tickerFineFundamentalFolder = Path.Combine(fineFundamentalFolder.FullName, ticker);
                        var fineAvailableDates = Enumerable.Empty<DateTime>();
                        if (Directory.Exists(tickerFineFundamentalFolder))
                        {
                            fineAvailableDates = Directory.GetFiles(tickerFineFundamentalFolder, "*.zip")
                                .Select(f => DateTime.ParseExact(Path.GetFileNameWithoutExtension(f), DateFormat.EightCharacter, CultureInfo.InvariantCulture))
                                .ToList();
                        }

                        // Get daily data only for the time the ticker was
                        foreach (var tradeBar in tickerDailyData.Where(tb => tb.Time >= startDate && tb.Time <= endDate))
                        {
                            var coarseRow = GenerateFactorFileRow(ticker, sidContext, factorFile, tradeBar, fineAvailableDates, fineFundamentalFolder);
                            List<string> tempList;

                            outputCoarseContent.AddOrUpdate(tradeBar.Time,
                                new List<string> { coarseRow },
                                (time, list) =>
                            {
                                lock (list)
                                {
                                    list.Add(coarseRow);
                                    return list;
                                }
                            });
                        }
                    }

                    if (symbolCount % 1000 == 0)
                    {
                        var elapsed = DateTime.UtcNow - startTime;
                        Log.Trace($"CoarseUniverseGeneratorProgram.Run(): Processed {symbolCount} in {elapsed:g} at {symbolCount / elapsed.TotalMinutes:F2} symbols/minute ");
                    }
                });

                _destinationFolder.Create();
                var startWriting = DateTime.UtcNow;
                Parallel.ForEach(outputCoarseContent, coarseByDate =>
                {
                    var filename = $"{coarseByDate.Key.ToString(DateFormat.EightCharacter, CultureInfo.InvariantCulture)}.csv";
                    var filePath = Path.Combine(_destinationFolder.FullName, filename);
                    Log.Debug($"CoarseUniverseGeneratorProgram.Run(): Saving {filename} with {coarseByDate.Value.Count} entries.");
                    File.WriteAllLines(filePath, coarseByDate.Value.OrderBy(cr => cr));
                    var filesCount = Interlocked.Increment(ref coarseFilesGenerated);
                    if (filesCount % 1000 == 0)
                    {
                        var elapsed = DateTime.UtcNow - startWriting;
                        Log.Trace($"CoarseUniverseGeneratorProgram.Run(): Processed {filesCount} in {elapsed:g} at {filesCount / elapsed.TotalSeconds:F2} files/second ");
                    }
                });

                Log.Trace($"\n\nTotal of {coarseFilesGenerated} coarse files generated in {DateTime.UtcNow - startTime:g}:\n" +
                          $"\t => {filesRead} daily data files read.\n");
            }
            catch (Exception e)
            {
                Log.Error(e, $"CoarseUniverseGeneratorProgram.Run(): FAILED!");
                success = false;
            }

            return success;
        }
Example #39
0
 public bool Contains(T item)
 {
     return(item != null && _data.ContainsKey(item));
 }
        private async Task ProcessChatMessageAsync(Chat.IChatMessage message)
        {
            switch (message)
            {
            case Chat.ChatMessage chat:
            {
                if (_isFirstConnection == false && _isInitialCommentsReceiving == true)
                {
                    //再接続時は初期コメントを無視する
                    return;
                }
                var  userId = chat.UserId;
                var  user   = GetUser(userId);
                bool isFirstComment;
                if (_userCommentCountDict.ContainsKey(userId))
                {
                    _userCommentCountDict[userId]++;
                    isFirstComment = false;
                }
                else
                {
                    _userCommentCountDict.AddOrUpdate(userId, 1, (s, n) => n);
                    isFirstComment = true;
                }
                //var comment = await Tools.CreateNicoComment(chat, user, _siteOptions, roomName, async userid => await API.GetUserInfo(_dataSource, userid), _logger);
                INicoMessage         comment;
                INicoMessageMetadata metadata;
                if (IsAd(chat))
                {
                    ///nicoad {"totalAdPoint":215500,"message":"シュガーさんが1700ptニコニ広告しました","version":"1"}
                    var     adJson = chat.Content.Replace("/nicoad", "");
                    dynamic d      = JsonConvert.DeserializeObject(adJson);
                    if ((string)d.version != "1")
                    {
                        throw new ParseException(chat.Raw);
                    }
                    var content = (string)d.message;
                    var ad      = new NicoAd(chat.Raw)
                    {
                        PostedAt = Common.UnixTimeConverter.FromUnixTime(chat.Date),
                        UserId   = userId,
                        Text     = content,
                    };
                    comment  = ad;
                    metadata = new AdMessageMetadata(ad, _options, _siteOptions)
                    {
                        IsInitialComment = _isInitialCommentsReceiving,
                        SiteContextGuid  = SiteContextGuid,
                    };
                }
                else if (IsGift(chat))
                {
                    var match = Regex.Match(chat.Content, "/gift (\\S+) (\\d+|NULL) \"(\\S+)\" (\\d+) \"(\\S*)\" \"(\\S+)\"(?: (\\d+))?");
                    if (!match.Success)
                    {
                        throw new ParseException(chat.Raw);
                    }
                    var giftId    = match.Groups[1].Value;
                    var userIdp   = match.Groups[2].Value;      //ギフトを投げた人。userId == "900000000"
                    var username  = match.Groups[3].Value;
                    var point     = match.Groups[4].Value;
                    var what      = match.Groups[5].Value;
                    var itemName  = match.Groups[6].Value;
                    var itemCount = match.Groups[7].Value;        //アイテムの個数?ギフト貢献n位?
                    var text      = $"{username}さんがギフト「{itemName}({point}pt)」を贈りました";
                    var gift      = new NicoGift(chat.Raw)
                    {
                        Text      = text,
                        PostedAt  = Common.UnixTimeConverter.FromUnixTime(chat.Date),
                        UserId    = userIdp == "NULL" ? "" : userIdp,
                        NameItems = Common.MessagePartFactory.CreateMessageItems(username),
                    };
                    comment  = gift;
                    metadata = new ItemMessageMetadata(gift, _options, _siteOptions)
                    {
                        IsInitialComment = _isInitialCommentsReceiving,
                        SiteContextGuid  = SiteContextGuid,
                    };
                }
                else if (IsSpi(chat))
                {
                    var spi = new NicoSpi(chat.Raw)
                    {
                        Text     = chat.Content,
                        PostedAt = Common.UnixTimeConverter.FromUnixTime(chat.Date),
                        UserId   = chat.UserId,
                    };
                    comment  = spi;
                    metadata = new SpiMessageMetadata(spi, _options, _siteOptions)
                    {
                        IsInitialComment = _isInitialCommentsReceiving,
                        SiteContextGuid  = SiteContextGuid,
                    };
                }
                else if (IsEmotion(chat))
                {
                    var content = chat.Content.Substring("/emotion ".Length);
                    var abc     = new NicoEmotion("")
                    {
                        ChatNo    = chat.No,
                        Anonymity = chat.Anonymity,
                        PostedAt  = Common.UnixTimeConverter.FromUnixTime(chat.Date),
                        Content   = content,
                        UserId    = chat.UserId,
                    };
                    comment  = abc;
                    metadata = new EmotionMessageMetadata(abc, _options, _siteOptions, user, this)
                    {
                        IsInitialComment = _isInitialCommentsReceiving,
                        SiteContextGuid  = SiteContextGuid,
                    };
                }
                else if (IsInfo(chat))
                {
                    var match = Regex.Match(chat.Content, "^/info (?<no>\\d+) (?<content>.+)$", RegexOptions.Singleline);
                    if (!match.Success)
                    {
                        throw new ParseException(chat.Raw);
                    }
                    else
                    {
                        var no      = int.Parse(match.Groups["no"].Value);
                        var content = match.Groups["content"].Value;
                        var info    = new NicoInfo(chat.Raw)
                        {
                            Text     = content,
                            PostedAt = Common.UnixTimeConverter.FromUnixTime(chat.Date),
                            UserId   = chat.UserId,
                            No       = no,
                        };
                        comment  = info;
                        metadata = new InfoMessageMetadata(info, _options, _siteOptions)
                        {
                            IsInitialComment = _isInitialCommentsReceiving,
                            SiteContextGuid  = SiteContextGuid,
                        };
                    }
                }
                else
                {
                    if (IsDisconnect(chat))        //NicoCommentではなく専用のクラスを作っても良いかも。
                    {
                        _chatProvider?.Disconnect();
                    }
                    string username;
                    if (IsRawUserId(chat.UserId) && chat.UserId != SystemUserId && _siteOptions.IsAutoGetUsername)
                    {
                        var userInfo = await Api.GetUserInfo(_server, _cc, chat.UserId);

                        username  = userInfo.Nickname;
                        user.Name = Common.MessagePartFactory.CreateMessageItems(username);
                    }
                    else
                    {
                        username = null;
                    }
                    if (_siteOptions.IsAutoSetNickname)
                    {
                        var nick = SitePluginCommon.Utils.ExtractNickname(chat.Content);
                        if (!string.IsNullOrEmpty(nick))
                        {
                            user.Nickname = nick;
                        }
                    }
                    var abc = new NicoComment("")
                    {
                        ChatNo   = chat.No,
                        Id       = chat.No.ToString(),
                        Is184    = chat.Anonymity == 1,
                        PostedAt = Common.UnixTimeConverter.FromUnixTime(chat.Date),
                        Text     = chat.Content,
                        UserId   = chat.UserId,
                        UserName = username,
                    };
                    comment  = abc;
                    metadata = new CommentMessageMetadata(abc, _options, _siteOptions, user, this, isFirstComment)
                    {
                        IsInitialComment = _isInitialCommentsReceiving,
                        SiteContextGuid  = SiteContextGuid,
                    };
                }


                var context = new NicoMessageContext(comment, metadata, new NicoMessageMethods());
                RaiseMessageReceived(context);
            }
            break;

            case Chat.Ping ping:
                if (ping.Content == "rs:0")
                {
                    _isInitialCommentsReceiving = true;
                }
                else if (ping.Content == "rf:0")
                {
                    _isInitialCommentsReceiving = false;
                }
                break;

            case Chat.UnknownMessage unknown:
                _logger.LogException(new ParseException(unknown.Raw));
                break;

            default:
                break;
            }
        }
Example #41
0
        public static void DefaultTableValues(object o)
        {
            var currentType = o.GetType();

            List <Action <object> > actions = null;

            //Cache the PropertySet delegates
            if (!PropertyCache.ContainsKey(currentType))
            {
                actions = new List <Action <object> >();

                PropertyInfo id = currentType.GetProperty("ID");
                if (id != null)
                {
                    actions.Add(p => (currentType.DelegateForSetPropertyValue("ID"))(p, Guid.NewGuid()));
                }

                PropertyInfo createdBy = currentType.GetProperty("CreatedBy");
                if (createdBy != null)
                {
                    actions.Add(p => (currentType.DelegateForSetPropertyValue("CreatedBy"))(p, AryaTools.Instance.InstanceData.CurrentUser.ID));
                }

                PropertyInfo createdOn = currentType.GetProperty("CreatedOn");
                if (createdOn != null)
                {
                    actions.Add(p => (currentType.DelegateForSetPropertyValue("CreatedOn"))(p, DateTime.Now));
                }

                PropertyInfo active = currentType.GetProperty("Active");
                if (active != null)
                {
                    actions.Add(p => (currentType.DelegateForSetPropertyValue("Active"))(p, true));
                }

                PropertyInfo before = currentType.GetProperty("BeforeEntity");
                if (before != null)
                {
                    actions.Add(p => (currentType.DelegateForSetPropertyValue("BeforeEntity"))(p, false));
                }

                PropertyInfo isCanned = currentType.GetProperty("IsCanned");
                if (isCanned != null)
                {
                    actions.Add(p => (currentType.DelegateForSetPropertyValue("IsCanned"))(p, true));
                }

                PropertyInfo remark = currentType.GetProperty("CreatedRemark");
                if (remark != null)
                {
                    actions.Add(p => (currentType.DelegateForSetPropertyValue("CreatedRemark"))(p, AryaTools.Instance.RemarkID));
                }

                List <Action <object> > actions1 = actions;
                PropertyCache.AddOrUpdate(currentType, actions, (key, oldValue) => actions1);
            }

            if (actions == null)
            {
                actions = PropertyCache[currentType];
            }

            actions.ForEach(act => act(o));
        }
Example #42
0
 public bool Satisfies(HashDigest <SHA256> blockHash, bool ignoreTransientCompletions = false)
 {
     return((!ignoreTransientCompletions && _satisfiedBlocks.ContainsKey(blockHash)) ||
            (!(_completionPredicate is null) && _completionPredicate(blockHash)));
 }
Example #43
0
 /// <summary>
 /// 判断是否存在ServiceMap
 /// </summary>
 /// <param name="map"></param>
 /// <returns></returns>
 public bool CheckServiceMapExist(ServiceMap map)
 {
     m_Logger.Debug("判断服务配置信息是否存在,服务名称:" + map.ServiceFullName);
     return(m_ServiceMapDic.ContainsKey(map.ServiceId));
 }
        public override void Initialize(AnalysisContext context)
        {
            context.EnableConcurrentExecution();

            // We need to analyze generated code, but don't intend to report diagnostics for generated code fields.
            context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze);

            context.RegisterCompilationStartAction(
                (compilationContext) =>
            {
                ConcurrentDictionary <IFieldSymbol, UnusedValue> maybeUnreferencedPrivateFields = new ConcurrentDictionary <IFieldSymbol, UnusedValue>();
                ConcurrentDictionary <IFieldSymbol, UnusedValue> referencedPrivateFields        = new ConcurrentDictionary <IFieldSymbol, UnusedValue>();

                ImmutableHashSet <INamedTypeSymbol> specialAttributes = GetSpecialAttributes(compilationContext.Compilation);
                var structLayoutAttribute = compilationContext.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemRuntimeInteropServicesStructLayoutAttribute);

                compilationContext.RegisterSymbolAction(
                    (symbolContext) =>
                {
                    IFieldSymbol field = (IFieldSymbol)symbolContext.Symbol;

                    // Fields of types marked with StructLayoutAttribute with LayoutKind.Sequential should never be flagged as unused as their removal can change the runtime behavior.
                    if (structLayoutAttribute != null && field.ContainingType != null)
                    {
                        foreach (var attribute in field.ContainingType.GetAttributes())
                        {
                            if (structLayoutAttribute.Equals(attribute.AttributeClass.OriginalDefinition) &&
                                attribute.ConstructorArguments.Length == 1)
                            {
                                var argument = attribute.ConstructorArguments[0];
                                if (argument.Type != null)
                                {
                                    SpecialType specialType = argument.Type.TypeKind == TypeKind.Enum ?
                                                              ((INamedTypeSymbol)argument.Type).EnumUnderlyingType.SpecialType :
                                                              argument.Type.SpecialType;

                                    if (DiagnosticHelpers.TryConvertToUInt64(argument.Value, specialType, out ulong convertedLayoutKindValue) &&
                                        convertedLayoutKindValue == (ulong)System.Runtime.InteropServices.LayoutKind.Sequential)
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                    }

                    if (field.DeclaredAccessibility == Accessibility.Private && !referencedPrivateFields.ContainsKey(field))
                    {
                        // Fields with certain special attributes should never be considered unused.
                        if (!specialAttributes.IsEmpty)
                        {
                            foreach (var attribute in field.GetAttributes())
                            {
                                if (specialAttributes.Contains(attribute.AttributeClass.OriginalDefinition))
                                {
                                    return;
                                }
                            }
                        }

                        maybeUnreferencedPrivateFields.TryAdd(field, default);
                    }
                },
                    SymbolKind.Field);

                compilationContext.RegisterOperationAction(
                    (operationContext) =>
                {
                    IFieldSymbol field = ((IFieldReferenceOperation)operationContext.Operation).Field;
                    if (field.DeclaredAccessibility == Accessibility.Private)
                    {
                        referencedPrivateFields.TryAdd(field, default);
                        maybeUnreferencedPrivateFields.TryRemove(field, out _);
                    }
                },
                    OperationKind.FieldReference);

                // Private field reference information reaches a state of consistency as each type symbol completes
                // analysis. Reporting information at the end of each named type provides incremental analysis
                // support inside the IDE.
                compilationContext.RegisterSymbolStartAction(
                    context =>
                {
                    context.RegisterSymbolEndAction(context =>
                    {
                        var namedType = (INamedTypeSymbol)context.Symbol;
                        foreach (var member in namedType.GetMembers())
                        {
                            if (member is not IFieldSymbol field)
                            {
                                continue;
                            }

                            if (!maybeUnreferencedPrivateFields.ContainsKey(field) || referencedPrivateFields.ContainsKey(field))
                            {
                                continue;
                            }

                            context.ReportDiagnostic(field.CreateDiagnostic(Rule, field.Name));
                        }
                    });
                },
                    SymbolKind.NamedType);
            });
        }
Example #45
0
 /// <summary>
 /// Checks whether the SIP channel has a connection matching a unique connection ID.
 /// </summary>
 /// <param name="connectionID">The connection ID to check for a match on.</param>
 /// <returns>True if a match is found or false if not.</returns>
 public override bool HasConnection(string connectionID)
 {
     return(m_connections.ContainsKey(connectionID));
 }
Example #46
0
 public bool Contains(TItem item)
 {
     return(_items.ContainsKey(item));
 }
Example #47
0
 /// <summary>
 /// True/false indicating whether or not the region has provinces configured in the Merchello.config file
 /// </summary>
 /// <param name="countryCode">
 /// The two letter ISO Region code (country code)
 /// </param>
 /// <returns>
 /// A value indicating whether or not the country has provinces.
 /// </returns>
 public static bool CountryHasProvinces(string countryCode)
 {
     return(RegionProvinceCache.ContainsKey(countryCode));
 }
Example #48
0
 public static T2 Get <T, T2>(this ConcurrentDictionary <T, T2> dic, T id)
     where T2 : class
 {
     return(dic.ContainsKey(id) ? dic[id] : null);
 }
Example #49
0
 /// <summary>
 /// Check if this collection contains this symbol.
 /// </summary>
 /// <param name="symbol">Symbol we're checking for.</param>
 /// <remarks>IDictionary implementation</remarks>
 /// <returns>Bool true if contains this symbol pair</returns>
 public bool ContainsKey(Symbol symbol)
 {
     return(_securityManager.ContainsKey(symbol));
 }
 public override bool Exists(FileSystemObject fso)
 {
     return(fileMap.ContainsKey(fso.FullName));
 }
        public static void appServer_NewMessageReceived(WebSocket session, string message_string, string path, List <KeyValuePair <string, string> > headers)
        {
            try
            {
                string skey = manager == null ? null : manager.GetId(session);
                if (!string.IsNullOrWhiteSpace(message_string))
                {
                    DateTime t1 = DateTime.Now;

                    QuantApp.Kernel.RTDMessage message = null;

                    if (path.StartsWith("/lab/"))
                    {
                        var sessionID = session.GetHashCode() + path;
                        if (RTDSocketMiddleware._proxies.ContainsKey(sessionID))
                        {
                            var _client = RTDSocketMiddleware._proxies[sessionID];
                            _client.Send(message_string);
                        }
                        else
                        {
                            Console.WriteLine("Socket Not Found(" + path + "): " + message_string);
                        }
                    }

                    else
                    {
                        try
                        {
                            message = JsonConvert.DeserializeObject <QuantApp.Kernel.RTDMessage>(message_string);
                        }
                        catch {}

                        if (message != null)
                        {
                            if (message.Type == QuantApp.Kernel.RTDMessage.MessageType.Subscribe)
                            {
                                try
                                {
                                    string contract = message.Content.ToString();

                                    if (contract.StartsWith("$"))
                                    {
                                        contract = contract.Substring(1, contract.Length - 1);
                                        if (!traders.ContainsKey(contract))
                                        {
                                            traders.TryAdd(contract, skey);
                                            Send(session, message_string);
                                        }
                                    }



                                    if (!subscriptions.ContainsKey(contract))
                                    {
                                        subscriptions.TryAdd(contract, new ConcurrentDictionary <string, WebSocket>());
                                    }

                                    if (!subscriptions[contract].ContainsKey(skey))
                                    {
                                        subscriptions[contract].TryAdd(skey, session);
                                    }

                                    if (!users.ContainsKey(contract))
                                    {
                                        users.TryAdd(contract, new ConcurrentDictionary <string, QuantApp.Kernel.UserData>());
                                    }

                                    if (!users[contract].ContainsKey(skey))
                                    {
                                        users[contract].TryAdd(skey, QuantApp.Kernel.User.ContextUser);
                                    }

                                    // Console.WriteLine("Subscribed: " + skey + " -- " + contract);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("Subsribe Exception: " + e + " " + skey);
                                }
                            }

                            else if (message.Type == QuantApp.Kernel.RTDMessage.MessageType.SaveM)
                            {
                                try
                                {
                                    string mid = message.Content.ToString();

                                    M m = M.Base(mid);
                                    m.Save();
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("SaveM Exception: " + e + " " + skey);
                                }
                            }
                            else if (message.Type == QuantApp.Kernel.RTDMessage.MessageType.PING)
                            {
                                try
                                {
                                    DateTime stamp = (DateTime)message.Content;

                                    var response = JsonConvert.SerializeObject(new QuantApp.Kernel.RTDMessage()
                                    {
                                        Type = QuantApp.Kernel.RTDMessage.MessageType.PING, Content = DateTime.Now
                                    });
                                    Send(session, response);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("MarketData Exception: " + e + " " + skey);
                                }
                            }
                            else if (message.Type == QuantApp.Kernel.RTDMessage.MessageType.UpdateQueue)
                            {
                                QuantApp.Kernel.QueueMessage qm = JsonConvert.DeserializeObject <QuantApp.Kernel.QueueMessage>(message.Content.ToString());

                                QuantApp.Kernel.RTDEngine.UpdateQueue(qm);

                                Share(session, qm.TopicID, message_string);
                            }
                            else if (message.Type == QuantApp.Kernel.RTDMessage.MessageType.CRUD)
                            {
                                QuantApp.Kernel.RTDMessage.CRUDMessage qm = JsonConvert.DeserializeObject <QuantApp.Kernel.RTDMessage.CRUDMessage>(message.Content.ToString());

                                try
                                {
                                    var type = Type.GetType(qm.ValueType);
                                    if (type == null)
                                    {
                                        Assembly assembly = QuantApp.Kernel.M._systemAssemblies.ContainsKey(qm.ValueType) ? QuantApp.Kernel.M._systemAssemblies[qm.ValueType] : (QuantApp.Kernel.M._compiledAssemblies.ContainsKey(qm.ValueType) ? QuantApp.Kernel.M._compiledAssemblies[qm.ValueType] : System.Reflection.Assembly.Load(qm.ValueAssembly));
                                        type = assembly.GetType(QuantApp.Kernel.M._systemAssemblyNames.ContainsKey(qm.ValueType) ? QuantApp.Kernel.M._systemAssemblyNames[qm.ValueType] : (QuantApp.Kernel.M._compiledAssemblyNames.ContainsKey(qm.ValueType) ? QuantApp.Kernel.M._compiledAssemblyNames[qm.ValueType] : qm.ValueType));
                                    }

                                    string filtered_string = qm.Value.ToString().Replace((char)27, '"').Replace((char)26, '\'');
                                    if (filtered_string.StartsWith("\"") && filtered_string.EndsWith("\""))
                                    {
                                        filtered_string = filtered_string.Substring(1, filtered_string.Length - 2).Replace("\\\"", "\"");
                                    }

                                    if (type == typeof(string) || qm.ValueType == null || type == typeof(Nullable))
                                    {
                                        qm.Value = filtered_string;
                                    }

                                    else if (type != null)
                                    {
                                        qm.Value = JsonConvert.DeserializeObject(filtered_string, type);
                                    }
                                }
                                catch {}

                                if (qm.Class == QuantApp.Kernel.M.CRUDClass)
                                {
                                    QuantApp.Kernel.M.Base(qm.TopicID).Process(qm);
                                }

                                Share(session, qm.TopicID, message_string);
                            }

                            else if (message.Type == QuantApp.Kernel.RTDMessage.MessageType.ProxyOpen)
                            {
                                var pd     = JsonConvert.DeserializeObject <HttpProxyRequest>(message.Content.ToString());
                                var client = ProxyConnection.Client(session, pd.Url);
                                client.Connect(pd.Content, pd.Headers);
                            }
                            else if (message.Type == QuantApp.Kernel.RTDMessage.MessageType.ProxyContent)
                            {
                                var pd = JsonConvert.DeserializeObject <HttpProxyRequest>(message.Content.ToString());

                                var sessionId = session.GetHashCode() + pd.Url;
                                if (RTDSocketMiddleware._proxies.ContainsKey(sessionId))
                                {
                                    var client = RTDSocketMiddleware._proxies[sessionId];
                                    client.Send(pd.Content);
                                }
                                else
                                {
                                    var client = ProxyConnection.Client(session, pd.Url);
                                    client.Send(pd.Content);
                                }
                            }

                            else if (RTDMessageFunction != null)
                            {
                                var mess = RTDMessageFunction(message_string);
                                if (mess != null)
                                {
                                    Share(session, mess.Item1, mess.Item2);
                                }
                            }
                        }

                        else
                        {
                            Console.WriteLine("UNKNOWN(" + path + "): " + message_string);
                        }
                    }

                    counter++;
                }
                else
                {
                    Console.WriteLine("--------------EMPTY STRING: " + path);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Server Receive Message Exception: " + e);
            }
        }
Example #52
0
 public bool Contains(Guid id)
 {
     return(_items.ContainsKey(id));
 }
 /// <inheritDoc />
 public bool Contains(Uri uri)
 {
     return(m_UrlRepository.ContainsKey(uri.GetHashCode()));
 }
Example #54
0
 public bool Contains(string indexName)
 {
     return(indexNameToId.ContainsKey(indexName));
 }
Example #55
0
        private void MaybeAddFutureBatch(List <JsonDocument> past)
        {
            if (context.Configuration.DisableDocumentPreFetchingForIndexing || context.RunIndexing == false)
            {
                return;
            }
            if (context.Configuration.MaxNumberOfParallelIndexTasks == 1)
            {
                return;
            }
            if (past.Count == 0)
            {
                return;
            }

            var size  = 1024;
            var count = context.LastActualIndexingBatchInfo.Count;

            if (count > 0)
            {
                size = context.LastActualIndexingBatchInfo.Aggregate(0, (o, c) => o + c.TotalDocumentCount) / count;
            }
            var alreadyLoadedSize = futureIndexBatches.Values.Sum(x =>
            {
                if (x.Task.IsCompleted)
                {
                    return(x.Task.Result.Sum(doc => doc.SerializedSizeOnDisk));
                }

                return(size);
            });

            if (alreadyLoadedSize > context.Configuration.AvailableMemoryForRaisingIndexBatchSizeLimit)
            {
                return;
            }

            if (futureIndexBatches.Count > 5)             // we limit the number of future calls we do
            {
                int alreadyLoaded = futureIndexBatches.Values.Sum(x =>
                {
                    if (x.Task.IsCompleted)
                    {
                        return(x.Task.Result.Count);
                    }
                    return(autoTuner.NumberOfItemsToIndexInSingleBatch / 4 * 3);
                });

                if (alreadyLoaded > autoTuner.NumberOfItemsToIndexInSingleBatch)
                {
                    return;
                }
            }

            // ensure we don't do TOO much future caching
            if (MemoryStatistics.AvailableMemory <
                context.Configuration.AvailableMemoryForRaisingIndexBatchSizeLimit)
            {
                return;
            }

            // we loaded the maximum amount, there are probably more items to read now.
            Etag highestLoadedEtag = GetHighestEtag(past);
            Etag nextEtag          = GetNextDocumentEtagFromDisk(highestLoadedEtag);

            if (nextEtag == highestLoadedEtag)
            {
                return;                                   // there is nothing newer to do
            }
            if (futureIndexBatches.ContainsKey(nextEtag)) // already loading this
            {
                return;
            }

            var futureBatchStat = new FutureBatchStats
            {
                Timestamp = SystemTime.UtcNow,
            };
            Stopwatch sp = Stopwatch.StartNew();

            context.AddFutureBatch(futureBatchStat);
            futureIndexBatches.TryAdd(nextEtag, new FutureIndexBatch
            {
                StartingEtag = nextEtag,
                Age          = Interlocked.Increment(ref currentIndexingAge),
                Task         = Task.Factory.StartNew(() =>
                {
                    List <JsonDocument> jsonDocuments = null;
                    int localWork = 0;
                    while (context.RunIndexing)
                    {
                        jsonDocuments = GetJsonDocsFromDisk(Abstractions.Util.EtagUtil.Increment(nextEtag, -1), null);
                        if (jsonDocuments.Count > 0)
                        {
                            break;
                        }

                        futureBatchStat.Retries++;

                        context.WaitForWork(TimeSpan.FromMinutes(10), ref localWork, "PreFetching");
                    }
                    futureBatchStat.Duration = sp.Elapsed;
                    futureBatchStat.Size     = jsonDocuments == null ? 0 : jsonDocuments.Count;
                    if (jsonDocuments != null)
                    {
                        MaybeAddFutureBatch(jsonDocuments);
                    }
                    return(jsonDocuments);
                })
            });
        }
Example #56
0
 /// <summary>
 /// Checks that configuration provides a section for the given dispatcher.
 /// This does not guarantee that no <see cref="ConfigurationException"/> will be thrown
 /// when using the dispatcher, because the details can only be checked by trying to
 /// instantiate it, which might be undesirable when just checking.
 /// </summary>
 /// <param name="id">TBD</param>
 public bool HasDispatcher(string id)
 {
     return(_dispatcherConfigurators.ContainsKey(id) || _cachingConfig.HasPath(id));
 }
        public override bool Exists(string key)
        {
            Guard.NotNullOrWhiteSpace(key, nameof(key));

            return(_cache.ContainsKey(key));
        }
Example #58
0
 public IEnumerable <IDeletion> DeletionsFor <T>()
 {
     return(_operations.ContainsKey(typeof(T))
         ? _operations[typeof(T)].OfType <IDeletion>()
         : Enumerable.Empty <IDeletion>());
 }
        private void ClientSyncLoop()
        {
            //clear the clients list
            _clients.Clear();
            int decodeErrors = 0; //if the JSON is unreadable - new version likely

            using (var reader = new StreamReader(_tcpClient.GetStream(), Encoding.UTF8))
            {
                try
                {
                    var sideInfo = _clientStateSingleton.DcsPlayerSideInfo;
                    //start the loop off by sending a SYNC Request
                    SendToServer(new NetworkMessage
                    {
                        Client = new SRClient
                        {
                            Coalition  = sideInfo.side,
                            Name       = sideInfo.name.Length > 0 ? sideInfo.name : _clientStateSingleton.LastSeenName,
                            Position   = sideInfo.Position,
                            ClientGuid = _guid
                        },
                        MsgType = NetworkMessage.MessageType.SYNC
                    });

                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        try
                        {
                            var serverMessage = JsonConvert.DeserializeObject <NetworkMessage>(line);
                            decodeErrors = 0; //reset counter
                            if (serverMessage != null)
                            {
                                switch (serverMessage.MsgType)
                                {
                                case NetworkMessage.MessageType.PING:
                                    // Do nothing for now
                                    break;

                                case NetworkMessage.MessageType.UPDATE:

                                    _serverSettings.Decode(serverMessage.ServerSettings);

                                    if (_clients.ContainsKey(serverMessage.Client.ClientGuid))
                                    {
                                        var srClient        = _clients[serverMessage.Client.ClientGuid];
                                        var updatedSrClient = serverMessage.Client;
                                        if (srClient != null)
                                        {
                                            srClient.LastUpdate = DateTime.Now.Ticks;
                                            srClient.Name       = updatedSrClient.Name;
                                            srClient.Coalition  = updatedSrClient.Coalition;
                                            srClient.Position   = updatedSrClient.Position;

//                                                Logger.Info("Recevied Update Client: " + NetworkMessage.MessageType.UPDATE + " From: " +
//                                                            srClient.Name + " Coalition: " +
//                                                            srClient.Coalition + " Pos: " + srClient.Position);
                                        }
                                    }
                                    else
                                    {
                                        var connectedClient = serverMessage.Client;
                                        connectedClient.LastUpdate = DateTime.Now.Ticks;

                                        //init with LOS true so you can hear them incase of bad DCS install where
                                        //LOS isnt working
                                        connectedClient.LineOfSightLoss = 0.0f;
                                        //0.0 is NO LOSS therefore full Line of sight

                                        _clients[serverMessage.Client.ClientGuid] = connectedClient;

//                                            Logger.Info("Recevied New Client: " + NetworkMessage.MessageType.UPDATE +
//                                                        " From: " +
//                                                        serverMessage.Client.Name + " Coalition: " +
//                                                        serverMessage.Client.Coalition);
                                    }

                                    if (_clientStateSingleton.InExternalAWACSMode &&
                                        !_serverSettings.GetSettingAsBool(Common.Setting.ServerSettingsKeys.EXTERNAL_AWACS_MODE))
                                    {
                                        DisconnectExternalAWACSMode();
                                    }

                                    CallUpdateUIOnMain();

                                    break;

                                case NetworkMessage.MessageType.SYNC:
                                    // Logger.Info("Recevied: " + NetworkMessage.MessageType.SYNC);

                                    //check server version
                                    if (serverMessage.Version == null)
                                    {
                                        Logger.Error("Disconnecting Unversioned Server");
                                        Disconnect();
                                        break;
                                    }

                                    var serverVersion   = Version.Parse(serverMessage.Version);
                                    var protocolVersion = Version.Parse(UpdaterChecker.MINIMUM_PROTOCOL_VERSION);

                                    ServerVersion = serverMessage.Version;

                                    if (serverVersion < protocolVersion)
                                    {
                                        Logger.Error($"Server version ({serverMessage.Version}) older than minimum procotol version ({UpdaterChecker.MINIMUM_PROTOCOL_VERSION}) - disconnecting");

                                        ShowVersionMistmatchWarning(serverMessage.Version);

                                        Disconnect();
                                        break;
                                    }

                                    if (serverMessage.Clients != null)
                                    {
                                        foreach (var client in serverMessage.Clients)
                                        {
                                            client.LastUpdate = DateTime.Now.Ticks;
                                            //init with LOS true so you can hear them incase of bad DCS install where
                                            //LOS isnt working
                                            client.LineOfSightLoss = 0.0f;
                                            //0.0 is NO LOSS therefore full Line of sight
                                            _clients[client.ClientGuid] = client;
                                        }
                                    }
                                    //add server settings
                                    _serverSettings.Decode(serverMessage.ServerSettings);

                                    if (_clientStateSingleton.InExternalAWACSMode &&
                                        !_serverSettings.GetSettingAsBool(Common.Setting.ServerSettingsKeys.EXTERNAL_AWACS_MODE))
                                    {
                                        DisconnectExternalAWACSMode();
                                    }

                                    CallUpdateUIOnMain();

                                    break;

                                case NetworkMessage.MessageType.SERVER_SETTINGS:

                                    //  Logger.Info("Recevied: " + NetworkMessage.MessageType.SERVER_SETTINGS);
                                    _serverSettings.Decode(serverMessage.ServerSettings);
                                    ServerVersion = serverMessage.Version;

                                    if (_clientStateSingleton.InExternalAWACSMode &&
                                        !_serverSettings.GetSettingAsBool(Common.Setting.ServerSettingsKeys.EXTERNAL_AWACS_MODE))
                                    {
                                        DisconnectExternalAWACSMode();
                                    }

                                    CallUpdateUIOnMain();

                                    break;

                                case NetworkMessage.MessageType.CLIENT_DISCONNECT:
                                    //   Logger.Info("Recevied: " + NetworkMessage.MessageType.CLIENT_DISCONNECT);

                                    SRClient outClient;
                                    _clients.TryRemove(serverMessage.Client.ClientGuid, out outClient);

                                    if (outClient != null)
                                    {
                                        MessageHub.Instance.Publish(outClient);
                                    }

                                    break;

                                case NetworkMessage.MessageType.VERSION_MISMATCH:
                                    Logger.Error($"Version Mismatch Between Client ({UpdaterChecker.VERSION}) & Server ({serverMessage.Version}) - Disconnecting");

                                    ShowVersionMistmatchWarning(serverMessage.Version);

                                    Disconnect();
                                    break;

                                case NetworkMessage.MessageType.EXTERNAL_AWACS_MODE_PASSWORD:
                                    if (serverMessage.Client.Coalition == 0)
                                    {
                                        Logger.Info("External AWACS mode authentication failed");

                                        CallExternalAWACSModeOnMain(false, 0);
                                    }
                                    else if (_radioDCSSync != null && _radioDCSSync.IsListening)
                                    {
                                        Logger.Info("External AWACS mode authentication succeeded, coalition {0}", serverMessage.Client.Coalition == 1 ? "red" : "blue");

                                        CallExternalAWACSModeOnMain(true, serverMessage.Client.Coalition);

                                        _radioDCSSync.StartExternalAWACSModeLoop();
                                    }
                                    break;

                                default:
                                    Logger.Error("Recevied unknown " + line);
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            decodeErrors++;
                            if (!_stop)
                            {
                                Logger.Error(ex, "Client exception reading from socket ");
                            }

                            if (decodeErrors > MAX_DECODE_ERRORS)
                            {
                                ShowVersionMistmatchWarning("unknown");
                                Disconnect();
                                break;
                            }
                        }

                        // do something with line
                    }
                }
                catch (Exception ex)
                {
                    if (!_stop)
                    {
                        Logger.Error(ex, "Client exception reading - Disconnecting ");
                    }
                }
            }

            //disconnected - reset DCS Info
            ClientStateSingleton.Instance.DcsPlayerRadioInfo.LastUpdate = 0;

            //clear the clients list
            _clients.Clear();
        }
Example #60
0
 public bool HasStream(Guid id)
 {
     return(_events.ContainsKey(id));
 }