Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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());
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }