Пример #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
 public void Dispose()
 {
     _waitUntilRequestsAreFinished.Signal();
     _waitUntilRequestsAreFinished.Wait(5000);
     _httpClient.Dispose();
     _waitUntilRequestsAreFinished.Dispose();
 }
Пример #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
        private static long[] MergeAll(long[] output, LinkedList <int> bounds)
        {
            var buffer = new long[output.Count()];

            while (bounds.Count > 2)
            {
                var tmp_src = output;
                var tmp_buf = buffer;

                var w_node = bounds.First.Next;
                var w_copy = (bounds.Count - 1) % 2 == 1;
                int merges = (bounds.Count - 1) / 2;

                var counter = new System.Threading.CountdownEvent(merges);

                while (merges > 0)
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(
                        w =>
                    {
                        MergeTwo(tmp_src, tmp_buf, (MergeWindow)w);
                        counter.Signal();
                    },
                        new MergeWindow(w_node)
                        );
                    var w_next = w_node.Next.Next;
                    bounds.Remove(w_node);
                    w_node = w_next;
                    merges--;
                }

                if (w_copy)
                {
                    var w_prev = w_node.Previous;
                    Array.Copy(tmp_src, w_prev.Value, tmp_buf, w_prev.Value, w_node.Value - w_prev.Value);
                }

                counter.Wait();

                output = tmp_buf;
                buffer = tmp_src;
            }

            return(output);
        }
Пример #5
0
        public void TestRunTwoExperimentsSimultanouslyAndTerminateOneExperiment()
        {
            //assure workspace is empty
            AppContext.WorkspaceInstance.Clear();

            var done = new System.Threading.CountdownEvent(2);

            //start experiment one (takes more than 2 seconds to finish successfully)
            Experiment   experimentOne = LoadExperiment("long-experiment.teml");
            MockProgress progressOne   = new MockProgress();

            experimentOne.RunExperiment(progressOne, AppContext.WorkspaceInstance, AppContext.Components);
            experimentOne.ExperimentCompleted += (sender, args) =>
            {
                done.Signal();
            };

            //start experiment two and terminate it
            MockProgress progressTwo   = new MockProgress();
            Experiment   experimentTwo = LoadExperiment("infinite_loop_terminate_experiment_test.teml");

            experimentTwo.RunExperiment(progressTwo, AppContext.WorkspaceInstance, AppContext.Components);
            experimentTwo.ExperimentStarted += (sender, args) =>
            {
                experimentTwo.StopRunningExperiment();
            };
            experimentTwo.ExperimentCompleted += (sender, args) =>
            {
                done.Signal();
            };

            //wait for both experiment to end
            done.Wait(5000);

            //the experiment one should have ended successfully (it SHOULD NOT have been terminated)
            Assert.IsFalse(progressOne.HasError);
            Assert.AreEqual(Messages.ExperimentRunnerSuccessMessage, progressOne.CurrentStatus);

            //while exepriment two should be terminated
            Assert.IsTrue(progressTwo.HasError);
            Assert.AreEqual(Messages.ExperimentExecutionTerminated, progressTwo.CurrentStatus);
        }
Пример #6
0
        public async void Test1()
        {
            IBus  bus  = new Bus();
            IPort port = await bus.GetPort();

            var latch = new System.Threading.CountdownEvent(1);

            port.Subscribe <string>(s =>
            {
                if (string.Equals("Hello", s))
                {
                    latch.Signal();
                }
            });

            IPort pub = await bus.GetPort();

            pub.Publish("Hello");
            Assert.True(latch.Wait(1000));
        }
        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);
            }
        }
        public void Test_Get_Async()
        {
            var mockHttp = new MockHttpMessageHandler();

            // Setup a respond for the user api (including a wildcard in the URL)
            mockHttp.When("http://localhost/api/user/*")
            .Respond("application/json", "{'name' : 'foobar2'}");

            APGatewayBuilder <APGateway> builder = new APGatewayBuilder <APGateway>();

            builder.Uri("http://localhost/api/user/foo");

            APGateway gateway = builder.Build();

            gateway.RestClient = new APRestClient(mockHttp);

            // Use a countdown latch for the asynchronous call
            System.Threading.CountdownEvent CountDown = new System.Threading.CountdownEvent(1);
            string result = null;

            gateway.GetAsync(url: "/foo", callback: new StringCallback()
            {
                OnSuccess = (string s) => {
                    Console.WriteLine("result: " + s);

                    result = s;
                    CountDown.Signal();
                }
            });

            CountDown.Wait();

            Assert.AreEqual("{'name' : 'foobar2'}", result);

            mockHttp.Flush();
        }
        public void TestRunTwoExperimentsSimultanouslyAndTerminateOneExperiment()
        {
            //assure workspace is empty
            AppContext.WorkspaceInstance.Clear();

            var done = new System.Threading.CountdownEvent(2);

            //start experiment one (takes more than 2 seconds to finish successfully)
            Experiment experimentOne = LoadExperiment("long-experiment.teml");
            MockProgress progressOne = new MockProgress();
            experimentOne.RunExperiment(progressOne, AppContext.WorkspaceInstance, AppContext.Components);
            experimentOne.ExperimentCompleted += (sender, args) =>
            {
                done.Signal();
            };

            //start experiment two and terminate it
            MockProgress progressTwo = new MockProgress();
            Experiment experimentTwo = LoadExperiment("infinite_loop_terminate_experiment_test.teml");
            experimentTwo.RunExperiment(progressTwo, AppContext.WorkspaceInstance, AppContext.Components);
            experimentTwo.ExperimentStarted += (sender, args) =>
            {
                experimentTwo.StopRunningExperiment();
            };
            experimentTwo.ExperimentCompleted += (sender, args) =>
            {
                done.Signal();
            };

            //wait for both experiment to end
            done.Wait(5000);

            //the experiment one should have ended successfully (it SHOULD NOT have been terminated)
            Assert.IsFalse(progressOne.HasError);
            Assert.AreEqual(Messages.ExperimentRunnerSuccessMessage, progressOne.CurrentStatus);

            //while exepriment two should be terminated
            Assert.IsTrue(progressTwo.HasError);
            Assert.AreEqual(Messages.ExperimentExecutionTerminated, progressTwo.CurrentStatus);
        }
Пример #11
0
        private static List <Entry> GetEntryList(Area area, DirectoryInfo root, DirectoryInfo adminFolder)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Restart();
            try
            {
                Func <string, List <FlatFSEntry> > nativeGenerator = null;
                if (!Utilities.MultiArchPInvoke.IsRunningOnMono)
                {
                    if (GetFSFast == null)
                    {
                        var asm = System.Reflection.Assembly.LoadFrom(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/x64/VersionrCore.Win32.dll");
                        GetFSFast = asm.GetType("Versionr.Win32.FileSystem").GetMethod("EnumerateFileSystem").CreateDelegate(typeof(Func <string, List <FlatFSEntry> >)) as Func <string, List <FlatFSEntry> >;
                    }
                    nativeGenerator = GetFSFast;
                }
                else
                {
                    nativeGenerator = PosixFS.GetFlatEntries;
                }

                List <FlatFSEntry> flatEntries = null;
                if (!Utilities.MultiArchPInvoke.IsRunningOnMono)
                {
                }

                if (nativeGenerator != null)
                {
                    string fn = root.FullName.Replace('\\', '/');
                    if (fn[fn.Length - 1] != '/')
                    {
                        fn += '/';
                    }
                    System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket(System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
                    if (flatEntries == null)
                    {
                        Printer.PrintDiagnostics("#q#Using native file scanner...##");
                        sw.Restart();
                        flatEntries = nativeGenerator(fn);
                        if (area.GetLocalPath(fn) != "")
                        {
                            flatEntries.Insert(0, new FlatFSEntry()
                            {
                                Attributes = (int)root.Attributes, ChildCount = flatEntries.Count, Length = -1, FileTime = root.LastWriteTimeUtc.Ticks, FullName = fn
                            });
                        }
                        sw.Restart();
                    }
                }
                if (flatEntries != null)
                {
                    FSScan scan = new FSScan();
                    scan.FRIgnores   = area?.Directives?.Ignore?.RegexFilePatterns;
                    scan.FRIncludes  = area?.Directives?.Include?.RegexFilePatterns;
                    scan.ExtIgnores  = area?.Directives?.Ignore?.Extensions;
                    scan.ExtIncludes = area?.Directives?.Include?.Extensions;
                    List <Entry> e2 = new List <Entry>(flatEntries.Count);
                    System.Collections.Concurrent.ConcurrentBag <Entry> entries2 = new System.Collections.Concurrent.ConcurrentBag <Entry>();
                    System.Threading.CountdownEvent ce2 = new System.Threading.CountdownEvent(1);
                    ProcessListFast(scan, area, flatEntries, area.RootDirectory.FullName, ce2, entries2, 0, flatEntries.Count, null);
                    ce2.Signal();
                    ce2.Wait();
                    var ea = entries2.ToArray();
                    e2.Capacity = ea.Length;
                    e2.AddRange(ea);
                    return(e2);
                }
            }
            catch (System.Exception e)
            {
                // try again with the slow mode
                Printer.PrintDiagnostics("#q#Couldn't use fast scanners {0}##", e);
            }
            Printer.PrintDiagnostics("#q#Using fallback file scanner...##");
            sw.Restart();
            System.Collections.Concurrent.ConcurrentBag <Entry> entries = new System.Collections.Concurrent.ConcurrentBag <Entry>();
            System.Threading.CountdownEvent ce = new System.Threading.CountdownEvent(1);
            PopulateList(entries, ce, area, null, root, area.GetLocalPath(root.FullName), adminFolder, false);
            ce.Signal();
            ce.Wait();
            Entry[] entryArray = entries.ToArray();
            Array.Sort(entryArray, (Entry x, Entry y) => { return(string.CompareOrdinal(x.CanonicalName, y.CanonicalName)); });
            return(entryArray.ToList());
        }