Exemple #1
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            // Save the data from our current view control
            if (currentViewControl != null)
            {
                currentViewControl.SaveData();
            }

            // Close our connection
            try
            {
                ManagementInterfaceClient.Disconnect();
            }
            catch
            {
            }

            // Clear out our greeting cache
            string greetingsCacheFolder = WOSI.Utilities.FileUtils.GetApplicationRelativePath(Properties.Settings.Default.GreetingsSoundCache);

            if (WOSI.Utilities.FileUtils.GetDirectorySize(greetingsCacheFolder) >= 100000000)
            {
                Directory.Delete(greetingsCacheFolder, true);
            }

            // Clear out our voicemail cache
            string voicemailCacheFolder = WOSI.Utilities.FileUtils.GetApplicationRelativePath(Properties.Settings.Default.VoicemailSoundCache);

            if (WOSI.Utilities.FileUtils.GetDirectorySize(voicemailCacheFolder) >= 100000000)
            {
                Directory.Delete(voicemailCacheFolder, true);
            }

            // Unload our pluings
            PluginManager.UnloadPlugins();

            if (Properties.Settings.Default.DisplayShutdownDialog)
            {
                if (connectionError == false)
                {
                    Forms.ShutownForm shutdownForm = new CallButler.Manager.Forms.ShutownForm();

                    shutdownForm.ShowDialog();
                }
            }
        }
        private ConnectionResponse TryConnection(string server, int port, string password, int timeoutInSeconds)
        {
            ConnectionResponse response = ConnectionResponse.UnableToConnect;

            global::Controls.LoadingDialog.ShowDialog(null, String.Format(CallButler.Manager.Utils.PrivateLabelUtils.ReplaceProductName(Properties.LocalizedStrings.MainForm_ConnectingTo), server), Properties.Resources.loading, false, 0);

            // Try connecting
            DateTime endTime = DateTime.Now.AddSeconds(timeoutInSeconds);

            while (true)
            {
                try
                {
                    ManagementInterfaceClient.Connect(server, port, password);
                    response = ConnectionResponse.Connected;
                    break;
                }
                catch (Exception ex)
                {
                    if ((ex is System.Runtime.Remoting.RemotingException || ex is Exception) && ex.Message.Contains("Failed to authenticate"))
                    {
                        response = ConnectionResponse.FailedToAuthenticate;
                    }
                    else if ((ex is System.Runtime.Remoting.RemotingException || ex is Exception) && ex.Message.Contains("Remote Management not allowed"))
                    {
                        response = ConnectionResponse.RemoteManagementNotAllowed;
                    }
                }

                if (timeoutInSeconds == 0)
                {
                    break;
                }

                System.Threading.Thread.Sleep(1000);
            }

            return(response);
        }