static void Main(string[] args)
        {
            try
            {
                m_storageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;
                m_connStr     = AppState.GetConfigSetting(m_connStrKey);

                CustomerSessionManager customerSessionManager = new CustomerSessionManager(m_storageType, m_connStr);
                SSHServerDaemon        daemon = new SSHServerDaemon(customerSessionManager);

                if (args != null && args.Length == 1 && args[0].StartsWith("-c"))
                {
                    Console.WriteLine("SSH Server starting");

                    Thread daemonThread = new Thread(daemon.Start);
                    daemonThread.Start();

                    m_serverUp.WaitOne();
                }
                else
                {
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception Main. " + excp.Message);
            }
        }
Ejemplo n.º 2
0
        public void ExecuteNonQuery(StorageTypes storageType, string dbConnString, string query,
                                    Dictionary <string, object> parameters)
        {
            try
            {
                using (IDbConnection dbConn = GetDbConnection(storageType, dbConnString))
                {
                    dbConn.Open();
                    IDbCommand command = GetDbCommand(storageType, dbConn, query);

                    if (parameters != null && parameters.Count > 0)
                    {
                        foreach (KeyValuePair <string, object> parameter in parameters)
                        {
                            command.Parameters.Add(GetDbParameter(storageType, parameter.Key, parameter.Value));
                        }
                    }

                    command.ExecuteNonQuery();
                }
            }
            catch (Exception excp)
            {
                Logger.Logger.Error("Exception ExecuteNonQuery. ->" + excp.Message);
                throw excp;
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                logger.Debug("SIP Notifier starting");

                m_sipNotifierStorageType    = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;;
                m_sipNotifierStorageConnStr = AppState.GetConfigSetting(m_connStrKey);

                if (m_sipNotifierStorageType == StorageTypes.Unknown || m_sipNotifierStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The SIP Notifier cannot start with no persistence settings.");
                }

                if (m_sipNotifierStorageType == StorageTypes.XML && !Directory.Exists(m_sipNotifierStorageConnStr))
                {
                    throw new ApplicationException("Directory " + m_sipNotifierStorageConnStr + " does not exist for XML persistor.");
                }

                SIPAssetPersistor <Customer> customerPersistor = SIPAssetPersistorFactory <Customer> .CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_customersXMLFilename);

                SIPAssetPersistor <SIPAccount> sipAccountsPersistor = SIPAssetPersistorFactory <SIPAccount> .CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_sipAccountsXMLFilename);

                SIPAssetPersistor <SIPRegistrarBinding> sipRegistrarBindingsPersistor = SIPAssetPersistorFactory <SIPRegistrarBinding> .CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_registrarBindingsXMLFilename);

                SIPAssetPersistor <SIPDialogueAsset> sipDialoguePersistor = SIPAssetPersistorFactory <SIPDialogueAsset> .CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_sipDialoguesXMLFilename);

                SIPDomainManager sipDomainManager = new SIPDomainManager(m_sipNotifierStorageType, m_sipNotifierStorageConnStr);

                SIPNotifierDaemon daemon = new SIPNotifierDaemon(
                    customerPersistor.Get,
                    sipDialoguePersistor.Get,
                    sipDialoguePersistor.Get,
                    sipDomainManager.GetDomain,
                    sipAccountsPersistor,
                    sipRegistrarBindingsPersistor.Get,
                    sipAccountsPersistor.Get,
                    sipRegistrarBindingsPersistor.Count,
                    SIPRequestAuthenticator.AuthenticateSIPRequest,
                    null);

                if (args != null && args.Length == 1 && args[0].StartsWith("-c"))
                {
                    Thread daemonThread = new Thread(daemon.Start);
                    daemonThread.Start();
                    m_notifierUp.WaitOne();
                }
                else
                {
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception Main. " + excp.Message);
                logger.Error("Exception Main. " + excp.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                m_storageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;
                m_connStr = AppState.GetConfigSetting(m_connStrKey);

                CustomerSessionManager customerSessionManager = new CustomerSessionManager(m_storageType, m_connStr);
                SSHServerDaemon daemon = new SSHServerDaemon(customerSessionManager);

                if (args != null && args.Length == 1 && args[0].StartsWith("-c"))
                {
                    Console.WriteLine("SSH Server starting");

                    Thread daemonThread = new Thread(daemon.Start);
                    daemonThread.Start();

                    m_serverUp.WaitOne();
                }
                else
                {
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception Main. " + excp.Message);
            }
        }
Ejemplo n.º 5
0
        //private static TextWriter dbLinqLogWriter = new StreamWriter(@"C:\Temp\sipsorcery\dblinq.log", true, Encoding.ASCII);

        public static DataContext CreateDBLinqDataContext(StorageTypes storageType, string connectionString)
        {
            DataContext dataContext = null;

            //DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
            //new MySql.Data.MySqlClient.MySqlClientFactory();
            //DbProviderFactory factory = Npgsql.NpgsqlFactory.Instance;

            switch (storageType)
            {
            case StorageTypes.DBLinqMySQL:
                IDbConnection mySqlConn = new MySqlConnection(connectionString);
                dataContext = new DataContext(mySqlConn, m_mappingSource, new DbLinq.MySql.MySqlVendor());
                break;

            case StorageTypes.DBLinqPostgresql:
                IDbConnection npgsqlConn = new NpgsqlConnection(connectionString);
                dataContext = new DataContext(npgsqlConn, m_mappingSource, new DbLinq.PostgreSql.PgsqlVendor());
                break;

            default:
                throw new NotSupportedException("Database type " + storageType + " is not supported by CreateDBLinqDataContext.");
            }

            //dataContext.QueryCacheEnabled = true;
            //dataContext.Log = Console.Out;
            //dataContext.Log = dbLinqLogWriter;
            dataContext.ObjectTrackingEnabled = false;
            return(dataContext);
        }
Ejemplo n.º 6
0
        public object ExecuteScalar(StorageTypes storageType, string dbConnString, string query,
                                    Dictionary <string, object> parameters)
        {
            QuerySecurityCheck(query);

            try
            {
                using (IDbConnection dbConn = GetDbConnection(storageType, dbConnString))
                {
                    dbConn.Open();
                    IDbCommand command = GetDbCommand(storageType, dbConn, query);

                    if (parameters != null && parameters.Count > 0)
                    {
                        foreach (KeyValuePair <string, object> parameter in parameters)
                        {
                            command.Parameters.Add(GetDbParameter(storageType, parameter.Key, parameter.Value));
                        }
                    }

                    return(command.ExecuteScalar());
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception ExecuteScalar. " + excp.Message);
                throw excp;
            }
        }
Ejemplo n.º 7
0
        public SIPSorceryPersistor(StorageTypes storageType, string storageConnectionStr)
        {
            if (storageType == StorageTypes.XML)
            {
                if (!storageConnectionStr.Contains(":"))
                {
                    // Relative path.
                    storageConnectionStr = AppDomain.CurrentDomain.BaseDirectory + storageConnectionStr;
                }

                if (!storageConnectionStr.EndsWith(@"\"))
                {
                    storageConnectionStr += @"\";
                }

                if (!Directory.Exists(storageConnectionStr))
                {
                    throw new ApplicationException("Directory " + storageConnectionStr +
                                                   " does not exist for XML persistor.");
                }
            }

            m_sipAccountsPersistor =
                SIPAssetPersistorFactory <SIPAccount> .CreateSIPAssetPersistor(storageType, storageConnectionStr,
                                                                               m_sipAccountsXMLFilename);

            m_dialPlanPersistor =
                SIPAssetPersistorFactory <SIPDialPlan> .CreateSIPAssetPersistor(storageType, storageConnectionStr,
                                                                                m_sipDialplansXMLFilename);

            m_sipProvidersPersistor =
                SIPAssetPersistorFactory <SIPProvider> .CreateSIPAssetPersistor(storageType, storageConnectionStr,
                                                                                m_sipProvidersXMLFilename);

            m_sipProviderBindingsPersistor =
                SIPAssetPersistorFactory <SIPProviderBinding> .CreateSIPAssetPersistor(storageType, storageConnectionStr,
                                                                                       m_sipProviderBindingsXMLFilename);

            var sipDomainAssetPersistor =
                SIPAssetPersistorFactory <SIPDomain> .CreateSIPAssetPersistor(storageType, storageConnectionStr,
                                                                              m_sipProvidersXMLFilename);

            m_sipDomainManager             = new SIPDomainManager(sipDomainAssetPersistor);
            m_sipRegistrarBindingPersistor =
                SIPAssetPersistorFactory <SIPRegistrarBinding> .CreateSIPAssetPersistor(storageType, storageConnectionStr,
                                                                                        m_sipRegistrarBindingsXMLFilename);

            m_sipDialoguePersistor =
                SIPAssetPersistorFactory <SIPDialogueAsset> .CreateSIPAssetPersistor(storageType, storageConnectionStr,
                                                                                     m_sipDialoguesXMLFilename);

            m_sipCDRPersistor =
                SIPAssetPersistorFactory <SIPCDRAsset> .CreateSIPAssetPersistor(storageType, storageConnectionStr,
                                                                                m_sipCDRsXMLFilename);

            //if (m_sipCDRPersistor != null)
            //{
            //    ThreadPool.QueueUserWorkItem(delegate { WriteCDRs(); });
            //}
        }
Ejemplo n.º 8
0
 public IStorageItem GetItem(string path, StorageTypes itemType = StorageTypes.All,bool createIfNotExisted=false)
 {
     
     var absolutePath = new AbsolutePath(path, this);
     if (itemType.IsDirectory())
     {
         if (System.IO.Directory.Exists(absolutePath))
         {
             return new StorageDirectory(new DirectoryInfo(absolutePath), null, absolutePath.Storage);
         }
         else if(createIfNotExisted){
             var dir = new DirectoryInfo(absolutePath);
             dir.Create();
             return new StorageDirectory(dir, null, absolutePath.Storage);
         }
     }
     if (itemType.IsFile())
     {
         if (System.IO.File.Exists(absolutePath))
         {
             return new StorageFile(new FileInfo(absolutePath), null, absolutePath.Storage);
         }
         else if(createIfNotExisted){
             var info = new FileInfo(absolutePath);
             if (!info.Directory.Exists) info.Directory.Create();
             using (var s = info.Create()) { };
             return new StorageFile(info, null, absolutePath.Storage);
         }
     }
     return null;
 }
Ejemplo n.º 9
0
        public SIPSorceryPersistor(StorageTypes storageType, string storageConnectionStr)
        {
            if (storageType == StorageTypes.XML)
            {
                if (!storageConnectionStr.Contains(":"))
                {
                    // Relative path.
                    storageConnectionStr = AppDomain.CurrentDomain.BaseDirectory + storageConnectionStr;
                }

                if (!storageConnectionStr.EndsWith(@"\"))
                {
                    storageConnectionStr += @"\";
                }

                if (!Directory.Exists(storageConnectionStr))
                {
                    throw new ApplicationException("Directory " + storageConnectionStr + " does not exist for XML persistor.");
                }
            }

            m_sipAccountsPersistor = SIPAssetPersistorFactory<SIPAccount>.CreateSIPAssetPersistor(storageType, storageConnectionStr, m_sipAccountsXMLFilename);
            m_dialPlanPersistor = SIPAssetPersistorFactory<SIPDialPlan>.CreateSIPAssetPersistor(storageType, storageConnectionStr, m_sipDialplansXMLFilename);
            m_sipProvidersPersistor = SIPAssetPersistorFactory<SIPProvider>.CreateSIPAssetPersistor(storageType, storageConnectionStr, m_sipProvidersXMLFilename);
            m_sipProviderBindingsPersistor = SIPAssetPersistorFactory<SIPProviderBinding>.CreateSIPAssetPersistor(storageType, storageConnectionStr, m_sipProviderBindingsXMLFilename);
            m_sipDomainManager = new SIPDomainManager(storageType, storageConnectionStr);
            m_sipRegistrarBindingPersistor = SIPAssetPersistorFactory<SIPRegistrarBinding>.CreateSIPAssetPersistor(storageType, storageConnectionStr, m_sipRegistrarBindingsXMLFilename);
            m_sipDialoguePersistor = SIPAssetPersistorFactory<SIPDialogueAsset>.CreateSIPAssetPersistor(storageType, storageConnectionStr, m_sipDialoguesXMLFilename);
            m_sipCDRPersistor = SIPAssetPersistorFactory<SIPCDRAsset>.CreateSIPAssetPersistor(storageType, storageConnectionStr, m_sipCDRsXMLFilename);

            //if (m_sipCDRPersistor != null)
            //{
            //    ThreadPool.QueueUserWorkItem(delegate { WriteCDRs(); });
            //}
        }
Ejemplo n.º 10
0
		public AuditLog_other(StorageTypes storageType, string dbConnStr)
		{
			m_storageType = storageType;
			m_dbConnStr = dbConnStr;

			m_storageLayer = new StorageLayer(m_storageType, m_dbConnStr);
		}
Ejemplo n.º 11
0
        static WebState() {
            try {
                #region Configure logging.

                try {

                    log4net.Config.XmlConfigurator.Configure();
                    logger = log4net.LogManager.GetLogger(LOGGER_NAME);
                }
                catch (Exception logExcp) {
                    Console.WriteLine("Exception SIPProxyState Configure Logging. " + logExcp.Message);
                }

                #endregion

                CRMStorageType = (ConfigurationManager.AppSettings[m_storageTypeKey] != null) ? StorageTypesConverter.GetStorageType(ConfigurationManager.AppSettings[m_storageTypeKey]) : StorageTypes.Unknown;
                CRMStorageConnStr = ConfigurationManager.AppSettings[m_connStrKey];

                if (CRMStorageType == StorageTypes.Unknown || CRMStorageConnStr.IsNullOrBlank()) {
                    logger.Error("The SIPSorcery.CRM.Web does not have any persistence settings configured.");
                }

                XmlNode validationRulesNode = (XmlNode)ConfigurationManager.GetSection(CUSTOMER_VALIDATION_RULES);
                if (validationRulesNode != null) {
                    foreach (XmlNode validationNode in validationRulesNode) {
                         ValidationRules.Add(validationNode.SelectSingleNode("field").InnerText, validationNode.SelectSingleNode("rule").InnerText);
                    }
                }
            }
            catch (Exception excp) {
                logger.Error("Exception WebState. " + excp.Message);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Populates the data in the specified datagridview.
        /// Takes a dgv to be managed, type of storage and optionally a storeName to populate it with according data
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="stype"></param>
        /// <param name="OptioalStoreName"></param>
        static public void PopulateGridData(DataGridView dgv, StorageTypes stype, String OptioalStoreName = "")
        {
            dgv.Rows.Clear();

            List <Product> lp = new List <Product>();

            if (stype == StorageTypes.GLOBAL)
            {
                lp = Warehouse.GetAllProducts();
            }
            else
            {
                lp = Warehouse.GetAllProducts(OptioalStoreName);
            }
            if (dgv.Columns.Count < 4)
            {
                dgv.Columns.Add("colID", "ID");
                dgv.Columns.Add("colName", "Name");
                dgv.Columns.Add("colPrice", "Price");
                dgv.Columns.Add("colQuantity", "Qunatity");
            }
            dgv.Width = dgv.Columns.GetColumnsWidth(DataGridViewElementStates.None);
            foreach (ProductToSell p in lp)
            {
                dgv.Rows.Add(p.Id, p.Name, p.Price, p.Quantity);
            }
        }
Ejemplo n.º 13
0
        //private static TextWriter dbLinqLogWriter = new StreamWriter(@"C:\Temp\sipsorcery\dblinq.log", true, Encoding.ASCII);

        public static DataContext CreateDBLinqDataContext(StorageTypes storageType, string connectionString) {
            DataContext dataContext = null;
            //DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
            //new MySql.Data.MySqlClient.MySqlClientFactory();
            //DbProviderFactory factory = Npgsql.NpgsqlFactory.Instance;
            
            switch (storageType) {
                case StorageTypes.DBLinqMySQL:
                    IDbConnection mySqlConn = new MySqlConnection(connectionString);
                    dataContext = new DataContext(mySqlConn, m_mappingSource, new DbLinq.MySql.MySqlVendor());
                    break;
                case StorageTypes.DBLinqPostgresql:
                    IDbConnection npgsqlConn = new NpgsqlConnection(connectionString);
                    dataContext = new DataContext(npgsqlConn, m_mappingSource, new DbLinq.PostgreSql.PgsqlVendor());
                    break;
                default:
                    throw new NotSupportedException("Database type " + storageType + " is not supported by CreateDBLinqDataContext.");
            }

            //dataContext.QueryCacheEnabled = true;
            //dataContext.Log = Console.Out;
            //dataContext.Log = dbLinqLogWriter;
            dataContext.ObjectTrackingEnabled = false;
            return dataContext;
        }
Ejemplo n.º 14
0
        public AuditLog_other(StorageTypes storageType, string dbConnStr)
        {
            m_storageType = storageType;
            m_dbConnStr   = dbConnStr;

            m_storageLayer = new StorageLayer(m_storageType, m_dbConnStr);
        }
Ejemplo n.º 15
0
 protected StorageItem(StorageTypes storageType, FileSystemInfo info,StorageDirectory parent,Storage root=null) {
     this.StorageType = storageType;
     this.FileSystemInfo = info;
     
     this._parent = parent;
     this.InternalStorage = root;
     
 }
        //public SIPDomainManager()
        //{ }

        public SIPDomainManager(StorageTypes storageType, string storageConnectionStr)
        {
            m_sipDomainPersistor = SIPAssetPersistorFactory<SIPDomain>.CreateSIPAssetPersistor(storageType, storageConnectionStr, m_storageFileName);
            m_sipDomainPersistor.Added += new SIPAssetDelegate<SIPDomain>(d => { LoadSIPDomains(); });
            m_sipDomainPersistor.Deleted += new SIPAssetDelegate<SIPDomain>(d => { LoadSIPDomains(); });
            m_sipDomainPersistor.Updated += new SIPAssetDelegate<SIPDomain>(d => { LoadSIPDomains(); });
            m_sipDomainPersistor.Modified += new SIPAssetsModifiedDelegate(() => { LoadSIPDomains(); });
            LoadSIPDomains();
        }
Ejemplo n.º 17
0
        public StorageServiceBase(IJSRuntime jSRuntime, StorageTypes storageType)
        {
            _jSRuntime   = jSRuntime;
            _storageType = storageType;

            var name = _storageType.ToString();

            _storageName = name.Substring(0, 1).ToLower() + name.Substring(1);
        }
Ejemplo n.º 18
0
 public storage(Dictionary <string, string> itemsDictionary, Dictionary <int, int> itemCompo)
 {
     name        = itemsDictionary["name"];
     itemID      = int.Parse(itemsDictionary["itemID"]);
     itemType    = (ItemTypes)System.Enum.Parse(typeof(baseItem.ItemTypes), itemsDictionary["itemType"]);
     inventory   = new Class.inventory(int.Parse(itemsDictionary["inventorySpace"]));
     storageType = (StorageTypes)System.Enum.Parse(typeof(storage.StorageTypes), itemsDictionary["type"]);
     compo       = itemCompo;
 }
Ejemplo n.º 19
0
        public CustomerSessionManager(SIPSorceryConfiguration sipSorceryConfig)
        {
            StorageTypes storageType      = sipSorceryConfig.PersistenceStorageType;
            string       connectionString = sipSorceryConfig.PersistenceConnStr;

            m_customerPersistor = SIPAssetPersistorFactory <Customer> .CreateSIPAssetPersistor(storageType, connectionString, CUSTOMERS_XML_FILENAME);

            m_customerSessionPersistor = SIPAssetPersistorFactory <CustomerSession> .CreateSIPAssetPersistor(storageType, connectionString, CUSTOMER_SESSIONS_XML_FILENAME);
        }
        static void Main(string[] args)
        {
            try
            {
                logger.Debug("SIP Notifier starting");

                m_sipNotifierStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown; ;
                m_sipNotifierStorageConnStr = AppState.GetConfigSetting(m_connStrKey);

                if (m_sipNotifierStorageType == StorageTypes.Unknown || m_sipNotifierStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The SIP Notifier cannot start with no persistence settings.");
                }

                if (m_sipNotifierStorageType == StorageTypes.XML && !Directory.Exists(m_sipNotifierStorageConnStr))
                {
                    throw new ApplicationException("Directory " + m_sipNotifierStorageConnStr + " does not exist for XML persistor.");
                }

                SIPAssetPersistor<Customer> customerPersistor = SIPAssetPersistorFactory<Customer>.CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_customersXMLFilename);
                SIPAssetPersistor<SIPAccount> sipAccountsPersistor = SIPAssetPersistorFactory<SIPAccount>.CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_sipAccountsXMLFilename);
                SIPAssetPersistor<SIPRegistrarBinding> sipRegistrarBindingsPersistor = SIPAssetPersistorFactory<SIPRegistrarBinding>.CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_registrarBindingsXMLFilename);
                SIPAssetPersistor<SIPDialogueAsset> sipDialoguePersistor = SIPAssetPersistorFactory<SIPDialogueAsset>.CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_sipDialoguesXMLFilename);
                SIPDomainManager sipDomainManager = new SIPDomainManager(m_sipNotifierStorageType, m_sipNotifierStorageConnStr);

                SIPNotifierDaemon daemon = new SIPNotifierDaemon(
                    customerPersistor.Get, 
                    sipDialoguePersistor.Get, 
                    sipDialoguePersistor.Get, 
                    sipDomainManager.GetDomain, 
                    sipAccountsPersistor, 
                    sipRegistrarBindingsPersistor.Get,
                    sipAccountsPersistor.Get,
                    sipRegistrarBindingsPersistor.Count,
                    SIPRequestAuthenticator.AuthenticateSIPRequest, 
                    null);

                if (args != null && args.Length == 1 && args[0].StartsWith("-c"))
                {
                    Thread daemonThread = new Thread(daemon.Start);
                    daemonThread.Start();
                    m_notifierUp.WaitOne();
                }
                else
                {
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception Main. " + excp.Message);
                logger.Error("Exception Main. " + excp.Message);
            }
        }
Ejemplo n.º 21
0
        //public SIPDomainManager()
        //{ }

        public SIPDomainManager(StorageTypes storageType, string storageConnectionStr)
        {
            m_sipDomainPersistor = SIPAssetPersistorFactory <SIPDomain> .CreateSIPAssetPersistor(storageType, storageConnectionStr, m_storageFileName);

            //m_sipDomainPersistor.Added += new SIPAssetDelegate<SIPDomain>(d => { LoadSIPDomains(); });
            //m_sipDomainPersistor.Deleted += new SIPAssetDelegate<SIPDomain>(d => { LoadSIPDomains(); });
            //m_sipDomainPersistor.Updated += new SIPAssetDelegate<SIPDomain>(d => { LoadSIPDomains(); });
            //m_sipDomainPersistor.Modified += new SIPAssetsModifiedDelegate(() => { LoadSIPDomains(); });
            LoadSIPDomains();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Initializes a new instance of the AccountStorageService class.
        /// </summary>
        /// <param name="accOwner"></param>
        /// <returns>instance</returns>
        public AccountStorageService(StorageTypes storage)
        {
            switch (storage)
            {
            case StorageTypes.StorageWithList:
                currStorage = new AccountsStorage();
                break;

            default:
                throw new Exception("Can't create service");
            }
        }
Ejemplo n.º 23
0
        public static SIPProvisioningWebService CreateProvisioningService()
        {
            try
            {
                m_serverStorageType    = (ConfigurationManager.AppSettings[m_storageTypeKey] != null) ? StorageTypesConverter.GetStorageType(ConfigurationManager.AppSettings[m_storageTypeKey]) : StorageTypes.Unknown;
                m_serverStorageConnStr = ConfigurationManager.AppSettings[m_connStrKey];
                Int32.TryParse(ConfigurationManager.AppSettings[NEW_CUSTOMERS_ALLOWED_LIMIT_KEY], out m_newCustomersAllowedLimit);
                Boolean.TryParse(ConfigurationManager.AppSettings[INVITE_CODE_REQUIRED_KEY], out m_inviteCodeRequired);

                if (m_serverStorageType == StorageTypes.Unknown || m_serverStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The Provisioning Web Service cannot start with no persistence settings specified.");
                }

                // Prevent users from creaing loopback or other crazy providers.
                m_disabledProviderServerPattern = ConfigurationManager.AppSettings[DISABLED_PROVIDER_SERVERS_PATTERN];
                if (!m_disabledProviderServerPattern.IsNullOrBlank())
                {
                    SIPProvider.DisallowedServerPatterns = m_disabledProviderServerPattern;
                }

                // The Registration Agent wants to know about any changes to SIP Provider entries in order to update any SIP
                // Provider bindings it is maintaining or needs to add or remove.
                SIPAssetPersistor <SIPProvider> sipProviderPersistor = SIPAssetPersistorFactory <SIPProvider> .CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_providersStorageFileName);

                SIPAssetPersistor <SIPProviderBinding> sipProviderBindingsPersistor = SIPAssetPersistorFactory <SIPProviderBinding> .CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_providerBindingsStorageFileName);

                SIPProviderBindingSynchroniser sipProviderBindingSynchroniser = new SIPProviderBindingSynchroniser(sipProviderBindingsPersistor);

                sipProviderPersistor.Added   += sipProviderBindingSynchroniser.SIPProviderAdded;
                sipProviderPersistor.Updated += sipProviderBindingSynchroniser.SIPProviderUpdated;
                sipProviderPersistor.Deleted += sipProviderBindingSynchroniser.SIPProviderDeleted;

                return(new SIPProvisioningWebService(
                           SIPAssetPersistorFactory <SIPAccountAsset> .CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_sipAccountsStorageFileName),
                           SIPAssetPersistorFactory <SIPDialPlan> .CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_dialplansStorageFileName),
                           sipProviderPersistor,
                           sipProviderBindingsPersistor,
                           SIPAssetPersistorFactory <SIPRegistrarBinding> .CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_registrarBindingsStorageFileName),
                           SIPAssetPersistorFactory <SIPDialogueAsset> .CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_dialoguesStorageFileName),
                           SIPAssetPersistorFactory <SIPCDRAsset> .CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_cdrsStorageFileName),
                           new CustomerSessionManager(m_serverStorageType, m_serverStorageConnStr),
                           new SIPDomainManager(m_serverStorageType, m_serverStorageConnStr),
                           (e) => { logger.Debug(e.Message); },
                           m_newCustomersAllowedLimit,
                           m_inviteCodeRequired));
            }
            catch (Exception excp)
            {
                logger.Error("Exception CreateProvisioningServicee. " + excp.Message);
                throw;
            }
        }
 public SIPAppServerDaemon(
     StorageTypes storageType,
     string connectionString,
     SIPEndPoint appServerEndPoint,
     string callManagerServiceAddress,
     bool monitorCalls)
 {
     m_storageType               = storageType;
     m_connectionString          = connectionString;
     m_appServerEndPoint         = appServerEndPoint;
     m_callManagerServiceAddress = callManagerServiceAddress;
     m_monitorCalls              = monitorCalls;
 }
        public static SIPProvisioningWebService CreateProvisioningService()
        {
            try
            {
                m_serverStorageType = (ConfigurationManager.AppSettings[m_storageTypeKey] != null) ? StorageTypesConverter.GetStorageType(ConfigurationManager.AppSettings[m_storageTypeKey]) : StorageTypes.Unknown;
                m_serverStorageConnStr = ConfigurationManager.AppSettings[m_connStrKey];
                Int32.TryParse(ConfigurationManager.AppSettings[NEW_CUSTOMERS_ALLOWED_LIMIT_KEY], out m_newCustomersAllowedLimit);
                Boolean.TryParse(ConfigurationManager.AppSettings[INVITE_CODE_REQUIRED_KEY], out m_inviteCodeRequired);

                if (m_serverStorageType == StorageTypes.Unknown || m_serverStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The Provisioning Web Service cannot start with no persistence settings specified.");
                }

                // Prevent users from creaing loopback or other crazy providers.
                m_disabledProviderServerPattern = ConfigurationManager.AppSettings[DISABLED_PROVIDER_SERVERS_PATTERN];
                if (!m_disabledProviderServerPattern.IsNullOrBlank())
                {
                    SIPProvider.DisallowedServerPatterns = m_disabledProviderServerPattern;
                }

                // The Registration Agent wants to know about any changes to SIP Provider entries in order to update any SIP
                // Provider bindings it is maintaining or needs to add or remove.
                SIPAssetPersistor<SIPProvider> sipProviderPersistor = SIPAssetPersistorFactory<SIPProvider>.CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_providersStorageFileName);
                SIPAssetPersistor<SIPProviderBinding> sipProviderBindingsPersistor = SIPAssetPersistorFactory<SIPProviderBinding>.CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_providerBindingsStorageFileName);
                SIPProviderBindingSynchroniser sipProviderBindingSynchroniser = new SIPProviderBindingSynchroniser(sipProviderBindingsPersistor);

                sipProviderPersistor.Added += sipProviderBindingSynchroniser.SIPProviderAdded;
                sipProviderPersistor.Updated += sipProviderBindingSynchroniser.SIPProviderUpdated;
                sipProviderPersistor.Deleted += sipProviderBindingSynchroniser.SIPProviderDeleted;

                return new SIPProvisioningWebService(
                    SIPAssetPersistorFactory<SIPAccount>.CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_sipAccountsStorageFileName),
                    SIPAssetPersistorFactory<SIPDialPlan>.CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_dialplansStorageFileName),
                    sipProviderPersistor,
                    sipProviderBindingsPersistor,
                    SIPAssetPersistorFactory<SIPRegistrarBinding>.CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_registrarBindingsStorageFileName),
                    SIPAssetPersistorFactory<SIPDialogueAsset>.CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_dialoguesStorageFileName),
                    SIPAssetPersistorFactory<SIPCDRAsset>.CreateSIPAssetPersistor(m_serverStorageType, m_serverStorageConnStr, m_cdrsStorageFileName),
                    new CustomerSessionManager(m_serverStorageType, m_serverStorageConnStr),
                    new SIPDomainManager(m_serverStorageType, m_serverStorageConnStr),
                    (e) => { logger.Debug(e.Message); },
                    m_newCustomersAllowedLimit,
                    m_inviteCodeRequired);
            }
            catch (Exception excp)
            {
                logger.Error("Exception CreateProvisioningServicee. " + excp.Message);
                throw;
            }
        }
        private void Construct(ICouchBaseLite CouchBaseLiteLite, StorageTypes storage, string dbName)
        {
            if (CouchBaseLiteLite == null)
            {
                throw new ArgumentNullException("CouchBaseLiteLite");
            }

            this.CouchBaseLiteLite = CouchBaseLiteLite;
            this.CollectionName    = typeof(T).Name;

            ConnectToDatabase(storage, dbName);

            CreateAllDocView();
        }
        static void Main(string[] args)
        {
            try
            {
                logger.Debug("SIP Registration Agent starting");

                m_sipRegAgentStorageType    = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;
                m_sipRegAgentStorageConnStr = AppState.GetConfigSetting(m_connStrKey);

                if (m_sipRegAgentStorageType == StorageTypes.Unknown || m_sipRegAgentStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The SIP Registration Agent cannot start with no persistence settings.");
                }

                if (m_sipRegAgentStorageType == StorageTypes.XML && !Directory.Exists(m_sipRegAgentStorageConnStr))
                {
                    throw new ApplicationException("Directory " + m_sipRegAgentStorageConnStr + " does not exist for XML persistor.");
                }

                int minWorker, minIOC;
                ThreadPool.GetMinThreads(out minWorker, out minIOC);
                ThreadPool.SetMinThreads(MIN_THREADPOOL_WORKERS, minIOC);
                logger.Debug("ThreadPool minimum idle thread adusted from " + minWorker + " to " + MIN_THREADPOOL_WORKERS + ".");

                SIPAssetPersistor <SIPProvider> sipProvidersPersistor = SIPAssetPersistorFactory <SIPProvider> .CreateSIPAssetPersistor(m_sipRegAgentStorageType, m_sipRegAgentStorageConnStr, m_sipProvidersXMLFilename);

                SIPAssetPersistor <SIPProviderBinding> sipProviderBindingsPersistor = SIPAssetPersistorFactory <SIPProviderBinding> .CreateSIPAssetPersistor(m_sipRegAgentStorageType, m_sipRegAgentStorageConnStr, m_sipProviderBindingsXMLFilename);

                SIPRegAgentDaemon daemon = new SIPRegAgentDaemon(sipProvidersPersistor, sipProviderBindingsPersistor);
                SIPDNSManager.SIPMonitorLogEvent = daemon.FireSIPMonitorEvent;

                if (args != null && args.Length == 1 && args[0].StartsWith("-c"))
                {
                    Thread daemonThread = new Thread(daemon.Start);
                    daemonThread.Start();
                    m_regAgentUp.WaitOne();
                }
                else
                {
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception Main. " + excp.Message);
                logger.Error("Exception Main. " + excp.Message);
            }
        }
        private void ConnectToDatabase(StorageTypes storage, string dbName)
        {
            var databaseOptions = this.CouchBaseLiteLite.CreateDatabaseOptions();

            databaseOptions.Create      = true;
            databaseOptions.StorageType = storage;

            this.database = this.CouchBaseLiteLite.CreateConnection(dbName, databaseOptions);

            if (this.database == null)
            {
                throw new NullReferenceException("CreateConnection returned no connection");
            }
        }
        static void Main(string[] args)
        {
            try
            {
                logger.Debug("SIP Registration Agent starting");

                m_sipRegAgentStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;
                m_sipRegAgentStorageConnStr = AppState.GetConfigSetting(m_connStrKey);

                if (m_sipRegAgentStorageType == StorageTypes.Unknown || m_sipRegAgentStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The SIP Registration Agent cannot start with no persistence settings.");
                }

                if (m_sipRegAgentStorageType == StorageTypes.XML && !Directory.Exists(m_sipRegAgentStorageConnStr))
                {
                    throw new ApplicationException("Directory " + m_sipRegAgentStorageConnStr + " does not exist for XML persistor.");
                }

                int minWorker, minIOC;
                ThreadPool.GetMinThreads(out minWorker, out minIOC);
                ThreadPool.SetMinThreads(MIN_THREADPOOL_WORKERS, minIOC);
                logger.Debug("ThreadPool minimum idle thread adusted from " + minWorker + " to " + MIN_THREADPOOL_WORKERS + ".");

                SIPAssetPersistor<SIPProvider> sipProvidersPersistor = SIPAssetPersistorFactory<SIPProvider>.CreateSIPAssetPersistor(m_sipRegAgentStorageType, m_sipRegAgentStorageConnStr, m_sipProvidersXMLFilename);
                SIPAssetPersistor<SIPProviderBinding> sipProviderBindingsPersistor = SIPAssetPersistorFactory<SIPProviderBinding>.CreateSIPAssetPersistor(m_sipRegAgentStorageType, m_sipRegAgentStorageConnStr, m_sipProviderBindingsXMLFilename);

                SIPRegAgentDaemon daemon = new SIPRegAgentDaemon(sipProvidersPersistor, sipProviderBindingsPersistor);
                SIPDNSManager.SIPMonitorLogEvent = daemon.FireSIPMonitorEvent;

                if (args != null && args.Length == 1 && args[0].StartsWith("-c"))
                {
                    Thread daemonThread = new Thread(daemon.Start);
                    daemonThread.Start();
                    m_regAgentUp.WaitOne();
                }
                else
                {
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception Main. " + excp.Message);
                logger.Error("Exception Main. " + excp.Message);
            }
        }
Ejemplo n.º 30
0
        static SIPSqlite()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "Config\\";

            m_storageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;
            m_connStr     = AppState.GetConfigSetting(m_connStrKey);
            if (m_storageType == StorageTypes.SQLite)
            {
                m_connStr = string.Format(m_connStr, path);
            }
            if (m_storageType == StorageTypes.Unknown || m_connStr.IsNullOrBlank())
            {
                throw new ApplicationException("The SIP Registrar cannot start with no persistence settings.");
            }
        }
Ejemplo n.º 31
0
        public object ExecuteScalar(StorageTypes storageType, string dbConnString, string query)
        {
            QuerySecurityCheck(query);

            try {
                using (IDbConnection dbConn = GetDbConnection(storageType, dbConnString)) {
                    dbConn.Open();
                    IDbCommand command = GetDbCommand(storageType, dbConn, query);
                    return(command.ExecuteScalar());
                }
            }
            catch (Exception excp) {
                logger.Error("Exception ExecuteScalar. " + excp.Message);
                throw excp;
            }
        }
Ejemplo n.º 32
0
        // here init the gb28181.xml file setting from app.config
        static SipAccountStorage()
        {
            m_storageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;

            var rootPath = AppDomain.CurrentDomain.BaseDirectory;

            m_connStr = Path.Combine(rootPath, AppState.GetConfigSetting(m_connStrKey));
            if (m_storageType == StorageTypes.SQLite)
            {
                m_connStr = string.Format(m_connStr, rootPath);
            }
            if (m_storageType == StorageTypes.Unknown || m_connStr.IsNullOrBlank())
            {
                throw new ApplicationException("The SIP Registrar cannot start with no persistence settings.");
            }
        }
Ejemplo n.º 33
0
 public static SIPAssetPersistor <T> CreateSIPAssetPersistor(StorageTypes storageType, string storageConnectionStr, string filename)
 {
     try
     {
         if (storageType == StorageTypes.XML)
         {
             if (!storageConnectionStr.EndsWith(@"\"))
             {
                 storageConnectionStr += @"\";
             }
             return(new XMLAssetPersistor <T>(storageConnectionStr + filename));
         }
         if (storageType == StorageTypes.SQLLinqMySQL)
         {
             return(new SQLAssetPersistor <T>(MySql.Data.MySqlClient.MySqlClientFactory.Instance, storageConnectionStr));
         }
         else if (storageType == StorageTypes.SQLite)
         {
             return(new SQLAssetPersistor <T>(System.Data.SQLite.SQLiteFactory.Instance, storageConnectionStr));
         }
         //else if (storageType == StorageTypes.SQLLinqPostgresql)
         //{
         //    return new SQLAssetPersistor<T>(Npgsql.NpgsqlFactory.Instance, storageConnectionStr);
         //}
         //else if (storageType == StorageTypes.SimpleDBLinq)
         //{
         //    return new SimpleDBAssetPersistor<T>(storageConnectionStr);
         //}
         //else if (storageType == StorageTypes.SQLLinqMSSQL)
         //{
         //    return new MSSQLAssetPersistor<T>(System.Data.SqlClient.SqlClientFactory.Instance, storageConnectionStr);
         //}
         //else if (storageType == StorageTypes.SQLLinqOracle)
         //{
         //    return new SQLAssetPersistor<T>(Oracle.DataAccess.Client.OracleClientFactory.Instance, storageConnectionStr);
         //}
         else
         {
             throw new ApplicationException(storageType + " is not supported as a CreateSIPAssetPersistor option.");
         }
     }
     catch (Exception excp)
     {
         logger.Error("Exception CreateSIPAssetPersistor for " + storageType + ". " + excp.Message);
         throw;
     }
 }
Ejemplo n.º 34
0
 public static IDbCommand GetDbCommand(StorageTypes storageType, IDbConnection dbConn, string cmdText)
 {
     //if (storageType == StorageTypes.Postgresql) {
     //    return new NpgsqlCommand(cmdText, (NpgsqlConnection)dbConn);
     //}
     if (storageType == StorageTypes.MySQL)
     {
         return(new MySqlCommand(cmdText, (MySqlConnection)dbConn));
     }
     //else if (storageType == StorageTypes.MSSQL)
     //{
     //    return new SqlCommand(cmdText, (SqlConnection)dbConn);
     //}
     else
     {
         throw new ApplicationException("Storage type " + storageType + " is not supported by GetDbConnection.");
     }
 }
Ejemplo n.º 35
0
 public static IDbConnection GetDbConnection(StorageTypes storageType, string dbConnStr)
 {
     //if (storageType == StorageTypes.Postgresql) {
     //    return new NpgsqlConnection(dbConnStr);
     //}
     //else if (storageType == StorageTypes.MySQL) {
     //    return new MySqlConnection(dbConnStr);
     //}
     //else if (storageType == StorageTypes.MSSQL)
     //{
     //    return new SqlConnection(dbConnStr);
     //}
     //else
     //{
     //    throw new ApplicationException("Storage type " + storageType + " is not supported by GetDbConnection.");
     //}
     return(null);
 }
Ejemplo n.º 36
0
 private IDataAdapter GetDataAdapter(StorageTypes storageType, IDbConnection dbConn, string cmdText)
 {
     //if (storageType == StorageTypes.Postgresql) {
     //    return new NpgsqlDataAdapter(cmdText, (NpgsqlConnection)dbConn);
     //}
     //else if (storageType == StorageTypes.MySQL) {
     //    return new MySqlDataAdapter(cmdText, (MySqlConnection)dbConn);
     //}
     //else if (storageType == StorageTypes.MSSQL)
     //{
     //    return new SqlDataAdapter(cmdText, (SqlConnection)dbConn);
     //}
     //else
     //{
     //    throw new ApplicationException("Storage type " + storageType + " is not supported by GetDbConnection.");
     //}
     throw new ApplicationException("Storage type " + storageType + " is not supported by GetDbConnection.");
 }
Ejemplo n.º 37
0
        private void Initialize()
        {
            _deviceList = new List <string>();
            m_sipRegistrarStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ?
                                        StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) :
                                        StorageTypes.Unknown;
            m_sipRegistrarStorageConnStr = AppState.GetConfigSetting(m_connStrKey);

            if (m_sipRegistrarStorageType == StorageTypes.Unknown || m_sipRegistrarStorageConnStr.IsNullOrBlank())
            {
                throw new ApplicationException("The SIP Registrar cannot start with no persistence settings.");
            }

            lBoxDevice.Items.Add("34020000001320000077");
            lBoxDevice.Items.Add("34020000001320000088");
            lBoxDevice.SelectedIndex = 0;
            _deviceList = lBoxDevice.Items.Cast <string>().ToList();
        }
Ejemplo n.º 38
0
 public static IDataParameter GetDbParameter(StorageTypes storageType, string name, object value)
 {
     //if (storageType == StorageTypes.Postgresql) {
     //    return new NpgsqlParameter(name, value);
     //}
     //else if (storageType == StorageTypes.MySQL) {
     //    return new MySqlParameter(name, value);
     //}
     //else if (storageType == StorageTypes.MSSQL)
     //{
     //    return new SqlParameter(name, value);
     //}
     //else
     //{
     //    throw new ApplicationException("Storage type " + storageType + " is not supported by GetDbParameter.");
     //}
     throw new ApplicationException("Storage type " + storageType + " is not supported by GetDbParameter.");
 }
Ejemplo n.º 39
0
 public static IDbConnection GetDbConnection(StorageTypes storageType, string dbConnStr)
 {
     if (storageType == StorageTypes.Postgresql)
     {
         return(new NpgsqlConnection(dbConnStr));
     }
     else if (storageType == StorageTypes.MySQL)
     {
         return(new MySqlConnection(dbConnStr));
     }
     else if (storageType == StorageTypes.MSSQL)
     {
         return(new SqlConnection(dbConnStr));
     }
     else
     {
         throw new ApplicationException("Storage type " + storageType + " is not supported by GetDbConnection.");
     }
 }
Ejemplo n.º 40
0
 public IStorageItem CreateItem(string path, StorageTypes itemType = StorageTypes.Directory)
 {
     //CreateFilePathIfNotExisted(path);
     var filename = new AbsolutePath(path,this);
     if (itemType == StorageTypes.Directory)
     {
         var dirInfo = System.IO.Directory.CreateDirectory(filename);
         return new StorageDirectory(dirInfo,null, filename.Storage);
     }
     if (itemType == StorageTypes.File)
     {
         var info = new FileInfo(filename);
         System.IO.Directory.CreateDirectory(info.DirectoryName);
         using (info.Create()) { } ;
         
         return new StorageFile(info,null,filename.Storage);
     }
     return null;
 }
Ejemplo n.º 41
0
        public void ExecuteNonQuery(StorageTypes storageType, string dbConnString, string query)
        {
            QuerySecurityCheck(query);

            try
            {
                using (IDbConnection dbConn = GetDbConnection(storageType, dbConnString))
                {
                    dbConn.Open();
                    IDbCommand command = GetDbCommand(storageType, dbConn, query);
                    command.ExecuteNonQuery();
                }
            }
            catch (Exception excp)
            {
                Logger.Logger.Error("Exception ExecuteNonQuery. ->" + excp.Message);
                throw excp;
            }
        }
Ejemplo n.º 42
0
        public DataSet GetDataSet(StorageTypes storageType, string dbConnString, string query)
        {
            QuerySecurityCheck(query);

            try {
                using (IDbConnection dbConn = GetDbConnection(storageType, dbConnString)) {
                    dbConn.Open();
                    IDataAdapter adapter = GetDataAdapter(storageType, dbConn, query);

                    DataSet resultSet = new DataSet();
                    adapter.Fill(resultSet);

                    return(resultSet);
                }
            }
            catch (Exception excp) {
                logger.Error("Exception GetDataSet. " + excp.Message);
                throw excp;
            }
        }
Ejemplo n.º 43
0
        static void Main(string[] args)
        {
            try
            {
                logger.Debug("RTCC Server starting");

                m_rtccStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown; ;
                m_rtccStorageConnStr = AppState.GetConfigSetting(m_connStrKey);

                if (m_rtccStorageType == StorageTypes.Unknown || m_rtccStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The RTCC Server cannot start with no persistence settings.");
                }

                var sipSorceryPersistor = new SIPSorceryPersistor(m_rtccStorageType, m_rtccStorageConnStr);
                RTCCDaemon daemon = new RTCCDaemon(sipSorceryPersistor);

                if (args != null && args.Length == 1 && args[0].StartsWith("-c"))
                {
                    Thread daemonThread = new Thread(daemon.Start);
                    daemonThread.Start();
                    m_rtccUp.WaitOne();
                }
                else
                {
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception Main. " + excp.Message);
                logger.Error("Exception Main. " + excp.Message);
            }
        }
Ejemplo n.º 44
0
 public CustomerSessionManager(StorageTypes storageType, string connectionString)
 {
     m_customerPersistor = SIPAssetPersistorFactory<Customer>.CreateSIPAssetPersistor(storageType, connectionString, CUSTOMERS_XML_FILENAME);
     m_customerSessionPersistor = SIPAssetPersistorFactory<CustomerSession>.CreateSIPAssetPersistor(storageType, connectionString, CUSTOMER_SESSIONS_XML_FILENAME);
 }
Ejemplo n.º 45
0
 public SIPAllInOneDaemon(
     StorageTypes storageType,
     string connectionString,
     SIPEndPoint appServerEndPoint,
     string callManagerServiceAddress,
     bool monitorCalls)
 {
     m_storageType = storageType;
     m_connectionString = connectionString;
     m_appServerEndPoint = appServerEndPoint;
     m_callManagerServiceAddress = callManagerServiceAddress;
     m_monitorCalls = monitorCalls;
 }
Ejemplo n.º 46
0
 public SIPAllInOneDaemon(StorageTypes storageType, string connectionString)
 {
     m_storageType = storageType;
     m_connectionString = connectionString;
     m_monitorCalls = true;
 }
Ejemplo n.º 47
0
 public async Task<IList<IStorageItem>> ListItemsAsync(string path, StorageTypes itemType = StorageTypes.All)
 {
     return await Task<IList<IStorageItem>>.Run(()=>this.ListItems(path,itemType));
 }
Ejemplo n.º 48
0
 private IDbConnection GetDatabaseConnection(StorageTypes storageType, string dbConnStr)
 {
     IDbConnection dbConn = StorageLayer.GetDbConnection(storageType, dbConnStr);
     dbConn.Open();
     return dbConn;
 }
Ejemplo n.º 49
0
 public async Task<IStorageItem> GetItemAsync(string path, StorageTypes itemType = StorageTypes.All,bool createIfNotExisted=false)
 {
     return await Task.Run(() => this.GetItem(path, itemType,createIfNotExisted));
 }
Ejemplo n.º 50
0
 public async Task<IStorageItem> CreateItemAsync(string path, StorageTypes itemType = StorageTypes.Directory) {
     return await Task.Run(()=>this.CreateItem(path,itemType));
 }
Ejemplo n.º 51
0
        private void DBDelete(StorageTypes storageType, string dbConnStr, string key)
        {
            try
            {
                if (ServiceLevel == CustomerServiceLevels.Free)
                {
                    Log("Your service level of " + ServiceLevel + " is not authorised to use the " + System.Reflection.MethodBase.GetCurrentMethod().Name + " method.");
                }
                else
                {
                    /*StorageLayer storageLayer = new StorageLayer(storageType, dbConnStr);

                    Dictionary<string, object> parameters = new Dictionary<string, object>();
                    parameters.Add("dataowner", m_username);
                    parameters.Add("datakey", key);
                    storageLayer.ExecuteNonQuery(storageType, dbConnStr, "delete from dialplandata where dataowner = @dataowner and datakey = @datakey", parameters);
                    Log("DBDelete sucessful for datakey \"" + key + "\".");*/

                    //using (IDbConnection dbConn = StorageLayer.GetDbConnection(storageType, dbConnStr))
                    //{
                    //    dbConn.Open();

                    if (m_userDataDBConnection == null)
                    {
                        m_userDataDBConnection = GetDatabaseConnection(storageType, dbConnStr);
                    }

                    IDataParameter dataOwnerParameter = StorageLayer.GetDbParameter(storageType, "dataowner", m_username);
                    IDataParameter dataKeyParameter = StorageLayer.GetDbParameter(storageType, "datakey", key);
                    IDbCommand dbCommand = StorageLayer.GetDbCommand(storageType, m_userDataDBConnection, "delete from dialplandata where dataowner = @dataowner and datakey = @datakey");
                    dbCommand.Parameters.Add(dataOwnerParameter);
                    dbCommand.Parameters.Add(dataKeyParameter);
                    dbCommand.ExecuteNonQuery();
                    //}

                    Log("DBDelete sucessful for datakey \"" + key + "\".");
                }
            }
            catch (Exception excp)
            {
                Log("Exception DBDelete. " + excp.Message);
            }
        }
Ejemplo n.º 52
0
 static DialPlanScriptFacade()
 {
     try
     {
         m_userDataDBType = (AppState.GetConfigSetting(USERDATA_DBTYPE_KEY) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(USERDATA_DBTYPE_KEY)) : StorageTypes.Unknown;
         m_userDataDBConnStr = AppState.GetConfigSetting(USERDATA_DBCONNSTR_KEY);
         m_sendAnalytics = !AppState.GetConfigSetting(GOOGLE_ANALYTICS_KEY).IsNullOrBlank();
     }
     catch (Exception excp)
     {
         logger.Error("Exception DialPlanScriptFacade (static ctor). " + excp.Message);
     }
 }
Ejemplo n.º 53
0
        public IList<IStorageItem> ListItems(string path, StorageTypes itemType = StorageTypes.All)
        {
            
            var filename = new AbsolutePath(path , this);

            if (!System.IO.Directory.Exists(filename)) return null;
            var result = new List<IStorageItem>();
            if (itemType.IsFile())
            {
                var filenames = System.IO.Directory.GetFiles(filename);
                foreach(var name in filenames) result.Add(new StorageFile(new FileInfo(name),this,filename.Storage));
            }
            if (itemType.IsDirectory())
            {
                path += "/";
                var filenames = System.IO.Directory.GetDirectories(filename);
                foreach (var name in filenames) result.Add(new StorageDirectory(new DirectoryInfo(name),this,filename.Storage));
            }
            return result;
        }
Ejemplo n.º 54
0
        private string DBRead(StorageTypes storageType, string dbConnStr, string key, bool forUpdate)
        {
            try
            {
                if (ServiceLevel == CustomerServiceLevels.Free)
                {
                    Log("Your service level of " + ServiceLevel + " is not authorised to use the " + System.Reflection.MethodBase.GetCurrentMethod().Name + " method.");
                    return null;
                }
                else
                {
                    /*StorageLayer storageLayer = new StorageLayer(storageType, dbConnStr);

                    Dictionary<string, object> parameters = new Dictionary<string, object>();
                    parameters.Add("dataowner", m_username);
                    parameters.Add("datakey", key);
                    string result = storageLayer.ExecuteScalar("select datavalue from dialplandata where dataowner = @dataowner and datakey = @datakey", parameters) as string;
                    Log("DBRead sucessful for datakey \"" + key + "\", value=" + result + ".");
                    return result;*/

                    string result = null;

                    //using (IDbConnection dbConn = StorageLayer.GetDbConnection(storageType, dbConnStr))
                    //{
                    //    dbConn.Open();

                    if (m_userDataDBConnection == null)
                    {
                        m_userDataDBConnection = GetDatabaseConnection(storageType, dbConnStr);
                    }

                    IDataParameter dataOwnerParameter = StorageLayer.GetDbParameter(storageType, "dataowner", m_username);
                    IDataParameter dataKeyParameter = StorageLayer.GetDbParameter(storageType, "datakey", key);

                    string sqlCommandText = "select datavalue from dialplandata where dataowner = @dataowner and datakey = @datakey";
                    if (forUpdate)
                    {
                        sqlCommandText += " for update";
                    }

                    IDbCommand dbCommand = StorageLayer.GetDbCommand(storageType, m_userDataDBConnection, sqlCommandText);
                    dbCommand.Parameters.Add(dataOwnerParameter);
                    dbCommand.Parameters.Add(dataKeyParameter);
                    result = dbCommand.ExecuteScalar() as string;
                    //}

                    if (forUpdate)
                    {
                        //Log("DBReadForUpdate sucessful for datakey \"" + key + "\", value=" + result + ".");
                        Log("DBReadForUpdate sucessful for datakey \"" + key + "\".");
                    }
                    else
                    {
                        //Log("DBRead sucessful for datakey \"" + key + "\", value=" + result + ".");
                        Log("DBRead sucessful for datakey \"" + key + "\".");
                    }

                    return result;
                }
            }
            catch (Exception excp)
            {
                Log("Exception DBRead. " + excp.Message);
                return null;
            }
        }
Ejemplo n.º 55
0
        void InternalListItems(List<IStorageItem>  result ,StorageDirectory dir, bool includeSubs = false, StorageTypes itemType = StorageTypes.All) {
            var dirInfo = (dir.FileSystemInfo as DirectoryInfo);
            

            if (itemType.IsFile())
            {
                var subInfos = dirInfo .GetFiles();
                foreach (var sub in subInfos)
                {
                    result.Add(new StorageFile(sub, dir,this.InternalStorage));
                }
            }
            if (itemType.IsDirectory() || includeSubs) {
                var subs = dirInfo.GetDirectories();

                foreach (var sub in subs)
                {
                    var subItem = new StorageDirectory(sub, dir, this.InternalStorage);
                    if(itemType.IsDirectory())result.Add(subItem);
                    if (includeSubs) InternalListItems(result, subItem, includeSubs, itemType);
                }
            }
            

        }
Ejemplo n.º 56
0
        private void DBWrite(StorageTypes storageType, string dbConnStr, string key, string value)
        {
            try
            {
                if (ServiceLevel == CustomerServiceLevels.Free)
                {
                    Log("Your service level of " + ServiceLevel + " is not authorised to use the " + System.Reflection.MethodBase.GetCurrentMethod().Name + " method.");
                }
                else
                {
                    /* StorageLayer storageLayer = new StorageLayer(storageType, dbConnStr);

                     Dictionary<string, object> parameters = new Dictionary<string, object>();
                     parameters.Add("dataowner", m_username);
                     int ownerKeyCount = Convert.ToInt32(storageLayer.ExecuteScalar("select count(*) from dialplandata where dataowner = @dataowner", parameters));

                     if (ownerKeyCount == MAX_DATA_ENTRIES_PER_USER)
                     {
                         Log("DBWrite failed, you have reached the maximum number of database entries allowed.");
                     }
                     else
                     {*/
                    /*parameters.Add("datakey", key);
                    int count = Convert.ToInt32(storageLayer.ExecuteScalar("select count(*) from dialplandata where datakey = @datakey and dataowner = @dataowner", parameters));
                    parameters.Add("datavalue", value);

                    if (count == 0)
                    {
                        storageLayer.ExecuteNonQuery(storageType, dbConnStr, "insert into dialplandata (dataowner, datakey, datavalue) values (@dataowner, @datakey, @datavalue)", parameters);
                    }
                    else
                    {
                        storageLayer.ExecuteNonQuery(storageType, dbConnStr, "update dialplandata set datavalue = @datavalue where dataowner = @dataowner and datakey = @datakey", parameters);
                    }
                    Log("DBWrite sucessful for datakey \"" + key + "\".");*/

                    if (m_userDataDBConnection == null)
                    {
                        m_userDataDBConnection = GetDatabaseConnection(storageType, dbConnStr);
                    }

                    IDataParameter dataOwnerParameter = StorageLayer.GetDbParameter(storageType, "dataowner", m_username);
                    IDataParameter dataKeyParameter = StorageLayer.GetDbParameter(storageType, "datakey", key);
                    IDataParameter dataValueParameter = StorageLayer.GetDbParameter(storageType, "datavalue", value);

                    IDbCommand countCommand = StorageLayer.GetDbCommand(storageType, m_userDataDBConnection, "select count(*) from dialplandata where datakey = @datakey and dataowner = @dataowner");
                    countCommand.Parameters.Add(dataOwnerParameter);
                    countCommand.Parameters.Add(dataKeyParameter);
                    int count = Convert.ToInt32(countCommand.ExecuteScalar());

                    string sqlCommand = (count == 0) ? "insert into dialplandata (dataowner, datakey, datavalue) values (@dataowner, @datakey, @datavalue)" : "update dialplandata set datavalue = @datavalue where dataowner = @dataowner and datakey = @datakey";
                    IDbCommand dbCommand = StorageLayer.GetDbCommand(storageType, m_userDataDBConnection, sqlCommand);
                    dbCommand.Parameters.Add(dataOwnerParameter);
                    dbCommand.Parameters.Add(dataKeyParameter);
                    dbCommand.Parameters.Add(dataValueParameter);
                    dbCommand.ExecuteNonQuery();

                    Log("DBWrite sucessful for datakey \"" + key + "\".");
                    //}
                }
            }
            catch (Exception excp)
            {
                Log("Exception DBWrite. " + excp.Message);
            }
        }
Ejemplo n.º 57
0
 public IList<IStorageItem> ListItems(bool includeSubs = false, StorageTypes itemType = StorageTypes.All) {
     var result = new List<IStorageItem>();
     if (this.FileSystemInfo==null) throw new InvalidOperationException("Cannot list all the items for file system root.");
     InternalListItems(result,this,includeSubs,itemType);
     return result;
 }
Ejemplo n.º 58
0
        static void Main(string[] args)
        {
            bool isConsole = false;

            try
            {
                // Get DateTime.ToString() to use a format ot ToString("o") instead of ToString("G").
                CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
                culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
                culture.DateTimeFormat.LongTimePattern = "THH:mm:ss.fffffffzzz";
                Thread.CurrentThread.CurrentCulture = culture;

                m_serverStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;
                m_serverStorageConnStr = AppState.GetConfigSetting(m_connStrKey);
                bool monitorCalls = true;

                if (m_serverStorageType == StorageTypes.Unknown || m_serverStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The SIP Application Service cannot start with no persistence settings specified.");
                }

                if (args != null && args.Length > 0)
                {
                    isConsole = true;
                    Console.WriteLine("SIP App Server starting");
                    logger.Debug("SIP App Server Console starting...");

                    string sipSocket = null;
                    string callManagerSvcAddress = null;

                    foreach (string arg in args) {
                        if (arg.StartsWith("-sip:")) {
                            sipSocket = arg.Substring(5);
                        }
                        else if (arg.StartsWith("-cms:")) {
                            callManagerSvcAddress = arg.Substring(5);
                        }
                        else if (arg.StartsWith("-hangupcalls:")) {
                            monitorCalls = Convert.ToBoolean(arg.Substring(13));
                        }
                    }

                    SIPAllInOneDaemon daemon = null;

                    if (sipSocket.IsNullOrBlank() || callManagerSvcAddress.IsNullOrBlank()) {
                        daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr);
                    }
                    else {
                        daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr, SIPEndPoint.ParseSIPEndPoint(sipSocket), callManagerSvcAddress, monitorCalls);
                    }

                    Thread daemonThread = new Thread(new ThreadStart(daemon.Start));
                    daemonThread.Start();

                    m_proxyUp.WaitOne();
                }
                else
                {
                    logger.Debug("SIP App Server Windows Service Starting...");
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    SIPAllInOneDaemon daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr);
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception SIP App Server Main. " + excp.Message);

                if (isConsole) {
                    Console.WriteLine("press any key to exit...");
                    Console.ReadLine();
                }
            }
        }
Ejemplo n.º 59
0
 public async Task<IList<IStorageItem>> ListItemsAsync(bool includeSubs = false, StorageTypes itemType = StorageTypes.All) {
     return await Task<IList<IStorageItem>>.Run(()=>ListItems(includeSubs,itemType));
 }
Ejemplo n.º 60
0
        static void Main(string[] args)
        {
            bool isConsole = false;

            try
            {
                // Get DateTime.ToString() to use a format ot ToString("o") instead of ToString("G").
                CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
                culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
                culture.DateTimeFormat.LongTimePattern = "THH:mm:ss.fffffffzzz";
                Thread.CurrentThread.CurrentCulture = culture;

                m_serverStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;
                m_serverStorageConnStr = AppState.GetConfigSetting(m_connStrKey);
                bool monitorCalls = true;

                if (m_serverStorageType == StorageTypes.Unknown || m_serverStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The SIP Application Service cannot start with no persistence settings specified.");
                }

                SIPAllInOneDaemon daemon = null;

                if (args != null && args.Length == 1 && args[0] == "-i")
                {
                    try
                    {
                        using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).Assembly, args))
                        {
                            IDictionary state = new Hashtable();
                            inst.UseNewContext = true;
                            try
                            {
                                //if (undo)
                                //{
                                //    inst.Uninstall(state);
                                //}
                                //else
                                //{
                                inst.Install(state);
                                inst.Commit(state);
                                //}
                            }
                            catch
                            {
                                try
                                {
                                    inst.Rollback(state);
                                }
                                catch { }
                                throw;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex.Message);
                    }
                }
                else if (args != null && args.Length == 1 && args[0] == "-u")
                {
                    try
                    {
                        using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).Assembly, args))
                        {
                            IDictionary state = new Hashtable();
                            inst.UseNewContext = true;
                            try
                            {

                                inst.Uninstall(state);
                            }
                            catch
                            {
                                try
                                {
                                    inst.Rollback(state);
                                }
                                catch { }
                                throw;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex.Message);
                    }
                }
                else if (args != null && args.Length == 1 && args[0].StartsWith("-c") || System.Environment.UserInteractive == true)
                {
                    isConsole = true;
                    Console.WriteLine("SIP App Server starting");
                    logger.Debug("SIP App Server Console starting...");

                    string sipSocket = null;
                    string callManagerSvcAddress = null;

                    if (args != null && args.Length > 0)
                    {
                        foreach (string arg in args)
                        {
                            if (arg.StartsWith("-sip:"))
                            {
                                sipSocket = arg.Substring(5);
                            }
                            else if (arg.StartsWith("-cms:"))
                            {
                                callManagerSvcAddress = arg.Substring(5);
                            }
                            else if (arg.StartsWith("-hangupcalls:"))
                            {
                                monitorCalls = Convert.ToBoolean(arg.Substring(13));
                            }
                        }
                    }

                    if (sipSocket.IsNullOrBlank() || callManagerSvcAddress.IsNullOrBlank())
                    {
                        daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr);
                    }
                    else
                    {
                        daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr, SIPEndPoint.ParseSIPEndPoint(sipSocket), callManagerSvcAddress, monitorCalls);
                    }

                    Thread daemonThread = new Thread(new ThreadStart(daemon.Start));
                    daemonThread.Start();

                    Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e) {
                        e.Cancel = true;
                        Console.WriteLine("Ctrl-C, clean up and exit...");
                        daemon.Stop();
                        m_proxyUp.Set();
                    };

                    m_proxyUp.WaitOne();
                }
                else
                {
                    logger.Debug("SIP App Server Windows Service Starting...");
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr);
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception SIP App Server Main. " + excp.Message);

                if (isConsole) {
                    Console.WriteLine("press any key to exit...");
                    Console.ReadLine();
                }
            }
        }