Пример #1
0
 private void ConnectBtn_Click(object sender, EventArgs e)
 {
     try
     {
         Uri url = new Uri(SwarmUrlCB.Text);
         SwarmBrowser.Navigate(url, null, null, null);
     }
     catch (Exception ex)
     {
         P4VsOutputWindow.AppendMessage("[E_ERROR] " + ex.Message);
         FileLogger.LogException("Swarm Connection Error", ex);
         DialogResult res = P4ErrorDlg.Show(ex.Message, false, false);
     }
 }
Пример #2
0
        public static DialogResult Show(P4.P4CommandResult results, bool showCancel)
        {
            if ((results == null) || (results.ErrorList == null) || (results.ErrorList.Count <= 0))
            {
                return(DialogResult.Ignore);
            }
            int           numWarnings = 0;
            List <string> WarningMsgs = new List <string>();

            foreach (P4.P4ClientError error in results.ErrorList)
            {
                if (error.SeverityLevel <= P4.ErrorSeverity.E_WARN)
                {
                    numWarnings++;
                }
                WarningMsgs.Add(string.Format("{0}: {1}", error.SeverityLevel, error.ErrorMessage));
            }
            if ((results.ErrorList.Count - numWarnings) <= 0)
            {
                if (WarningMsgs.Count > 0)
                {
                    // error dlialog will not display, so list any warning in the output pane
                    foreach (string msg in WarningMsgs)
                    {
                        P4VsOutputWindow.AppendMessage(msg);
                    }
                }
                return(DialogResult.Ignore);
            }

            P4ErrorDlg dlg = new P4ErrorDlg(results, showCancel);

            dlg.PromptLbl.Text = Resources.P4ErrorDlg_PromptLabel;
            dlg.TopMost        = true;
            return(dlg.ShowDialog());
        }
Пример #3
0
        // Used to open a connection to a Perforce depot
        public void OpenConnection(string Port, string User, string Workspace)
        {
#if DB_DEBUG
            P4VsOutputWindow.AppendMessage(string.Format("Opening connection, CurrentScm scm ID:{0}",
                                                         CurrentScm != null?CurrentScm.__Id:-1));
#endif

            P4ScmProvider scm = new P4ScmProvider(SccService);
            scm.LoadingSolution = !string.IsNullOrEmpty(SccService.LoadingControlledSolutionLocation);

#if DB_DEBUG
            P4VsOutputWindow.AppendMessage(string.Format("Opening connection, new scm ID:{0}", scm.__Id));
#endif
            bool noUi = InCommandLineMode() || (Port != null) && (User != null) && (Workspace != null);

            // trigger the connection dialog
            scm.Connection.Connect(Port, User, Workspace, noUi, null);
            if (scm.Connected)
            {
#if DB_DEBUG
                P4VsOutputWindow.AppendMessage(string.Format("Opening connection user clicked OK, new scm ID:{0}", scm.__Id));
#endif
                if (SccService.ScmProvider != null)
                {
                    BroadcastNewConnection(null);
                    SccService.Dispose();
                    SccService.ScmProvider = null;
                }
                SccService.ScmProvider = scm;

                createActiveChangelists(SccService);

                if (string.IsNullOrEmpty(SccService.ScmProvider.SolutionFile))
                {
                    string solutionFile = GetSolutionFileName();
                    if (string.IsNullOrEmpty(solutionFile) == false)
                    {
                        SccService.ScmProvider.SolutionFile = GetSolutionFileName();

                        if (Preferences.LocalSettings.GetBool("TagSolutionProjectFiles", false))
                        {
                            // Need to tag sln file if tagging is enabled, so mark dirty props so
                            // it'll get tagged
                            SolutionHasDirtyProps = true;
                        }
                    }

                    if (!SccService.IsProjectControlled(null))
                    {
                        SccService.OnAfterOpenSolution(null, 0);
                    }
                }
                Cursor oldCursor = Cursor.Current;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;

                    // now refresh the selected nodes' glyphs
                    if (Preferences.LocalSettings.GetBool("LazyLoadStatus", false) == false)
                    {
                        Glyphs.RefreshNodesGlyphs(null, null);
                    }
                }
                finally
                {
                    Cursor.Current = oldCursor;
                }

                BroadcastNewConnection(SccService.ScmProvider);

                MRUList recentConnections = (MRUList)Preferences.LocalSettings["RecentConnections"];
                currentConnectionDropDownComboChoice = recentConnections[0].ToString();

                SuppressConnection            = true;
                LastConnectionInfo            = new ConnectionData();
                LastConnectionInfo.ServerPort = SccService.ScmProvider.Connection.Port;
                LastConnectionInfo.UserName   = SccService.ScmProvider.Connection.User;
                LastConnectionInfo.Workspace  = SccService.ScmProvider.Connection.Workspace;

#if _DBB_DEBUG
                // How to set a setting for the ide (Generally from tool/options dialog)
                // The category and page values are listed on MSDN at:
                // http://msdn.microsoft.com/en-us/library/ms165643(v=vs.100).aspx
                // The category and pages no longer follow the layout in the options dialog,
                // they seem to still follow the old layout fro VS 2003. There's a general
                // discussion on MSDN about properties here:
                // http://msdn.microsoft.com/en-us/library/ms165641(v=vs.100).aspx
                // and:
                // http://msdn.microsoft.com/en-us/library/awdwz11a(v=vs.100).aspx
                // The Property object is documented here:
                // http://msdn.microsoft.com/en-us/library/envdte.property(v=vs.100).aspx
                // The Properties interface is documented here:
                // http://msdn.microsoft.com/en-us/library/envdte.properties(v=vs.100).aspx
                try
                {
                    EnvDTE.DTE dte2;
                    dte2 = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
                    EnvDTE.Properties generalPnS = dte2.DTE.Properties["Environment", "ProjectsAndSolution"];

                    EnvDTE.Property prop2 = generalPnS.Item("ProjectsLocation");
                    string          val   = prop2.Value as string;

                    //dynamic v2 = val + "\\temp";
                    prop2.Value = val;

                    val = prop2.Value as string;
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                    MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
#endif
                // How to set a setting for the ide (Generally from tool/options dialog)
                // The category and page values are listed on MSDN at:
                // http://msdn.microsoft.com/en-us/library/ms165643(v=vs.100).aspx
                // The category and pages no longer follow the layout in the options dialog,
                // they seem to still follow the old layout fro VS 2003. There's a general
                // discussion on MSDN about properties here:
                // http://msdn.microsoft.com/en-us/library/ms165641(v=vs.100).aspx
                // and:
                // http://msdn.microsoft.com/en-us/library/awdwz11a(v=vs.100).aspx
                // The Property object is documented here:
                // http://msdn.microsoft.com/en-us/library/envdte.property(v=vs.100).aspx
                // The Properties interface is documented here:
                // http://msdn.microsoft.com/en-us/library/envdte.properties(v=vs.100).aspx

                if (Preferences.LocalSettings.GetBool("SetProjectFileLocation", true) &&
                    !string.IsNullOrEmpty(scm.Connection.WorkspaceRoot))
                {
                    try
                    {
                        EnvDTE.Property prop = null;
                        EnvDTE.DTE      dte2;
                        dte2 = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));

                        EnvDTE.Properties generalPnS = dte2.get_Properties("Environment", "ProjectsAndSolution");
                        foreach (EnvDTE.Property temp in generalPnS)
                        {
                            prop = temp;
                            if (prop.Name == "ProjectsLocation")
                            {
                                if (Directory.Exists(scm.Connection.WorkspaceRoot))
                                {
                                    prop.Value = scm.Connection.WorkspaceRoot.Replace("/", "\\");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                        MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
#if DB_DEBUG
            P4VsOutputWindow.AppendMessage(string.Format("Leaving open connection, CurrentScm scm ID:{0}",
                                                         CurrentScm != null ? CurrentScm.__Id : -1));
#endif
        }
Пример #4
0
        // Get Revision button click
        private void newOKBtn_Click(object sender, EventArgs e)
        {
            bool        updateSolution = false;
            IVsSolution solution       = null;
            string      path           = _scm.SolutionFile;

            IList <IVsHierarchy> projectsUpdating    = new List <IVsHierarchy>();
            IList <string>       projectsClosed      = new List <string>();
            IList <Guid>         projectsGuidsClosed = new List <Guid>();

            if (_isSolutionIncluded)
            {
                // Figure out a better test

                //updateSolution = _scm.SyncFile(
                //    new P4.SyncFilesCmdOptions(P4.SyncFilesCmdFlags.Preview, 1),
                //    path);

                updateSolution = true;
            }
            if (updateSolution)
            {
                if (DialogResult.Cancel == MessageBox.Show(
                        Resources.GetRevisionDlg_UpdatingSlnWarninig,
                        Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                {
                    return;
                }
                solution = (IVsSolution)P4VsProvider.Instance.GetService(typeof(SVsSolution));

                P4VsProvider.Instance.SuppressConnection = true;

                if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, null, 0))
                {
                    MessageBox.Show(Resources.Error_ClosingSolution, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else if (P4VsProvider.Instance.SccService.SelectedNodes != null)
            {
                bool needToAsk = true;
                foreach (VSITEMSELECTION pItem in P4VsProvider.Instance.SccService.SelectedNodes)
                {
                    if ((pItem.itemid == VSConstants.VSITEMID_ROOT) && (P4VsProvider.Instance.SccService.IsProjectControlled(pItem.pHier)))
                    {
#if VS2008
                        if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_UpdatingProjWarninig,
                                                                   Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                        {
                            return;
                        }
                        updateSolution = true;

                        solution = (IVsSolution)GetService(typeof(SVsSolution));

                        P4VsProvider.Instance.SuppressConnection = true;

                        if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, null, 0))
                        {
                            MessageBox.Show(Resources.Error_ClosingSolution, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
#else
                        IVsProject3 pProj = pItem.pHier as IVsProject3;
                        if (pProj != null)
                        {
                            if (needToAsk == true)
                            {
                                if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_UpdatingProjWarninig,
                                                                           Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                                {
                                    return;
                                }
                                needToAsk = false;
                            }
                            projectsUpdating.Add(pItem.pHier);

                            if (solution == null)
                            {
                                solution = (IVsSolution)P4VsProvider.Instance.GetService(typeof(SVsSolution));
                            }
                            Guid projGuid;
                            solution.GetGuidOfProject(pItem.pHier, out projGuid);
                            projectsGuidsClosed.Add(projGuid);

                            if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, pItem.pHier, 0))
                            {
                                MessageBox.Show(Resources.Error_ClosingProject, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
#endif
                    }
                }
            }
            List <string> refreshItems = new List <string>();

            try
            {
                //change this to a better global validator
                int  test = 0;
                bool num  = int.TryParse(ValueTB.Text, out test);
                if (specifierRB.Checked == true &&
                    num == false &&
                    specifierCB.SelectedIndex == 0 &&
                    ValueTB.Text != "head" &&
                    ValueTB.Text != "have" &&
                    ValueTB.Text != "none"
                    )
                {
                    MessageBox.Show(string.Format(Resources.GetRevisionDlg_InvalidRevisionSpecifierWarninig, ValueTB.Text));
                    ValueTB.Text = string.Empty;
                    return;
                }
                ////////
                _files = new List <P4.FileSpec>();

                foreach (ListViewItem item in filesListView.Items)
                {
                    P4.FileSpec     file = new P4.FileSpec();
                    P4.FileMetaData fmd  = new P4.FileMetaData();
                    if (item.Text.EndsWith("/..."))
                    {
                        fmd.DepotPath = new P4.DepotPath(item.Text);
                    }
                    else
                    {
                        fmd = _scm.GetFileMetaData(item.Text);
                    }

                    if (fmd.LocalPath != null)
                    {
                        file.LocalPath = fmd.LocalPath;
                    }
                    if (fmd.ClientPath != null)
                    {
                        file.ClientPath = fmd.ClientPath;
                    }
                    if (fmd.DepotPath != null)
                    {
                        file.DepotPath = fmd.DepotPath;
                    }
                    _files.Add(file);
                    refreshItems.Add(item.Text.ToString());
                }

                P4.SyncFilesCmdFlags flags = new P4.SyncFilesCmdFlags();
                flags = P4.SyncFilesCmdFlags.None;
                if (forceChk.Checked == true)
                {
                    flags = P4.SyncFilesCmdFlags.Force;
                }

                P4.Options options = new P4.Options(flags, -1);

                // set up the list of paths with specifiers that we will sync to
                IList <P4.FileSpec> files = new List <P4.FileSpec>();
                //int idx = 0;

                if (specifierRB.Checked == true)
                {
                    // #revision
                    if (specifierCB.SelectedIndex == 0)
                    {
                        bool disconnectAfterSync = false;
                        int  number = 0;
                        bool isnum  = int.TryParse(Value, out number);
                        if (isnum == true)
                        {
                            if (number == 0)
                            {
                                if (_isSolutionIncluded)
                                {
                                    if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_RemovingSlnWarninig,
                                                                               Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                                    {
                                        this.DialogResult = DialogResult.Cancel;
                                        return;
                                    }
                                    disconnectAfterSync = true;
                                }
                                else
                                {
                                    if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_RemovingProjWarninig,
                                                                               Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                                    {
                                        this.DialogResult = DialogResult.Cancel;
                                        return;
                                    }
                                }
                            }
                        }
                        foreach (P4.FileSpec file in _files)
                        {
                            if (isnum == true)
                            {
                                // skip meta data check for rev 0 there is none, but we dtill want to allow
                                // this as a way to remove the local copy of the file, but still keep checking
                                // to make sure other bad revisions are not fetched such as file that was moved
                                if (number != 0)
                                {
                                    IList <P4.FileSpec> fs = new List <FileSpec>();
                                    file.Version = new P4.Revision(number);
                                    fs.Add(file);
                                    IList <P4.FileMetaData> fmd = _scm.GetFileMetaData(fs, null);
                                    if (fmd == null)
                                    {
                                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                                        {
                                            if (_files.Count == 1)
                                            {
                                                P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                            }
                                            P4VsOutputWindow.AppendMessage(_scm.Connection.Repository.Connection.LastResults.ErrorList[0].ToString());
                                        }
                                        continue;
                                    }
                                }
                                file.Version = new P4.Revision(number);
                            }
                            else if (Value == "head")
                            {
                                file.Version = new P4.HeadRevision();
                            }
                            else if (Value == "have")
                            {
                                file.Version = new P4.HaveRevision();
                            }
                            else if (Value == "none")
                            {
                                file.Version = new P4.NoneRevision();
                            }
                            files.Add(file);
                        }
                        if (files.Count > 0)
                        {
                            _scm.SyncFiles(options, files);
                        }
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            if (_scm.SccService == null)
                            {
                                return;
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            if (_scm.SccService == null)
                            {
                                return;
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        if (disconnectAfterSync)
                        {
                            P4VsProvider.Instance.SccService.Dispose();
                        }
                    }

                    // @workspace
                    if (specifierCB.SelectedIndex == 4)
                    {
                        foreach (P4.FileSpec file in _files)
                        {
                            file.Version = new P4.ClientNameVersion(Value.ToString());
                            files.Add(file);
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @date/time
                    if (specifierCB.SelectedIndex == 2)
                    {
                        DateTime value = dateTimePicker.Value;

                        string timestamp = value.Date.ToShortDateString() + ":" + value.TimeOfDay.ToString();

                        foreach (P4.FileSpec file in _files)
                        {
                            file.Version = new P4.DateTimeVersion(value);
                            files.Add(file);
                        }
                        _scm.SyncFiles(options, _files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @changelist
                    if (specifierCB.SelectedIndex == 1)
                    {
                        if (changelistFilesChk.Checked == true)
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.VersionRange(new P4.ChangelistIdVersion(Convert.ToInt16(Value)),
                                                                   new P4.ChangelistIdVersion(Convert.ToInt32(Value)));
                                files.Add(file);
                            }
                        }
                        else
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.ChangelistIdVersion(Convert.ToInt32(Value));
                                files.Add(file);
                            }
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @label
                    if (specifierCB.SelectedIndex == 3)
                    {
                        if (removeChk.Checked == true)
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.LabelNameVersion(Value.ToString());
                                files.Add(file);
                            }
                        }
                        else
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.VersionRange(new P4.LabelNameVersion(Value.ToString()),
                                                                   new P4.LabelNameVersion(Value.ToString()));
                                files.Add(file);
                            }
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                }

                else if (getLatestRB.Checked == true)
                {
                    files = _files;
                    _scm.SyncFiles(options, files);
                    if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                    {
                        IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                        foreach (P4.P4ClientError error in errors)
                        {
                            if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                            {
                                P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                return;
                            }
                        }
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                }
            }
            finally
            {
                if (updateSolution)
                {
                    if (path != null)
                    {
                        solution.OpenSolutionFile(0, path);
                    }
                    if (_scm.SccService != null)
                    {
                        _scm.SccService.ResetSelection();
                    }
                }
#if !VS2008
                else if (projectsUpdating.Count > 0)
                {
                    foreach (Guid projGuid in projectsGuidsClosed)
                    {
                        Guid rProjGuid = projGuid;

                        var vsSolution4 = (IVsSolution4)solution;
                        if (vsSolution4 != null)
                        {
                            int res = vsSolution4.ReloadProject(ref rProjGuid);
                        }
                    }
                }
#endif
                // now refresh the selected nodes' glyphs
                if (_scm.SccService != null)
                {
                    _scm.SccService.UpdateProjectGlyphs(refreshItems, true);
                }
            }
        }