コード例 #1
0
        }// ImportCodegroup

        private NamedPermissionSet ImportPermissionSet()
        {
            // We're importing a permission set
            NamedPermissionSet nps = null;

            try
            {
                SecurityElement se = SecurityXMLStuff.GetSecurityElementFromXMLFile(PermissionSetFilename);
                if (se == null)
                {
                    throw new Exception("Invalid XML");
                }

                nps = new NamedPermissionSet("Hi");
                nps.FromXml(se);

                if (nps.Name == null || nps.Name.Length == 0)
                {
                    nps.Name = Security.FindAGoodPermissionSetName(m_pl, "CustomPermissionSet");
                }

                return(nps);
            }
            catch (Exception)
            {
                MessageBox(CResourceStore.GetString("XMLNoPermSet"),
                           CResourceStore.GetString("XMLNoPermSetTitle"),
                           MB.ICONEXCLAMATION);
            }
            return(null);
        }// ImportPermissionSet
コード例 #2
0
        }// onPropertiesClick

        void onImport(Object o, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();

            fd.Title  = CResourceStore.GetString("CNewPermSetWiz2:FDTitle");
            fd.Filter = CResourceStore.GetString("XMLFDMask");
            System.Windows.Forms.DialogResult dr = fd.ShowDialog();
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    SecurityElement se = SecurityXMLStuff.GetSecurityElementFromXMLFile(fd.FileName);
                    if (se == null)
                    {
                        throw new Exception("Null Element");
                    }
                    Type   type;
                    String className = se.Attribute("class");

                    if (className == null)
                    {
                        throw new Exception("Bad classname");
                    }

                    type = Type.GetType(className);

                    IPermission perm = (IPermission)Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, new Object[] { PermissionState.None }, null);

                    if (perm == null)
                    {
                        throw new Exception("Unable to create class");
                    }

                    perm.FromXml(se);
                    // We should check to see if this permission is already being stored
                    if (CheckForDuplicatePermission(ref perm))
                    {
                        PermissionPair pp = new PermissionPair();
                        int            nIndexOfPermName = className.LastIndexOf('.');
                        String         sPermissionName  = className.Substring(nIndexOfPermName + 1);

                        pp.sPermName = sPermissionName;
                        pp.perm      = perm;
                        m_alPermissions.Add(pp);
                        m_lbAssignedPerm.Items.Add(pp.sPermName);
                        RemoveThisTypeFromAvailablePermissions(perm);
                    }
                }
                catch (Exception)
                {
                    MessageBox(CResourceStore.GetString("Csinglecodegroupmemcondprop:BadXML"),
                               CResourceStore.GetString("Csinglecodegroupmemcondprop:BadXMLTitle"),
                               MB.ICONEXCLAMATION);
                }
            }
        }// onImport
コード例 #3
0
        }// NewPermissions

        protected override int WizFinish(IntPtr hwnd)
        {
            if (isImportXMLFile)
            {
                // We're importing a permission set
                try
                {
                    SecurityElement se = SecurityXMLStuff.GetSecurityElementFromXMLFile(XMLFilename);
                    if (se == null)
                    {
                        throw new Exception("Invalid XML");
                    }

                    m_ps = new NamedPermissionSet("Hi");
                    m_ps.FromXml(se);

                    if (m_ps.Name == null || m_ps.Name.Length == 0)
                    {
                        m_ps.Name = Security.FindAGoodPermissionSetName(m_pl, "CustomPermissionSet");
                    }

                    return(0);
                }
                catch (Exception)
                {
                    MessageBox(CResourceStore.GetString("XMLNoPermSet"),
                               CResourceStore.GetString("XMLNoPermSetTitle"),
                               MB.ICONEXCLAMATION);
                    SendMessage(GetParent(hwnd), PSM.SETCURSEL, (IntPtr)0, (IntPtr)(-1));
                    return(-1);
                }
            }

            // Ok, let's create our permission set
            NamedPermissionSet nps = new NamedPermissionSet(NewPermissionSetName, PermissionState.None);

            nps.Description = NewPermissionSetDescription;

            IPermission[] perms = NewPermissions;

            for (int i = 0; i < perms.Length; i++)
            {
                nps.SetPermission(perms[i]);
            }
            // Ok, now that we have this permission set, let's add it to
            // our other ones....
            m_ps = nps;
            return(0);
        }// WizFinish
コード例 #4
0
        }// NewPermissionSetDescription


        private CodeGroup ImportCodegroup()
        {
            CodeGroup cg = null;

            try
            {
                SecurityElement se = SecurityXMLStuff.GetSecurityElementFromXMLFile(CodeGroupFilename);
                if (se == null)
                {
                    throw new Exception("Invalid XML");
                }

                Type t = Type.GetType((String)se.Attributes["class"]);

                if (t != null)
                {
                    cg = (CodeGroup)Activator.CreateInstance(t, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null);
                }
                if (cg == null)
                {
                    MessageBox(CResourceStore.GetString("CNewCodeGroupWizard:UnknownClass"),
                               String.Format(CResourceStore.GetString("CNewCodeGroupWizard:UnknownClassTitle"), (String)se.Attributes["class"]),
                               MB.ICONEXCLAMATION);
                }
                else
                {
                    cg.FromXml(se);

                    if (cg.Name == null || cg.Name.Length == 0)
                    {
                        cg.Name = Security.FindAGoodCodeGroupName(m_pl, "CustomCodegroup");
                    }

                    return(cg);
                }
            }
            catch (Exception)
            {
                MessageBox(CResourceStore.GetString("CNewCodeGroupWizard:XMLNoCodegroup"),
                           CResourceStore.GetString("CNewCodeGroupWizard:XMLNoCodegroupTitle"),
                           MB.ICONEXCLAMATION);
            }
            return(null);
        }// ImportCodegroup