Ejemplo n.º 1
0
 private ServerSingleton()
 {
     ServerClient = new ServerClient();
 }
Ejemplo n.º 2
0
        void WaitForRdpCapturePkg(object data)
        {
            var rdpTokenId = (string)data;
            int retry      = 0;

            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
            {
                this.Hide();   // Disappear while RDP session is in progress
            }));
            while (true)
            {
                try
                {
                    var resp    = Server.SendRequest("RdpInfo", false, "&token=" + rdpTokenId);
                    var rdpInfo = ServerClient.DeserializeJson <RdpInfoData>(resp);
                    if (rdpInfo != null)
                    {
                        if (rdpInfo.status == (int)RdpTokenStatus.PkgBuilt &&
                            rdpInfo.pkgId != null && rdpInfo.pkgId != lastPkgId)
                        {
                            lastPkgId = rdpInfo.pkgId;
                            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                            {
                                var pkgInfo = Server.AppDetails(lastPkgId, false);
                                PkgIconPath = pkgInfo.IconUrl;                           // ToDo
                                PkgAppName  = pkgInfo.AppID;                             // ToDo
                                PkgLocation = Server.ServerUrl() + "/apps/" + lastPkgId; // ?auth= must be added by consuming functions

                                // Show form and bring it to front
                                this.WindowState = WindowState.Minimized;
                                this.Show();   // Restore
                                this.WindowState = WindowState.Normal;

                                DisplayResultingPkg();
                            }));
                            //break;
                        }
                        //if (rdpInfo.status >= (int)RdpTokenStatus.Error)
                        if (rdpInfo.status != (int)RdpTokenStatus.PkgBuilt &&
                            rdpInfo.status != (int)RdpTokenStatus.ApplicationReady)   // The only other correct value
                        {
                            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                            {
                                this.Show();   // Restore
                                DisplayError("Failed creating package. Please retry.");
                            }));
                            break;
                        }
                    }
                    retry = 0;   // No technical error
                }
                catch
                {
                    if (retry++ >= 3)
                    {
                        Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                        {
                            this.Show();   // Restore
                            DisplayError("Failed creating package (b). Please retry.");
                        }));
                        break;
                    }
                }
                Thread.Sleep(5 * 1000);
            }
        }