private void AddCourse()
        {
            string strPath       = txtServer.Text;
            string strCourseName = txtCourseName.Text;
            string strGuid       = System.Guid.NewGuid().ToString();

            if ((strCourseName == "") || (strPath == "") || (strPath == "http://"))
            {
                //User hasn't entered the information, so display error dialog
                MessageBox.Show(AMResources.GetLocalizedString("AddCourse_ErrorBlankField"),
                                this.Text,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }

            FacultyTools fac = new FacultyTools(m_applicationObject);

            if (!fac.CheckVersion(strPath + "/amversion.xml"))
            {
                //Error message has already been displayed
                return;
            }

            Utilities.RegisterAssignmentManagerCourse(m_applicationObject, strCourseName, strPath, strGuid);
            fac.RegenerateUserCustomTab(false);
            strPath += "/Faculty/AddCourse.aspx?CourseID=" + strGuid + "&CourseName=" + System.Web.HttpUtility.UrlEncode(strCourseName);
            m_applicationObject.ItemOperations.Navigate(strPath, vsNavigateOptions.vsNavigateOptionsDefault);
            this.Close();
        }
Exemple #2
0
 private void LocalizeLabels()
 {
     lblDescription.Text = AMResources.GetLocalizedString("AMStudentRemoveCourse_lblDescription");
     btnRemove.Text      = AMResources.GetLocalizedString("AMStudentRemoveCourse_btnRemove");
     btnCancel.Text      = AMResources.GetLocalizedString("BtnCancel");
     this.Text           = AMResources.GetLocalizedString("AMStudentRemoveCourse_DialogCaption");
 }
 private void LocalizeLabels()
 {
     lblDescription.Text    = AMResources.GetLocalizedString("DeleteCourse_lblDescription");
     btnDeleteSelected.Text = AMResources.GetLocalizedString("DeleteCourse_btnDelete");
     btnCancel.Text         = AMResources.GetLocalizedString("BtnCancel");
     this.Text = AMResources.GetLocalizedString("DeleteCourse_DialogCaption");
 }
Exemple #4
0
 private void LocalizeLabels()
 {
     lblAMUrl.Text  = AMResources.GetLocalizedString("AddExistingCourse_LblAMUrl");
     btnAdd.Text    = AMResources.GetLocalizedString("BtnAdd");
     btnCancel.Text = AMResources.GetLocalizedString("BtnCancel");
     txtServer.Text = AMResources.GetLocalizedString("HttpText");
     this.Text      = AMResources.GetLocalizedString("AddExistingCourse_DialogCaption");
 }
 private void LocalizeLabels()
 {
     lblDescription.Text = AMResources.GetLocalizedString("AMStudentAddCourse_lblDescription");
     lblAMUrl.Text       = AMResources.GetLocalizedString("AMStudentAddCourse_lblAMUrl");
     btnAdd.Text         = AMResources.GetLocalizedString("BtnAdd");
     btnCancel.Text      = AMResources.GetLocalizedString("BtnCancel");
     txtCourseURL.Text   = AMResources.GetLocalizedString("HttpText");
     this.Text           = AMResources.GetLocalizedString("AMStudentAddCourse_DialogCaption");
 }
Exemple #6
0
        /// <summary>
        /// Registers a command and places it onto the context menu for the editor
        /// window.
        /// </summary>
        public void OnConnection(EnvDTE._DTE application, Extensibility.ext_ConnectMode connectMode, EnvDTE.AddIn addIn)
        {
            m_applicationObject = (EnvDTE._DTE)application;
            m_addInInstance     = (EnvDTE.AddIn)addIn;

            m_strCommandName = "MarkCodeForExtraction";
            m_strName        = AMResources.GetLocalizedString("CodeMarkerName");
            m_strItemText    = AMResources.GetLocalizedString("CodeMarkerItemText");

            string description = AMResources.GetLocalizedString("CodeMarkerDescription");

            EnvDTE.Commands commands = null;
            EnvDTE.Command  command  = null;
            Microsoft.Office.Core._CommandBars      officeCommandBars    = null;
            Microsoft.Office.Core.CommandBar        officeCommandBar     = null;
            Microsoft.Office.Core.CommandBarControl officeCommandControl = null;
            Microsoft.Office.Core.CommandBar        officeAcademic       = null;
            object [] contextGuids;
            contextGuids = new object[] { };

            commands = m_applicationObject.Commands;
            try
            {
                command = commands.AddNamedCommand(m_addInInstance, m_strCommandName, m_strName, description,
                                                   true, 12, ref contextGuids, (int)(EnvDTE.vsCommandStatus.vsCommandStatusEnabled | EnvDTE.vsCommandStatus.vsCommandStatusSupported));

                // Add the new command to the top-level context menu for the editor
                // code window, if possible.
                officeCommandBars            = m_applicationObject.CommandBars;
                officeCommandBar             = (CommandBar)officeCommandBars["Code Window"];
                officeCommandControl         = command.AddControl((object)officeCommandBar, 1);
                officeCommandControl.Caption = m_strItemText;

                string amFacultyMenuItem = AMResources.GetLocalizedString("AMFacultyMenuItem");
                // Also attempt to add it to the Tools menu as well, for accessibility.
                try
                {
                    officeAcademic = (CommandBar)officeCommandBars[amFacultyMenuItem];
                }
                catch
                {
                }
                if (officeAcademic == null)
                {
                    officeCommandBar = (CommandBar)officeCommandBars["Tools"];
                    officeAcademic   = (CommandBar)m_applicationObject.Commands.AddCommandBar(amFacultyMenuItem, EnvDTE.vsCommandBarType.vsCommandBarTypeMenu, officeCommandBar, 1);
                }

                officeCommandControl         = command.AddControl((object)officeAcademic, 1);
                officeCommandControl.Caption = AMResources.GetLocalizedString("CodeMarkerToolsMenuItemText");
            }
            catch (System.Exception /*e*/)
            {
                // Falling into this simply means that the command was already registered.
            }
        }
        /// <summary>
        /// Called when the AddIn is loaded. This method allows each of the commands to
        /// store member variables with the objects passed in and ensure that the menu
        /// items and commands have been properly added to the object model.
        /// </summary>
        /// <param name="application"> Root object in the application </param>
        /// <param name="connectMode"> 'Mode' in which the environment is starting up the addin </param>
        /// <param name="addIn"> Object representing this AddIn in the Object Model</param>
        public void OnConnection(EnvDTE._DTE application, Extensibility.ext_ConnectMode connectMode, EnvDTE.AddIn addIn)
        {
            try
            {
                m_applicationObject = (EnvDTE._DTE)application;
                m_addInInstance     = (EnvDTE.AddIn)addIn;

                m_strCommandName = "AMDeleteCourse";
                m_strName        = AMResources.GetLocalizedString("AMDeleteCourseName");
                m_strItemText    = AMResources.GetLocalizedString("AMDeleteCourseItemText");

                string            description          = AMResources.GetLocalizedString("AMDeleteCourseDescription");
                EnvDTE.Commands   commands             = null;
                EnvDTE.Command    command              = null;
                _CommandBars      officeCommandBars    = null;
                CommandBar        officeCommandBar     = null;
                CommandBarControl officeCommandControl = null;
                CommandBar        officeAcademic       = null;

                object [] contextGuids;
                contextGuids = new object[] { };

                commands = m_applicationObject.Commands;
                try
                {
                    command = commands.AddNamedCommand(m_addInInstance, m_strCommandName, m_strName, description,
                                                       false, 108, ref contextGuids, (int)(EnvDTE.vsCommandStatus.vsCommandStatusEnabled | EnvDTE.vsCommandStatus.vsCommandStatusSupported));

                    // Add the new command to the tools menu
                    officeCommandBars = m_applicationObject.CommandBars;
                    string amFacultyMenuItem = AMResources.GetLocalizedString("AMFacultyMenuItem");
                    try
                    {
                        officeAcademic = (CommandBar)officeCommandBars[amFacultyMenuItem];
                    }
                    catch
                    {
                    }
                    if (officeAcademic == null)
                    {
                        officeCommandBar = (CommandBar)officeCommandBars["Tools"];
                        officeAcademic   = (CommandBar)m_applicationObject.Commands.AddCommandBar(amFacultyMenuItem, EnvDTE.vsCommandBarType.vsCommandBarTypeMenu, officeCommandBar, 1);
                    }
                    officeCommandControl         = command.AddControl((object)officeAcademic, 1);
                    officeCommandControl.Caption = m_strItemText;
                }
                catch
                {
                    // Falling into this simply means that the command was already registered.
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception e = " + e.Message);
            }
        }
Exemple #8
0
        /// <summary>
        /// Registers a command and places it on the Tools menu.
        /// </summary>
        public void OnConnection(EnvDTE._DTE application, Extensibility.ext_ConnectMode connectMode, EnvDTE.AddIn addIn)
        {
            m_applicationObject = (EnvDTE._DTE)application;
            m_addInInstance     = (EnvDTE.AddIn)addIn;

            m_strCommandName = "AMStudentGotoHomePage";
            m_strName        = AMResources.GetLocalizedString("AMStudentGotoHomePageName");
            m_strItemText    = AMResources.GetLocalizedString("AMStudentGotoHomePageItemText");
            m_strHomePageUrl = "vs:/default.htm?tab=" + AMResources.GetLocalizedString("AMStudentGotoHomePagePageName");

            string strDescription = AMResources.GetLocalizedString("GotoHomePageDescription");

            EnvDTE.Commands commands = null;
            EnvDTE.Command  command  = null;
            Microsoft.Office.Core._CommandBars      officeCommandBars    = null;
            Microsoft.Office.Core.CommandBar        officeCommandBar     = null;
            Microsoft.Office.Core.CommandBarControl officeCommandControl = null;
            Microsoft.Office.Core.CommandBar        officeAcademic       = null;
            object [] contextGuids;
            contextGuids = new object[] { };

            commands = m_applicationObject.Commands;
            try
            {
                command = commands.AddNamedCommand(m_addInInstance, m_strCommandName, m_strName, strDescription,
                                                   false, 108, ref contextGuids, (int)(EnvDTE.vsCommandStatus.vsCommandStatusEnabled | EnvDTE.vsCommandStatus.vsCommandStatusSupported));

                // Add the new command to the tools menu
                officeCommandBars = m_applicationObject.CommandBars;
                string amStudentMenuItem = AMResources.GetLocalizedString("AMStudentMenuItem");
                try
                {
                    officeAcademic = (CommandBar)officeCommandBars[amStudentMenuItem];
                }
                catch
                {
                }
                if (officeAcademic == null)
                {
                    officeCommandBar = (CommandBar)officeCommandBars["Tools"];
                    officeAcademic   = (CommandBar)m_applicationObject.Commands.AddCommandBar(amStudentMenuItem, EnvDTE.vsCommandBarType.vsCommandBarTypeMenu, officeCommandBar, 1);
                }
                officeCommandControl         = command.AddControl((object)officeAcademic, 1);
                officeCommandControl.Caption = m_strItemText;
            }
            catch (System.Exception /*e*/)
            {
                // Falling into this simply means that the command was already registered.
            }
        }
Exemple #9
0
        /// <summary>
        /// The current comments are retrieved by obtaining the Properites object from the
        /// Tools Options window associated with the Academic toolset and walking down the
        /// set of registered file extensions looking for the one corresponding to
        /// the file type currently opened.
        /// </summary>
        private CommentPair GetCurrentComments()
        {
            EnvDTE.Document     document            = null;
            EnvDTE.TextDocument textDocument        = null;
            EnvDTE.Properties   extractorProperties = null;
            Extensions          extensions          = null;
            string extension;
            int    lastIndex;

            try
            {
                // While we don't *do* anything with the document object, we check for its presence because
                // we only know how to do insertions on the TextDocument class of object.
                document = m_applicationObject.ActiveDocument;
                if ((document == null) ||
                    ((textDocument = document.Object("TextDocument") as EnvDTE.TextDocument) == null))
                {
                    return(null);
                }

                extension = m_applicationObject.ActiveDocument.Name;
                lastIndex = extension.LastIndexOf('.');
                if (lastIndex == -1)
                {
                    return(null);
                }
                extension = extension.Remove(0, lastIndex + 1);                 // Trim off the 'name.' part of 'name.ext'

                extractorProperties = m_applicationObject.get_Properties("Assignment Manager", "Code Extractor");
                if (extractorProperties == null)
                {
                    throw new Exception(AMResources.GetLocalizedString("CollapseMarkedInvalidInstallation"));
                }

                extensions = extractorProperties.Item("Extensions").Object as Extensions;
                if (extensions == null)
                {
                    throw new Exception(AMResources.GetLocalizedString("CollapseMarkedInvalidInstallation"));
                }

                return(extensions[extension]);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #10
0
        /// <summary>
        /// This function is only called when the UI is about to be displayed. Therefore, the
        /// InitializeComponent() call has been moved into here to avoid making users of the
        /// automation model to drive this object pay the UI initialization penalty.
        /// </summary>
        public void OnAfterCreated(EnvDTE.DTE dte)
        {
            m_applicationObject = dte;
            m_extComments       = new ExtensionComments();
            m_extComments.LoadFromRegistry();

            try
            {
                m_strFileExtensionField = AMResources.GetLocalizedString("ToolsOptionsFileExtensionField");
                m_strBeginCommentField  = AMResources.GetLocalizedString("ToolsOptionsBeginCommentsField");
                m_strEndCommentField    = AMResources.GetLocalizedString("ToolsOptionsEndCommentsField");
            }
            catch (System.Exception)
            {
                m_strFileExtensionField = "";
                m_strBeginCommentField  = "";
                m_strEndCommentField    = "";
                return;
            }

            InitializeComponent();

            PopulateTable();
        }
Exemple #11
0
        private void btnRemove_Click(object sender, System.EventArgs e)
        {
            //Confirm
            string       text   = AMResources.GetLocalizedString("ConfirmRemoveCourse");
            DialogResult result = MessageBox.Show(text, "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                int         nCount      = deleteCourseList.Items.Count;
                ClientTools clientTools = new ClientTools(m_applicationObject);
                for (int i = 0; i < nCount; i++)
                {
                    if (deleteCourseList.GetSelected(i))
                    {
                        string courseGuid = courseGuids[i];
                        if (courseGuid != null && courseGuid != String.Empty)
                        {
                            clientTools.UnregisterAssignmentManagerCourse(courseGuid);
                        }
                    }
                }
                this.Close();
            }
        }
        private void AddCourse()
        {
            if ((this.txtCourseURL.Text == String.Empty) || (this.txtCourseURL.Text == "http://"))
            {
                //User hasn't entered the information, so display error dialog
                MessageBox.Show(AMResources.GetLocalizedString("AMStudentAddCourse_ErrorBlankField"),
                                this.Text,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }

            ClientTools clientTools = new ClientTools(m_applicationObject);
            string      courseGuid  = Guid.NewGuid().ToString();
            string      url         = txtCourseURL.Text;

            string versionURL = "";

            try
            {
                string strServer;
                if (url.StartsWith("http://"))
                {
                    versionURL = "http://";
                    strServer  = url.Substring(7);
                }
                else if (url.StartsWith("https://"))
                {
                    versionURL = "https://";
                    strServer  = url.Substring(8);
                }
                else
                {
                    versionURL = "http://";
                    strServer  = url;
                }

                int nIndex = strServer.IndexOf("/");
                if (nIndex == -1)
                {
                    throw new System.ArgumentException();
                }

                //find the second one
                nIndex = strServer.IndexOf("/", nIndex + 1);

                strServer   = strServer.Substring(0, nIndex);
                versionURL += strServer + "/amversion.xml";
            }
            catch
            {
                versionURL = "";
            }

            if (versionURL == "")
            {
                string message = AssignmentManager.ClientUI.AMResources.GetLocalizedString("AddCourse_ErrorWrongServerName");
                string caption = AssignmentManager.ClientUI.AMResources.GetLocalizedString("AddCourse_ErrorWrongServerNameCaption");
                message = message.Replace("%1", url);
                System.Windows.Forms.MessageBox.Show(message, caption, System.Windows.Forms.MessageBoxButtons.OK,
                                                     System.Windows.Forms.MessageBoxIcon.Warning);
                return;
            }
            else if (!clientTools.CheckVersion(versionURL))
            {
                return;
            }

            XmlDocument xmlCourseDoc = clientTools.GetCourseFile(url);

            if (xmlCourseDoc == null)
            {
                //Not a valid course file
                string text = AMResources.GetLocalizedString("AddCourseFail");
                MessageBox.Show(text, "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                XmlNode node          = xmlCourseDoc.SelectSingleNode("/course/assnmgr");
                string  strCourseName = xmlCourseDoc.SelectSingleNode("/course/name").InnerText;
                string  strUrl        = node.SelectSingleNode("amurl").InnerText;
                string  strGUID       = node.SelectSingleNode("guid").InnerText;
                clientTools.RegisterAssignmentManagerCourse(strCourseName, strUrl, strGUID, url);

                strUrl += "/Student/AddCourse.aspx?CourseID=" + strGUID;
                try
                {
                    m_applicationObject.ItemOperations.Navigate(strUrl, vsNavigateOptions.vsNavigateOptionsNewWindow);
                }
                catch
                {
                }
                this.Close();
            }
        }
        /// <summary>
        /// Given a source and a destination, this function creates a new project, optionally performing code
        /// extraction upon it. A return of false means that either the project could not be created or
        /// there was an error with the extraction process.
        /// </summary>
        /// <param name="sourceUniqueProjectName"> The 'uniquename' property of the project to retrieve params from</param>
        /// <param name="path"> Output path, UNC / file paths only</param>
        /// <param name="destProjectName"> Name of the project to create </param>
        /// <param name="performExtraction"> Whether or not to extract properly-delimited sections of text from the source</param>
        public bool CreateNewProject(string sourceUniqueProjectName, string path, string destProjectName, bool performExtraction)
        {
            bool fSucceeded = true;

            if (sourceUniqueProjectName == null)
            {
                throw new System.ArgumentNullException("sourceUniqueProjectName");
            }
            if (path == null)
            {
                throw new System.ArgumentNullException("path");
            }
            if (destProjectName == null)
            {
                throw new System.ArgumentNullException("destProjectName");
            }

            string strProjDestUniqueName = null;

            EnvDTE.Project projDest        = null;
            EnvDTE.Project projSource      = null;
            EnvDTE._DTE    dteOutOfProcess = null;

            try
            {
                //        if (m_taskWindow == null) {
                //          m_taskWindow = new TaskWindow.DelayLoadTaskWindow(m_application);
                //        }

                projSource = GetValidProject(sourceUniqueProjectName);
                if (projSource == null)
                {
                    throw new Exception(AMResources.GetLocalizedString("CodeExtractorNoBaseProject"));
                }

                // NOTE: This is a method in the docs, but a property in implementation.
                object ignore = m_application.ItemOperations.PromptToSave;


                dteOutOfProcess = (EnvDTE._DTE) new VisualStudio_DTE_7_1();
                projDest        = CopyProject(projSource, dteOutOfProcess, path, destProjectName);
                if (projDest == null)
                {
                    throw new Exception(AMResources.GetLocalizedString("CodeExtractorInvalidProjectType"));
                }

                strProjDestUniqueName = projDest.UniqueName;
                if (performExtraction)
                {
                    // Perform extraction - on first user error, open handle to task-list. Log all errors to it.
                    if (!ExtractItems(projSource.ProjectItems, dteOutOfProcess, projDest.ProjectItems))
                    {
                        throw new Exception(AMResources.GetLocalizedString("CodeExtractorInvalidMarkedTags"));
                    }
                }
            }
            finally
            {
                if ((dteOutOfProcess != null) &&
                    (dteOutOfProcess != m_application))
                {
                    // The solution has to be closed because if we're out of process, the
                    // application might not close for a little while, leaving around
                    // extant 'file opened exclusively' problems.
                    dteOutOfProcess.Solution.Close(false);

                    dteOutOfProcess.Quit();
                    dteOutOfProcess = null;
                }
            }

            return(fSucceeded);
        }
        /// <summary>
        /// This actually removes the text or, if there are errors, logs them to the task list.
        ///
        /// There are six cases to handle:
        /// <no tags> -> true
        /// <just a start> -> error
        /// <just an end> -> error
        /// <end> <start> -> error
        /// <start> <start> -> error
        /// <start> <end> -> success -- remove *and* proceed to loop again!
        /// </summary>
        /// <param name="TextDoc"> Document upon which to operate. </param>
        /// <param name="currentPos"> The current position from which execution should proceed. </param>
        /// <param name="begin"> String denoting the begin tag to find. </param>
        /// <param name="end"> String denoting the end tag to find. </param>
        /// <param name="linesRemoved"> Number of lines that have already been removed from the file. </param>
        private bool ExtractTextHelper(EnvDTE.Document doc, EnvDTE.EditPoint currentPos, string begin, string end, EnvDTE.ProjectItems projSourceItems, int linesRemoved)
        {
            EnvDTE.EditPoint  startTagPoint, endTagPoint, nextStartTagPoint;
            EnvDTE.TextRanges trIgnore = null;
            bool fGotStart, fGotEnd, fGotNextStart;

            startTagPoint = currentPos.CreateEditPoint();
            endTagPoint   = currentPos.CreateEditPoint();

            fGotStart = startTagPoint.FindPattern(begin, (int)EnvDTE.vsFindOptions.vsFindOptionsNone, ref startTagPoint, ref trIgnore);
            fGotEnd   = endTagPoint.FindPattern(end, (int)EnvDTE.vsFindOptions.vsFindOptionsNone, ref endTagPoint, ref trIgnore);

            if (!fGotStart && !fGotEnd)
            {
                return(true);
            }

            if (fGotStart && !fGotEnd)
            {
                // Error, end tag expected after startTagPoint
                string strError = AMResources.GetLocalizedString("TagValidationMissingEndAfter");
                //        m_taskWindow.LogErrorToTaskWindow(System.String.Format(strError, end),
                //          projSourceItems.Item(doc.Name).get_FileNames(1), startTagPoint.Line + linesRemoved);
                return(false);
            }

            if (fGotEnd && !fGotStart)
            {
                // Error, start tag expected before endTagPoint
                string strError = AMResources.GetLocalizedString("TagValidationMissingStartBefore");
                //        m_taskWindow.LogErrorToTaskWindow(System.String.Format(strError, begin),
                //          projSourceItems.Item(doc.Name).get_FileNames(1), endTagPoint.Line + linesRemoved);
                return(false);
            }

            if (endTagPoint.AbsoluteCharOffset < startTagPoint.AbsoluteCharOffset)
            {
                // Error, start tag expected before endTagPoint
                string strError = AMResources.GetLocalizedString("TagValidationMissingStartBefore");
                //        m_taskWindow.LogErrorToTaskWindow(System.String.Format(strError, begin),
                //          projSourceItems.Item(doc.Name).get_FileNames(1), endTagPoint.Line + linesRemoved);
                return(false);
            }

            nextStartTagPoint = startTagPoint.CreateEditPoint();
            fGotNextStart     = nextStartTagPoint.FindPattern(begin, (int)EnvDTE.vsFindOptions.vsFindOptionsNone, ref nextStartTagPoint, ref trIgnore);

            if (fGotNextStart && (endTagPoint.AbsoluteCharOffset > nextStartTagPoint.AbsoluteCharOffset))
            {
                // Error, end tag expected before endTagPoint
                string strError = AMResources.GetLocalizedString("TagValidationMissingEndBefore");
                //        m_taskWindow.LogErrorToTaskWindow(System.String.Format(strError, end),
                //          projSourceItems.Item(doc.Name).get_FileNames(1), nextStartTagPoint.Line + linesRemoved);
                return(false);
            }

            if (startTagPoint.AbsoluteCharOffset < endTagPoint.AbsoluteCharOffset)
            {
                linesRemoved += (endTagPoint.Line - startTagPoint.Line);
                startTagPoint.CharLeft(begin.Length);
                startTagPoint.Delete((object)endTagPoint);

                return(ExtractTextHelper(doc, endTagPoint, begin, end, projSourceItems, linesRemoved));
            }

            System.Diagnostics.Debug.Assert(false, "Impossible code path followed in ExtractTextHelper()");
            return(true);
        }
Exemple #15
0
        private void AddCourse()
        {
            if (this.txtServer.Text == String.Empty || this.txtServer.Text == "http://")
            {
                //User hasn't entered the information, so display error dialog
                MessageBox.Show(AMResources.GetLocalizedString("AddExistingCourse_ErrorBlankField"),
                                this.Text,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }

            FacultyTools fac        = new FacultyTools(m_applicationObject);
            string       url        = txtServer.Text;
            string       versionURL = "";

            try
            {
                string strServer;
                if (url.StartsWith("http://"))
                {
                    versionURL = "http://";
                    strServer  = url.Substring(7);
                }
                else if (url.StartsWith("https://"))
                {
                    versionURL = "https://";
                    strServer  = url.Substring(8);
                }
                else
                {
                    versionURL = "http://";
                    strServer  = url;
                }

                int nIndex = strServer.IndexOf("/");
                if (nIndex == -1)
                {
                    throw new System.ArgumentException();
                }

                //find the second one
                nIndex = strServer.IndexOf("/", nIndex + 1);

                strServer   = strServer.Substring(0, nIndex);
                versionURL += strServer + "/amversion.xml";
            }
            catch
            {
                versionURL = "";
            }

            if (versionURL == "" || !fac.CheckVersion(versionURL))
            {
                return;
            }

            string courseUrl = fac.RegisterCourseFromUrl(url);

            if (courseUrl == null)
            {
                string errorMessage = AMResources.GetLocalizedString("AddExisting_Error_UnableToRegisterExistingCourse");
                if (errorMessage != String.Empty)
                {
                    MessageBox.Show(errorMessage, "Add Existing Course", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                m_applicationObject.ItemOperations.Navigate(courseUrl, vsNavigateOptions.vsNavigateOptionsDefault);
                this.Close();
            }
        }
        /// <summary>
        /// This checks the registry for pre-existing values for file extensions and tags. If they are there, it
        /// loads them into memory. If they are not, then it loads the defaults from the resources embedded into
        /// the module itself.
        /// If the data are inconsitant in the registry, then an InvalidOperationException will be thrown.
        /// </summary>
        public void LoadFromRegistry()
        {
            int iCollapse      = 0;
            int iPromptForTodo = 0;

            m_Entries = new System.Collections.ArrayList();

            Microsoft.Win32.RegistryKey keyRoot  = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(s_strRoot);
            Microsoft.Win32.RegistryKey keyID    = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(s_strRoot + "\\" + s_strIDKey);
            Microsoft.Win32.RegistryKey keyBegin = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(s_strRoot + "\\" + s_strBeginTagsKey);
            Microsoft.Win32.RegistryKey keyEnd   = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(s_strRoot + "\\" + s_strEndTagsKey);

            if ((keyID != null) &&
                (keyBegin != null) &&
                (keyEnd != null) &&
                (keyRoot != null))
            {
                try
                {
                    // First, get the Collapse-state. Default to 'true', if the value no
                    // longer exists.
                    iCollapse = (int)keyRoot.GetValue(s_strCollapseValue, 1);
                    if (iCollapse == 0)
                    {
                        m_collapse = false;
                    }
                    else
                    {
                        m_collapse = true;
                    }

                    iPromptForTodo = (int)keyRoot.GetValue(s_strPromptForTodoValue, 1);
                    if (iPromptForTodo == 0)
                    {
                        m_todo = false;
                    }
                    else
                    {
                        m_todo = true;
                    }

                    // Then, all of the comment settings.
                    string [] values = keyID.GetValueNames();

                    foreach (string value in values)
                    {
                        string extensions = (string)keyID.GetValue(value);
                        string begin      = (string)keyBegin.GetValue(value);
                        string end        = (string)keyEnd.GetValue(value);

                        m_Entries.Add(new ExtensionComment(extensions, begin, end));
                    }
                }
                catch (System.Exception)
                {
                    throw new System.InvalidOperationException();
                }
            }
            else
            {
                m_collapse = true;
                m_todo     = true;

                try
                {
                    m_Entries.Add(new ExtensionComment(AMResources.GetLocalizedString("ToolsOptionsDefaultCPPExtensions"),
                                                       AMResources.GetLocalizedString("ToolsOptionsDefaultCPPBeginTag"),
                                                       AMResources.GetLocalizedString("ToolsOptionsDefaultCPPEndTag")));
                    m_Entries.Add(new ExtensionComment(AMResources.GetLocalizedString("ToolsOptionsDefaultCExtensions"),
                                                       AMResources.GetLocalizedString("ToolsOptionsDefaultCBeginTag"),
                                                       AMResources.GetLocalizedString("ToolsOptionsDefaultCEndTag")));
                    m_Entries.Add(new ExtensionComment(AMResources.GetLocalizedString("ToolsOptionsDefaultVBExtensions"),
                                                       AMResources.GetLocalizedString("ToolsOptionsDefaultVBBeginTag"),
                                                       AMResources.GetLocalizedString("ToolsOptionsDefaultVBEndTag")));
                }
                catch (System.Exception)
                {
                    // Failed to load localization support, so just fall back on English default values and attempt to continue.
                    m_Entries.Add(new ExtensionComment(".cpp, .cs, .h", "//BEGIN_STUDENT_CODE", "//END_STUDENT_CODE"));
                    m_Entries.Add(new ExtensionComment(".c", "/* BEGIN_STUDENT_CODE */", "/* END_STUDENT_CODE */"));
                    m_Entries.Add(new ExtensionComment(".vb", "' BEGIN_STUDENT_CODE", "' END_STUDENT_CODE"));
                }
            }
        }
Exemple #17
0
        /// <summary>
        /// This is called when the user leaves the datagrid control. At that point,
        /// we check to make sure that:
        /// - All entries have a begin, end, and extension
        /// - That there are no duplicate extensions
        /// - That no entry has an identical begin & end
        /// If there is an error, we report it to the user and put the cursor
        /// on the entry with the issue.
        /// </summary>
        internal void ValidateGrid()
        {
            System.Collections.Specialized.StringCollection allExtensions = new System.Collections.Specialized.StringCollection();
            string extensions, begin, end;
            int    nRow = 0;

            string [] rgExtensions = null;
            char []   splitChars = { ',' };
            string    working;

            dtValues.AcceptChanges();
            foreach (System.Data.DataRow row in dtValues.Rows)
            {
                extensions = (string)row[m_strFileExtensionField];
                begin      = (string)row[m_strBeginCommentField];
                end        = (string)row[m_strEndCommentField];

                // Non-null or single-space extension(s)?
                if ((extensions == null) || (extensions == "") || (extensions == " "))
                {
                    System.Windows.Forms.MessageBox.Show(AMResources.GetLocalizedString("ToolsOptionsInvalidExtension"),
                                                         AMResources.GetLocalizedString("ToolsOptionsErrorTitle"),
                                                         System.Windows.Forms.MessageBoxButtons.OK,
                                                         System.Windows.Forms.MessageBoxIcon.Exclamation);
                    dgEntries.Select(nRow);
                    throw new System.Exception();
                }

                // Non-null or single-space begin comment?
                if ((begin == null) || (begin == "") || (begin == " "))
                {
                    System.Windows.Forms.MessageBox.Show(AMResources.GetLocalizedString("ToolsOptionsInvalidBegin"),
                                                         AMResources.GetLocalizedString("ToolsOptionsErrorTitle"),
                                                         System.Windows.Forms.MessageBoxButtons.OK,
                                                         System.Windows.Forms.MessageBoxIcon.Exclamation);
                    dgEntries.Select(nRow);
                    throw new System.Exception();
                }

                // Non-null or single-space end comment?
                if ((end == null) || (end == "") || (end == " "))
                {
                    System.Windows.Forms.MessageBox.Show(AMResources.GetLocalizedString("ToolsOptionsInvalidEnd"),
                                                         AMResources.GetLocalizedString("ToolsOptionsErrorTitle"),
                                                         System.Windows.Forms.MessageBoxButtons.OK,
                                                         System.Windows.Forms.MessageBoxIcon.Exclamation);
                    dgEntries.Select(nRow);
                    throw new System.Exception();
                }

                // Identical begin & end comments?
                if (begin == end)
                {
                    System.Windows.Forms.MessageBox.Show(AMResources.GetLocalizedString("ToolsOptionsInvalidBeginAndEnd"),
                                                         AMResources.GetLocalizedString("ToolsOptionsErrorTitle"),
                                                         System.Windows.Forms.MessageBoxButtons.OK,
                                                         System.Windows.Forms.MessageBoxIcon.Exclamation);
                    dgEntries.Select(nRow);
                    throw new System.Exception();
                }

                // Validate both that there are extensions there and that they aren't
                // already elsewhere in the datagrid.
                rgExtensions = extensions.Split(splitChars);
                foreach (string extension in rgExtensions)
                {
                    working = extension.Trim().ToUpper();

                    if (working[0] != '.')
                    {
                        System.Windows.Forms.MessageBox.Show(AMResources.GetLocalizedString("ToolsOptionsInvalidExtension"),
                                                             AMResources.GetLocalizedString("ToolsOptionsErrorTitle"),
                                                             System.Windows.Forms.MessageBoxButtons.OK,
                                                             System.Windows.Forms.MessageBoxIcon.Exclamation);
                        dgEntries.Select(nRow);
                        throw new System.Exception();
                    }

                    if (allExtensions.Contains(working))
                    {
                        System.Windows.Forms.MessageBox.Show(AMResources.GetLocalizedString("ToolsOptionsInvalidExtensionAlreadyExists"),
                                                             AMResources.GetLocalizedString("ToolsOptionsErrorTitle"),
                                                             System.Windows.Forms.MessageBoxButtons.OK,
                                                             System.Windows.Forms.MessageBoxIcon.Exclamation);
                        dgEntries.Select(nRow);
                        throw new System.Exception();
                    }

                    allExtensions.Add(working);
                }

                nRow++;
            }
        }
Exemple #18
0
        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            // This method will be called every time that the Tools Options dialog is loaded. The first
            // time, we initialize the internal controls, etc. All subsequent times, however, we re-initialize
            // the datagrid and checkboxes.
            try
            {
                if (!m_fInitialized)
                {
                    m_fInitialized = true;

                    this.components      = new System.ComponentModel.Container();
                    this.bDelete         = new System.Windows.Forms.Button();
                    this.label1          = new System.Windows.Forms.Label();
                    this.cbCollapse      = new System.Windows.Forms.CheckBox();
                    this.cbPromptForTodo = new System.Windows.Forms.CheckBox();
                    this.bNew            = new System.Windows.Forms.Button();
                    this.dgEntries       = new System.Windows.Forms.DataGrid();
                    //@this.TrayLargeIcon = false;
                    //@this.TrayAutoArrange = true;
                    //@this.TrayHeight = 0;
                    this.Size = new System.Drawing.Size(400, 300);

                    label1.Location = new System.Drawing.Point(0, 8);
                    label1.Text     = AMResources.GetLocalizedString("ToolsOptionsDescriptionLabel");
                    label1.Size     = new System.Drawing.Size(376, 26);
                    label1.TabIndex = 100;

                    cbCollapse.Location = new System.Drawing.Point(0, 240);
                    cbCollapse.Text     = AMResources.GetLocalizedString("ToolsOptionsCollapseCombo");
                    cbCollapse.Size     = new System.Drawing.Size(300, 24);
                    cbCollapse.TabIndex = 3;

                    cbPromptForTodo.Location = new System.Drawing.Point(0, 265);
                    cbPromptForTodo.Text     = AMResources.GetLocalizedString("ToolsOptionsTodoCommentCombo");
                    cbPromptForTodo.Size     = new System.Drawing.Size(300, 24);
                    cbPromptForTodo.TabIndex = 4;

                    bNew.Location    = new System.Drawing.Point(0, 42);
                    bNew.Size        = new System.Drawing.Size(96, 23);
                    bNew.TabIndex    = 0;
                    bNew.Text        = AMResources.GetLocalizedString("ToolsOptionsAddRuleButton");
                    bNew.Click      += new System.EventHandler(bNew_OnClick);
                    bDelete.Location = new System.Drawing.Point(102, 42);
                    bDelete.Size     = new System.Drawing.Size(132, 23);
                    bDelete.TabIndex = 1;
                    bDelete.Text     = AMResources.GetLocalizedString("ToolsOptionsDeleteMarkedRulesButton");
                    bDelete.Click   += new System.EventHandler(bDelete_OnClick);

                    // Create the DataTable to contain the data stored in the registry.
                    dtValues = new System.Data.DataTable("ExtractionOptions");

                    dtValues.Columns.Add(new System.Data.DataColumn("X", typeof(bool)));
                    dtValues.Columns.Add(new System.Data.DataColumn(m_strFileExtensionField, typeof(string)));
                    dtValues.Columns.Add(new System.Data.DataColumn(m_strBeginCommentField, typeof(string)));
                    dtValues.Columns.Add(new System.Data.DataColumn(m_strEndCommentField, typeof(string)));

                    // This supresses the automatic new row that is otherwise created by the
                    // DataGrid control. However, the 'Add' button in the UI will still be able
                    // to add new rows explicitly.
                    dtValues.DefaultView.AllowNew = false;

                    // Place the DataGrid control on the form and set some properties
                    dgEntries.Location        = new System.Drawing.Point(0, 71);
                    dgEntries.Size            = new System.Drawing.Size(395, 165);
                    dgEntries.TabIndex        = 2;
                    dgEntries.BackgroundColor = System.Drawing.Color.White;
                    dgEntries.FlatMode        = true;
                    dgEntries.CaptionVisible  = false;
                    dgEntries.AllowNavigation = false;
                    dgEntries.MouseDown      += new System.Windows.Forms.MouseEventHandler(dgEntries_OnMouseDown);

                    // Attach the DataTable to the DataGrid
                    dgEntries.SetDataBinding(dtValues, null);

                    // Reconfigure all of the columns and styles of the DataGrid to better fit our
                    // DataTable.
                    DataGridTableStyle tableStyle = new DataGridTableStyle();
                    tableStyle.MappingName          = dtValues.TableName;
                    tableStyle.AllowSorting         = false;
                    tableStyle.ColumnHeadersVisible = true;
                    tableStyle.RowHeadersVisible    = false;
                    tableStyle.PreferredRowHeight   = 25;

                    // Allocate all of the column style objects (they aren't created automatically
                    // when binding the DataTable to the DataGrid) and set the properites for each
                    // of the individual columns.
                    for (int i = 0; i < dtValues.Columns.Count; i++)
                    {
                        DataGridColumnStyle    gridColumn = null;
                        System.Data.DataColumn dataColumn = dtValues.Columns[i];
                        string sName = dataColumn.ColumnName;

                        if (sName == "X")
                        {
                            gridColumn = new DataGridBoolColumn();                             // A checkbox
                            ((DataGridBoolColumn)gridColumn).AllowNull = false;                // Don't allow the gray-state.
                            gridColumn.Alignment = HorizontalAlignment.Left;
                            gridColumn.Width     = 25;
                        }
                        else if (sName == m_strFileExtensionField)
                        {
                            gridColumn = new DataGridTextBoxColumn();
                            ((DataGridTextBox)((DataGridTextBoxColumn)gridColumn).TextBox).Multiline = false;                             // Don't allow multi-line edits, since they are difficult to handle.
                            gridColumn.Alignment = HorizontalAlignment.Left;
                            gridColumn.Width     = 87;
                        }
                        else if (sName == m_strBeginCommentField)
                        {
                            gridColumn = new DataGridTextBoxColumn();
                            ((DataGridTextBox)((DataGridTextBoxColumn)gridColumn).TextBox).Multiline = false;                             // Don't allow multi-line edits, since they are difficult to handle.
                            gridColumn.Alignment = HorizontalAlignment.Left;
                            gridColumn.Width     = 139;
                        }
                        else if (sName == m_strEndCommentField)
                        {
                            gridColumn = new DataGridTextBoxColumn();
                            ((DataGridTextBox)((DataGridTextBoxColumn)gridColumn).TextBox).Multiline = false;                             // Don't allow multi-line edits, since they are difficult to handle.
                            gridColumn.Alignment = HorizontalAlignment.Left;
                            gridColumn.Width     = 139;
                        }
                        else
                        {
                            System.Diagnostics.Debug.Assert(false, "A column was added to the ToolsOptions dialog, but its style was not created.");
                            return;
                        }

                        gridColumn.MappingName = sName;
                        gridColumn.HeaderText  = sName;
                        tableStyle.GridColumnStyles.Add(gridColumn);
                    }
                    dgEntries.TableStyles.Add(tableStyle);

                    this.bNew.AccessibleName            = "bNew";
                    this.bDelete.AccessibleName         = "bDelete";
                    this.dgEntries.AccessibleName       = "dgEntries";
                    this.cbCollapse.AccessibleName      = "cbCollapse";
                    this.cbPromptForTodo.AccessibleName = "cbPromptForTodo";
                    this.label1.AccessibleName          = "label1";

                    this.Controls.Add(this.bNew);
                    this.Controls.Add(this.bDelete);
                    this.Controls.Add(this.dgEntries);
                    this.Controls.Add(this.cbCollapse);
                    this.Controls.Add(this.cbPromptForTodo);
                    this.Controls.Add(this.label1);
                }
                else
                {
                    // Reset the UI.
                    PopulateTable();
                }
            }
            catch (System.Exception e)
            {
                System.Diagnostics.Debug.Assert(false, "Unable to initialize the dialog." + e.Message);
            }
        }