Пример #1
0
    /// <summary>
    /// Handles the Click event of the cmdRunTest control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void cmdStartProcess_Click(object sender, EventArgs e)
    {
        ImportManager importManager = Page.Session["importManager"] as ImportManager;

        if (importManager == null)
        {
            return;
        }

        using (new SessionScopeWrapper(true))
        {
            ThreadPoolHelper.QueueTask(OnStartImportProcess);
        }
        //string sourceFileName = ((ImportCSVReader)importManager.SourceReader).SourceFileName;
        //if (sourceFileName != null)
        //{
        //string targetFileName = String.Format("{0}{1}-{2}.csv", ImportService.GetImportCompletedPath(),
        //                                      importManager.ImportHistory.AlternateKeyPrefix,
        //                                      importManager.ImportHistory.AlternateKeySuffix);
        //    ImportService.MoveToPath(sourceFileName, targetFileName);
        //}
        //RemoveJob(importManager);


        //importManager.Dispose();
        //object objShutDown = Page.Session["SessionShutDown"];
        //if (Convert.ToBoolean(objShutDown))
        //{
        //    if (CanShutDown())
        //    {
        //        ApplicationContext.Shutdown();
        //        Page.Session.Abandon();
        //    }
        //}
    }
Пример #2
0
        /// <summary>
        /// Update the User based on an EntityRow.
        /// </summary>
        /// <param name="entityRow">The row to update from.</param>
        public override void Update(EntityRow entityRow)
        {
            UserRow userRow = DataModel.User.UserKey.Find(entityRow.EntityId);

            base.Update(entityRow);

            if (userRow != null)
            {
                if (!this.Modified && entityRow.EntityId == this.EntityId)
                {
                    this.IdentityName = userRow.IdentityName;
                    this.isRemoved    = userRow.IsRemoved;

                    this.groups.Clear();
                    foreach (GroupUsersRow groupRow in userRow.GetGroupUsersRows())
                    {
                        this.groups.Add(Entity.New(groupRow.GroupRow.RightsHolderRow.EntityRow) as Group);
                    }

                    // The information kept in AD takes a really long time to come back, so we'll grab it in another thread.
                    ThreadPoolHelper.QueueUserWorkItem(data => this.LoadAdInformation(data as String), this.IdentityName);
                }

                this.rowVersion = userRow.RowVersion;
            }
        }
Пример #3
0
 /// <summary>
 /// Handles the OnClick event of the StartProcess control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void StartImportTest_OnClick(object sender, EventArgs e)
 {
     using (new SessionScopeWrapper(true))
     {
         ThreadPoolHelper.QueueTask(StartTestImport);
     }
 }
Пример #4
0
        public void PerformSomeOperationWithNoLockTest()
        {
            const int counter    = 40;
            var       doneEvents = new ManualResetEvent[counter];
            IList <InputOutputValue> inputOutputValues = new List <InputOutputValue>();

            for (var loopCounter = 0; loopCounter < counter; loopCounter++)
            {
                doneEvents[loopCounter] = new ManualResetEvent(false);
                var inputOutputValue = new InputOutputValue {
                    Input = loopCounter
                };
                var helper = new ThreadPoolHelper(doneEvents[loopCounter]);
                ThreadPool.QueueUserWorkItem(helper.ThreadPoolCallbackWithNoLock, inputOutputValue);
                inputOutputValues.Add(inputOutputValue);
            }

            WaitHandle.WaitAll(doneEvents);

            var inputOutputValueCounter = 0;

            foreach (InputOutputValue inputOutputValue in inputOutputValues)
            {
                if (inputOutputValue.Input == inputOutputValue.Output)
                {
                    inputOutputValueCounter++;
                }
            }
            Assert.NotEqual(counter, inputOutputValueCounter);
        }
Пример #5
0
 /// <summary>
 /// Handle the apply command.
 /// </summary>
 /// <param name="sender">The apply button.</param>
 /// <param name="eventArgs">The event arguments.</param>
 private void OnApply(object sender, EventArgs eventArgs)
 {
     ThreadPoolHelper.QueueUserWorkItem(
         data =>
         this.Apply(data as Blotter),
         this.Entity.Clone());
 }
        /// <summary>
        /// Create a new user accounts window.
        /// </summary>
        public WindowUserAccounts()
        {
            InitializeComponent();
            this.Loaded   += this.OnLoaded;
            this.Unloaded += this.OnUnloaded;

            ThreadPoolHelper.QueueUserWorkItem(data => this.CheckAdminStatus());
        }
    private void LoadView()
    {
        if (Job != null)
        {
            if (String.IsNullOrEmpty(Job.JobId))
            {
                using (new SessionScopeWrapper(true))
                {
                    IDeDupJobProcess job = GetJob();
                    if (job != null)
                    {
                        if (string.IsNullOrEmpty(job.JobId))
                        {
                            IDeDupService srv   = ApplicationContext.Current.Services.Get <IDeDupService>();
                            string        jobId = srv.SubmitJob(job);
                            Page.Session["DeDupJobId"] = jobId;
                        }
                        ThreadPoolHelper.QueueTask(StartJobProcess);
                    }
                }
            }
            try
            {
                lnkJobNumber.Text = String.Format("{0}", Job.ProgressInfo.JobNumber);
                switch (Job.ProcessState)
                {
                case DeDupJobProcessState.Aborted:
                    break;

                case DeDupJobProcessState.Completed:
                {
                    cmdAbort.Visible         = false;
                    lblHeader.Text           = String.Format(GetLocalResourceObject("CompletedMsg").ToString());
                    Page.Session["DeDupJob"] = null;
                    RadProgressContext jobProgress = RadProgressContext.Current;
                    jobProgress["ProcessCompleted"]  = "True";
                    jobProgress["OperationComplete"] = "True";
                }
                break;

                default:
                    cmdAbort.Visible = true;
                    lblHeader.Text   = String.Format(GetLocalResourceObject("lblPrimary_Progress.Caption").ToString());
                    lblHeader2.Text  = String.Format(GetLocalResourceObject("ProcessingMsg").ToString());
                    break;
                }
            }
            catch (Exception)
            {
            }
        }
        else
        {
            RadProgressContext jobProgress = RadProgressContext.Current;
            jobProgress["OperationComplete"] = "True";
            GoToDeDupManager();
        }
    }
        /// <summary>
        /// Updates the data in the report.
        /// </summary>
        public override void Refresh()
        {
            if (this.reportGrid != null)
            {
                this.reportGrid.UpdateBodyCanvasCursor(true);
            }

            ThreadPoolHelper.QueueUserWorkItem(RefreshThread);
        }
        private void reportMatch_SelectionChanged(object sender, EventArgs e)
        {
            ReportCell reportCell = ViewerDebtBlotter.reportMatch.FocusedCell;

            if (reportCell != null)
            {
                ThreadPoolHelper.QueueUserWorkItem(InitializeMatchReport, reportCell);
            }
        }
 /// <summary>
 /// Handles the end of merging data into the client side data model.
 /// </summary>
 /// <param name="sender">The object that originated the event.</param>
 /// <param name="eventArgs">The unused event arguments.</param>
 private void OnEndMerge(object sender, EventArgs eventArgs)
 {
     // The content of the report is regenerated in a worker thread when the data related to this report has changed.  When
     // the content is regenerated, it will be sent to the foreground to be presented in the report.
     if (this.isDataChanged)
     {
         ThreadPoolHelper.QueueUserWorkItem(RefreshThread, false);
         this.isDataChanged = false;
     }
 }
        /// <summary>
        /// Handle the Entity changing.
        /// </summary>
        protected override void OnEntityChanged()
        {
            base.OnEntityChanged();

            ThreadPoolHelper.QueueUserWorkItem(delegate(object data)
            {
                lock (DataModel.SyncRoot)
                    this.entityId = (Guid)data;
            },
                                               this.Entity.EntityId);
        }
        private void OnOkay(object sender, EventArgs eventArgs)
        {
            String name   = this.OrganizationName;
            Guid   typeId = this.OrganizationType;

            ThreadPoolHelper.QueueUserWorkItem(
                data =>
                this.Create(name, typeId));

            this.Close();
        }
Пример #13
0
            /// <summary>
            /// ctor
            /// </summary>
            /// <param name="serverAdmin"></param>
            /// <param name="clientProxy"></param>
            /// <param name="scriptFilePath">script file to load (path to file on the server)</param>
            /// <param name="asyncTicket">ticket string to pass back to caller though callback so caller can match message to the original request</param>
            /// <param name="streamConents">should the contents of the file be streamed back to the client</param>
            public LoadSciptFileMethodImpl(ServerAdmin serverAdmin, ClientProxy clientProxy, string scriptFilePath, string asyncTicket, bool streamConents)
            {
                this.streamConents  = streamConents;
                this.clientProxy    = clientProxy;
                this.serverAdmin    = serverAdmin;
                this.scriptFilePath = scriptFilePath.Trim().ToLowerInvariant();
                this.asyncTicket    = asyncTicket;

                //start the thread to do the work
                ThreadPoolHelper.QueueUserWorkItem(new System.Threading.WaitCallback(this.LoadScriptFileProc));
            }
Пример #14
0
        /// <summary>
        /// Create a new debt rule list.
        /// </summary>
        public DebtRuleList(Guid blotterId)
        {
            this.blotterId = blotterId;

            DataModel.EntityTree.RowChanged += this.OnTreeChanged;

            ThreadPoolHelper.QueueUserWorkItem(delegate(object data)
            {
                this.blotterList = this.GetBlotterList();
                this.InitializeList();
            });
        }
Пример #15
0
        /// <summary>
        /// Handle the parent folder changing.
        /// </summary>
        /// <param name="sender">The unlink folder window.</param>
        /// <param name="eventArgs">The event arguments.</param>
        private static void OnParentFolderChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
        {
            WindowUnlinkFolder chooser = sender as WindowUnlinkFolder;

            if (chooser.ParentFolder != null)
            {
                ThreadPoolHelper.QueueUserWorkItem(data => chooser.InitializeFolders((Guid)data), chooser.ParentFolder.EntityId);
            }
            else
            {
                chooser.Folders = null;
            }
        }
        /// <summary>
        /// Handle the Group changing.
        /// </summary>
        /// <param name="eventArgs">The event arguments.</param>
        private void OnGroupChanged(DependencyPropertyChangedEventArgs eventArgs)
        {
            ThreadPoolHelper.QueueUserWorkItem(delegate(object guid)
            {
                lock (DataModel.SyncRoot)
                    this.groupId = (Guid)guid;
            }, this.Group.GroupId);

            this.users.ItemsSource = new UserList()
            {
                FilterMethod = u => (u as User).Groups.Any(g => g.GroupId == this.groupId)
            };
        }
    /// <summary>
    /// Handles the Click event of the cmdRunTest control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void cmdRunTest_Click(object sender, EventArgs e)
    {
        ImportManager importManager = Page.Session["importManager"] as ImportManager;

        if (importManager == null)
        {
            return;
        }
        AssignMatchFilters();
        using (new SessionScopeWrapper(true))
        {
            ThreadPoolHelper.QueueTask(StartTestImport);
        }
    }
        /// <summary>
        /// Refreshes the data in the report in a worker thread.
        /// </summary>
        /// <param name="state">The unused thread start parameters.</param>
        private void RefreshThread(object state)
        {
            bool requestGC = true.Equals(state);

            // Once the module is compiled and loaded into memory, an instance of the specified viewer is created.  The
            // IDocumentView is all that is needed to communicate with the loaded view.  Note that an array of delegates is passed
            // into the newly compiled and loaded View that allow the View to communicate back to the host Viewer.

            // Note that SetContent method will dispatch the thread hence it was not done here.
            lock (DataModel.SyncRoot)
                this.SetContent(this.CreditCardHeaderSelector(this.guid), requestGC);

            ThreadPoolHelper.QueueUserWorkItem(RefreshThreadCompleted);
        }
Пример #19
0
    /// <summary>
    /// Handles the Click event of the cmdRunTest control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void cmdStartProcess_Click(object sender, EventArgs e)
    {
        ImportManager importManager = Page.Session["importManager"] as ImportManager;

        if (importManager == null)
        {
            return;
        }

        using (new SessionScopeWrapper(true))
        {
            ThreadPoolHelper.QueueTask(OnStartImportProcess);
        }
    }
 /// <summary>
 /// Handles the FinishButtonClick event of the wzdImportLeads control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Web.UI.WebControls.WizardNavigationEventArgs"/> instance containing the event data.</param>
 protected void wzdImportLeads_FinishButtonClick(object sender, WizardNavigationEventArgs e)
 {
     frmManageDuplicates.AssignMatchFilters();
     using (new SessionScopeWrapper(true))
     {
         ImportManager importManager = Page.Session["importManager"] as ImportManager;
         if (importManager != null)
         {
             importManager.ImportHistory.Save(); //Save the import history
             Page.Session["importManager"]   = importManager;
             Page.Session["importHistoryId"] = importManager.ImportHistory.Id;
             ThreadPoolHelper.QueueTask(frmProcessRequest.StartImportProcess);
         }
     }
 }
Пример #21
0
        /// <summary>
        /// Handle the Okay event.
        /// </summary>
        /// <param name="sender">The cancel button.</param>
        /// <param name="eventArgs">The event arguments.</param>
        protected override void OnOkay(object sender, ExecutedRoutedEventArgs eventArgs)
        {
            if (this.Folder != null)
            {
                Entity parent = this.ParentFolder.Clone() as Entity;
                Entity child  = this.Folder.Clone() as Entity;
                ThreadPoolHelper.QueueUserWorkItem(data => this.Commit(parent, child));
                this.DialogResult = true;
            }
            else
            {
                this.DialogResult = false;
            }

            this.Close();
        }
        /// <summary>
        /// Change data contexts when the entity changes.
        /// </summary>
        protected override void OnEntityChanged()
        {
            Guid entityId   = this.Entity.EntityId;
            Guid?debtRuleId = (this.Entity as DebtClass).DebtRuleId;

            base.OnEntityChanged();

            ThreadPoolHelper.QueueUserWorkItem(delegate(object data)
            {
                lock (DataModel.SyncRoot)
                {
                    this.entityId   = entityId;
                    this.debtRuleId = debtRuleId;
                }
            });
        }
        /// <summary>
        /// Create a new properties dialog box.
        /// </summary>
        public WindowBlotterProperties()
            : base()
        {
            this.BuildPaymentScheduleTab();
            this.CommandBindings.Add(new CommandBinding(WindowBlotterProperties.EditCommissionSchedule, this.OnEditCommissionSchedule, this.CanEditCommissionSchedule));
            ThreadPoolHelper.QueueUserWorkItem(data =>
                                               this.InitializeUser());

            this.Loaded += delegate(object sender, RoutedEventArgs eventArgs)
            {
                DataModel.Blotter.RowChanging += this.FilterRow;
            };
            this.Unloaded += delegate(object sender, RoutedEventArgs eventArgs)
            {
                DataModel.Blotter.RowChanging -= this.FilterRow;
            };
        }
        /// <summary>
        /// Handle the Entity changing.
        /// </summary>
        protected override void OnEntityChanged()
        {
            base.OnEntityChanged();

            (this.Entity as User).Groups.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs eventArgs)
            {
                if (!this.Populating)
                {
                    this.CanApply = true;
                }
            };

            ThreadPoolHelper.QueueUserWorkItem(delegate(object data)
            {
                lock (DataModel.SyncRoot)
                    this.entityId = (Guid)data;
            },
                                               this.Entity.EntityId);
        }
Пример #25
0
        /// <nodoc/>
        public App(Stream clientStream, Stream serverStream, string pathToLogFile)
        {
            Contract.Requires(clientStream != null);
            Contract.Requires(serverStream != null);
            Contract.Requires(!string.IsNullOrEmpty(pathToLogFile));

            ContentHashingUtilities.SetDefaultHashType();

            // Note that we cannot start listening (i.e. use Attach) until
            // we have finished constructing the app.
            // Otherwise we can receive an incoming message
            // before we finish initialization.
            var jsonRpcChannel = new JsonRpcWithException(clientStream, serverStream, this);

            m_mainRpcChannel = jsonRpcChannel;

            m_mainRpcChannel.AddLocalRpcTarget(this, new JsonRpcTargetOptions {
                AllowNonPublicInvocation = true
            });

            // We need to create the project management provider before we start listening on the
            // RPC channel as you cannot attach them after it has started listening.
            m_projectManagementProvider = new ProjectManagementProvider(GetAppStateDelegate(), m_mainRpcChannel);

            m_tracer = new Tracer(m_mainRpcChannel, pathToLogFile, EventLevel.Verbose, EventLevel.Informational);

            m_progressReporter = new ProgressReporter(m_mainRpcChannel, testContext: null);

            Logger.LanguageServerStarted(LoggingContext);
            Logger.LanguageServerLogFileLocation(LoggingContext, pathToLogFile);

            jsonRpcChannel.SetLoggingContext(Logger, LoggingContext);

            // Change minimal number of threads for performance reasons.
            // 5 is a reasonable number that should prevent thread pool exhaustion and will not spawn too many threads.
            ThreadPoolHelper.ConfigureWorkerThreadPools(Environment.ProcessorCount, 5);

            // This must be last after initialization
            m_mainRpcChannel.StartListening();

            SubscribeToUnhandledErrors();
        }
Пример #26
0
        protected override void Merge(int[] array, int[] arrayResult, int start, int pivot, int end)
        {
            // collect separate action arrays for each individual operation
            var firstPart = Enumerable.Range(start, pivot - start).Select(index => new Action(() =>
            {
                var value = array[index];
                var less  = BinarySearchHelper.FindLess(array, value, pivot, end);
                arrayResult[index + less] = value;
            }));

            var secondPart = Enumerable.Range(pivot, end - pivot).Select(index => new Action(() =>
            {
                var value = array[index];
                var less  = BinarySearchHelper.FindLessOrEqual(array, value, start, pivot);
                arrayResult[start + index - pivot + less] = value;
            }));

            // combine into 4 big actions
            var actions = new Action[4];
            var i       = 0;

            foreach (var action in firstPart)
            {
                actions[i] += action;
                i++;
                if (i == actions.Length)
                {
                    i = 0;
                }
            }
            foreach (var action in secondPart)
            {
                actions[i] += action;
                i++;
                if (i == actions.Length)
                {
                    i = 0;
                }
            }
            ThreadPoolHelper.SpawnAndWait(actions);
        }
        /// <summary>
        /// a delegate to
        /// </summary>
        private void Listen()
        {
            //construct a listener
            listener = new TcpListener(IPAddress.Any, port);
            //backlog是最大允许的同时排队的连接数,用于处理并发的连接,与实际的连接数无关,因此该数不必太大
            listener.Start(512);

            while (isRunning)
            {
                try
                {
                    if (!listener.Pending())
                    {
                        Thread.Sleep(1);
                        continue;
                    }

                    //accept the pending connection
                    Socket client = listener.AcceptSocket();
                    // TcpClient client = listener.AcceptTcpClient();

                    if (action != null)
                    {
                        ThreadPoolHelper.ExecThreadPool(action, client);
                    }

                    //client.Shutdown(SocketShutdown.Both);
                    //client.Close();
                    //RequestHandle requestHandle = new RequestHandle(client);
                    //ThreadPoolHelper.ExecThreadPool(ThreadProc, requestHandle);
                    Thread.Sleep(1);
                }
                catch (Exception ex)
                {
                    _lastEx = ex;
                }
            }
        }
Пример #28
0
        /// <summary>
        /// Load up the user-specific information.
        /// </summary>
        protected override void FinishLoad()
        {
            UserRow userRow = DataModel.User.UserKey.Find(this.EntityId);

            base.FinishLoad();

            this.isRemoved    = userRow.IsRemoved;
            this.identityName = userRow.IdentityName;
            this.rowVersion   = userRow.RowVersion;

            if (this.groups == null)
            {
                this.groups = new ObservableCollection <Group>();
                this.groups.CollectionChanged += this.OnGroupsChanged;
            }

            foreach (GroupUsersRow groupRow in userRow.GetGroupUsersRows())
            {
                this.groups.Add(Entity.New(groupRow.GroupRow.RightsHolderRow.EntityRow) as Group);
            }

            // The information kept in AD takes a really long time to come back, so we'll grab it in another thread.
            ThreadPoolHelper.QueueUserWorkItem(data => this.LoadAdInformation(data as String), this.IdentityName);
        }
 /// <summary>
 /// Initializes the components found in the dynamic XAML source.
 /// </summary>
 public void LoadSource()
 {
     ThreadPoolHelper.QueueUserWorkItem(LoadSource);
 }
 private void OnLoad(object sender, EventArgs eventArgs)
 {
     ThreadPoolHelper.QueueUserWorkItem(this.LoadTypes);
 }