public bool SetActiveUser(string name) { // Make sure the user specified is not a label if (name.IndexOf("[") != -1) { return(false); } // Set our active user if (MOG_ControllerProject.SetActiveUserName(name)) { // If we have an asset manager, update it if (mainForm.mAssetManager != null) { // Set the gui to reflect changes mainForm.mAssetManager.SetActiveUser(name); // Make sure this user actually exists in the project? MOG_User user = MOG_ControllerProject.GetUser(); if (user != null) { return(true); } } } return(false); }
public static void BlessAssets_Worker(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <object> parameters = e.Argument as List <object>; List <MOG_Filename> filenames = parameters[0] as List <MOG_Filename>; string comment = parameters[1] as string; bool maintainLock = (bool)parameters[2]; bool bUserAltered = false; string loginUser = MOG_ControllerProject.GetUser().GetUserName(); string activeUser = MOG_ControllerProject.GetActiveUser().GetUserName(); // Make sure the inbox that we are in matches the logged in user if (string.Compare(MOG_ControllerProject.GetUser().GetUserName(), MOG_ControllerProject.GetActiveUser().GetUserName(), true) != 0) { // Login as this user so that his bless targets will be respected during this bless! MOG_ControllerProject.LoginUser(MOG_ControllerProject.GetActiveUser().GetUserName()); bUserAltered = true; } // Obtain a unique bless jobLabel string timestamp = MOG_Time.GetVersionTimestamp(); string jobLabel = "Bless." + MOG_ControllerSystem.GetComputerName() + "." + timestamp; // Changed to a for-loop to facilitate the loop breakout box on bless failure below for (int assetIndex = 0; assetIndex < filenames.Count; assetIndex++) { MOG_Filename asset = filenames[assetIndex] as MOG_Filename; if (asset != null) { string message = "Blessing:\n" + " " + asset.GetAssetClassification() + "\n" + " " + asset.GetAssetName(); worker.ReportProgress(assetIndex * 100 / filenames.Count, message); // Try to bless each asset and report if there is a failure try { if (MOG_ControllerInbox.BlessAsset(asset, comment, maintainLock, jobLabel, worker)) { WorkspaceManager.MarkLocalAssetBlessed(asset, timestamp); } else { // If there are more assets to bless, ask the user how to proceed if (assetIndex < filenames.Count - 1) { MOGPromptResult result = MOG_Prompt.PromptResponse("Bless Error", "An error has occurred while blessing " + asset.GetAssetFullName() + "\nWould you like to continue blessing assets?", MOGPromptButtons.YesNo); if (result == MOGPromptResult.Yes) { // continue with the next asset continue; } else if (result == MOGPromptResult.No) { // bail return; } } } } catch (Exception ex) { // Send this Exception back to the server MOG_Report.ReportMessage("Bless", ex.Message, ex.StackTrace, MOG_ALERT_LEVEL.CRITICAL); // Check if we are logged in an anyone? if (MOG_ControllerProject.IsUser()) { // Send a notification to the ofending user MOG_Report.ReportMessage("Bless", ex.Message, ex.StackTrace, MOG_ALERT_LEVEL.CRITICAL); } } } } // Start the job MOG_ControllerProject.StartJob(jobLabel); // Restore user if changed if (bUserAltered) { MOG_ControllerProject.LoginUser(loginUser); MOG_ControllerProject.SetActiveUserName(activeUser); } }