Example #1
0
        public async Task <bool> ToggleLoggingEnabledDisabledAsync()
        {
            CheckDisposed();
            IsBusy = true;

            try
            {
                bool enabled;

                if (session != null)
                {
                    string finalLogFilePath = await CloseSessionSaveFinalLogFile();

                    session.Dispose();
                    session = null;
                    if (StatusChanged != null)
                    {
                        StatusChanged.Invoke(this, new FileLogEventArgs(FileLogEventType.LogFileGeneratedAtDisable, finalLogFilePath));
                    }
                    ApplicationData.Current.LocalSettings.Values[LOGGING_ENABLED_SETTING_KEY_NAME] = false;
                    enabled = false;
                }

                else
                {
                    StartLogging();
                    ApplicationData.Current.LocalSettings.Values[LOGGING_ENABLED_SETTING_KEY_NAME] = true;
                    enabled = true;
                }

                if (StatusChanged != null)
                {
                    StatusChanged.Invoke(this, new FileLogEventArgs(enabled));
                }

                return(enabled);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #2
0
        /// <summary>
        /// SAMPLE CODE Prepare this scenario for suspend.
        /// </summary>
        /// <returns>
        /// Void Task.
        /// </returns>
        public async Task PrepareToSuspendAsync()
        {
            CheckDisposed();

            if (localFileLogSession != null)
            {
                IsPreparingForSuspend = true;

                try
                {
                    // Before suspend, save any final log file.
                    string finalFileBeforeSuspend = await CloseSessionSaveFinalLogFile();

                    localFileLogSession.Dispose();
                    localFileLogSession = null;

                    // Save values used when the app is resumed or started later. Logging is enabled.
                    CommonLocalSettings.LoggingEnabled = true;

                    // Save the log file name saved at suspend so the sample UI can be updated on
                    // resume with that information.
                    ApplicationData.Current.LocalSettings.Values["LogFileGeneratedBeforeSuspend"] = finalFileBeforeSuspend;
                }
                finally
                {
                    IsPreparingForSuspend = false;
                }
            }
            else
            {
                // Save values used when the app is resumed or started later. Logging is not enabled
                // and no log file was saved.
                CommonLocalSettings.LoggingEnabled = false;
                ApplicationData.Current.LocalSettings.Values["LogFileGeneratedBeforeSuspend"] = null;
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (isDisposed == false)
            {
                isDisposed = true;

                if (disposing)
                {
                    if (channel != null)
                    {
                        channel.Dispose();
                        channel = null;
                    }

                    if (session != null)
                    {
                        session.Dispose();
                        session = null;
                    }
                }
            }
        }