Exemplo n.º 1
0
        private static void UpdateLocalProgress_Worker(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            int autoCount = 0;
            int userCount = 0;

            // Suspend the auto packaging
            WorkspaceManager.SuspendPackaging(true);

            // Begin this GetLatest
            WorkspaceManager.ModifyLocalWorkspace_Begin();

            while (true)
            {
                MOG_Filename filename      = new MOG_Filename();
                bool         userInitiated = false;

                lock (mAutoUpdateQueue)
                {
                    // See if there are any auto update items needing to be processed?
                    if (mAutoUpdateQueue.Count > 0)
                    {
                        filename = mAutoUpdateQueue.Dequeue();
                        autoCount++;
                    }
                    // See if there are any user initiated items needing to be processed?
                    else if (mUserUpdateQueue.Count > 0)
                    {
                        filename = mUserUpdateQueue.Dequeue();
                        userCount++;
                        userInitiated = true;
                    }
                }

                // Recalulate total within this loop because it can be changing outside of us in another thread...
                int    total   = (mAutoUpdateQueue.Count + autoCount) + (mUserUpdateQueue.Count + userCount);
                string message = "Updating:\n" +
                                 "     " + filename.GetAssetClassification() + "\n" +
                                 "     " + filename.GetAssetName();
                worker.ReportProgress((autoCount + userCount) * 100 / total, message);

                // Only allow updates of valid assets
                if (filename.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset ||
                    filename.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Group)
                {
                    // Add this asset to all of our active workspaces
                    WorkspaceManager.AddAssetToWorkspaces(filename, userInitiated, worker);
                }

                lock (mUpdateQueueLock)
                {
                    if (mAutoUpdateQueue.Count == 0 &&
                        mUserUpdateQueue.Count == 0)
                    {
                        mAutoUpdateQueue = null;
                        mUserUpdateQueue = null;
                        break;
                    }

                    // Check if the user canceled things?
                    if (worker.CancellationPending)
                    {
                        mAutoUpdateQueue = null;
                        mUserUpdateQueue = null;
                        break;
                    }
                }
            }

            // Restore the auto packaging
            WorkspaceManager.SuspendPackaging(false);

            // End this GetLatest
            WorkspaceManager.ModifyLocalWorkspace_Complete();
        }