Пример #1
0
        public static string GetConnectionString()
        {
            var xk = new KryptoLib.X509Krypto();

            return(xk.GetKTextConnectionString("MicrosoftMgmtSvcCmpContext",
                                               "MicrosoftMgmtSvcCmpContextPassword"));
        }
Пример #2
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        ///
        //*********************************************************************

        public static List <BasicCreds> SetDefaultAccountList()
        {
            if (null == UserList)
            {
                UserList = new List <BasicCreds>(1);
            }

            var xk = new KryptoLib.X509Krypto(null);

            var cmpServiceUserName =
                Microsoft.Azure.CloudConfigurationManager.GetSetting("CmpServiceUserName") as string;
            var cmpServiceUserPassword =
                Microsoft.Azure.CloudConfigurationManager.GetSetting("CmpServiceUserPassword") as string;

            if (null == cmpServiceUserName)
            {
                return(UserList);
            }
            if (null == cmpServiceUserPassword)
            {
                return(UserList);
            }

            cmpServiceUserPassword = xk.DecrpytKText(cmpServiceUserPassword);

            UserList.Add(new BasicCreds(cmpServiceUserName, cmpServiceUserPassword));

            return(UserList);
        }
Пример #3
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        ///
        //*********************************************************************

        public static List <CmpServiceLib.Models.CmpServiceUserAccount> GetDefaultAccountList()
        {
            var ual = new List <CmpServiceLib.Models.CmpServiceUserAccount>(1);

            var xk = new KryptoLib.X509Krypto(null);

            var cmpServiceUserName =
                Microsoft.Azure.CloudConfigurationManager.GetSetting("CmpServiceUserName") as string;
            var cmpServiceUserPassword =
                Microsoft.Azure.CloudConfigurationManager.GetSetting("CmpServiceUserPassword") as string;

            if (null == cmpServiceUserName)
            {
                return(ual);
            }
            if (null == cmpServiceUserPassword)
            {
                return(ual);
            }

            cmpServiceUserPassword = xk.DecrpytKText(cmpServiceUserPassword);

            ual.Add(new CmpServiceLib.Models.CmpServiceUserAccount()
            {
                Name = cmpServiceUserName, Password = cmpServiceUserPassword
            });

            return(ual);
        }
Пример #4
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        ///
        //*********************************************************************

        public override bool OnStart()
        {
            try
            {
                _EventLog        = new EventLog("Application");
                _EventLog.Source = CmpCommon.Constants.CmpAzureServiceWorkerRole_EventlogSourceName;
                _EventLog.WriteEntry("Service Starting", EventLogEntryType.Information, 1, 1);
            }
            catch (Exception)
            {
                _EventLog = null;
            }

            try
            {
                InitDiagnostics();

                if (JoinDomain())
                {
                    return(false);
                }

                // Set the maximum number of concurrent connections
                ServicePointManager.DefaultConnectionLimit = 12;

                // Create the queue if it does not exist already
                var connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

                var xk = new KryptoLib.X509Krypto(null);
                connectionString = xk.DecrpytKText(connectionString);

                var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
                if (!namespaceManager.QueueExists(QueueName))
                {
                    namespaceManager.CreateQueue(QueueName);
                }

                // Initialize the connection to Service Bus Queue
                //Client = QueueClient.CreateFromConnectionString(connectionString, QueueName);

                _CS = new CmpServiceLib.CmpService(_EventLog, null, null);
                //_CS.PerformSingleRun();
                _CS.AsynchStart();

                if (null != _EventLog)
                {
                    _EventLog.WriteEntry("Service Started", EventLogEntryType.Information, 2, 1);
                }
            }
            catch (Exception ex)
            {
                if (null != _EventLog)
                {
                    _EventLog.WriteEntry("Service not started : " + CmpCommon.Utilities.UnwindExceptionMessages(ex), EventLogEntryType.Error, 100, 100);
                }
            }

            return(base.OnStart());
        }
Пример #5
0
 public static string GetConnectionString()
 {
     using (var xk = new KryptoLib.X509Krypto())
     {
         return(xk.GetKTextConnectionString("CMPContext",
                                            "CMPContextPassword"));
     }
 }
Пример #6
0
        private string GetQueueConnectionString(string storeName, string storeLocation, string thumbprint, string connectionString)
        {
            if (null == _queueConnectionString)
            {
                _queueConnectionString = connectionString;
                var xk = new KryptoLib.X509Krypto(storeName, storeLocation, thumbprint);
                _queueConnectionString = xk.DecrpytKText(_queueConnectionString);
            }

            return(_queueConnectionString);
        }
Пример #7
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        ///
        //*********************************************************************

        private string GetQueueConnectionString()
        {
            if (null == _queueConnectionString)
            {
                _queueConnectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
                var xk = new KryptoLib.X509Krypto(null);
                _queueConnectionString = xk.DecrpytKText(_queueConnectionString);
            }

            return(_queueConnectionString);
        }
Пример #8
0
 private string GetCmpContextConnectionStringFromConfig()
 {
     try
     {
         var xk = new KryptoLib.X509Krypto(null);
         return(xk.GetKTextConnectionString("CMPContext", "CMPContextPassword"));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Пример #9
0
        //********************************************************************
        ///
        /// <summary>
        /// Ugly code, does not belong here. Belongs in a lib. Should remove
        /// this when we solve the big 'method not returning' bug
        /// </summary>
        /// <returns></returns>
        ///
        //********************************************************************

        private string GetCmpContextConnectionStringFromConfig()
        {
            try
            {
                var xk = new KryptoLib.X509Krypto(null);
                return(xk.GetKTextConnectionString("CMPContext", "CMPContextPassword"));
            }
            catch (Exception ex)
            {
                if (null != _eventLog)
                {
                    _eventLog.WriteEntry("Exception when reading CMPContext connection string : " +
                                         ex.Message, EventLogEntryType.Error, 100, 100);
                }

                return(null);
            }
        }
Пример #10
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        ///
        //*********************************************************************

        void InitCmpContextConnectionString()
        {
            try
            {
                var XK = new KryptoLib.X509Krypto(null);
                Controllers.VmDeploymentsController.cmpDbConnectionString =
                    XK.GetKTextConnectionString("CMPContext", "CMPContextPassword");
                Controllers.VmMigrationsController.cmpDbConnectionString =
                    Controllers.VmDeploymentsController.cmpDbConnectionString;
            }
            catch (Exception ex)
            {
                if (null != _EventLog)
                {
                    _EventLog.WriteEntry("Exception when reading CMPContext connection string : " +
                                         ex.Message, EventLogEntryType.Error, 100, 100);
                }
            }
        }
Пример #11
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        ///
        //*********************************************************************

        private void GetDbConnectionString()
        {
            try
            {
                var xk = new KryptoLib.X509Krypto(null);
                _cmpDbConnectionString = xk.GetKTextConnectionString(
                    "CMPContext", "CMPContextPassword");

                if (null == _cmpDbConnectionString)
                {
                    if (null != _eventLog)
                    {
                        _eventLog.WriteEntry(
                            "Startup Exception: Unable to get DB connection string. Check the .config file 'CMPContext' and 'CMPContextPassword' keys",
                            EventLogEntryType.Error, 10, 10);
                    }
                    return;
                }

                if (null != _eventLog)
                {
                    _eventLog.WriteEntry("CMP DB Connection string : " +
                                         GetClippenConnectionString(_cmpDbConnectionString),
                                         EventLogEntryType.Information, 1, 1);
                }
            }
            catch (Exception ex)
            {
                if (null != _eventLog)
                {
                    _eventLog.WriteEntry(
                        "Startup Exception: Exception in GetDbConnectionString() CMP : " +
                        CmpInterfaceModel.Utilities.UnwindExceptionMessages(ex),
                        EventLogEntryType.Error, 10, 10);
                }
            }
        }
Пример #12
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        ///
        //*********************************************************************

        bool JoinDomain()
        {
            string currectDomainName = null;

            try
            {
                if (ActiveDirLib.DomainJoin.IsDomainJoined(out currectDomainName))
                {
                    if (null != _EventLog)
                    {
                        _EventLog.WriteEntry("Domain Joined : " + currectDomainName, EventLogEntryType.Information, 10, 1);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (null != _EventLog)
                {
                    _EventLog.WriteEntry("Exception while detecting domain : " +
                                         CmpCommon.Utilities.UnwindExceptionMessages(ex), EventLogEntryType.Error, 100, 100);
                }
                return(true);
            }

            try
            {
                if (null != _EventLog)
                {
                    _EventLog.WriteEntry("Joining domain", EventLogEntryType.Information, 10, 1);
                }

                var domainName   = CloudConfigurationManager.GetSetting("CmpWorker.DomainJoin.DomainName");
                var userName     = CloudConfigurationManager.GetSetting("CmpWorker.DomainJoin.UserName");
                var userPassword = CloudConfigurationManager.GetSetting("CmpWorker.DomainJoin.UserPassword");
                //string destinationOU = CloudConfigurationManager.GetSetting("CmpWorker.DomainJoin.OU");
                string destinationOU = null;

                using (var XK = new KryptoLib.X509Krypto())
                    userPassword = XK.DecrpytKText(userPassword);

                ActiveDirLib.DomainJoin.Join(domainName, userPassword, userName, destinationOU);
            }
            catch (Exception ex)
            {
                if (null != _EventLog)
                {
                    _EventLog.WriteEntry("Exception while joining domain : " +
                                         CmpCommon.Utilities.UnwindExceptionMessages(ex), EventLogEntryType.Error, 100, 100);
                }
                return(true);
            }

            try
            {
                Thread.Sleep(20000);

                if (null != _EventLog)
                {
                    _EventLog.WriteEntry("Restarting after joining domain", EventLogEntryType.Information, 10, 1);
                }

                System.Diagnostics.Process.Start("shutdown", "/r");
            }
            catch (Exception ex)
            {
                if (null != _EventLog)
                {
                    _EventLog.WriteEntry("Exception while restarting after joining domain : " +
                                         CmpCommon.Utilities.UnwindExceptionMessages(ex), EventLogEntryType.Error, 100, 100);
                }
                return(true);
            }

            return(true);
        }
Пример #13
0
        //*********************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        ///
        //*********************************************************************

        private void GetDbConnectionString()
        {
            try
            {
                var xk = new KryptoLib.X509Krypto(null);
                _cmpDbConnectionString = xk.GetKTextConnectionString(
                    "CMPContext", "CMPContextPassword");

                if (null == _cmpDbConnectionString)
                {
                    if (null != _eventLog)
                    {
                        _eventLog.WriteEntry(
                            "Startup Exception: Unable to get DB connection string. Check the .config file 'CMPContext' and 'CMPContextPassword' keys",
                            EventLogEntryType.Error, 10, 10);
                    }
                    return;
                }

                if (null != _eventLog)
                {
                    _eventLog.WriteEntry("CMP DB Connection string : " +
                                         GetClippenConnectionString(_cmpDbConnectionString),
                                         EventLogEntryType.Information, 1, 1);
                }
            }
            catch (Exception ex)
            {
                if (null != _eventLog)
                {
                    _eventLog.WriteEntry(
                        "Startup Exception: Exception in GetDbConnectionString() CMP : " +
                        CmpInterfaceModel.Utilities.UnwindExceptionMessages(ex),
                        EventLogEntryType.Error, 10, 10);
                }
            }

            //*** Uncomment for AFTS support ***

            /*try
             * {
             *  var xk = new KryptoLib.X509Krypto(null);
             *  _aftsDbConnectionString = xk.GetKTextConnectionString(
             *      "AzureFileTransferContext", "AzureFileTransferContextPassword");
             *
             *  if (null == _aftsDbConnectionString)
             *  {
             *      if (null != _eventLog)
             *          _eventLog.WriteEntry(
             *              "Startup Exception: Unable to get AFTS DB connection string. Check the .config file 'AzureFileTransferContext' and 'AzureFileTransferContextPassword' keys",
             *              EventLogEntryType.Error, 10, 10);
             *      return;
             *  }
             *
             *  if (null != _eventLog)
             *      _eventLog.WriteEntry("AFTS DB Connection string : " +
             *          GetClippenConnectionString(_cmpDbConnectionString),
             *          EventLogEntryType.Information, 1, 1);
             * }
             * catch (Exception ex)
             * {
             *  if (null != _eventLog)
             *      _eventLog.WriteEntry(
             *          "Startup Exception: Exception in GetDbConnectionString() AFTS : " +
             *          CmpInterfaceModel.Utilities.UnwindExceptionMessages(ex),
             *          EventLogEntryType.Error, 10, 10);
             * }*/
        }