private void chkStorageCache_CheckedChanged(object sender, EventArgs e)
 {
     if (this.chkStorageCache.Checked && this.chkCache.Checked)
     {
         this.chkCache.Checked = false;
     }
     this.cache = null;
 }
 private void rbCheckedChanged()
 {
     if (this.rbWindowsUser.Checked)
     {
         this.txtWindowsUser.ReadOnly  = false;
         this.txtWindowsUser.BackColor = SystemColors.Window;
         this.txtDBUser.BackColor      = SystemColors.Control;
         this.txtWindowsUser.Text      = String.Empty;
     }
     else
     {
         this.txtWindowsUser.ReadOnly  = true;
         this.txtWindowsUser.BackColor = SystemColors.Control;
         this.txtDBUser.BackColor      = SystemColors.Window;
     }
     this.txtWindowsUser.Text = String.Empty;
     this.txtDBUser.Text      = String.Empty;
     this.cache  = null;
     this.wid    = null;
     this.dbuser = null;
 }
 private void rbCheckedChanged()
 {
     if (this.rbWindowsUser.Checked)
     {
         this.txtWindowsUser.ReadOnly = false;
         this.txtWindowsUser.BackColor = SystemColors.Window;
         this.txtDBUser.BackColor = SystemColors.Control;
         this.txtWindowsUser.Text = String.Empty;
     }
     else
     {
         this.txtWindowsUser.ReadOnly = true;
         this.txtWindowsUser.BackColor = SystemColors.Control;
         this.txtDBUser.BackColor = SystemColors.Window;
     }
     this.txtWindowsUser.Text = String.Empty;
     this.txtDBUser.Text = String.Empty;
     this.cache = null;
     this.wid = null;
     this.dbuser = null;
 }
 private void chkStorageCache_CheckedChanged(object sender, EventArgs e)
 {
     if (this.chkStorageCache.Checked && this.chkCache.Checked)
         this.chkCache.Checked = false;
     this.cache = null;
 }
        private void checkAccessTest(TreeNode tn, Boolean turboMode, Hashtable resultCache, Hashtable attributesCache)
        {
            string sItemType = String.Empty;
            switch (tn.ImageIndex)
            {
                case 3: sItemType = Globalization.MultilanguageResource.GetString("Domain_Role"); break;
                case 4: sItemType = Globalization.MultilanguageResource.GetString("Domain_Task"); break;
                case 5: sItemType = Globalization.MultilanguageResource.GetString("Domain_Operation"); break;
            }
            AuthorizationType auth = AuthorizationType.Neutral;
            string sAuth = String.Empty;
            Stopwatch elapsed = new Stopwatch();

            List<KeyValuePair<string, string>> attributes = null;
            //Cache Build
            if (this.chkCache.Checked && this.cache == null)
            {
                this.WriteDetailMessage("Building UserPermissionCache ...");
                if (this.wid != null)
                {
                    this.cache = new NetSqlAzMan.Cache.UserPermissionCache(this.application.Store.Storage, this.application.Store.Name, this.application.Name, this.wid, true, true);
                }
                else if (this.dbuser != null)
                {
                    this.cache = new NetSqlAzMan.Cache.UserPermissionCache(this.application.Store.Storage, this.application.Store.Name, this.application.Name, this.dbuser, true, true);
                }
                elapsed.Stop();
                this.WriteLineDetailMessage(String.Format("[{0} mls.]\r\n", elapsed.ElapsedMilliseconds));
            }
            else if (this.chkStorageCache.Checked && this.storageCache == null)
            {
                this.WriteDetailMessage("Building StorageCache ...");
                this.storageCache = new NetSqlAzMan.Cache.StorageCache(this.application.Store.Storage.ConnectionString);
                this.storageCache.BuildStorageCache(this.application.Store.Name, application.Name);
                elapsed.Stop();
                this.WriteLineDetailMessage(String.Format("[{0} mls.]\r\n", elapsed.ElapsedMilliseconds));
            }
            elapsed.Restart();
            this.WriteDetailMessage(String.Format("{0} {1} '{2}' ... ", Globalization.MultilanguageResource.GetString("frmCheckAccessTest_Msg70"), sItemType, tn.Text));
            try
            {
                String itemName = tn.Text;
                if (!resultCache.ContainsKey(itemName))
                {
                    if (this.wid != null)
                    {
                        if (this.chkCache.Checked)
                        {
                            auth = this.cache.CheckAccess(tn.Text, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, out attributes);
                        }
                        else if (this.chkStorageCache.Checked)
                        {
                            IAzManItem item = (IAzManItem)tn.Tag;
                            auth = this.storageCache.CheckAccess(item.Application.Store.Name, item.Application.Name, item.Name, this.wid.GetUserBinarySSid(), this.wid.GetGroupsBinarySSid(), this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, false, out attributes);
                        }
                        else
                        {
                            auth = this.application.Store.Storage.CheckAccess(this.application.Store.Name, this.application.Name, tn.Text, this.wid, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, false, out attributes);
                        }
                    }
                    else if (this.dbuser != null)
                    {
                        if (this.chkCache.Checked)
                        {
                            auth = this.cache.CheckAccess(tn.Text, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, out attributes);
                        }
                        else if (this.chkStorageCache.Checked)
                        {
                            IAzManItem item = (IAzManItem)tn.Tag;
                            auth = this.storageCache.CheckAccess(item.Application.Store.Name, item.Application.Name, item.Name, this.dbuser.CustomSid.StringValue, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, false);
                        }
                        else
                        {
                            auth = this.application.Store.Storage.CheckAccess(this.application.Store.Name, this.application.Name, tn.Text, this.dbuser, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, false, out attributes);
                        }
                    }
                    resultCache.Add(itemName, auth);
                    attributesCache.Add(itemName, attributes);
                }
                else
                {
                    auth = (AuthorizationType)resultCache[itemName];
                    attributes = (List<KeyValuePair<String, String>>)attributesCache[itemName];
                }
                elapsed.Stop();
                sAuth = Globalization.MultilanguageResource.GetString("Domain_Neutral");
                switch (auth)
                {
                    case AuthorizationType.AllowWithDelegation:
                        sAuth = Globalization.MultilanguageResource.GetString("Domain_AllowWithDelegation");
                        tn.BackColor = Color.SkyBlue;
                        break;
                    case AuthorizationType.Allow:
                        sAuth = Globalization.MultilanguageResource.GetString("Domain_Allow");
                        tn.BackColor = Color.LightGreen;
                        break;
                    case AuthorizationType.Deny:
                        sAuth = Globalization.MultilanguageResource.GetString("Domain_Deny");
                        tn.BackColor = Color.LightSalmon;
                        break;
                    case AuthorizationType.Neutral:
                        sAuth = Globalization.MultilanguageResource.GetString("Domain_Neutral");
                        tn.BackColor = Color.Gainsboro;
                        break;
                }
                this.WriteLineDetailMessage(String.Format("{0} [{1} mls.]", sAuth, elapsed.ElapsedMilliseconds));
                if (attributes != null && attributes.Count > 0)
                {
                    this.WriteLineDetailMessage(String.Format(" {0} attribute(s) found:", attributes.Count));
                    int attributeIndex = 0;
                    foreach (KeyValuePair<string, string> attr in attributes)
                    {
                        this.WriteLineDetailMessage(String.Format("  {0}) Key: {1} Value: {2}", ++attributeIndex, attr.Key, attr.Value));
                    }
                }
            }
            catch (Exception ex)
            {
                sAuth = Globalization.MultilanguageResource.GetString("frmCheckAccessTest_Msg10");
                this.WriteLineDetailMessage(String.Format("{0} [{1} mls.]", ex.Message, elapsed.ElapsedMilliseconds));
            }
            tn.Text = String.Format("{0} - ({1})", tn.Text, sAuth.ToUpper());
            if (!turboMode)
            {
                tn.EnsureVisible();
                Application.DoEvents();
            }
            foreach (TreeNode tnChild in tn.Nodes)
            {
                this.checkAccessTest(tnChild, turboMode, resultCache, attributesCache);
            }
        }
        private void checkAccessTest(TreeNode tn, Boolean turboMode, Hashtable resultCache, Hashtable attributesCache)
        {
            string sItemType = String.Empty;

            switch (tn.ImageIndex)
            {
            case 3: sItemType = Globalization.MultilanguageResource.GetString("Domain_Role"); break;

            case 4: sItemType = Globalization.MultilanguageResource.GetString("Domain_Task"); break;

            case 5: sItemType = Globalization.MultilanguageResource.GetString("Domain_Operation"); break;
            }
            AuthorizationType auth    = AuthorizationType.Neutral;
            string            sAuth   = String.Empty;
            Stopwatch         elapsed = new Stopwatch();

            List <KeyValuePair <string, string> > attributes = null;

            //Cache Build
            if (this.chkCache.Checked && this.cache == null)
            {
                this.WriteDetailMessage("Building UserPermissionCache ...");
                if (this.wid != null)
                {
                    this.cache = new NetSqlAzMan.Cache.UserPermissionCache(this.application.Store.Storage, this.application.Store.Name, this.application.Name, this.wid, true, true);
                }
                else if (this.dbuser != null)
                {
                    this.cache = new NetSqlAzMan.Cache.UserPermissionCache(this.application.Store.Storage, this.application.Store.Name, this.application.Name, this.dbuser, true, true);
                }
                elapsed.Stop();
                this.WriteLineDetailMessage(String.Format("[{0} mls.]\r\n", elapsed.ElapsedMilliseconds));
            }
            else if (this.chkStorageCache.Checked && this.storageCache == null)
            {
                this.WriteDetailMessage("Building StorageCache ...");
                this.storageCache = new NetSqlAzMan.Cache.StorageCache(this.application.Store.Storage.ConnectionString);
                this.storageCache.BuildStorageCache(this.application.Store.Name, application.Name);
                elapsed.Stop();
                this.WriteLineDetailMessage(String.Format("[{0} mls.]\r\n", elapsed.ElapsedMilliseconds));
            }
            elapsed.Restart();
            this.WriteDetailMessage(String.Format("{0} {1} '{2}' ... ", Globalization.MultilanguageResource.GetString("frmCheckAccessTest_Msg70"), sItemType, tn.Text));
            try
            {
                String itemName = tn.Text;
                if (!resultCache.ContainsKey(itemName))
                {
                    if (this.wid != null)
                    {
                        if (this.chkCache.Checked)
                        {
                            auth = this.cache.CheckAccess(tn.Text, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, out attributes);
                        }
                        else if (this.chkStorageCache.Checked)
                        {
                            IAzManItem item = (IAzManItem)tn.Tag;
                            auth = this.storageCache.CheckAccess(item.Application.Store.Name, item.Application.Name, item.Name, this.wid.GetUserBinarySSid(), this.wid.GetGroupsBinarySSid(), this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, false, out attributes);
                        }
                        else
                        {
                            auth = this.application.Store.Storage.CheckAccess(this.application.Store.Name, this.application.Name, tn.Text, this.wid, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, false, out attributes);
                        }
                    }
                    else if (this.dbuser != null)
                    {
                        if (this.chkCache.Checked)
                        {
                            auth = this.cache.CheckAccess(tn.Text, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, out attributes);
                        }
                        else if (this.chkStorageCache.Checked)
                        {
                            IAzManItem item = (IAzManItem)tn.Tag;
                            auth = this.storageCache.CheckAccess(item.Application.Store.Name, item.Application.Name, item.Name, this.dbuser.CustomSid.StringValue, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, false);
                        }
                        else
                        {
                            auth = this.application.Store.Storage.CheckAccess(this.application.Store.Name, this.application.Name, tn.Text, this.dbuser, this.dtValidFor.Checked ? this.dtValidFor.Value : DateTime.Now, false, out attributes);
                        }
                    }
                    resultCache.Add(itemName, auth);
                    attributesCache.Add(itemName, attributes);
                }
                else
                {
                    auth       = (AuthorizationType)resultCache[itemName];
                    attributes = (List <KeyValuePair <String, String> >)attributesCache[itemName];
                }
                elapsed.Stop();
                sAuth = Globalization.MultilanguageResource.GetString("Domain_Neutral");
                switch (auth)
                {
                case AuthorizationType.AllowWithDelegation:
                    sAuth        = Globalization.MultilanguageResource.GetString("Domain_AllowWithDelegation");
                    tn.BackColor = Color.SkyBlue;
                    break;

                case AuthorizationType.Allow:
                    sAuth        = Globalization.MultilanguageResource.GetString("Domain_Allow");
                    tn.BackColor = Color.LightGreen;
                    break;

                case AuthorizationType.Deny:
                    sAuth        = Globalization.MultilanguageResource.GetString("Domain_Deny");
                    tn.BackColor = Color.LightSalmon;
                    break;

                case AuthorizationType.Neutral:
                    sAuth        = Globalization.MultilanguageResource.GetString("Domain_Neutral");
                    tn.BackColor = Color.Gainsboro;
                    break;
                }
                this.WriteLineDetailMessage(String.Format("{0} [{1} mls.]", sAuth, elapsed.ElapsedMilliseconds));
                if (attributes != null && attributes.Count > 0)
                {
                    this.WriteLineDetailMessage(String.Format(" {0} attribute(s) found:", attributes.Count));
                    int attributeIndex = 0;
                    foreach (KeyValuePair <string, string> attr in attributes)
                    {
                        this.WriteLineDetailMessage(String.Format("  {0}) Key: {1} Value: {2}", ++attributeIndex, attr.Key, attr.Value));
                    }
                }
            }
            catch (Exception ex)
            {
                sAuth = Globalization.MultilanguageResource.GetString("frmCheckAccessTest_Msg10");
                this.WriteLineDetailMessage(String.Format("{0} [{1} mls.]", ex.Message, elapsed.ElapsedMilliseconds));
            }
            tn.Text = String.Format("{0} - ({1})", tn.Text, sAuth.ToUpper());
            if (!turboMode)
            {
                tn.EnsureVisible();
                Application.DoEvents();
            }
            foreach (TreeNode tnChild in tn.Nodes)
            {
                this.checkAccessTest(tnChild, turboMode, resultCache, attributesCache);
            }
        }