Exemplo n.º 1
0
        protected void PublishNextDocument(object sender, EventArgs e)
        {
            WBLogging.Debug("Attempting to publishg the next document " + process.CurrentItemID);

            process = manager.PublishDocument(process);

            WBLogging.Debug("Published the document");

            DocumentPublishingProgress.WBxUpdateTask(process.LastTaskFeedback);

            PublishingProcessJSON.Text = WBUtils.SerializeToCompressedJSONForURI(process);

            WBLogging.Debug("Serialized to: " + PublishingProcessJSON.Text);

            if (process.HasMoreDocumentsToPublish && process.PublishMode == WBPublishingProcess.PUBLISH_MODE__ALL_TOGETHER)
            {
                Image image = (Image)DocumentPublishingProgress.WBxFindNestedControlByID(DocumentPublishingProgress.WBxMakeControlID(process.CurrentItemID, "image"));
                image.ImageUrl = "/_layouts/images/WorkBoxFramework/processing-task-32.gif";

                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "TriggerNextStepFunction", "WorkBoxFramework_triggerPublishNextDocument();", true);
            }
            else
            {
                if (process.HasMoreDocumentsToPublish)
                {
                    WBLogging.Debug("Trying to set button text to Publish next doc");
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ChangeDoneButtonTextFunction", "WorkBoxFramework_finishedProcessing('Publish Next Document');", true);
                }
                else
                {
                    WBLogging.Debug("Trying to set button text to done");
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ChangeDoneButtonTextFunction", "WorkBoxFramework_finishedProcessing('Done');", true);
                }
            }
        }
        protected void publishButton_OnClick(object sender, EventArgs e)
        {
            WBLogging.Debug("In publishButton_OnClick()");

            Hashtable metadataProblems = checkMetadataState();

            string protectiveZone = "";


            if (metadataProblems.Count > 0)
            {
                RecordsTypeFieldMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__RECORDS_TYPE].WBxToString();

                FunctionalAreaFieldMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__FUNCTIONAL_AREA].WBxToString();
                ProtectiveZoneMessage.Text      = metadataProblems[WorkBox.COLUMN_NAME__PROTECTIVE_ZONE].WBxToString();

                //               SubjectTagsMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__SUBJECT_TAGS].WBxToString();
                ReferenceIDMessage.Text    = metadataProblems[WorkBox.COLUMN_NAME__REFERENCE_ID].WBxToString();;
                ReferenceDateMessage.Text  = metadataProblems[WorkBox.COLUMN_NAME__REFERENCE_DATE].WBxToString();;
                SeriesTagFieldMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__SERIES_TAG].WBxToString();
                ScanDateMessage.Text       = metadataProblems[WorkBox.COLUMN_NAME__SCAN_DATE].WBxToString();

                OwningTeamFieldMessage.Text    = metadataProblems[WorkBox.COLUMN_NAME__OWNING_TEAM].WBxToString();
                InvolvedTeamsFieldMessage.Text = metadataProblems[WorkBox.COLUMN_NAME__INVOLVED_TEAMS].WBxToString();

                pageRenderingRequired = true;
            }
            else
            {
                pageRenderingRequired = false;
            }

            if (pageRenderingRequired)
            {
                WBLogging.Debug("In publishButton_OnClick(): Page render required - not publishing at this point");
                renderPage();
            }
            else
            {
                WBLogging.Debug("In publishButton_OnClick(): No page render required - so moving to publish");

                // The event should only be processed if there is no other need to render the page again

                // First let's update the item with the new metadata values submitted:
                SPDocumentLibrary sourceDocLib    = (SPDocumentLibrary)SPContext.Current.Web.Lists[new Guid(ListGUID.Value)];
                SPListItem        sourceDocAsItem = sourceDocLib.GetItemById(int.Parse(ItemID.Value));

                WBDocument document = CaptureAsDocument(sourceDocAsItem, documentRecordsType);

                document.Update();

                /*
                 *
                 *   OK So now we actually publish out the document:
                 *
                 */


                SPFile sourceFile   = sourceDocAsItem.File;
                string errorMessage = "";

                string successMessage = "<h3>Successfully Published Out</h3> <table cellpadding='5'>";
                if (TheDestinationType.Value.Equals(WorkBox.PUBLISHING_OUT_DESTINATION_TYPE__WORK_BOX))
                {
                    using (WorkBox workBox = new WorkBox(DestinationURL.Value))
                    {
                        string selectedFolderPath = Request.QueryString["SelectedFolderPath"];
                        if (string.IsNullOrEmpty(selectedFolderPath))
                        {
                            selectedFolderPath = "/";
                        }

                        string destinationRootFolderUrl = DestinationURL.Value + "/" + workBox.DocumentLibrary.RootFolder.Url + selectedFolderPath;

                        errorMessage = sourceFile.WBxCopyTo(destinationRootFolderUrl, new List <String>());

                        if (errorMessage == "")
                        {
                            successMessage += "<tr><td>Filename</td><td><b>" + sourceFile.Name + "</b></td></tr><tr><td>Published out to:</td><td><a href=\"" + destinationRootFolderUrl + "\"><b>" + destinationRootFolderUrl + "</b></a></td></tr>";
                        }
                    }
                }
                else
                {
                    // WBRecordsType recordsType = new WBRecordsType(recordsTypeTaxonomy, document[WBColumn.RecordsType].WBxToString());

                    using (WBRecordsManager manager = new WBRecordsManager(SPContext.Current.Web.CurrentUser.LoginName))
                    {
                        try
                        {
                            WBLogging.Debug("In publishButton_OnClick(): About to try to publish");

                            manager.PublishDocument(WorkBox, document);

                            WBLogging.Debug("In publishButton_OnClick(): Should have finished the publishing");

                            //recordsType.PublishDocument(document, sourceFile.OpenBinaryStream());

                            string fullClassPath = "Just a test"; //  WBUtils.NormalisePath(document.FunctionalArea.Names() + "/" + recordsType.FullPath);

                            successMessage += "<tr><td>Published out to location:</td><td>" + fullClassPath + "</td></tr>\n";


                            if (document.ProtectiveZone == WBRecordsType.PROTECTIVE_ZONE__PUBLIC)
                            {
                                successMessage += "<tr><td>To public records library</td><td><a href=\"http://stagingweb/publicrecords\">Our public library</a></td></tr>\n";
                            }

                            if (document.ProtectiveZone == WBRecordsType.PROTECTIVE_ZONE__PUBLIC_EXTRANET)
                            {
                                successMessage += "<tr><td>To public extranet records library</td><td><a href=\"http://stagingextranets/records\">Our public extranet library</a></td></tr>\n";
                            }

                            successMessage += "<tr><td>To internal records library</td><td><a href=\"http://sp.izzi/library/Pages/ViewByFunctionThenType.aspx\">Our internal library</a></td></tr>\n";
                        }
                        catch (Exception exception)
                        {
                            errorMessage = "An error occurred when trying to publish: " + exception.Message;
                            WBLogging.Generic.Unexpected(exception);
                        }
                    }
                }

/*
 *              WBFarm farm = WBFarm.Local;
 *              string destinationRootFolderUrl = farm.ProtectedRecordsLibraryUrl;
 *              List<String> filingPath = null;
 *
 *
 *              filingPath = documentRecordsType.FilingPathForItem(sourceDocAsItem);
 *
 *              string filingPathString = string.Join("/", filingPath.ToArray());
 *
 *              WBLogging.Generic.Verbose("The file is: " + sourceFile.Url);
 *              WBLogging.Generic.Verbose("The destination is: " + destinationRootFolderUrl);
 *              WBLogging.Generic.Verbose("The destination filing path is: " + filingPathString);
 *
 *
 *              string errorMessage = sourceFile.WBxCopyTo(destinationRootFolderUrl, filingPath);
 *
 *              if (errorMessage == "")
 *              {
 *                  successMessage += "<tr><td>Filename</td><td><b>" + sourceFile.Name + "</b></td></tr><tr><td>Published out to:</td><td><a href=\"" + destinationRootFolderUrl + "\"><b>" + destinationRootFolderUrl + "</b></a></td></tr><tr><td>Filing path:</td><td><a href=\"" + destinationRootFolderUrl + "/" + filingPathString + "\"><b>" + filingPathString + "</b></td></tr>";
 *              }
 *
 *              WBLogging.Generic.Verbose("Protective zone was set to be: " + protectiveZone);
 *
 *
 *              if (!TheDestinationType.Value.Equals(WorkBox.PUBLISHING_OUT_DESTINATION_TYPE__WORK_BOX)
 *                  && protectiveZone.Equals(WBRecordsType.PROTECTIVE_ZONE__PUBLIC))
 *              {
 *                  // OK so we're going to copy this to the public library as well:
 *              WBLogging.Generic.Verbose("The file is: " + sourceFile.Url);
 *              WBLogging.Generic.Verbose("The destination is: " + farm.PublicRecordsLibraryUrl);
 *              WBLogging.Generic.Verbose("The destination filing path is: " + filingPathString);
 *
 *                  string errorMessagePublic = sourceFile.WBxCopyTo(farm.PublicRecordsLibraryUrl, filingPath);
 *
 *                  if (errorMessagePublic == "")
 *                  {
 *                      successMessage += "<tr><td colspan='2'><b>And also published to the public library.</b></td></tr>";
 *                  }
 *              }
 *
 *              if (!TheDestinationType.Value.Equals(WorkBox.PUBLISHING_OUT_DESTINATION_TYPE__WORK_BOX)
 *                  && protectiveZone.Equals(WBRecordsType.PROTECTIVE_ZONE__PUBLIC_EXTRANET))
 *              {
 *                  // OK so we're going to copy this to the public extranet library as well:
 *                  WBLogging.Generic.Verbose("The file is: " + sourceFile.Url);
 *                  WBLogging.Generic.Verbose("The destination is: " + farm.PublicExtranetRecordsLibraryUrl);
 *                  WBLogging.Generic.Verbose("The destination filing path is: " + filingPathString);
 *
 *                  string errorMessagePublicExtranet = sourceFile.WBxCopyTo(farm.PublicExtranetRecordsLibraryUrl, filingPath);
 *
 *                  if (errorMessagePublicExtranet == "")
 *                  {
 *                      successMessage += "<tr><td colspan='2'><b>And also published to the public extranet library.</b></td></tr>";
 *                  }
 *              }
 */
                successMessage += "</table>";

                if (errorMessage == "")
                {
                    //returnFromDialogOKAndRefresh();
                    GoToGenericOKPage("Publishing Out Success", successMessage);
                }
                else
                {
                    GoToGenericOKPage("Publishing Out Error", errorMessage);

                    //returnFromDialogOK("An error occurred during publishing: " + errorMessage);
                }
            }
        }