Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SharedWindowsViewModel"/> class.
        ///     Initializes a new instance of the <see cref="RemoteViewerViewModel"/> class.
        /// </summary>
        /// <param name="screen">
        /// The screen.
        /// </param>
        /// <param name="remoteHost">
        /// The favorite.
        /// </param>
        /// <param name="shareableWindows">
        /// The shareable Windows.
        /// </param>
        /// <param name="header">
        /// The header.
        /// </param>
        public SharedWindowsViewModel(IScreen screen, RemoteHost remoteHost, IObservableCache<ShareableWindow, IntPtr> shareableWindows, string header)
        {
            this.HostScreen = screen;
            this.RemoteHost = remoteHost;

            this.Header = header;

            // create proxy objects from source cache to have individual instances per RemoteHost
            this.cleanUp = shareableWindows.Connect().Transform(
                window => {
                    // observe IsShared property and update header if necessary
                    var w = new RemoteHostShareableWindow(window);
                    w.WhenPropertyChanged(shareableWindow => shareableWindow.IsShared).Subscribe(
                        shareableWindow => this.RaisePropertyChanged("Header"));

                    w.WhenPropertyChanged(shareableWindow => shareableWindow.IsShared).Subscribe( x => {
                        if (x.Value)
                            RemoteContext.Instance.ShareWindows(
                                remoteHost.Name,
                                this.shareableWindows.Select(sw => new Window() { Id = sw.Handle.ToString(), Name = sw.ProcessName }).ToList());
                    });

                    //w.WhenAnyValue(x => x.IsShared).Where(x => x)
                    //    .Subscribe(x => RemoteContext.Instance.ShareWindows(
                    //        remoteHost.Name, this.shareableWindows.Select(sw => new Window() { Id = sw.Handle.ToString(), Name = sw.ProcessName }).ToList()));

                    return w;
                }).ObserveOnDispatcher().Bind(out this.shareableWindows).Subscribe();

            // Update Header when Number of windows changed, maybe a shared window has been removed
            this.shareableWindows.WhenPropertyChanged(windows => windows.Count).Subscribe(windows => this.RaisePropertyChanged("Header"));
        }
Example #2
0
        /// <summary>
        ///     create new remotehost instance
        /// </summary>
        /// <param name="name">Hostname</param>
        /// <param name="ip">IPAddress</param>
        /// <returns></returns>
        private RemoteHost CreateRemoteHost(string name, string ip)
        {
            if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(ip))
                throw new ArgumentException("Please enter either IPAddress or Hostname!");

            // create new remotehost
            var rh = new RemoteHost { IpAddress = ip, Name = name };

            // add some information if missing
            var ns = new NetworkServices();
            if (string.IsNullOrEmpty(name))
                rh.Name = ns.GetHostnameByIp(ip);
            else if (string.IsNullOrEmpty(ip)) // in case of quickadd, any input will be provided in name attribute, so we have to check for ip or name
                if (ns.IsValidIpAddress(name)) {
                    rh.IpAddress = name;
                    rh.Name = ns.GetHostnameByIp(rh.IpAddress);
                } else
                    rh.IpAddress = ns.GetIpByHostname(name);

            rh.Name = rh.Name.ToUpper();

            // add first tab for "my shares"
            rh.Tabs.Add(new SharedWindowsViewModel(this.HostScreen, rh, this.ShareableWindows.AsObservableCache(), "My Shares"));

            return rh;
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteViewerViewModel"/> class.
 /// </summary>
 /// <param name="screen">
 /// The screen.
 /// </param>
 /// <param name="remoteHost">
 /// The favorite.
 /// </param>
 /// <param name="tabName">
 /// The tab name.
 /// </param>
 public RemoteViewerViewModel(IScreen screen, RemoteHost remoteHost, string tabName)
 {
     this.HostScreen = screen;
     this.RemoteHost = remoteHost;
     this.Header = tabName;
 }