InitManager.cs 3.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
using Linphone.Core;
using System;
using System.IO;
using Windows.Storage;


namespace Linphone.Agents
{
    /// <summary>
    /// Class to handle the initialization process of the application
    /// </summary>
    public static class InitManager
    {
        /// <summary>
        /// Get the path of the default config file stored in the package
        /// </summary>
        /// <returns>The path of the default config file</returns>
        public static String GetDefaultConfigPath()
        {
            return Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Assets", "linphonerc");
        }

        /// <summary>
        /// Get the path of the config file stored in the Isolated Storage
        /// </summary>
        /// <returns>The path of the config file</returns>
        public static String GetConfigPath()
        {
            return Path.Combine(ApplicationData.Current.LocalFolder.Path, "linphonerc");
        }

        /// <summary>
        /// Get the path of the factory config file stored in the package
        /// </summary>
        /// <returns>The path of the factory config file</returns>
        public static String GetFactoryConfigPath()
        {
            return "Assets/linphonerc-factory";
        }

        /// <summary>
        /// Get the path of the database file used to store chat messages stored in the Isolated Storage
        /// </summary>
        /// <returns>The path of the config file</returns>
        public static String GetChatDatabasePath()
        {
            return Path.Combine(ApplicationData.Current.LocalFolder.Path, "chat.db");
        }

        /// <summary>
        /// Configure the Logger
        /// </summary>
        /// <param name="server">The out-of-process server</param>
        /// <param name="level">The log level to use for the Logger</param>
        public static void ConfigureLogger(Linphone.Core.OutOfProcess.Server server, OutputTraceLevel level)
        {
            server.LinphoneCoreFactory.SetLogLevel(level);
            Logger.Instance.TraceListener = server.BackgroundModeLogger;
        }

        /// <summary>
        /// Create the linphone core and set some basic configuration values
        /// </summary>
        /// <param name="server">The out-of-process server</param>
        /// <param name="listener">The LinphoneCoreListener</param>
        /// <param name="level">The log level to use for the Logger</param>
        public static void CreateLinphoneCore(Linphone.Core.OutOfProcess.Server server, LinphoneCoreListener listener, OutputTraceLevel level)
        {
            LpConfig config = server.LinphoneCoreFactory.CreateLpConfig(GetConfigPath(), GetFactoryConfigPath());
            ConfigureLogger(server, level);
            server.LinphoneCoreFactory.CreateLinphoneCore(listener, config);
72 73
            server.LinphoneCore.RootCA = "Assets/rootca.pem";
            server.LinphoneCore.ChatDatabasePath = GetChatDatabasePath();
74 75 76 77
            server.LinphoneCore.SetUserAgent(Customs.UserAgent, Linphone.Version.Number);
        }
    }
}