コード例 #1
0
        /// <summary>
        /// Parses XML file, processes Class Server information class by class.
        /// Works from a non-UI thread using BackgroundWorker. Handles all exceptions.
        /// Reports progress.
        /// Reads data for one class at a time and calls ProcessClass to create class,
        /// its groups and users
        /// </summary>
        /// <param name="XMLFilePath">Full path of the XML file to be parsed</param>
        /// <param name="LogFilePath">File name of the log file, it will be created in working directory</param>
        /// <param name="worker">BackgroundWorker object for passing status</param>
        /// <param name="e">DoWorkEventArgs (not used)</param>
        /// <returns>true if the file was successfully parsed. Any errors encountered while creating sites will be just written to the log file and will not affect this result</returns>

        public bool CreateSitesFromXML(string xmlFilePath, string logFilePath,
                                       BackgroundWorker worker, DoWorkEventArgs e)
        {
            bool status = false;

            try
            {
                LogFile             log          = new LogFile(logFilePath);
                ConfigXMLFileReader configReader = new ConfigXMLFileReader(xmlFilePath);
                CS4Class            nextClass    = configReader.GetNextClass();
                while (nextClass != null)
                {
                    worker.ReportProgress(0, TextResources.ProcessingClass + ": " + nextClass.ClassWeb);
                    string logText = String.Empty;
                    ProcessClass(nextClass, ref logText);
                    log.WriteToLogFile(logText);
                    nextClass = configReader.GetNextClass();
                }
                configReader.Dispose();
                log.FinishLogging();
                status = true;
            }
            catch (System.Exception ex)
            {
                worker.ReportProgress(0, TextResources.AnError + ex.Message);
            }

            return(status);
        }
コード例 #2
0
        /// <summary>
        /// Reads Class Server 4 settings xml file,
        /// class by class, and transfers assignments for every class.
        /// Works from a non-UI thread using BackgroundWorker. Handles all exceptions.
        /// Reports progress.
        /// </summary>
        /// <param name="xmlFilePath">path to Classes.xml</param>
        /// <param name="logFilePath">path to log file</param>
        /// <param name="worker"></param>
        /// <param name="e"></param>
        /// <returns>true if there were no exceptions during the transfer</returns>
        public bool MoveUserAssignments(string xmlFilePath, string logFilePath,
                                        BackgroundWorker worker, DoWorkEventArgs e)
        {
            bool    status = false;
            LogFile log    = null;

            try
            {
                log = new LogFile(logFilePath);
                //gather info about learning packages available in the document gallery
                SLKSite site = new SLKSite();
                log.WriteToLogFile(TextResources.ReadingPackages + Environment.NewLine);
                worker.ReportProgress(0, TextResources.ReadingPackages);
                Hashtable learningResourcesSLK = site.GetAllLearningResources(SiteBuilder.Default.SLKDocLibraryWeb, SiteBuilder.Default.SLKDocLibraryName);
                //loop through classes and transfer assignments
                ConfigXMLFileReader configReader = new ConfigXMLFileReader(xmlFilePath);
                CS4Class            nextClass    = configReader.GetNextClass();
                while (nextClass != null)
                {
                    //if class is marked for transfer in the xml file
                    if (nextClass.Transfer)
                    {
                        log.WriteToLogFile(String.Format(TextResources.TransferringAssignmentsForClass, nextClass.ClassWeb) + Environment.NewLine);
                        worker.ReportProgress(0, TextResources.ProcessingClass + nextClass.ClassWeb);
                        string logText = "";
                        MoveAssignments(nextClass, ref logText, learningResourcesSLK);
                        log.WriteToLogFile(logText);
                    }
                    else
                    {
                        //assignments for this class will not be transferred, log
                        log.WriteToLogFile(String.Format(TextResources.NotTransferringAssignmentsClassNotForTransfer, nextClass.ClassWeb) + Environment.NewLine);
                    }
                    nextClass = configReader.GetNextClass();
                }
                configReader.Dispose();
                status = true;
            }
            catch (System.Exception ex)
            {
                worker.ReportProgress(0, TextResources.AnError + ex.Message);
                log.WriteToLogFile(TextResources.AnError + ex.Message + Environment.NewLine);
            }
            finally
            {
                try
                {
                    if (log != null)
                    {
                        log.FinishLogging();
                    }
                }
                catch (System.Exception ex)
                {
                    worker.ReportProgress(0, TextResources.AnError + ex.Message);
                }
            }

            return(status);
        }