示例#1
0
        public static IList <Client> GetClientList()
        {
            var result = new Perforce();

            var con = result.Repository?.Connection;

            if (con == null)
            {
                return(null);
            }

            con.UserName = result.Username;

            IList <Client> clients = null;

            try
            {
                con.Connect(null);
                var options = new ClientsCmdOptions(ClientsCmdFlags.None, result.Username, string.Empty, 64, string.Empty);
                clients = result.Repository.GetClients(options);
            }
            finally
            {
                con.Disconnect();
            }

            return(clients);
        }
示例#2
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            string P4Server    = ServerBox.Text;
            string P4Workspace = WorkspaceBox.Text;
            string P4User      = UserBox.Text;

            Console.WriteLine("Attempting connection...");

            Server     Svr  = new Server(new ServerAddress(P4Server));
            Repository Repo = new Repository(Svr);

            Repo.Connection.UserName = P4User;
            ClientsCmdOptions opts = new ClientsCmdOptions(ClientsCmdFlags.IgnoreCase, null, null, 10, null);

            Repo.Connection.SetClient(P4Workspace);

            Connect(Repo, false);
        }
示例#3
0
        public bool TryConnectFromPersistance()
        {
            if (HasSavedP4Data())
            {
                Console.WriteLine("Attempting connection from persistent data...");

                Server     Svr  = new Server(new ServerAddress(Settings.Default.LastP4Server));
                Repository Repo = new Repository(Svr);

                Repo.Connection.UserName = Settings.Default.LastP4User;
                ClientsCmdOptions opts = new ClientsCmdOptions(ClientsCmdFlags.IgnoreCase, null, null, 10, null);

                Repo.Connection.SetClient(Settings.Default.LastP4Workspace);

                return(Connect(Repo, true));
            }

            return(false);
        }
示例#4
0
        private void DiscoverClient(string path)
        {
            var con = this.Repository?.Connection;

            if (con == null)
            {
                return;
            }

            con.UserName = this.Username;

            try
            {
                if (!con.Connect(new Options()))
                {
                    return;
                }

                var options = new ClientsCmdOptions(ClientsCmdFlags.None, this.Username, string.Empty, 64, string.Empty);

                var clients = this.Repository.GetClients(options);

                foreach (var c in clients)
                {
                    if (c.Host == ClientHostName && c.Name == WorkspaceName)
                    {
                        if (PathHelper.PathIsChild(c.Root, path))
                        {
                            this.Client = c;
                            break;
                        }
                    }
                }
            }
            finally
            {
                con.Disconnect();
            }
        }
示例#5
0
        public WorkspaceBrowserDlg(RepoStorage repo, string sender)
        {
            PreferenceKey = "WorkspaceBrowserDlg";

            Repo = repo;
            InitializeComponent();

            if (components == null)
            {
                components = new Container();
            }
            //this.Icon = Images.icon_p4vs_16px;

            imageList1 = new System.Windows.Forms.ImageList(components);

            //
            // imageList1
            //
            imageList1.TransparentColor = System.Drawing.Color.Transparent;
            imageList1.Images.Add("workspace_icon.png", Images.workspace_icon);

            this.listView1.LargeImageList = this.imageList1;
            this.listView1.SmallImageList = this.imageList1;

            if (Repo != null)
            {
                ClientsCmdOptions opts = new ClientsCmdOptions(ClientsCmdFlags.None, null,
                                                               null, 0, null);
                try
                {
                    IList <Client> workspaces = Repo.rep.GetClients(opts);
                    foreach (Client workspace in workspaces)
                    {
                        string id = workspace.Name;

                        DateTime localAccess = workspace.Accessed;

                        // we need a pref for local time, until then, don't do this:
                        //DateTime localAccess = TimeZone.CurrentTimeZone.ToLocalTime(user.Accessed);
                        string access = "";
                        //if (Preferences.LocalSettings.GetBool("P4Date_format", true))
                        //{
                        //    access = localAccess.ToString("yyyy/MM/dd HH:mm:ss");
                        //}
                        //else
                        //{
                        access = string.Format("{0} {1}", localAccess.ToShortDateString(),
                                               localAccess.ToShortTimeString());
                        //}

                        string lastAccessed = access;
                        string email        = workspace.OwnerName;
                        string name         = workspace.Description;

                        string[]     theUser = new string[] { id, email, lastAccessed, name };
                        ListViewItem lvi     = new ListViewItem(theUser);
                        lvi.Tag        = workspace;
                        lvi.ImageIndex = 0;
                        listView1.Items.Add(lvi);
                    }
                }
                catch (Exception ex)
                {
                    Message dlg = new Message(Properties.Resources.MessageDlg_Exception, ex.Message);
                    dlgCancelled = true;
                    dlg.ShowDialog();
                }
            }
            ClosedByDoubleClick = false;
        }
示例#6
0
        private void NewWorkspaceBtn_Click(object sender, EventArgs e)
        {
            this.TopMost = false;

            RepoStorage repo = SetRepoFromDlg();

            if (repo != null && CheckConnection(repo) && CheckLogin(repo))
            {
                Client workspace  = null;
                Client clientInfo = new Client();
                string newName    = GetStringDlg.Show(Properties.Resources.OpenConnectionDlg_NewWorkspaceDlgTitle,
                                                      Properties.Resources.OpenConnectionDlg_NewWorkspaceDlgPrompt, null);
                if ((newName != null) && (newName != string.Empty))
                {
                    if (newName.Contains(" "))
                    {
                        MessageBox.Show(Properties.Resources.OpenConnectionDlg_NameContainsSpacesWarning, Properties.Resources.P4EXP,
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    ClientsCmdOptions opts = new ClientsCmdOptions(ClientsCmdFlags.None, null, newName, 1, null);
                    //IList<Client> checkExisting = _scm.getClients(ClientsCmdFlags.None, null, newName, 1, null);
                    IList <Client> checkExisting = repo.rep.GetClients(opts);

                    if (checkExisting == null)
                    {
                        clientInfo = repo.rep.GetClient(newName);
                        if (clientInfo != null)
                        {
                            // adjust root here based on users dir
                            string root = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                            int    idx  = root.LastIndexOf(@"\");
                            root            = root.Remove(idx + 1);
                            root           += newName;
                            clientInfo.Root = root;
                            workspace       = DlgEditWorkspace.EditWorkspace(repo, clientInfo);
                        }
                    }
                    else
                    {
                        MessageBox.Show(string.Format(Properties.Resources.OpenConnectionDlg_WorkspaceExistsWarning, newName),
                                        Properties.Resources.P4EXP, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NewWorkspaceBtn_Click(null, null);
                    }
                }
                else
                {
                    if (newName == string.Empty)
                    {
                        MessageBox.Show(Properties.Resources.OpenConnectionDlg_EmptyWorkspaceNameWarning,
                                        Properties.Resources.P4EXP, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NewWorkspaceBtn_Click(null, null);
                    }
                }
                if (workspace != null)
                {
                    WorkspaceTB.Text = workspace.Name;
                }
            }
            this.TopMost = true;
        }
示例#7
0
        public void ConnectWS()
        {
            Server srv = new Server(new ServerAddress(P4PORT));

            p4 = new Repository(srv);

            con             = p4.Connection;
            con.UserName    = P4USER;
            con.Client      = new Client();
            con.Client.Name = P4CLIENT;

            connected = con.Connect(null);
            if (connected)
            {
                try
                {
                    // Attempt a Login
                    Credential cred = con.Login(P4PASSWD);

                    // Get workspace name
                    ClientsCmdOptions opts    = new ClientsCmdOptions(ClientsCmdFlags.None, P4USER, null, 10, null);
                    IList <Client>    clients = p4.GetClients(opts);

                    var wsList = new List <string>();

                    foreach (var client in clients)
                    {
                        wsList.Add(client.Name.ToString());
                    }

                    // Check to exist the workspace
                    if (wsList.Contains(P4CLIENT))
                    {
                        btnConnect.BackgroundImage = Properties.Resources.icon_Connect_On;
                        gbDropArea.AllowDrop       = true;

                        Console.WriteLine("Connected!");
                    }
                    else
                    {
                        DisconnectWS();

                        MessageBox.Show(P4CLIENT + " は存在しないワークスペースです。\n" +
                                        "設定を確認してください。");
                        Console.WriteLine("The workspace doesn't exist!");

                        OpenFormCon();
                    }
                }
                catch (P4Exception e)
                {
                    connected = false;
                    btnConnect.BackgroundImage = Properties.Resources.icon_Connect;

                    MessageBox.Show("接続に失敗しました。\n設定を確認してください");
                    Console.WriteLine("Couldn't connect P4-Server!\n {0} : {1}", e.ErrorCode, e.Message);

                    OpenFormCon();
                }
            }
        }