Exemple #1
0
        private Task ProcessLinksAsync()
        {
            processLinksCTS = new CancellationTokenSource();
            var task = Task.Run(() =>
            {
                bool allTaskFinished = false;

                while (!(linkList.IsEmpty && allTaskFinished) && searching)
                {
                    allTaskFinished = true;
                    string url      = "";
                    bool success    = linkList.TryPop(out url);
                    if (success && !downloadedUrls.Contains(url))
                    {
                        downloadedUrls.Push(url);
                        Webcrawl(url);
                    }

                    foreach (Task t in runningTasks)
                    {
                        if (!t.IsCompleted)
                        {
                            allTaskFinished = false;
                        }
                    }
                }
            }, processLinksCTS.Token);

            return(task);
        }
Exemple #2
0
        private void postToURLIfNeeded(string server, App.Network.EventType eventType, int[] args)
        {
            if (eventType != App.Network.EventType.FATE_BEGIN && eventType != App.Network.EventType.MATCH_ALERT)
            {
                return;
            }
            if (isUploaderEnable == false)
            {
                return;
            }

            string head = networks.Count <= 1 ? "" : "[" + server + "] ";

            switch (eventType)
            {
            case App.Network.EventType.MATCH_ALERT:
                //text += getTextRoulette(args[0]) + "|"; pos++;
                //text += getTextInstance(args[1]) + "|"; pos++;
                if (isDutyAlertEnable)
                {
                    postToURL(head + getFinderTextNotification(args[0], args[1]));
                }
                break;

            case App.Network.EventType.FATE_BEGIN:
                //text += getTextFate(args[0]) + "|" + getTextFateArea(args[0]) + "|"; pos++;
                if (SelectedFates.Contains(args[0].ToString()))
                {
                    postToURL(head + getTextFateArea(args[0]) + " >> " + getTextFate(args[0]));
                }
                break;
            }
        }
        public object Create(Type type)
        {
            object result;

            if (!_stack.Contains(type))
            {
                _stack.Push(type);

                if (type.IsGenericTypeDefinition)
                {
                    type = type.MakeGenericType(_currentGenericType.GenericTypeArguments);
                }

                ConstructorInfo constructor = GetConstructor(type);

                if (constructor != null)
                {
                    result = constructor.Invoke(GetConstructorParametersValues(constructor.GetParameters()));
                }
                else
                {
                    throw new ArgumentException("Can not find constructor");
                }
                _stack.TryPop(out type);
            }
            else
            {
                result = null;
                _stack.Clear();
            }

            return(result);
        }
Exemple #4
0
        private object CreateInst(Dependency dependency)
        {
            Type realizType = dependency._realiz;

            if (!stack.Contains(dependency._interface))
            {
                stack.Push(dependency._interface);
                if (realizType.IsGenericTypeDefinition)
                {
                    realizType = realizType.MakeGenericType(currType.GenericTypeArguments);
                }
                ConstructorInfo[] constructors = realizType.GetConstructors().OrderByDescending(z => z.GetParameters().Length).ToArray();
                Type type;
                stack.TryPop(out type);
                if (TryCreateInst(constructors, realizType))
                {
                    return(instance);
                }
                else
                {
                    return(null);
                }
            }
            return(instance);
        }
Exemple #5
0
        private async Task GetUrl(string url)
        {
            try
            {
                Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                var text    = httpClient.GetAsync(url).Result;
                var strText = await text.Content.ReadAsStringAsync();

                MatchCollection matches = regUrl.Matches(strText);
                if (matches.Count > 0)
                {
                    sum += matches.Count;
                    int i = 0;
                    while (i < matches.Count)
                    {
                        if (Url != null && Url.Contains(matches[i].Value))
                        {
                            //判断是否重复
                            i++;
                        }
                        else
                        {
                            Url.Push(matches[i].Value);
                            CQ.Enqueue(matches[i].Value);
                            i++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MatchCollection matches = reg.Matches("");
            }
        }
        ///<inheritdoc/>
        public override void Return(T element)
        {
            // Never put an instance to the stack, if pooling is disabled
            if (!IsPoolingEnabled)
            {
                return;
            }

            // This is a safe, but expensive check
            if (PoolSettings.CheckReturnedObjectsExistInPool && !_stack.IsEmpty && _stack.Contains(element))
            {
                throw new PoolingException(
                          $"Trying to return an object of type '{element.GetType()}', that has already been returned to the pool.", GetType());
            }

            PoolPolicy.ActionOnReturn?.Invoke(element);

            if (CountInactive < PoolPolicy.MaximumPoolSize)
            {
                _stack.Push(element);
            }
            else
            {
                PoolPolicy.ActionOnDestroy?.Invoke(element);
            }
        }
Exemple #7
0
        //here t is implementation
        public object Create(Type t)
        {
            object result;

            if (!stack.Contains(t))
            {
                stack.Push(t);

                if (t.IsGenericTypeDefinition)
                {
                    t = t.MakeGenericType(currentGenericType.GenericTypeArguments);
                }

                ConstructorInfo constructor = GetRightConstructor(t);

                if (constructor != null)
                {
                    result = constructor.Invoke(GetConstructorParametersValues(constructor.GetParameters()));
                }
                else
                {
                    throw new ConstructorNotFoundException("Cannot find right constructor!");
                }
                stack.TryPop(out t);
            }
            else
            {
                result = null;
            }

            return(result);
        }
Exemple #8
0
        public void SaveLogs(Log l, string loggerInstance)
        {
            if (_settings.Config.Database == null)
            {
                return;
            }

            if (l.Severity < _settings.Config.Database.VerbosityLevel)
            {
                return;
            }

            if (!_settings.Config.Database.IsEnabled)
            {
                return;
            }

            _cachedLogs.Push(l);

            foreach (LogMessage msg in l.LogMessages)
            {
                if (msg.LogMessageText != null && !_cachedMessageLookups.Contains(msg.LogMessageText))
                {
                    _cachedMessageLookups.Push(msg.LogMessageText);
                }

                if (msg.LogStackTrace != null && !_cachedStackLookups.Contains(msg.LogStackTrace))
                {
                    _cachedStackLookups.Push(msg.LogStackTrace);
                }
            }

            Flush(false);
        }
Exemple #9
0
        public async Task Push(NavigationPushInfo pushInfo)
        {
            var         newPage = GetInitializedPage(pushInfo);
            INavigation navigation;

            var masterDetailPage = _app.MainPage as MasterDetailPage;

            if (masterDetailPage != null && masterDetailPage.IsPresented)
            {
                masterDetailPage.IsPresented = false;
                await Task.Delay(300);
            }

            switch (pushInfo.Mode)
            {
            case NavigationMode.Normal:
                if (_navigations.TryPeek(out navigation))
                {
                    await navigation.PushAsync(newPage, pushInfo.WithAnimation);
                }
                break;

            case NavigationMode.Modal:
                if (_navigations.TryPeek(out navigation))
                {
                    await navigation.PushModalAsync(newPage, pushInfo.WithAnimation);

                    if (newPage.Navigation != null && !_navigations.Contains(newPage.Navigation))
                    {
                        _navigations.Push(newPage.Navigation);
                    }
                }
                break;

            case NavigationMode.RootPage:
                if (masterDetailPage != null)
                {
                    await SetRootDetailPage(masterDetailPage, newPage, pushInfo.WithAnimation);
                }
                else
                {
                    _app.MainPage = newPage;
                }

                DisposePages(_navigations.ToArray());

                _navigations.Clear();
                _navigations.Push(newPage.Navigation);
                break;

            case NavigationMode.Custom:
                await HandleCustomPushNavigation(masterDetailPage, pushInfo);

                break;

            default:
                throw new NotImplementedException();
            }
        }
 public ActivityDiscrepancyQueueTestFixtures AssertAllPushedMessagesHandled()
 {
     Assert.AreEqual(PushedMessages.Count, _handledMessages.Count);
     foreach (var message in PushedMessages)
     {
         Assert.IsTrue(_handledMessages.Contains(message));
     }
     return(this);
 }
Exemple #11
0
        private object Create(Dependency dependency)
        {
            object result = null;

            if (!cycleStack.Contains(dependency.Interface))
            {
                cycleStack.Push(dependency.Interface);

                Type instanceType = dependency.Realization;
                if (instanceType.IsGenericTypeDefinition)
                {
                    instanceType = instanceType.MakeGenericType(currentType.GenericTypeArguments);
                }

                ConstructorInfo[] constructors = instanceType.GetConstructors().OrderByDescending(x => x.GetParameters().Length).ToArray();
                bool isCreated = false;
                int  i         = 0;
                while (!isCreated && (i <= constructors.Count() - 1))
                {
                    try
                    {
                        ConstructorInfo current    = constructors[i];
                        object[]        parameters = GetConstructorParameters(current);
                        result    = Activator.CreateInstance(instanceType, parameters);
                        isCreated = true;
                    }
                    catch
                    {
                        isCreated = false;
                        i++;
                    }
                }

                Type type;
                cycleStack.TryPop(out type);

                if (isCreated)
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            return(result);
        }
Exemple #12
0
        /// <summary>
        ///     Intended time of use it that of a "post cache reset" time. If cache has been cleared, all the logic behind this
        ///     method will run.
        /// </summary>
        public static void TryDocRevImporting() =>
        CacheMan.Cache(() =>
        {
            ReadIDocModelCSharpCode();

            dirs.PushRange(Directory
                           .EnumerateDirectories(FilesystemTemplateController.DirectoryPath)
                           .Select(dirpath => new DirectoryInfo(dirpath).FullName)
                           .Where(dirpath => !dirs.Contains(dirpath))
                           .OrderByDescending(dirpath =>
                                              new[]
            {
                Directory.GetLastWriteTime(dirpath).Ticks
            }
                                              .Union(
                                                  GetRelativeFilePathsInDirectoryTree(dirpath, true)
                                                  .Select(filepath => File.GetLastWriteTimeUtc(filepath).Ticks))
                                              .Max())
                           .ToArray());

            // starting with the newest directory, synchronously process each & abend when its found that nothing is imported
            string dir;
            while (dirs.TryPop(out dir) && ImportContentFolder(dir).Any())
            {
            }

            // process the remaining directories queued asynchronously (as this is a resource intensive) on the chance that the "GetLastWriteTimeUtc" lied to us
            if (!dirs.IsEmpty)
            {
                Tasker.StartNewTask(() =>
                {
                    while (dirs.TryPop(out dir))
                    {
                        ImportContentFolder(dir);
                    }
                    return(true);
                });
            }

            return(new object());
        },
                       false,
                       "ImportDocModelsRunOnce"
                       );
Exemple #13
0
        private async Task GetID(string url)
        {
            try
            {
                Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                var text    = httpClient.GetAsync(url).Result;
                var strText = await text.Content.ReadAsStringAsync();

                MatchCollection matches = reg.Matches(strText);
                if (matches.Count > 0)
                {
                    int i = 0;
                    while (i < matches.Count)
                    {
                        if (ID != null && ID.Contains(matches[i].Value))
                        {
                            //判断是否重复
                            i++;
                        }
                        else
                        {
                            ID.Push(matches[i].Value);
                            ListViewItem lvi = new ListViewItem();
                            lvi.Text = matches[i].Value;
                            lvi.SubItems.Add(url);
                            this.Invoke(new Action(() => { this.listView1.Items.Add(lvi); }));
                            //this.listView1.Items.Add(lvi);
                            i++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MatchCollection matches = reg.Matches("");
            }
            finally
            {
            }
        }
        public bool AddToRecent(string pathToFile)
        {
            if (_container.Contains(pathToFile))
            {
                return(false);
            }

            string Value;

            if (_container.Count == 8)
            {
                if (_container.TryPop(out Value))
                {
                    OnRecentChanged(Value, RecentAction.Removed);
                }
            }

            _container.Push(pathToFile);
            OnRecentChanged(pathToFile, RecentAction.Added);
            return(true);
        }
Exemple #15
0
 public static void ReleaseInstance(PacketWriter pw)
 {
     if (!_Pool.Contains(pw))
     {
         _Pool.Push(pw);
     }
     else
     {
         try
         {
             using (StreamWriter op = new StreamWriter("neterr.log", true))
             {
                 op.WriteLine("{0}\tInstance pool contains writer", DateTime.Now);
                 op.WriteLine();
             }
         }
         catch
         {
             Console.WriteLine("net error");
         }
     }
 }
        private object Create(Type type)
        {
            var configuratedType = container.GetConfiguratedType(type);

            if (configuratedType != null)
            {
                if (!stack.Contains(configuratedType.GetImplementationInterface))
                {
                    stack.Push(configuratedType.GetImplementationInterface);

                    var instanceType = configuratedType.GetImplementation;
                    if (instanceType.IsGenericTypeDefinition)
                    {
                        instanceType = instanceType.MakeGenericType(currentType.GenericTypeArguments);
                    }

                    var constructors = instanceType.GetConstructors().OrderByDescending
                                           (x => x.GetParameters().Length).ToArray();

                    bool   isCreated         = false;
                    int    constructorNumber = 1;
                    object result            = null;

                    while (!isCreated && constructorNumber <= constructors.Count())
                    {
                        try
                        {
                            var useConstructor = constructors[constructorNumber - 1];
                            var param          = GetConstructorParam(useConstructor);
                            result    = Activator.CreateInstance(instanceType, param);
                            isCreated = true;
                        }
                        catch
                        {
                            isCreated = false;
                            constructorNumber++;
                        }
                    }

                    if (!stack.TryPop(out var temp) || temp != configuratedType.GetImplementationInterface)
                    {
                        throw new Exception("can't correctly pop element from stack");
                    }

                    if (isCreated)
                    {
                        return(result);
                    }
                    else
                    {
                        throw new Exception($"{type.FullName} can't be created");
                    }
                }
                else
                {
                    throw new Exception($"can't resolve type{stack.FirstOrDefault().Name}");
                }
            }
            else
            {
                throw new Exception($"{type.FullName} is not registered");
            }
        }
Exemple #17
0
        public void DownloadFolder(string destFolder, string srcFolder)
        {
            // Holds a list of folders that we need to traverse
            // using a stack to eliminate recursion
            var folders = new ConcurrentStack <string>();

            int foldersProcesed = 0;
            var remotelen       = srcFolder.Length;

            //Delete the local temp directory if it already exists.
            if (Directory.Exists(destFolder))
            {
                Directory.Delete(destFolder, true);
            }

            // Push the root folder onto the stack
            folders.Push(srcFolder);

            string currentFolderRemote = string.Empty;

            // Start looping.
            while (folders.TryPop(out currentFolderRemote) && foldersProcesed < FolderLimit)
            {
                foldersProcesed++;
                var currentFolderLocal = destFolder + currentFolderRemote.Substring(remotelen);

                var filesInRemote = new List <string>();

                // Create the local clone of a sub folder if needed
                if (!Directory.Exists(currentFolderLocal))
                {
                    Directory.CreateDirectory(currentFolderLocal);
                }

                Logger.Log($"Processing {currentFolderRemote}");

                Policy.GetDefaultPolicy().Execute(() =>
                {
                    // FTP into the server and get a list of all the files and folders that exist
                    using (FtpClient client = new FtpClient(FtpHost, FtpUser, FtpPassword))
                    {
                        client.Connect();

                        foreach (var item in client.GetListing(currentFolderRemote))
                        {
                            if (item.Type == FtpFileSystemObjectType.Directory)
                            {
                                //Send folders to get processed in this thread
                                if (!folders.Contains(item.FullName))
                                {
                                    folders.Push(item.FullName);
                                }
                            }
                            else if (item.Type == FtpFileSystemObjectType.File)
                            {
                                //Build a list of files in this folder
                                filesInRemote.Add(item.FullName);
                            }
                        }

                        if (filesInRemote.Any())
                        {
                            int batchNum = 0;
                            foreach (var chunk in Chunk(filesInRemote, DownloadChunkFileCount))
                            {
                                batchNum++;

                                var downloadedCount = client.DownloadFiles(currentFolderLocal, chunk);

                                Logger.Log($"Downloaded {downloadedCount} files in Batch {batchNum} to {currentFolderLocal}");
                            }
                        }

                        client.Disconnect();
                    }
                });
            }
        }
        private object Create(Type type)
        {
            var configuratedType = dependencyConfiguration.GetConfiguratedType(type);

            if (configuratedType != null)
            {
                if (configuratedType.IsSingleton && configuratedType.Instance != null)
                {
                    return(configuratedType.Instance);
                }

                if (!Implementations.Contains(configuratedType.Implementation))
                {
                    Implementations.Push(configuratedType.Implementation);

                    var instanceType = configuratedType.Implementation;

                    if (instanceType.IsGenericTypeDefinition)
                    {
                        instanceType = instanceType.MakeGenericType(_currentGenType.GenericTypeArguments);
                    }

                    ConstructorInfo[] constructors = instanceType.GetConstructors().OrderByDescending(x => x.GetParameters().Length).ToArray();

                    object result = null;

                    bool isCreated = false;
                    int  ctorNum   = 1;

                    while (!isCreated && ctorNum <= constructors.Count())
                    {
                        try
                        {
                            ConstructorInfo useConstructor = constructors[ctorNum - 1];
                            object[]        parameters     = GetConstructorParams(useConstructor);
                            result    = Activator.CreateInstance(instanceType, parameters);
                            isCreated = true;
                        }
                        catch
                        {
                            isCreated = false;
                            ctorNum++;
                        }
                    }

                    if (!Implementations.TryPop(out var temp))
                    {
                        return(null);
                    }

                    if (isCreated)
                    {
                        return(result);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
 public bool Contains(T item) => m_Stack.Contains(item);