示例#1
0
 public PStore(PStore other) : this(PapillonPINVOKE.new_PStore__SWIG_1(PStore.getCPtr(other)), true)
 {
     if (PapillonPINVOKE.SWIGPendingException.Pending)
     {
         throw PapillonPINVOKE.SWIGPendingException.Retrieve();
     }
 }
示例#2
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);
        }
示例#3
0
    public PResult WriteToStore(PStore store)
    {
        PResult ret = new PResult(PapillonPINVOKE.PWatchlist_WriteToStore(swigCPtr, PStore.getCPtr(store)), true);

        if (PapillonPINVOKE.SWIGPendingException.Pending)
        {
            throw PapillonPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
示例#4
0
    public static PResult ReadFromStore(PStore store, PWatchlist watchlist)
    {
        PResult ret = new PResult(PapillonPINVOKE.PWatchlist_ReadFromStore(PStore.getCPtr(store), PWatchlist.getCPtr(watchlist)), true);

        if (PapillonPINVOKE.SWIGPendingException.Pending)
        {
            throw PapillonPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
示例#5
0
    public static PResult Open(string dbName, PStore store)
    {
        PResult ret = new PResult(PapillonPINVOKE.PDatabaseStore_Open__SWIG_0(dbName, PStore.getCPtr(store)), true);

        if (PapillonPINVOKE.SWIGPendingException.Pending)
        {
            throw PapillonPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
示例#6
0
        /// <summary>
        /// Deletes pacakge and related attempts from database.
        /// </summary>
        /// <param name="packId">Long integer value represents package identifier.</param>
        protected void DeletePackage(long packId)
        {
            // set <packageId> to the ID of this package
            PackageItemIdentifier packageId = new PackageItemIdentifier(packId);

            // before we delete the package, we need to delete all attempts on the package --
            // the following query looks for those attempts
            LearningStoreJob   job   = LStore.CreateJob();
            LearningStoreQuery query = LStore.CreateQuery(
                Schema.MyAttempts.ViewName);

            query.AddCondition(Schema.MyAttempts.PackageId,
                               LearningStoreConditionOperator.Equal, packageId);
            query.AddCondition(Schema.MyAttempts.AttemptId,
                               LearningStoreConditionOperator.NotEqual, null);
            query.AddColumn(Schema.MyAttempts.AttemptId);
            query.AddSort(Schema.MyAttempts.AttemptId,
                          LearningStoreSortDirection.Ascending);
            job.PerformQuery(query);
            DataTable             dataTable         = job.Execute <DataTable>();
            AttemptItemIdentifier previousAttemptId = null;

            // loop once for each attempt on this package
            foreach (DataRow dataRow in dataTable.Rows)
            {
                // set <attemptId> to the ID of this attempt
                AttemptItemIdentifier attemptId;
                LStoreHelper.CastNonNull(dataRow["AttemptId"], out attemptId);

                // if <attemptId> is a duplicate attempt ID, skip it; note that the query
                // results are sorted by attempt ID (see above)
                if ((previousAttemptId != null) &&
                    (previousAttemptId.GetKey() == attemptId.GetKey()))
                {
                    continue;
                }

                // delete this attempt
                StoredLearningSession.DeleteAttempt(LStore, attemptId);

                // continue to the next attempt
                previousAttemptId = attemptId;
            }

            // delete the package
            PStore.DeletePackage(packageId);
        }
示例#7
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);
        }
示例#8
0
    protected void DeletePackagesButton_Click(object sender, EventArgs e)
    {
        // the user clicked "Upload"...

        // hide the confirmation panel
        ConfirmMessage.Visible = false;

        // the PackagesToDelete hidden form element contains a comma-delimited list of IDs of
        // packages to delete (copied from <dialogArguments> on the client) -- attempt to delete
        // those packages, and set <deleted> to the IDs of packages successfully deleted
        List <string> deleted = new List <string>();

        try
        {
            // loop once for each package to delete
            foreach (string id in PackagesToDelete.Value.Split(','))
            {
                // set <packageId> to the ID of this package
                PackageItemIdentifier packageId = new PackageItemIdentifier(
                    Convert.ToInt64(id, CultureInfo.InvariantCulture));

                // before we delete the package, we need to delete all attempts on the package --
                // the following query looks for those attempts
                LearningStoreJob   job   = LStore.CreateJob();
                LearningStoreQuery query = LStore.CreateQuery(
                    Schema.MyAttemptsAndPackages.ViewName);
                query.AddCondition(Schema.MyAttemptsAndPackages.PackageId,
                                   LearningStoreConditionOperator.Equal, packageId);
                query.AddCondition(Schema.MyAttemptsAndPackages.AttemptId,
                                   LearningStoreConditionOperator.NotEqual, null);
                query.AddColumn(Schema.MyAttemptsAndPackages.AttemptId);
                query.AddSort(Schema.MyAttemptsAndPackages.AttemptId,
                              LearningStoreSortDirection.Ascending);
                job.PerformQuery(query);
                DataTable             dataTable         = job.Execute <DataTable>();
                AttemptItemIdentifier previousAttemptId = null;

                // loop once for each attempt on this package
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    // set <attemptId> to the ID of this attempt
                    AttemptItemIdentifier attemptId;
                    LStoreHelper.CastNonNull(dataRow["AttemptId"], out attemptId);

                    // if <attemptId> is a duplicate attempt ID, skip it; note that the query
                    // results are sorted by attempt ID (see above)
                    if ((previousAttemptId != null) &&
                        (previousAttemptId.GetKey() == attemptId.GetKey()))
                    {
                        continue;
                    }

                    // delete this attempt
                    StoredLearningSession.DeleteAttempt(LStore, attemptId);

                    // continue to the next attempt
                    previousAttemptId = attemptId;
                }

                // delete the package
                PStore.DeletePackage(packageId);

                // add the package ID to the list of deleted packages
                deleted.Add(id);
            }

            // the operation was successful, and there are no messages to
            // display to the user, so close the dialog
            CloseDialogScript.Visible = true;
        }
        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 deleting a package:\n\n{0}\n\n", ex.ToString());
        }

        // update the buttons
        DeletePackagesButton.Visible = false;
        CloseButton.Text             = "OK";

        // set the hidden form element PackagesSuccessfullyDeleted to a
        // comma-separated list of IDs of packages that were successfully
        // deleted, and enable the client-side script that communicates this
        // information to the parent page
        PackagesSuccessfullyDeleted.Value = String.Join(",", deleted.ToArray());
        UpdateParentPageScript.Visible    = true;
    }
示例#9
0
    public static PResult Open(string dbHost, int dbPort, string dbName, string username, string password, PStore store)
    {
        PResult ret = new PResult(PapillonPINVOKE.PDatabaseStore_Open__SWIG_1(dbHost, dbPort, dbName, username, password, PStore.getCPtr(store)), true);

        if (PapillonPINVOKE.SWIGPendingException.Pending)
        {
            throw PapillonPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
示例#10
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PStore obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
    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());
        }
    }