예제 #1
0
        //Function import the certificate to the machine store and sets the friendly name
        static bool importCert()
        {
            try
            {
                //Create Certificate Object
                _certificate = new CertificateClass();
                //Load the certificate into the obejct from file
                _certificate.Load(_CertPath, "", CAPICOM_KEY_STORAGE_FLAG.CAPICOM_KEY_STORAGE_EXPORTABLE, CAPICOM_KEY_LOCATION.CAPICOM_LOCAL_MACHINE_KEY);
                //Create extended property Class for friendly name
                _friendlyProp        = new ExtendedPropertyClass();
                _friendlyProp.PropID = CAPICOM_PROPID.CAPICOM_PROPID_FRIENDLY_NAME;
                _friendlyProp.set_Value(CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BINARY, _FriendlyName);

                //Add extendedProp on cert object
                _extendedProp = _certificate.ExtendedProperties();
                //Set extendded prop to friendly name object
                _extendedProp.Add(_friendlyProp);
                _oCurrStore.Add(_certificate);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(_CertPath);
                return(true);
            }
        }
예제 #2
0
 /// <summary>
 /// Updates the item from the provided selection.
 /// </summary>
 /// <param name="selection">The selection</param>
 private void UpdateSelection(object selection)
 {
     if (!m_blockSelectionReentrancy)
     {
         SelectedCertificateClass = selection as CertificateClass;
     }
 }
예제 #3
0
        /// <summary>
        /// Gets the time to elite grade.
        /// </summary>
        /// <param name="certificateClass">The certificate class.</param>
        /// <returns>The time required to finish the final grade</returns>
        private static TimeSpan GetTimeToMaxLevel(CertificateClass certificateClass)
        {
            CertificateLevel levelFive = certificateClass.Certificate.GetCertificateLevel(5);

            return(levelFive.IsTrained
                ? TimeSpan.Zero
                : levelFive.GetTrainingTime);
        }
예제 #4
0
        /// <summary>
        /// When the tree's context menu opens,
        /// we update the submenus' statuses.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmListCerts_Opening(object sender, CancelEventArgs e)
        {
            ContextMenuStrip contextMenu = sender as ContextMenuStrip;

            e.Cancel = contextMenu?.SourceControl == null ||
                       (!contextMenu.SourceControl.Visible && m_selectedCertificateClass == null) ||
                       (!tvItems.Visible && m_plan == null);

            if (e.Cancel || contextMenu?.SourceControl == null)
            {
                return;
            }

            contextMenu.SourceControl.Cursor = Cursors.Default;

            CertificateClass certificateClass = null;
            TreeNode         node             = tvItems.SelectedNode;

            if (node != null)
            {
                certificateClass = node.Tag as CertificateClass;
            }

            if (m_selectedCertificateClass == null && certificateClass != null)
            {
                node = null;
            }

            cmiLvPlanToLevel.Visible = m_plan != null && m_selectedCertificateClass?.Certificate != null;
            planToSeparator.Visible  = m_plan != null && m_selectedCertificateClass?.Certificate != null && node != null && tvItems.Visible;

            // "Expand" and "Collapse" selected menu
            cmiExpandSelected.Visible   = m_selectedCertificateClass?.Certificate == null && node != null && !node.IsExpanded;
            cmiCollapseSelected.Visible = m_selectedCertificateClass?.Certificate == null && node != null && node.IsExpanded;

            cmiExpandSelected.Text = m_selectedCertificateClass?.Certificate == null && node != null && !node.IsExpanded
                ? $"Expand \"{node.Text}\""
                : String.Empty;
            cmiCollapseSelected.Text = m_selectedCertificateClass?.Certificate == null && node != null && node.IsExpanded
                ? $"Collapse \"{node.Text}\""
                : String.Empty;

            expandCollapseSeparator.Visible = m_selectedCertificateClass?.Certificate == null && node != null;

            // "Expand All" and "Collapse All" menu
            cmiCollapseAll.Enabled = cmiCollapseAll.Visible = tvItems.Visible && m_allExpanded;
            cmiExpandAll.Enabled   = cmiExpandAll.Visible = tvItems.Visible && !cmiCollapseAll.Enabled;

            if (m_selectedCertificateClass?.Certificate == null || m_plan == null)
            {
                return;
            }

            cmiLvPlanToLevel.Enabled = m_selectedCertificateClass?.Certificate != null &&
                                       !m_plan.WillGrantEligibilityFor(m_selectedCertificateClass.Certificate.GetCertificateLevel(5));

            cmiLvPlanToLevel.Text =
                $"Plan {(m_selectedCertificateClass == null ? String.Empty : $"\"{m_selectedCertificateClass?.Name}\" ")}to...";
        /// <summary>
        /// Updates the certificates tree.
        /// </summary>
        /// <param name="classes"></param>
        private void UpdateTree(IEnumerable <CertificateClass> classes)
        {
            //Reset selected object
            SelectedCertificateClass = null;

            // Fill the tree
            int numberOfItems = 0;

            tvItems.BeginUpdate();
            try
            {
                int imageIndex = tvItems.ImageList.Images.IndexOfKey("Certificate");

                foreach (TreeNode node in tvItems.Nodes)
                {
                    var category = (CertificateCategory)node.Tag;
                    node.ImageIndex         = imageIndex;
                    node.SelectedImageIndex = imageIndex;

                    node.Nodes.Clear();

                    foreach (var certClass in classes)
                    {
                        if (certClass.Category == category)
                        {
                            int index = GetCertImageIndex(certClass);

                            TreeNode childNode = new TreeNode()
                            {
                                Text               = certClass.Name,
                                ImageIndex         = index,
                                SelectedImageIndex = index,
                                Tag = certClass
                            };

                            numberOfItems++;
                            node.Nodes.Add(childNode);
                        }
                    }
                }
            }
            finally
            {
                tvItems.EndUpdate();
                m_allExpanded = false;

                // If the filtered set is small enough to fit all nodes on screen, call expandAll()
                if (numberOfItems < (tvItems.DisplayRectangle.Height / tvItems.ItemHeight))
                {
                    tvItems.ExpandAll();
                    m_allExpanded = true;
                }
            }
        }
예제 #6
0
        private void SetAdditionMenuStatus(ToolStripMenuItem menu, CertificateClass certClass, CertificateGrade grade)
        {
            var cert = certClass[grade];

            if (cert == null)
            {
                menu.Visible = false;
            }
            else
            {
                menu.Visible = true;
                menu.Enabled = !m_plan.WillGrantEligibilityFor(cert);
            }
        }
예제 #7
0
        /// <summary>
        /// Updates a "plan to" menu
        /// </summary>
        /// <param name="menu">The menu to update</param>
        /// <param name="certClass">The selected certificate class</param>
        /// <param name="grade">The grade represent by this menu</param>
        /// <param name="lastEligibleCert">The highest eligible certificate after this plan</param>
        private void UpdatePlanningMenuStatus(ToolStripMenuItem menu, CertificateClass certClass, CertificateGrade grade, Certificate lastEligibleCert)
        {
            var cert = certClass[grade];

            if (cert == null)
            {
                menu.Visible = false;
            }
            else
            {
                menu.Visible = true;
                if (lastEligibleCert == null)
                {
                    menu.Enabled = true;
                }
                else
                {
                    menu.Enabled = ((int)cert.Grade > (int)lastEligibleCert.Grade);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Gets the time to next grade.
        /// </summary>
        /// <param name="certificateClass">The certificate class.</param>
        /// <returns>The time required to finish the next grade</returns>
        private static TimeSpan GetTimeToNextLevel(CertificateClass certificateClass)
        {
            CertificateLevel lowestTrinedLevel = certificateClass.Certificate.LowestUntrainedLevel;

            return(lowestTrinedLevel?.GetTrainingTime ?? TimeSpan.Zero);
        }
예제 #9
0
 /// <summary>
 /// When the user select a new certificate class, we update everything.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void certSelectControl_SelectionChanged(object sender, EventArgs e)
 {
     SelectedCertificateClass = certSelectControl.SelectedCertificateClass;
 }
        /// <summary>
        /// Gets the image's index for the provided certificate class,
        /// lazily creating the images when they're needed.
        /// </summary>
        /// <param name="certClass"></param>
        /// <returns></returns>
        private int GetCertImageIndex(CertificateClass certClass)
        {
            // Prepare datas, especially image keys like "BSIE", "BSie", "BE", etc (lower for non-granted, upper for granted, only existing certs)
            // Correction : keys are insenstive, so we use 1234 instead of lower case letters
            char[]             chars   = new char[4];
            bool[]             granted = new bool[4];
            List <Certificate> certs   = new List <Certificate>(certClass);

            int index        = 0;
            int totalGranted = 0;

            foreach (var cert in certs)
            {
                bool isGranted = (cert.Status == CertificateStatus.Granted);
                if (isGranted)
                {
                    totalGranted++;
                    granted[index] = true;
                    chars[index]   = UpperCertificatesLetters[(int)cert.Grade]; // Gets "B" for granted basic
                }
                else
                {
                    chars[index] = LowerCertificatesLetters[(int)cert.Grade];  // Gets "b" for non-granted basic
                }

                index++;
            }

            // Special cases where we return immediately
            if (totalGranted == certs.Count)
            {
                return(tvItems.ImageList.Images.IndexOfKey("AllGranted"));
            }

            // Create key and retrieves its index, then returns if it already exists
            string key = new string(chars);

            index = tvItems.ImageList.Images.IndexOfKey(key);
            if (index != -1)
            {
                return(index);
            }

            // Create the image if it does not exist yet
            const int ImageSize      = 24;
            const int MaxLetterWidth = 6;
            Bitmap    bmp            = new Bitmap(ImageSize, ImageSize, PixelFormat.Format32bppArgb);

            using (var g = Graphics.FromImage(bmp))
            {
                string[] letters = new string[4];
                float[]  xPositions = new float[4];
                float    x = 0.0f, height = 0.0f;

                // Scroll through letters and measure them
                for (int i = 0; i < certs.Count; i++)
                {
                    letters[i] = UpperCertificatesLetters[(int)certs[i].Grade].ToString();
                    var size = g.MeasureString(letters[i], m_iconsFont, MaxLetterWidth, StringFormat.GenericTypographic);
                    height        = Math.Max(height, size.Height);
                    xPositions[i] = x;
                    x            += (size.Width + 1.0f);
                }

                // Y offset
                float y = Math.Max(0.0f, (ImageSize - (float)height) * 0.5f);

                // Draw the letters
                g.Clear(Color.White);
                using (var grantedBrush = new SolidBrush(Color.Blue))
                {
                    using (var nonGrantedBrush = new SolidBrush(Color.Gray))
                    {
                        for (int i = 0; i < certs.Count; i++)
                        {
                            // Special color for granted, gray for the other ones
                            bool isGranted = granted[i];
                            var  brush     = (isGranted ? grantedBrush : nonGrantedBrush);
                            g.DrawString(letters[i], m_iconsFont, brush, xPositions[i], y);
                        }
                    }
                }
            }

            // Insert image and return its index
            tvItems.ImageList.Images.Add(key, bmp);
            return(tvItems.ImageList.Images.IndexOfKey(key));
        }
        /// <summary>
        /// Updates the certificates tree.
        /// </summary>
        /// <param name="classes"></param>
        private void UpdateTree(IEnumerable<CertificateClass> classes)
        {
            //Reset selected object
            SelectedCertificateClass = null;

            // Fill the tree
            int numberOfItems = 0;
            tvItems.BeginUpdate();
            try
            {
                int imageIndex = tvItems.ImageList.Images.IndexOfKey("Certificate");

                foreach (TreeNode node in tvItems.Nodes)
                {

                    var category = (CertificateCategory)node.Tag;
                    node.ImageIndex = imageIndex;
                    node.SelectedImageIndex = imageIndex;

                    node.Nodes.Clear();

                    foreach (var certClass in classes)
                    {
                        if (certClass.Category == category)
                        {
                            int index = GetCertImageIndex(certClass);

                            TreeNode childNode = new TreeNode()
                            {
                                Text = certClass.Name,
                                ImageIndex = index,
                                SelectedImageIndex = index,
                                Tag = certClass
                            };

                            numberOfItems++;
                            node.Nodes.Add(childNode);
                        }
                    }
                }
            }
            finally
            {
                tvItems.EndUpdate();
                m_allExpanded = false;

                // If the filtered set is small enough to fit all nodes on screen, call expandAll()
                if (numberOfItems < (tvItems.DisplayRectangle.Height / tvItems.ItemHeight))
                {
                    tvItems.ExpandAll();
                    m_allExpanded = true;
                }
            }
        }
 /// <summary>
 /// Updates the selection with the provided item.
 /// </summary>
 /// <param name="selection"></param>
 private void UpdateSelection(object selection)
 {
     if (!m_blockSelectionReentrancy)
         SelectedCertificateClass = selection as CertificateClass;
 }
        /// <summary>
        /// Gets the image's index for the provided certificate class,
        /// lazily creating the images when they're needed.
        /// </summary>
        /// <param name="certClass"></param>
        /// <returns></returns>
        private int GetCertImageIndex(CertificateClass certClass)
        {
            // Prepare datas, especially image keys like "BSIE", "BSie", "BE", etc (lower for non-granted, upper for granted, only existing certs)
            // Correction : keys are insenstive, so we use 1234 instead of lower case letters
            char[] chars = new char[4];
            bool[] granted = new bool[4];
            List<Certificate> certs = new List<Certificate>(certClass);

            int index = 0;
            int totalGranted = 0;
            foreach (var cert in certs)
            {
                bool isGranted = (cert.Status == CertificateStatus.Granted);
                if (isGranted)
                {
                    totalGranted++;
                    granted[index] = true;
                    chars[index] = UpperCertificatesLetters[(int)cert.Grade];   // Gets "B" for granted basic
                }
                else
                {
                    chars[index] = LowerCertificatesLetters[(int)cert.Grade];  // Gets "b" for non-granted basic
                }

                index++;
            }

            // Special cases where we return immediately
            if (totalGranted == certs.Count)
                return tvItems.ImageList.Images.IndexOfKey("AllGranted");

            // Create key and retrieves its index, then returns if it already exists
            string key = new string(chars);
            index = tvItems.ImageList.Images.IndexOfKey(key);
            if (index != -1)
                return index;

            // Create the image if it does not exist yet
            const int ImageSize = 24;
            const int MaxLetterWidth = 6;
            Bitmap bmp = new Bitmap(ImageSize, ImageSize, PixelFormat.Format32bppArgb);

            using (var g = Graphics.FromImage(bmp))
            {
                string[] letters = new string[4];
                float[] xPositions = new float[4];
                float x = 0.0f, height = 0.0f;

                // Scroll through letters and measure them
                for (int i = 0; i < certs.Count; i++)
                {
                    letters[i] = UpperCertificatesLetters[(int)certs[i].Grade].ToString();
                    var size = g.MeasureString(letters[i], m_iconsFont, MaxLetterWidth, StringFormat.GenericTypographic);
                    height = Math.Max(height, size.Height);
                    xPositions[i] = x;
                    x += (size.Width + 1.0f);
                }

                // Y offset
                float y = Math.Max(0.0f, (ImageSize - (float)height) * 0.5f);

                // Draw the letters
                g.Clear(Color.White);
                using (var grantedBrush = new SolidBrush(Color.Blue))
                {
                    using (var nonGrantedBrush = new SolidBrush(Color.Gray))
                    {
                        for (int i = 0; i < certs.Count; i++)
                        {
                            // Special color for granted, gray for the other ones
                            bool isGranted = granted[i];
                            var brush = (isGranted ? grantedBrush : nonGrantedBrush);
                            g.DrawString(letters[i], m_iconsFont, brush, xPositions[i], y);
                        }
                    }
                }
            }

            // Insert image and return its index
            tvItems.ImageList.Images.Add(key, bmp);
            return tvItems.ImageList.Images.IndexOfKey(key);
        }