Esempio n. 1
0
        /// <summary>
        /// Adds package to the database
        /// </summary>
        /// <param name="package">Package value represents package object with necessary information.</param>
        public Training AddPackage(Package package)
        {
            PackageItemIdentifier packageId;
            ValidationResults     importLog;

            using (PackageReader packageReader = package.GetPackageReader())
            {
                AddPackageResult result = PStore.AddPackage(packageReader, new PackageEnforcement(false, false, false));
                packageId = result.PackageId;
                importLog = result.Log;
            }

            // fill in the application-specific columns of the PackageItem table
            LearningStoreJob            job        = LStore.CreateJob();
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties[Schema.PackageItem.Owner]          = new UserItemIdentifier(package.Owner);
            properties[Schema.PackageItem.FileName]       = package.FileName;
            properties[Schema.PackageItem.UploadDateTime] = package.UploadDateTime;
            job.UpdateItem(packageId, properties);
            job.Execute();

            // retrieve information about the package
            job = LStore.CreateJob();
            RequestMyTraining(job, packageId);

            DataTable dataTableResults = job.Execute <DataTable>();
            Training  training         = new Training(dataTableResults.Rows[0]);

            return(training);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds package to the database.
        /// </summary>
        /// <param name="package">Package value represents package object with necessary information.</param>
        protected PackageItemIdentifier AddPackage(Package package)
        {
            PackageItemIdentifier packageId = null;
            ValidationResults     importLog;

            using (PackageReader packageReader = package.GetPackageReader())
            {
                AddPackageResult result = PStore.AddPackage(packageReader, new PackageEnforcement(false, false, false));
                packageId = result.PackageId;
                importLog = result.Log;
            }

            LearningStoreJob            job = LStore.CreateJob();
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add(Schema.PackageItem.IudicoCourseRef, package.CourseID);
            job.UpdateItem(packageId, dic);
            job.Execute();

            return(packageId);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds package to the database.
        /// </summary>
        /// <param name="package">Package value represents package object with necessary information.</param>
        protected PackageItemIdentifier AddPackage(Package package)
        {
            PackageItemIdentifier packageId;

            using (PackageReader packageReader = package.GetPackageReader())
            {
                AddPackageResult result = this.PStore.AddPackage(
                    packageReader, new PackageEnforcement(false, false, false));
                packageId = result.PackageId;
            }

            LearningStoreJob job = this.LStore.CreateJob();
            var dic = new Dictionary <string, object> {
                { Schema.PackageItem.IudicoCourseRef, package.CourseID }
            };

            job.UpdateItem(packageId, dic);
            job.Execute();

            return(packageId);
        }
    protected void UploadPackageButton_OnClick(object sender, EventArgs e)
    {
        // the user clicked "Upload"...

        // do nothing if the user didn't select a file to upload
        if (!UploadedPackageFile.HasFile)
        {
            return;
        }

        // hide the upload panel and show the message panel; the message panel will hold
        // information about the success or failure of the package upload operation
        UploadPanel.Visible  = false;
        MessagePanel.Visible = true;

        // attempt to import the uploaded file into PackageStore
        try
        {
            // set <currentUser> to information about the current user; we need the current user's
            // UserItemIdentifier
            LStoreUserInfo currentUser = GetCurrentUserInfo();

            // import the package file; set packageId to the ID of the uploaded
            // package; set importLog to a collection of warnings (if any)
            // about the import process
            PackageItemIdentifier packageId;
            ValidationResults     importLog;
            using (PackageReader packageReader = PackageReader.Create(UploadedPackageFile.FileContent))
            {
                // Add package, asking to fix anything that can be fixed.
                AddPackageResult result = PStore.AddPackage(packageReader, new PackageEnforcement(false, false, false));
                packageId = result.PackageId;
                importLog = result.Log;
            }

            // fill in the application-specific columns of the PackageItem table
            LearningStoreJob            job        = LStore.CreateJob();
            Dictionary <string, object> properties = new Dictionary <string, object>();
            properties[Schema.PackageItem.Owner]          = currentUser.Id;
            properties[Schema.PackageItem.FileName]       = UploadedPackageFile.FileName;
            properties[Schema.PackageItem.UploadDateTime] = DateTime.Now;
            job.UpdateItem(packageId, properties);
            job.Execute();

            // retrieve information about the package
            job = LStore.CreateJob();
            RequestMyTraining(job, packageId);
            GetMyTrainingResultsToHtml(job.Execute <DataTable>(), TrainingGrid);

            // when the page loads in the browser, copy information about the from the TrainingGrid
            // hidden table to the main page using client-side script
            UpdateParentPageScript.Visible = true;

            // provide user feedback
            if (importLog.HasWarnings)
            {
                // display warnings
                WarningIntro.Visible    = true;
                WarningMessages.Visible = true;
                foreach (ValidationResult result in importLog.Results)
                {
                    ScrollingMessagesList.Items.Add(new ListItem(result.Message));
                }
            }
            else
            {
                // the operation was successful, and there are no messages to display to the user,
                // so close the dialog
                CloseDialogScript.Visible = true;
            }
        }
        catch (PackageImportException ex)
        {
            // a package import failure occurred -- display the error message
            ErrorIntro.Visible   = true;
            ErrorMessage.Visible = true;

            foreach (ValidationResult result in ex.Log.Results)
            {
                ErrorMessageScrollingList.Items.Add(new ListItem(result.Message));
            }

            if (ex.InnerException != null)
            {
                ErrorMessageScrollingList.Items.Add(new ListItem(
                                                        Server.HtmlEncode(ex.InnerException.Message)));
            }
        }
        catch (Exception ex)
        {
            // an unexpected error occurred -- display a generic message that doesn't include the
            // exception message (since that message may include sensitive information), and write
            // the exception message to the event log
            ErrorIntro.Visible   = true;
            ErrorMessage.Visible = true;
            ErrorMessage.Controls.Add(new System.Web.UI.LiteralControl(
                                          Server.HtmlEncode("A serious error occurred.  Please contact your system administrator.  More information has been written to the server event log.")));
            LogEvent(System.Diagnostics.EventLogEntryType.Error,
                     "An exception occurred while uploading a package:\n\n{0}\n\n", ex.ToString());
        }
    }