Пример #1
0
        private void SendCommandASynch()
        {
            countDown = new System.Threading.CountdownEvent(1);

            foreach (DataGridViewRow row in dgvComputers.Rows)
            {
                if (!_closing && !_wrongCrendentialsWatcher.IsAbortRequested)
                {
                    countDown.AddCount();
                    CommandParameters parameters = GetCommonParameters();
                    parameters.Row            = row;
                    parameters.TargetComputer = (ADComputer)row.Cells["ADComputer"].Value;

                    parameters.Login    = _login;
                    parameters.Password = _password;
                    System.Threading.ThreadPool.QueueUserWorkItem(SendCommandToComputer, (object)parameters);
                }
            }
            countDown.Signal();
            countDown.Wait(5000 * dgvComputers.Rows.Count);
            DisplayProgress();
            Action action = () =>
            {
                dgvComputers.Sort(dgvComputers.Columns["Result"], ListSortDirection.Descending);
                btnClose.Enabled = true;
                btnAbort.Enabled = false;
            };

            if (!_closing)
            {
                this.Invoke(action);
            }
        }
Пример #2
0
        //private bool disposed = false;

        public async Task CallService(HttpContext context)
        {
            _waitUntilRequestsAreFinished.AddCount();
            try
            {
                var apiPath = (string)context.GetRouteData().DataTokens["apiPath"];

                string remainingPath = context.Request.Path.Value.Substring(apiPath.Length);
                var    uriString     = $"http://{_hostString}{remainingPath}{context.Request.QueryString}";
                var    uri           = new Uri(uriString);

                var requestMessage = new HttpRequestMessage();
                if (!string.Equals(context.Request.Method, "GET", StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(context.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(context.Request.Method, "DELETE", StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(context.Request.Method, "TRACE", StringComparison.OrdinalIgnoreCase))
                {
                    var streamContent = new StreamContent(context.Request.Body);
                    requestMessage.Content = streamContent;
                }
                requestMessage.RequestUri = uri;
                requestMessage.Method     = new HttpMethod(context.Request.Method);
                // Copy the request headers
                foreach (var header in context.Request.Headers)
                {
                    if (!requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()) && requestMessage.Content != null)
                    {
                        requestMessage.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray());
                    }
                }

                requestMessage.Headers.Host = _hostString;

                requestMessage.Method = new HttpMethod(context.Request.Method);

                using (var responseMessage = await _httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, context.RequestAborted))
                {
                    context.Response.StatusCode = (int)responseMessage.StatusCode;
                    foreach (var header in responseMessage.Headers)
                    {
                        context.Response.Headers[header.Key] = header.Value.ToArray();
                    }

                    foreach (var header in responseMessage.Content.Headers)
                    {
                        context.Response.Headers[header.Key] = header.Value.ToArray();
                    }

                    // SendAsync removes chunking from the response. This removes the header so it doesn't expect a chunked response.
                    context.Response.Headers.Remove("transfer-encoding");
                    await responseMessage.Content.CopyToAsync(context.Response.Body);
                }
            }
            finally
            {
                _waitUntilRequestsAreFinished.Signal();
            }
        }
Пример #3
0
        private void StartResetSusClientID()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Properties.Settings.Default.Language);

            Credentials cred = Credentials.GetInstance();

            if (dtGrdVResult.SelectedRows.Count != 0)
            {
                if (cred.InitializeCredential() == false)
                {
                    return;
                }
            }
            Logger.Write(lblCredentials);

            Action startAction = () => { lblCredentials.Text = cred.CredentialNotice; };

            if (!_closing)
            {
                this.Invoke(startAction);
            }

            System.Threading.CountdownEvent countEvent = new System.Threading.CountdownEvent(1);

            foreach (DataGridViewRow row in dtGrdVResult.SelectedRows)
            {
                countEvent.AddCount();
                ASyncClientParameters parameters = new ASyncClientParameters();
                parameters.RowIndex   = row.Index;
                parameters.Login      = cred.Login;
                parameters.Password   = cred.Password;
                parameters.CountEvent = countEvent;

                if (!_closing & !_aborting)
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(ResetSusClientID, parameters);
                }
            }
            countEvent.Signal();
            countEvent.Wait(10000 * dtGrdVResult.SelectedRows.Count);

            if (!_closing && !_aborting)
            {
                SearchDuplicateWsusClientID();
            }

            Action endAction = () => { ChangeUIAccess(true); };

            if (!_closing)
            {
                this.Invoke(endAction);
            }
        }
Пример #4
0
        public void RealCall(Action <IRedisClient> callback)
        {
            //- 打开测试的 redis-server,请注意,每次调用都会清空数据。
#if REAL_REDIS
            cde.AddCount();
            using (var client = this.CreateClient())
            {
                client.FlushAll();
                callback(client);
            }
            cde.Signal();
#endif
        }
        private void SendUpdateCommand()
        {
            Logger.EnteringMethod();
            string[] options = GetOptions();

            if (dtGrvComputers.Rows.Count > 0)
            {
                System.Threading.CountdownEvent countDown = new System.Threading.CountdownEvent(1);
                foreach (DataGridViewRow row in dtGrvComputers.Rows)
                {
                    if (_aborting || _closing)
                    {
                        break;
                    }
                    countDown.AddCount();
                    DataForComputer data = new DataForComputer();
                    data.Row       = row;
                    data.Options   = options;
                    data.CountDown = countDown;
                    System.Threading.ThreadPool.QueueUserWorkItem(SendCommandToComputer, data);
                }
                countDown.Signal();
                countDown.Wait();
            }
            Action finishAction = () =>
            {
                chkBxCancelIfRebootIsPending.Enabled         = true;
                chkBxIncludeUpdatesthatRequireReboot.Enabled = true;
                chkBxPersonalizeSearchString.Enabled         = true;
                txtBxPersonalizeSearchString.Enabled         = true;
                btnStartUpdating.Enabled = true;
                btnClose.Enabled         = true;
                _aborting = false;
            };

            if (!_closing)
            {
                this.Invoke(finishAction);
            }
        }
        private void HighLightOnLineComputers()
        {
            Logger.EnteringMethod();
            string computerName = string.Empty;

            if (dGVComputer.Rows.Count > 0 && !cancelHighLightOnlineComputers)
            {
                DataGridViewRow[] rows = new DataGridViewRow[dGVComputer.Rows.Count];
                dGVComputer.Rows.CopyTo(rows, 0);

                cancelSearchOnlineComputers = false;
                System.Threading.CountdownEvent countDown = new System.Threading.CountdownEvent(1);
                foreach (DataGridViewRow row in rows)
                {
                    if (cancelHighLightOnlineComputers)
                    {
                        break;
                    }
                    countDown.AddCount();
                    SearchOnlineComputerData data = new SearchOnlineComputerData();
                    data.Row       = row;
                    data.countDown = countDown;
                    System.Threading.ThreadPool.QueueUserWorkItem(SearchOnlineComputers, (object)data);
                }
                countDown.Signal();
                countDown.Wait(dGVComputer.Rows.Count * 10000);
                Action action = () =>
                {
                    if (dGVComputer.SortedColumn != null && dGVComputer.SortedColumn.Name == "OnLine")
                    {
                        dGVComputer.Sort(dGVComputer.SortedColumn, (dGVComputer.SortOrder == SortOrder.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending);
                    }
                };
                this.Invoke(action);
            }
        }
Пример #7
0
        public async Task CallService(HttpContext context)
        {
            Stopwatch sw = new Stopwatch();

            _waitUntilRequestsAreFinished.AddCount();
            try
            {
                sw.Start();
                var uriString = $"http://{_hostString}{context.Request.Path.Value}{context.Request.QueryString}";

                var uri = new Uri(uriString);

                var requestMessage = new HttpRequestMessage();
                if (!string.Equals(context.Request.Method, "GET", StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(context.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(context.Request.Method, "DELETE", StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(context.Request.Method, "TRACE", StringComparison.OrdinalIgnoreCase))
                {
                    var streamContent = new StreamContent(context.Request.Body);
                    requestMessage.Content = streamContent;
                }
                requestMessage.RequestUri = uri;
                requestMessage.Method     = new HttpMethod(context.Request.Method);
                // Copy the request headers
                foreach (var header in context.Request.Headers)
                {
                    if (!requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()) && requestMessage.Content != null)
                    {
                        requestMessage.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray());
                    }
                }

                requestMessage.Headers.Host = _hostString;

                requestMessage.Method = new HttpMethod(context.Request.Method);

                using (var responseMessage = await _httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead, context.RequestAborted))
                {
                    context.Response.StatusCode = (int)responseMessage.StatusCode;
                    _stats?.RecordResponse(context.Response.StatusCode);
                    foreach (var header in responseMessage.Headers)
                    {
                        context.Response.Headers[header.Key] = header.Value?.ToArray();
                    }

                    foreach (var header in responseMessage.Content.Headers)
                    {
                        context.Response.Headers[header.Key] = header.Value?.ToArray();
                    }

                    // SendAsync removes chunking from the response. This removes the header so it doesn't expect a chunked response.
                    context.Response.Headers.Remove("transfer-encoding");
                    await responseMessage.Content.CopyToAsync(context.Response.Body);
                }
            }
            finally
            {
                sw.Stop();

                System.Threading.Interlocked.Add(ref _totalRequestTime, (int)sw.Elapsed.TotalMilliseconds);
                System.Threading.Interlocked.Increment(ref _calls);

                _waitUntilRequestsAreFinished.Signal();
            }
        }
Пример #8
0
 protected RedisTest()
 {
     cde.AddCount();
     this.redis = new RedisClient(6379);
     this.redis.FlushDb();
 }
Пример #9
0
        private static void ProcessListFast(FSScan scan, Area area, List <FlatFSEntry> results, string rootFolder, System.Threading.CountdownEvent ce, System.Collections.Concurrent.ConcurrentBag <Entry> e2, int start, int end, Entry parentEntry = null, bool ignoreFiles = false)
        {
            int rflen = rootFolder.Length;

            if (rootFolder[rflen - 2] == ':')
            {
                rflen--;
            }
            rflen++;
            for (int i = start; i < end; i++)
            {
                var r = results[i];
                if (r.Length == -1)
                {
                    bool   ignoreDirectory     = false;
                    bool   ignoreContents      = false;
                    bool   hide                = false;
                    string slashedSubdirectory = r.FullName.Substring(rflen);

                    if (slashedSubdirectory == ".versionr/")
                    {
                        if (parentEntry == null)
                        {
                            if (r.ChildCount != 0)
                            {
                                throw new Exception();
                            }
                            continue;
                        }
                    }

                    CheckDirectoryIgnores(area, slashedSubdirectory, ref ignoreDirectory, ref ignoreContents, ref hide);

                    if (hide)
                    {
                        i += r.ChildCount;
                        continue;
                    }

                    var parent = new Entry(area, parentEntry, slashedSubdirectory, r.FullName, parentEntry == null ? slashedSubdirectory : r.FullName.Substring(parentEntry.FullName.Length), r.FileTime, 0, ignoreDirectory, (FileAttributes)r.Attributes);

                    if (parent.IsSymlink)
                    {
                        i += r.ChildCount;
                        continue;
                    }

                    e2.Add(parent);
                    if (ignoreDirectory)
                    {
                        // have to find child files and mark them specifically as ignored
                        int next = r.ChildCount + i + 1;
                        for (int x = i + 1; x < next; x++)
                        {
                            if (results[x].Length != -1)
                            {
                                var    f  = results[x];
                                string fn = f.FullName.Substring(rflen);

                                var ignoredFile = new Entry(area, parent, fn, f.FullName, f.FullName.Substring(parent.FullName.Length), f.FileTime, f.Length, true, (FileAttributes)f.Attributes);
                                e2.Add(ignoredFile);
                            }
                            else
                            {
                                x += results[x].ChildCount;
                            }
                        }
                        i += r.ChildCount;
                    }
                    else
                    {
                        int s = i + 1;
                        int e = i + 1 + r.ChildCount;
                        if (r.ChildCount > 16)
                        {
                            ce.AddCount();
                            System.Threading.Tasks.Task.Factory.StartNew(() => { ProcessListFast(scan, area, results, rootFolder, ce, e2, s, e, parent, ignoreContents); ce.Signal(); });
                        }
                        else
                        {
                            ProcessListFast(scan, area, results, rootFolder, ce, e2, s, e, parent, ignoreContents);
                        }
                        i += r.ChildCount;
                    }
                }
                else
                {
                    if (!ignoreFiles)
                    {
                        string fn      = r.FullName.Substring(rflen);
                        string fnI     = fn.ToLowerInvariant();
                        bool   ignored = CheckFileIgnores(area, fn, fnI, scan.FRIncludes, scan.FRIgnores, scan.ExtIncludes, scan.ExtIgnores);
                        e2.Add(new Entry(area, parentEntry, fn, r.FullName, parentEntry == null ? fn : r.FullName.Substring(parentEntry.FullName.Length), r.FileTime, r.Length, ignored, (FileAttributes)r.Attributes));
                    }
                }
            }
        }
Пример #10
0
        private static void PopulateList(System.Collections.Concurrent.ConcurrentBag <Entry> entries, System.Threading.CountdownEvent ce, Area area, Entry parentEntry, DirectoryInfo info, string subdirectory, DirectoryInfo adminFolder, bool ignoreDirectory)
        {
            if (area.InExtern(info))
            {
                return;
            }
            bool   ignoreContents      = false;
            string slashedSubdirectory = subdirectory;

            if (subdirectory != string.Empty)
            {
                if (slashedSubdirectory[slashedSubdirectory.Length - 1] != '/')
                {
                    slashedSubdirectory += '/';
                }

                bool hide = false;
                if (slashedSubdirectory == ".versionr/")
                {
                    if (parentEntry == null)
                    {
                        return;
                    }
                    else
                    {
                        parentEntry.IsVersionrRoot = true;
                    }
                }

                CheckDirectoryIgnores(area, slashedSubdirectory, ref ignoreDirectory, ref ignoreContents, ref hide);

                if (hide)
                {
                    return;
                }

                parentEntry = new Entry(area, parentEntry, slashedSubdirectory, info.FullName, info.Name, info.LastWriteTimeUtc.ToFileTimeUtc(), 0, ignoreDirectory, info.Attributes);
                entries.Add(parentEntry);
                if (ignoreDirectory)
                {
                    return;
                }
            }

            // Don't add children for symlinks.
            if (Utilities.Symlink.Exists(info))
            {
                return;
            }

            List <Task <List <Entry> > > tasks = new List <Task <List <Entry> > >();
            string prefix = string.IsNullOrEmpty(subdirectory) ? string.Empty : slashedSubdirectory;

            foreach (var x in info.GetFileSystemInfos())
            {
                string fn = x.Name;
                if (fn.EndsWith(".pch"))
                {
                    int qx = 0;
                }
                string name = prefix + fn;
                if ((x.Attributes & FileAttributes.Directory) != 0)
                {
                    if (fn.Equals(".", StringComparison.Ordinal) || fn.Equals("..", StringComparison.Ordinal))
                    {
                        continue;
                    }

                    if (fn.Equals(".versionr", StringComparison.Ordinal))
                    {
                        continue;
                    }

#if DEBUG
                    if (true)
#else
                    if (Utilities.MultiArchPInvoke.IsRunningOnMono)
#endif
                    {
                        PopulateList(entries, ce, area, parentEntry, x as DirectoryInfo, name, adminFolder, ignoreDirectory);
                    }
                    else
                    {
                        ce.AddCount();
                        area.GetTaskFactory().StartNew(() => { PopulateList(entries, ce, area, parentEntry, x as DirectoryInfo, name, adminFolder, ignoreDirectory); ce.Signal(); });
                    }
                }
                else if (!ignoreContents)
                {
                    bool ignored = CheckFileIgnores(area, name, name.ToLowerInvariant(), area?.Directives?.Include?.RegexFilePatterns, area?.Directives?.Ignore?.RegexFilePatterns, area?.Directives?.Include?.Extensions, area?.Directives?.Ignore?.Extensions);
                    entries.Add(new Entry(area, parentEntry, name, x.FullName, x.Name, x.LastWriteTimeUtc.ToFileTimeUtc(), new FileInfo(x.FullName).Length, ignored, x.Attributes));
                }
            }
        }