Ejemplo n.º 1
0
        private void OptionChanged(AreaInitMode newOption)
        {
            Result = newOption;

            NotifyPropertyChanged("HostFieldVisibility");
            OkCommand.RaiseCanExecuteChanged();
        }
Ejemplo n.º 2
0
        public AreaVM(string path, string name, AreaInitMode areaInitMode, string host = null, int port = 0)
        {
            RefreshCommand = new DelegateCommand(Refresh);
            PullCommand = new DelegateCommand(Pull);
            PushCommand = new DelegateCommand(Push);

            _name = name;

            DirectoryInfo dir = new DirectoryInfo(path);
            switch (areaInitMode)
            {
                case AreaInitMode.Clone:
                    // Spawn another dialog for the source (or put it in the Clone New button)
                    Client client = new Client(dir);
                    if (client.Connect(host, port, null, true))
                    {
                        bool result = client.Clone(true);
                        if (!result)
                            result = client.Clone(false);
                        if (result)
                        {
                            string remoteName = "default";
                            client.Workspace.SetRemote(client.Host, client.Port, client.Module, remoteName);
                            client.Pull(false, client.Workspace.CurrentBranch.ID.ToString());
                            _area = Area.Load(client.Workspace.Root);
                            _area.Checkout(null, false, false);
                            client.SyncRecords();
                        }
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Couldn't connect to {0}:{1}", host, port), "Clone Failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    client.Close();
                    break;
                case AreaInitMode.InitNew:
                    // Tell versionr to initialize at path
                    try
                    {
                        dir.Create();
                    }
                    catch
                    {
                        MessageBox.Show("Error - couldn't create subdirectory \"{0}\"", dir.FullName);
                        break;
                    }
                    _area = Area.Init(dir, name);
                    break;
                case AreaInitMode.UseExisting:
                    // Add it to settings and refresh UI, get status etc.
                    _area = Area.Load(dir);
                    break;
            }
        }
Ejemplo n.º 3
0
        public void Init(string path, AreaInitMode areaInitMode, string host, int port, Action <AreaVM, string, string> afterInit)
        {
            Load(() =>
            {
                DirectoryInfo dir = new DirectoryInfo(path);
                string title      = String.Empty;
                string message    = String.Empty;
                switch (areaInitMode)
                {
                case AreaInitMode.Clone:
                    OperationStatusDialog.Start("Clone");
                    Client client = new Client(dir);
                    if (client.Connect(Client.ToVersionrURL(host, port, null), true))
                    {
                        bool result = client.Clone(true);
                        if (!result)
                        {
                            result = client.Clone(false);
                        }
                        if (result)
                        {
                            string remoteName = "default";
                            client.Workspace.SetRemote(Client.ToVersionrURL(client.Host, client.Port, client.Module), remoteName);
                            client.Pull(false, client.Workspace.CurrentBranch.ID.ToString());
                            Area = Area.Load(client.Workspace.Root);
                            Area.Checkout(null, false, false);
                        }
                    }
                    else
                    {
                        title   = "Clone Failed";
                        message = $"Couldn't connect to {host}:{port}";
                    }
                    client.Close();
                    OperationStatusDialog.Finish();
                    break;

                case AreaInitMode.InitNew:
                    // Tell versionr to initialize at path
                    try
                    {
                        dir.Create();
                    }
                    catch
                    {
                        title   = "Init Failed";
                        message = $"Couldn't create subdirectory \"{dir.FullName}\"";
                        break;
                    }
                    Area = Area.Init(dir, m_Name);
                    break;

                case AreaInitMode.UseExisting:
                    // Add it to settings and refresh UI, get status etc.
                    Area = Area.Load(dir);
                    if (Area == null)
                    {
                        title   = "Missing workspace";
                        message = $"Failed to load \"{m_Name}\". The location {path} may be have been removed.";
                    }
                    break;
                }
                RefreshAll();
                NotifyPropertyChanged(nameof(Directory));
                NotifyPropertyChanged(nameof(IsValid));
                NotifyPropertyChanged(nameof(Remotes));
                NotifyPropertyChanged(nameof(Status));
                NotifyPropertyChanged(nameof(Settings));
                NotifyPropertyChanged(nameof(Branches));
                MainWindow.Instance.Dispatcher.Invoke(afterInit, this, title, message);
            });
        }
Ejemplo n.º 4
0
        public static AreaVM Create(string name, string path, Action <AreaVM, string, string> afterInit, AreaInitMode areaInitMode, string host = null, int port = 0)
        {
            AreaVM area = new AreaVM(name);

            area.Init(path, areaInitMode, host, port, afterInit);
            return(area);
        }
Ejemplo n.º 5
0
        private void OptionChanged(AreaInitMode newOption)
        {
            Result = newOption;

            NotifyPropertyChanged("HostFieldVisibility");
            OkCommand.RaiseCanExecuteChanged();
        }