Пример #1
0
        public ConnectViewModel(MainModel model, IEventAggregator events)
        {
            this.config     = model.Config;
            this.connection = model.Connection;
            this.events     = events;

            this.config.Bind(s => s.MainConfig, (o, e) =>
            {
                this.LoadFromConfig();
            });

            this.connection.Bind(s => s.IsConnected, (o, e) =>
            {
                this.RefreshRunningInstances();
                this.NotifyOfPropertyChange(() => CanRefreshRunningInstances);
                this.NotifyOfPropertyChange(() => CanCreate);
                this.NotifyOfPropertyChange(() => CanReconnectInstance);
                this.NotifyOfPropertyChange(() => CanTerminateInstance);
                var spotPriceTask = this.RefreshCurrentSpotPriceAsync();
            });

            this.Bind(s => s.ActiveInstanceType, (o, e) => Task.Run(() => this.RefreshCurrentSpotPriceAsync()));

            this.DisplayName = "Create New Instance";
            this.LoadFromConfig();

            this.ActiveInstanceType    = this.InstanceTypes.FirstOrDefault(x => x.Key == "t1.micro");
            this.ActiveRunningInstance = this.RunningInstances[0];

            this.RefreshRunningInstances();
            var spotPriceTaskMain = this.RefreshCurrentSpotPriceAsync();
        }
Пример #2
0
        public InstanceViewModel(InstanceDetailsViewModel instanceDetailsModel, Logger logger, Config config, Ec2Connection connection, IVolumeViewModelFactory volumeViewModelFactory, IWindowManager windowManager)
        {
            this.Logger                 = logger;
            this.config                 = config;
            this.connection             = connection;
            this.volumeViewModelFactory = volumeViewModelFactory;
            this.windowManager          = windowManager;
            this.uptimeTimer            = new System.Timers.Timer();
            this.uptimeTimer.Elapsed   += async(o, e) =>
            {
                // This also acts as our attempt to reconnect if the connection drops....
                if (this.Client == null)
                {
                    this.uptimeTimer.Stop();
                }
                else
                {
                    this.Uptime = await this.Client.GetUptimeAsync(this.Logger);
                }
            };
            this.uptimeTimer.AutoReset = true;
            this.uptimeTimer.Interval  = 3000;

            instanceDetailsModel.Logger = logger;

            this.VolumeTypes = new BindableCollection <VolumeType>()
            {
                new VolumeType(null, "Loading...", null)
            };
            this.SelectedVolumeType = this.VolumeTypes[0];

            this.ActivateItem(instanceDetailsModel);
        }
Пример #3
0
        public MainModel(Config config, Ec2Connection connection)
        {
            this.Config     = config;
            this.Connection = connection;

            this.Config.MainConfig.Bind(s => s.AwsAccessKey, (o, e) => this.ReconnectConnection());
            this.Config.MainConfig.Bind(s => s.AwsSecretKey, (o, e) => this.ReconnectConnection());

            this.ReconnectConnection();
        }
Пример #4
0
        public VolumeViewModel(
            Logger logger,
            IWindowManager windowManager,
            Ec2Connection connection,
            ICreateSnapshotDetailsViewModelFactory createSnapshotDetailsViewModelFactory,
            IScriptDetailsViewModelFactory scriptDetailsViewModelFactory)
        {
            this.Logger        = logger;
            this.windowManager = windowManager;
            this.connection    = connection;
            this.createSnapshotDetailsViewModelFactory = createSnapshotDetailsViewModelFactory;
            this.scriptDetailsViewModelFactory         = scriptDetailsViewModelFactory;

            this.SelectedScript = this.Scripts[0];
        }
        public ManageFriendsViewModel(IWindowManager windowManager, Config config, Ec2Connection connection)
        {
            this.DisplayName = "Manage Friends";

            this.windowManager   = windowManager;
            this.config          = config;
            this.snapshotBrowser = connection.CreateSnapshotBrowser();

            var getUserIdTask = connection.GetUserIdAsync();

            getUserIdTask.ContinueWith(t => this.OwnUserId = t.Result, TaskContinuationOptions.OnlyOnRanToCompletion);
            getUserIdTask.ContinueWith(t => System.Windows.MessageBox.Show("Error occurred finding user ID\n" + t.Exception.Format(), "Error occurred finding User ID", System.Windows.MessageBoxButton.OK), TaskContinuationOptions.OnlyOnFaulted);

            this.ShowOfficialImages = config.MainConfig.ShowOfficialImages;
            this.Friends            = new BindableCollection <FriendModel>(config.FriendsWithoutDefaults.Select(x => new FriendModel(x, snapshotBrowser)));

            this.Bind(x => x.SelectedFriend, (o, e) => this.NotifyOfPropertyChange(() => this.CanEditFriend));
            this.Bind(x => x.SelectedFriend, (o, e) => this.NotifyOfPropertyChange(() => this.CanDeleteFriend));

            this.Bind(x => x.FriendBeingEdited, (o, e) => this.NotifyOfPropertyChange(() => this.CanAddFriend));
            this.Bind(x => x.FriendBeingEdited, (o, e) => this.NotifyOfPropertyChange(() => this.CanEditFriend));
            this.Bind(x => x.FriendBeingEdited, (o, e) => this.NotifyOfPropertyChange(() => this.CanSave));
        }
Пример #6
0
        public ShellViewModel(ConnectViewModel connectModel,
                              IEventAggregator events,
                              IWindowManager windowManager,
                              Config config,
                              Ec2Connection connection,
                              VersionManager versionManager,
                              IInstanceViewModelFactory instanceViewModelFactory,
                              ITerminateInstanceViewModelFactory terminateInstanceViewModelFactory)
        {
            this.DisplayName                       = "Ec2Manager";
            this.windowManager                     = windowManager;
            this.config                            = config;
            this.connection                        = connection;
            this.versionManager                    = versionManager;
            this.instanceViewModelFactory          = instanceViewModelFactory;
            this.terminateInstanceViewModelFactory = terminateInstanceViewModelFactory;

            this.Bind(s => s.ActiveItem, (o, e) => this.NotifyOfPropertyChange(() => SubActiveItem));
            this.connection.Bind(s => s.IsConnected, (o, e) => this.NotifyOfPropertyChange(() => CanManageFriends));

            events.Subscribe(this);

            this.ActivateItem(connectModel);
        }