Example #1
0
        private void Init3()
        {
            // OZ Initialize Company Web Site Semaphore
            CompanyWebSiteSemaphore.Initialize();

            DbHelper2.Init2();

            ValidateSqlServerVesion();
            _sqlServerEdition = (SqlServerEdition)DBCommon.GetSqlServerEdition();

            DatabaseState state = (DatabaseState)DBCommon.GetDatabaseState();

            if (state != DatabaseState.Ready)
            {
                throw new DatabaseStateException(state);
            }

            Alerts2.Init();
            PortalConfig.Current.Init();

            _host = PortalConfig.SystemHost;
            string scheme = PortalConfig.SystemScheme;
            string port   = PortalConfig.SystemPort;

            _companyType = PortalConfig.CompanyType;

            if (PortalConfig.CompanyEndDate.HasValue)
            {
                _endDate = PortalConfig.CompanyEndDate.Value;
            }
            else
            {
                _endDate = DateTime.MaxValue;
            }

            _portalLink = string.Format("{0}://{1}{2}", scheme, _host, !string.IsNullOrEmpty(port) ? (":" + port) : "");
            _serverLink = _portalLink + "/";

            _defaultLocale = DBCommon.GetDefaultLanguageName();


            _initialized = true;
        }
Example #2
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        public static bool Initialize()
        {
            bool bResult = false;

            if (CurrentElement == null)
            {
                // lock
                lock (typeof(CompanyWebSiteSemaphore))
                {
                    if (CurrentElement == null)
                    {
                        int maxPortalsCount = License.PortalsCount;

                        Semaphore semaphore = null;

                        if (maxPortalsCount > 0)
                        {
                            // Step 1. Try open Semaphore

                            try
                            {
                                semaphore = Semaphore.OpenExisting(Uid);
                            }
                            catch (WaitHandleCannotBeOpenedException)
                            {
                                // The named semaphore does not exist.
                                SemaphoreSecurity security = new SemaphoreSecurity();

                                // OZ 2009-03-10/Fix: System.Security.Principal.IdentityNotMappedException
                                //SemaphoreAccessRule accessRule = new SemaphoreAccessRule("Everyone", SemaphoreRights.TakeOwnership | SemaphoreRights.FullControl, AccessControlType.Allow);
                                SecurityIdentifier  everyoneSid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                                SemaphoreAccessRule accessRule  = new SemaphoreAccessRule(everyoneSid, SemaphoreRights.TakeOwnership | SemaphoreRights.FullControl, AccessControlType.Allow);

                                security.AddAccessRule(accessRule);

                                bool createdNew;
                                semaphore = new Semaphore(maxPortalsCount, maxPortalsCount, Uid, out createdNew, security);
                            }

                            // Wait one with timeout
                            if (!semaphore.WaitOne(3000, false))
                            {
                                throw new LicenseRestrictionException("License.PortalsCount");
                            }

                            CurrentElement = new CompanyWebSiteSemaphore(semaphore);
                        }
                        else if (maxPortalsCount == -1)
                        {
                            // Unlimited
                            CurrentElement = new CompanyWebSiteSemaphore(null);
                        }
                        else
                        {
                            throw new LicenseRestrictionException("Wrong License.PortalsCount = " + maxPortalsCount.ToString());
                        }

                        bResult = true;
                    }
                }
            }

            return(bResult);
        }
Example #3
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        public static bool Initialize()
        {
            bool bResult = false;

            if (CurrentElement == null)
            {
                // lock
                lock (typeof(CompanyWebSiteSemaphore))
                {
                    if (CurrentElement == null)
                    {
                        int maxPortalsCount = License.PortalsCount;

                        Semaphore semaphore = null;

                        if (maxPortalsCount > 0)
                        {
                            // Step 1. Try open Semaphore

                            try
                            {
                                semaphore = Semaphore.OpenExisting(Uid);
                            }
                            catch (WaitHandleCannotBeOpenedException)
                            {
                                // The named semaphore does not exist.
                                SemaphoreSecurity security = new SemaphoreSecurity();

                                // OZ 2009-03-10/Fix: System.Security.Principal.IdentityNotMappedException
                                //SemaphoreAccessRule accessRule = new SemaphoreAccessRule("Everyone", SemaphoreRights.TakeOwnership | SemaphoreRights.FullControl, AccessControlType.Allow);
                                SecurityIdentifier everyoneSid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                                SemaphoreAccessRule accessRule = new SemaphoreAccessRule(everyoneSid, SemaphoreRights.TakeOwnership | SemaphoreRights.FullControl, AccessControlType.Allow);

                                security.AddAccessRule(accessRule);

                                bool createdNew;
                                semaphore = new Semaphore(maxPortalsCount, maxPortalsCount, Uid, out createdNew, security);
                            }

                            // Wait one with timeout
                            if (!semaphore.WaitOne(3000, false))
                            {
                                throw new LicenseRestrictionException("License.PortalsCount");
                            }

                            CurrentElement = new CompanyWebSiteSemaphore(semaphore);
                        }
                        else if (maxPortalsCount==-1)
                        {
                            // Unlimited
                            CurrentElement = new CompanyWebSiteSemaphore(null);
                        }
                        else
                            throw new LicenseRestrictionException("Wrong License.PortalsCount = " + maxPortalsCount.ToString());

                        bResult = true;
                    }
                }
            }

            return bResult;
        }
Example #4
0
 public static void Uninitialize()
 {
     // OZ Relese Company Web Site Semaphore
     CompanyWebSiteSemaphore.Uninitialize();
 }