public static bool ShowModal(IWin32Window Owner, PerforceConnection DefaultConnection, string StreamName, string ProjectPath, out WorkspaceInfo WorkspaceInfo, TextWriter Log)
        {
            string WorkspaceName = FindDefaultWorkspace(Owner, DefaultConnection, StreamName, Log);

            AutomatedSyncWindow Window = new AutomatedSyncWindow(StreamName, ProjectPath, WorkspaceName, DefaultConnection, Log);

            if (Window.ShowDialog() == DialogResult.OK)
            {
                WorkspaceInfo = Window.SelectedWorkspaceInfo;
                return(true);
            }
            else
            {
                WorkspaceInfo = null;
                return(false);
            }
        }
Exemple #2
0
        public static bool ShowModal(IWin32Window Owner, PerforceConnection DefaultConnection, string StreamName, string ProjectPath, out WorkspaceInfo WorkspaceInfo, TextWriter Log)
        {
            FindDefaultWorkspaceTask FindWorkspace = new FindDefaultWorkspaceTask(StreamName);

            string ErrorMessage;

            PerforceModalTask.Execute(Owner, DefaultConnection, FindWorkspace, "Finding workspace", "Finding default workspace, please wait...", Log, out ErrorMessage);

            AutomatedSyncWindow Window = new AutomatedSyncWindow(StreamName, ProjectPath, FindWorkspace.WorkspaceName, DefaultConnection, Log);

            if (Window.ShowDialog() == DialogResult.OK)
            {
                WorkspaceInfo = Window.SelectedWorkspaceInfo;
                return(true);
            }
            else
            {
                WorkspaceInfo = null;
                return(false);
            }
        }
        AutomationRequestOutput StartAutomatedSync(AutomationRequest Request, bool bForceSync)
        {
            ShowAndActivate();

            BinaryReader Reader      = new BinaryReader(new MemoryStream(Request.Input.Data));
            string       StreamName  = Reader.ReadString();
            string       ProjectPath = Reader.ReadString();

            AutomatedSyncWindow.WorkspaceInfo WorkspaceInfo;
            if (!AutomatedSyncWindow.ShowModal(this, StreamName, ProjectPath, out WorkspaceInfo, Log))
            {
                return(new AutomationRequestOutput(AutomationRequestResult.Canceled));
            }

            if (WorkspaceInfo.bRequiresStreamSwitch)
            {
                // Close any tab containing this window
                for (int ExistingTabIdx = 0; ExistingTabIdx < TabControl.GetTabCount(); ExistingTabIdx++)
                {
                    WorkspaceControl ExistingWorkspace = TabControl.GetTabData(ExistingTabIdx) as WorkspaceControl;
                    if (ExistingWorkspace != null && ExistingWorkspace.ClientName.Equals(WorkspaceInfo.WorkspaceName))
                    {
                        TabControl.RemoveTab(ExistingTabIdx);
                        break;
                    }
                }

                // Switch the stream
                PerforceConnection Perforce = new PerforceConnection(WorkspaceInfo.UserName, WorkspaceInfo.WorkspaceName, WorkspaceInfo.ServerAndPort);
                if (!Perforce.SwitchStream(StreamName, Log))
                {
                    Log.WriteLine("Unable to switch stream");
                    return(new AutomationRequestOutput(AutomationRequestResult.Error));
                }
            }

            UserSelectedProjectSettings SelectedProject = new UserSelectedProjectSettings(WorkspaceInfo.ServerAndPort, WorkspaceInfo.UserName, UserSelectedProjectType.Client, String.Format("//{0}{1}", WorkspaceInfo.WorkspaceName, ProjectPath), null);

            int TabIdx = TryOpenProject(SelectedProject, -1, OpenProjectOptions.None);

            if (TabIdx == -1)
            {
                Log.WriteLine("Unable to open project");
                return(new AutomationRequestOutput(AutomationRequestResult.Error));
            }

            WorkspaceControl Workspace = TabControl.GetTabData(TabIdx) as WorkspaceControl;

            if (Workspace == null)
            {
                Log.WriteLine("Workspace was unable to open");
                return(new AutomationRequestOutput(AutomationRequestResult.Error));
            }

            if (!bForceSync && Workspace.CanLaunchEditor())
            {
                return(new AutomationRequestOutput(AutomationRequestResult.Ok, Encoding.UTF8.GetBytes(Workspace.SelectedFileName)));
            }

            Workspace.AddStartupCallback((Control, bCancel) => StartAutomatedSyncAfterStartup(Control, bCancel, Request));
            return(null);
        }