/// <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);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Asyncronously calls SLKSite.CreateSiteFromXML to parse XML file (file name
 /// is taken from application settings file) and create SLK sites system for
 /// Class Server classes, groups and users
 /// </summary>
 private void llCreateSLKClasses_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (!AllAppSettingsSet())
     {
         lblCreateSitesStatus.Text = TextResources.AppSettingsNotSet;
         return;
     }
     m_site = new SLKSite();
     System.ComponentModel.BackgroundWorker createSiteWorker = new BackgroundWorker();
     createSiteWorker.WorkerReportsProgress = true;
     createSiteWorker.DoWork             += new DoWorkEventHandler(createSiteWorker_DoWork);
     createSiteWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(createSiteWorker_RunWorkerCompleted);
     createSiteWorker.ProgressChanged    += new ProgressChangedEventHandler(createSiteWorker_ProgressChanged);
     createSiteWorker.RunWorkerAsync(System.IO.Directory.GetCurrentDirectory() + "\\" + SiteBuilder.Default.ClassStructureXML);
 }