コード例 #1
0
        private void AddFilesDetailsFromAlfresco(WBMigrationMapping mapping, SPSite controlSite, SPWeb controlWeb, SPList controlList, SPView controlView, SPListItem migrationItem, string folderPath)
        {
            WBFarm farm           = WBFarm.Local;
            string csvFileDetails = WBUtils.GetURLContents(folderPath, farm.MigrationUserName, farm.MigrationPassword);

            string[] filesDetails = csvFileDetails.Split('\n');

            foreach (string fileDetails in filesDetails)
            {
                string[] parts = fileDetails.Split(',');

                if (parts.Length > 3)
                {
                    // So we're only going to add new file paths to the migration control list:
                    if (WBUtils.FindItemByColumn(controlSite, controlList, WBColumn.SourceFilePath, parts[0]) == null)
                    {
                        SPListItem newMigrationItem = controlList.AddItem();

                        newMigrationItem.WBxCopyFrom(migrationItem, WBColumn.MappingPath);
                        newMigrationItem.WBxSet(WBColumn.SourceFilePath, parts[0]);
                        newMigrationItem.WBxSet(WBColumn.FileOrFolder, WBColumn.FILE_OR_FOLDER__FILE);
                        newMigrationItem.WBxSet(WBColumn.Title, parts[1]);
                        newMigrationItem.WBxSet(WBColumn.SourceID, parts[2]);
                        newMigrationItem.WBxSet(WBColumn.ReferenceID, parts[4]);
                        newMigrationItem.WBxSet(WBColumn.ReferenceDateString, parts[5]);
                        newMigrationItem.WBxSet(WBColumn.DeclaredDateString, parts[7]);

                        newMigrationItem.Update();
                    }
                }
            }

            migrationItem.WBxSet(WBColumn.MigrationStatus, WBColumn.MIGRATION_STATUS__DONE);
            migrationItem.Update();
        }
コード例 #2
0
ファイル: WBRecordsLibrary.cs プロジェクト: OliSharpe/wbf
        public bool RemoveDocumentByID(String recordID)
        {
            if (!IsOpen)
            {
                Open();
            }

            WBLogging.Debug("Call to RemoveDocumentByID with recordID = " + recordID + " for library: " + this.URL);

            SPListItem recordItem = WBUtils.FindItemByColumn(Site, List, WBColumn.RecordID, recordID);

            if (recordItem == null)
            {
                // There is currently no such item - so there is nothing to remove.
                return(false);
            }
            else
            {
                Records.UndeclareItemAsRecord(recordItem);
                recordItem.Delete();
                //libraryWeb.Update();

                return(true);
            }
        }
コード例 #3
0
ファイル: WBRecordsLibrary.cs プロジェクト: OliSharpe/wbf
        public WBDocument GetDocumentByID(String recordID)
        {
            if (!IsOpen)
            {
                Open();
            }

            SPListItem recordItem = WBUtils.FindItemByColumn(Site, List, WBColumn.RecordID, recordID);

            if (recordItem == null)
            {
                return(null);
            }
            return(new WBDocument(this, recordItem));
        }
コード例 #4
0
ファイル: UploadAndCreate.aspx.cs プロジェクト: OliSharpe/wbf
        private string ProcessPageText(SPSite site, SPList list, String pageText)
        {
            pageText = pageText.Replace("<h5>", "<h2>");
            pageText = pageText.Replace("</h5>", "</h2>");


            List <String> referencedURLs = WBUtils.GetReferencedURLs(pageText);

            foreach (String referencedURL in referencedURLs)
            {
                string withTrailing = WBUtils.EnsureHasHostHeader("http://izzi/", referencedURL);
                withTrailing = WBUtils.EnsureTrailingForwardSlash(withTrailing);

                SPListItem mappedPage = WBUtils.FindItemByColumn(site, list, RemotePageURLColumn, withTrailing);

                if (mappedPage == null)
                {
                    string withoutTrailing = WBUtils.EnsureNoTrailingForwardSlash(withTrailing);
                    mappedPage = WBUtils.FindItemByColumn(site, list, RemotePageURLColumn, withoutTrailing);
                }

                if (mappedPage != null)
                {
                    string newURLToUse = mappedPage.WBxGetColumnAsString(LOCAL_PAGE_URL);

                    if (newURLToUse == "")
                    {
                        string mappedPageNewLogicalLocation = mappedPage.WBxGetColumnAsString(NEW_LOGICAL_LOCATION);
                        string mappedPageSiteOrPage         = mappedPage.WBxGetColumnAsString(SITE_OR_PAGE);

                        newURLToUse = MakeLocalPageURL(mappedPageNewLogicalLocation, mappedPageSiteOrPage);
                    }

                    newURLToUse = WBUtils.GetURLWithoutHostHeader(newURLToUse);

                    WBLogging.Migration.Verbose("Replacing URL -> URL: " + referencedURL + " -> " + newURLToUse);

                    pageText = pageText.Replace(referencedURL, newURLToUse);
                }
                else
                {
                    WBLogging.Migration.Verbose("NOT Replacing URL: " + referencedURL);
                }
            }

            return(pageText);
        }
コード例 #5
0
ファイル: WBRecordsManager.cs プロジェクト: OliSharpe/wbf
        internal SPListItem GetFileTypeInfo(String fileType)
        {
            if (_fileTypeInfo.ContainsKey(fileType))
            {
                return(_fileTypeInfo[fileType]);
            }

            if (_fileTypesList == null)
            {
                _fileTypesList = this.Libraries.ProtectedMasterLibrary.Web.Lists.TryGetList(FILE_TYPES_LIST_TITLE);
            }

            SPListItem fileTypeInfo = WBUtils.FindItemByColumn(Libraries.ProtectedMasterLibrary.Site, _fileTypesList, WBColumn.FileTypeExtension, fileType);

            if (fileTypeInfo != null)
            {
                _fileTypeInfo[fileType] = fileTypeInfo;
            }

            return(fileTypeInfo);
        }
コード例 #6
0
        private void AddSubFilesAndFolders(WBMigrationMapping mapping, SPSite controlSite, SPWeb controlWeb, SPList controlList, SPView controlView, SPListItem migrationItem, String folderPath)
        {
            foreach (String subFolderPath in Directory.GetDirectories(folderPath))
            {
                // So we're only going to add new file paths to the migration control list:
                if (WBUtils.FindItemByColumn(controlSite, controlList, WBColumn.SourceFilePath, subFolderPath) == null)
                {
                    SPListItem newMigrationItem = controlList.AddItem();

                    newMigrationItem.WBxCopyFrom(migrationItem, WBColumn.MappingPath);
                    newMigrationItem.WBxSet(WBColumn.SourceFilePath, subFolderPath);
                    newMigrationItem.WBxSet(WBColumn.FileOrFolder, WBColumn.FILE_OR_FOLDER__FOLDER);

                    newMigrationItem.Update();

                    AddSubFilesAndFolders(mapping, controlSite, controlWeb, controlList, controlView, newMigrationItem, subFolderPath);
                }
            }

            foreach (String fileInFolder in Directory.GetFiles(folderPath))
            {
                // We're only going to add file paths that don't already exist in the control list:
                if (WBUtils.FindItemByColumn(controlSite, controlList, WBColumn.SourceFilePath, fileInFolder) == null)
                {
                    SPListItem newMigrationItem = controlList.AddItem();

                    newMigrationItem.WBxCopyFrom(migrationItem, WBColumn.MappingPath);
                    newMigrationItem.WBxSet(WBColumn.SourceFilePath, fileInFolder);
                    newMigrationItem.WBxSet(WBColumn.FileOrFolder, WBColumn.FILE_OR_FOLDER__FILE);

                    newMigrationItem.Update();
                }
            }

            // OK so if we've added all sub-files and folders for this folder then this folder is done:
            migrationItem.WBxSet(WBColumn.MigrationStatus, WBColumn.MIGRATION_STATUS__DONE);
            migrationItem.WBxSet(WBColumn.MigratedToUrl, "n/a");
            migrationItem.WBxSet(WBColumn.DateMigrated, DateTime.Now);
            migrationItem.Update();
        }
コード例 #7
0
ファイル: UploadAndCreate.aspx.cs プロジェクト: OliSharpe/wbf
        private void MigrateOnePage(SPSite site, SPWeb web, SPList list, SPListItem item, String username, String password)
        {
            string remotePageURL      = item.WBxGetColumnAsString(REMOTE_PAGE_URL);
            string newLogicalLocation = item.WBxGetColumnAsString(NEW_LOGICAL_LOCATION);
            string siteOrPage         = item.WBxGetColumnAsString(SITE_OR_PAGE);
            string localPageURL       = item.WBxGetColumnAsString(LOCAL_PAGE_URL);
            string resultMessage      = "";

            if (newLogicalLocation == "")
            {
                MigrationError(item, "There was no new logical location set!");
                return;
            }

            WBLogging.Migration.HighLevel("Starting MigrateOnePage() for newLogicalLocation : " + newLogicalLocation);

            if (siteOrPage == "")
            {
                MigrationError(item, "The 'Site or Page' value wasn't set!");
                return;
            }

            if (localPageURL == "")
            {
                localPageURL = MakeLocalPageURL(newLogicalLocation, siteOrPage);
                item.WBxSetColumnAsString(LOCAL_PAGE_URL, localPageURL);
            }

            string remotePageURLToUse = remotePageURL.Replace("/alfresco/web/izzi/", "/alfresco/service/mizzi/");

            string localSPWebRelativeURL = newLogicalLocation;

            if (siteOrPage == PAGE)
            {
                localSPWebRelativeURL = WBUtils.GetParentPath(newLogicalLocation, false);
            }

            if (remotePageURL != "")
            {
                WBLogging.Migration.Verbose("Migrating remote -> local: " + remotePageURL + " -> " + localPageURL);
            }
            else
            {
                WBLogging.Migration.Verbose("Creating new local unmapped site: " + localPageURL);
            }

            SPWeb localWeb = null;

            try
            {
                string pageTitle    = item.WBxGetColumnAsString("Title");
                string pageTemplate = "";

                if (remotePageURL != "")
                {
                    pageTitle     = WBUtils.GetURLContents(remotePageURLToUse + "?JUST_PAGE_TITLE=true", username, password);
                    item["Title"] = pageTitle;

                    pageTemplate        = WBUtils.GetURLContents(remotePageURLToUse + "?JUST_PAGE_TEMPLATE=true", username, password);
                    item[PAGE_TEMPLATE] = pageTemplate;
                }


                if (remotePageURL != "" && pageTemplate != "izziThreeColumn.ftl")
                {
                    resultMessage = "Not migrated yet (due to unhandled template)";
                }
                else
                {
                    bool newSiteCreated = false;

                    localWeb = site.OpenWeb(localSPWebRelativeURL);

                    if (!localWeb.Exists)
                    {
                        // OK let's try to get the parent web:
                        string parentURL = WBUtils.GetParentPath(localSPWebRelativeURL, false);
                        string childName = WBUtils.GetLastNameInPath(localSPWebRelativeURL);

                        WBLogging.Migration.Verbose("Trying to find parent URL: " + parentURL);

                        using (SPWeb parentWeb = site.OpenWeb(parentURL))
                        {
                            if (parentWeb.Exists)
                            {
                                if (pageTitle == "")
                                {
                                    pageTitle     = childName.WBxToUpperFirstLetter();
                                    item["Title"] = pageTitle;
                                }
                                localWeb       = parentWeb.Webs.Add(childName, pageTitle, pageTitle, 1033, "CMSPUBLISHING#0", true, false);
                                newSiteCreated = true;
                            }
                            else
                            {
                                WBLogging.Migration.Verbose("Couldn't find parente web site - Don't know how to handle this situation.");
                                resultMessage = "Couldn't find the parent web site";
                            }
                        }
                    }

                    if (localWeb.Exists)
                    {
                        if (localWeb.HasUniqueRoleAssignments)
                        {
                            localWeb.ResetRoleInheritance();
                            localWeb.Update();
                        }

                        PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(localWeb);

                        PageLayout layout = WBUtils.GetPageLayout(publishingWeb, "LBI Standard page layout");

                        if (layout == null)
                        {
                            MigrationError(item, "Didn't find the page layout!!");
                            return;
                        }

                        SPFile         pageFile = null;
                        PublishingPage page     = null;

                        // If this location is for a site then we get the default page:
                        if (siteOrPage == SITE)
                        {
                            pageFile = publishingWeb.DefaultPage;
                            page     = PublishingPage.GetPublishingPage(pageFile.Item);
                        }
                        else
                        {
                            // Otherwise we have to get or create a named page:
                            string pageName = WBUtils.GetLastNameInPath(newLogicalLocation) + ".aspx";

                            SPListItem pageItem = WBUtils.FindItemByColumn(site, publishingWeb.PagesList, WBColumn.Name, pageName);
                            if (pageItem != null)
                            {
                                page = PublishingPage.GetPublishingPage(pageItem);
                            }
                            else
                            {
                                // We couldn't find the page so we'll add it as a new page:
                                page = publishingWeb.AddPublishingPage(pageName, layout);
                            }

                            pageFile = page.ListItem.File;

                            string urlFromItem = "http://sp.izzi" + page.ListItem.File.ServerRelativeUrl;
                            if (localPageURL != urlFromItem)
                            {
                                MigrationError(item, "The generated names don't match: localPageURL | urlFromItem : " + localPageURL + " | " + urlFromItem);
                                return;
                            }
                        }

                        // So we'll update the content if we're migrating an izzi page or it's the first time
                        // creation of a new local page:
                        if (remotePageURL != "" || newSiteCreated)
                        {
                            string pageText = "This page is not being migrated so needs to be edited locally.";
                            if (remotePageURL != "")
                            {
                                pageText = WBUtils.GetURLContents(remotePageURLToUse + "?JUST_PAGE_TEXT=true", username, password);
                                pageText = ProcessPageText(site, list, pageText);
                            }

                            if (pageFile.CheckOutType == SPFile.SPCheckOutType.None)
                            {
                                WBLogging.Migration.Verbose("Checking out the pageFile");
                                pageFile.CheckOut();
                            }
                            else
                            {
                                WBLogging.Migration.Verbose("No need to check out the pageFile");
                            }

                            if (newSiteCreated)
                            {
                                page.Layout = layout;
                                page.Update();
                            }

                            pageFile.Item["Page Content"] = pageText;
                            pageFile.Item["Title"]        = pageTitle;


                            pageFile.Item.Update();
                            pageFile.Update();


                            pageFile.CheckIn("Checked in programmatically");
                            pageFile.Publish("Published programmatically");

                            WBLogging.Migration.Verbose("Publisehd migrated page: " + localPageURL);
                        }
                    }
                    else
                    {
                        WBLogging.Migration.Unexpected("Wasn't able to find or create the local web: " + localSPWebRelativeURL);
                        resultMessage += " Wasn't able to find or create the local web: " + localSPWebRelativeURL;
                    }
                }
            }
            catch (Exception error)
            {
                WBLogging.Migration.Unexpected("There was an error: " + error.Message + " Tried with remote | local : " + remotePageURL + " | " + localPageURL);
                resultMessage = "There was an error: " + error.Message + " Tried with remote | local : " + remotePageURL + " | " + localPageURL;
            }
            finally
            {
                if (localWeb != null)
                {
                    localWeb.Dispose();
                }
            }

            if (resultMessage == "")
            {
                resultMessage        = "Processed OK";
                item[LAST_MIGRATION] = DateTime.Now;
            }


            WBLogging.Migration.Verbose("Result message : " + resultMessage);

            item.WBxSetColumnAsString(RESULT_MESSAGE, resultMessage);
            item.Update();

            WBLogging.Migration.HighLevel("Finished MigrateOnePage() for newLogicalLocation : " + newLogicalLocation);
        }
コード例 #8
0
ファイル: UploadAndCreate.aspx.cs プロジェクト: OliSharpe/wbf
        private void AddChildrenForPage(SPSite site, SPWeb web, SPList list, SPListItem item, String username, String password)
        {
            string currentLocation    = item.WBxGetColumnAsString(CURRENT_LOCATION);
            string newLogicalLocation = item.WBxGetColumnAsString(NEW_LOGICAL_LOCATION);
            string remotePageURL      = item.WBxGetColumnAsString(REMOTE_PAGE_URL);

            if (currentLocation == "")
            {
                item.WBxSetColumnAsString(SITE_OR_PAGE, SITE);
                item.Update();

                return;
            }

            if (newLogicalLocation == "")
            {
                WBLogging.Migration.Verbose("The new location for this item was blank! :" + currentLocation);
                return;
            }

            if (remotePageURL == "")
            {
                remotePageURL = "http://izzi/alfresco/web/izzi" + currentLocation;
                item.WBxSetColumnAsString(REMOTE_PAGE_URL, remotePageURL);
            }

            string remotePageURLToUse = remotePageURL.Replace("/alfresco/web/izzi/", "/alfresco/service/mizzi/");

            // Let's make sure that our parent URLs end with a forward slash:
            currentLocation    = WBUtils.EnsureTrailingForwardSlash(currentLocation);
            newLogicalLocation = WBUtils.EnsureTrailingForwardSlash(newLogicalLocation);
            remotePageURL      = WBUtils.EnsureTrailingForwardSlash(remotePageURL);

            string childrenListString = WBUtils.GetURLContents(remotePageURLToUse + "?JUST_CHILD_PAGES=true", username, password);

            string parentIsSiteOrPage = PAGE;

            if (childrenListString.WBxTrim() != "")
            {
                parentIsSiteOrPage = SITE;

                string comments = item.WBxGetColumnAsString(COMMENTS);

                String[] children = childrenListString.Split(';');

                foreach (String child in children)
                {
                    if (child.WBxTrim() == "")
                    {
                        continue;
                    }

                    string cleanChild = child.Trim().Replace("&", "and").Replace(" ", "-").Replace(",", "-");

                    string childCurrentLocation    = currentLocation + child + "/";
                    string childNewLogicalLocation = newLogicalLocation + cleanChild + "/";
                    string childRemotePageURL      = remotePageURL + child + "/";

                    // OK so we need to check if another line item is already mapping to this new logical location:
                    SPListItem currentLocationExists = WBUtils.FindItemByColumn(site, list, CurrentLocationColumn, childCurrentLocation);
                    SPListItem newLocationExists     = WBUtils.FindItemByColumn(site, list, NewLogicalLocationColumn, childNewLogicalLocation);

                    if (newLocationExists == null && currentLocationExists == null)
                    {
                        // OK so this logical location isn't yet mapped to so we can create the child item:
                        WBLogging.Migration.Verbose("No duplicates found for current | new : " + childCurrentLocation + " | " + childNewLogicalLocation);

                        SPListItem childItem = list.AddItem();

                        childItem.WBxSetColumnAsString(CURRENT_LOCATION, childCurrentLocation);
                        childItem.WBxSetColumnAsString(NEW_LOGICAL_LOCATION, childNewLogicalLocation);
                        childItem.WBxSetColumnAsString(REMOTE_PAGE_URL, childRemotePageURL);
                        childItem.WBxSetColumnAsString(MIGRATION_ACTION, MIGRATION_ACTION__NOTHING);

                        childItem.Update();

                        AddChildrenForPage(site, web, list, childItem, username, password);
                    }
                    else
                    {
                        string duplicateComment = " Found duplication of";
                        if (currentLocationExists != null)
                        {
                            duplicateComment += " current location (" + currentLocationExists.ID + " : " + childCurrentLocation + ")";

                            if (newLocationExists != null)
                            {
                                duplicateComment += " and";
                            }
                        }

                        if (newLocationExists != null)
                        {
                            duplicateComment += " new logical location (" + newLocationExists.ID + " : " + childNewLogicalLocation + ")";
                        }

                        WBLogging.Migration.Verbose("Duplicates found comment: " + duplicateComment);
                        comments += duplicateComment;
                    }
                }

                item.WBxSetColumnAsString(COMMENTS, comments);
            }

            item.WBxSetColumnAsString(SITE_OR_PAGE, parentIsSiteOrPage);
            item.Update();
        }
コード例 #9
0
        private void MigrateOneDocumentToLibrary(
            WBMigrationMapping mapping,
            SPSite sourceSite,
            SPWeb sourceWeb,
            SPDocumentLibrary sourceLibrary,
            SPSite destinationSite,
            SPWeb destinationWeb,
            SPFolder destinationRootFolder,
            SPSite controlSite,
            SPWeb controlWeb,
            SPList controlList,
            SPView controlView,
            SPListItem migrationItem)
        {
            WBFarm farm = WBFarm.Local;

            //foreach (SPField field in migrationItem.Fields)
            //{
            //    WBLogging.Migration.Verbose("Field InternalName: " + field.InternalName + "  Field Title: " + field.Title +  " item[field.Title] : " + migrationItem[field.Title]);
            //}

            String sourceFilePath = migrationItem.WBxGetAsString(WBColumn.SourceFilePath);
            String mappingPath    = WBUtils.NormalisePath(migrationItem.WBxGetAsString(WBColumn.MappingPath));

            WBLogging.Migration.Verbose("Trying to migrate file      : " + sourceFilePath);
            WBLogging.Migration.Verbose("Migrating with mapping path : " + mappingPath);

            WBMappedPath mappedPath = mapping[mappingPath];

            SPListItem controlItem = migrationItem;
            SPListItem mappingItem = null;
            SPListItem subjectItem = null;

            String documentumSourceID = "";

            if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS)
            {
                documentumSourceID = controlItem.WBxGetAsString(WBColumn.SourceID);

                if (!String.IsNullOrEmpty(documentumSourceID))
                {
                    mappingItem = WBUtils.FindItemByColumn(controlSite, MigrationMappingList, WBColumn.SourceID, documentumSourceID);

                    subjectItem = WBUtils.FindItemByColumn(controlSite, MigrationSubjectsList, WBColumn.SourceID, documentumSourceID);
                }
            }



            if (mappedPath.InErrorStatus)
            {
                WBLogging.Migration.HighLevel("WBMigrationTimerJob.MigrateOneDocumentToLibrary(): There was an error with the mapped path: " + mappedPath.ErrorStatusMessage);
                return;
            }

            // OK so let's first get the various WBTerms from the mapped path so that if these
            // fail they fail before we copy the document!

            WBRecordsType                   recordsType    = null;
            WBTermCollection <WBTerm>       functionalArea = null;
            WBTermCollection <WBSubjectTag> subjectTags    = null;

            if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS)
            {
                string recordsTypePath = controlItem.WBxGetAsString(WBColumn.RecordsTypePath);
                if (String.IsNullOrEmpty(recordsTypePath) && mappingItem != null)
                {
                    recordsTypePath = mappingItem.WBxGetAsString(WBColumn.RecordsTypePath);
                }

                Term rterm = mapping.RecordsTypesTaxonomy.GetSelectedTermByPath(recordsTypePath);
                if (rterm != null)
                {
                    recordsType = new WBRecordsType(mapping.RecordsTypesTaxonomy, rterm);
                }


                string functionalAreaPath = controlItem.WBxGetAsString(WBColumn.FunctionalAreaPath);
                if (String.IsNullOrEmpty(functionalAreaPath) && mappingItem != null)
                {
                    functionalAreaPath = mappingItem.WBxGetAsString(WBColumn.FunctionalAreaPath);
                }

                if (!String.IsNullOrEmpty(functionalAreaPath))
                {
                    string[] paths = functionalAreaPath.Split(';');

                    List <WBTerm> fterms = new List <WBTerm>();

                    foreach (string path in paths)
                    {
                        WBLogging.Migration.Verbose("Trying to get a Functional Area by path with: " + path);

                        Term fterm = mapping.FunctionalAreasTaxonomy.GetOrCreateSelectedTermByPath(path);
                        if (fterm != null)
                        {
                            fterms.Add(new WBTerm(mapping.FunctionalAreasTaxonomy, fterm));
                        }
                        else
                        {
                            WBLogging.Debug("Coundn't find the functional area with path: " + path);
                        }
                    }

                    if (fterms.Count > 0)
                    {
                        functionalArea = new WBTermCollection <WBTerm>(mapping.FunctionalAreasTaxonomy, fterms);
                    }
                }


                string subjectTagsPaths = controlItem.WBxGetAsString(WBColumn.SubjectTagsPaths);
                if (String.IsNullOrEmpty(subjectTagsPaths) && mappingItem != null)
                {
                    subjectTagsPaths = mappingItem.WBxGetAsString(WBColumn.SubjectTagsPaths);
                }

                if (!String.IsNullOrEmpty(subjectTagsPaths))
                {
                    List <WBSubjectTag> sterms = new List <WBSubjectTag>();


                    // Note that it is not necessarily an error for the subject tags to be empty.
                    if (!String.IsNullOrEmpty(subjectTagsPaths) && subjectTagsPaths != "/")
                    {
                        string[] paths = subjectTagsPaths.Split(';');

                        foreach (string path in paths)
                        {
                            WBLogging.Migration.Verbose("Trying to get a Subject Tag by path with: " + path);

                            if (path != "/")
                            {
                                Term sterm = mapping.SubjectTagsTaxonomy.GetOrCreateSelectedTermByPath(path);
                                if (sterm != null)
                                {
                                    sterms.Add(new WBSubjectTag(mapping.SubjectTagsTaxonomy, sterm));
                                }
                                else
                                {
                                    WBLogging.Debug("Coundn't find the subject tag with path: " + path);
                                }
                            }
                        }
                    }

                    subjectTags = new WBTermCollection <WBSubjectTag>(mapping.SubjectTagsTaxonomy, sterms);
                }
            }
            else
            {
                recordsType    = mappedPath.RecordsType;
                functionalArea = mappedPath.FunctionalArea;
                subjectTags    = mappedPath.SubjectTags;
            }



            if (MigrationSubjectsList != null && MigrationSourceSystem == MIGRATION_SOURCE__HFI_INTRANET_DOCUMENTS)
            {
                //foreach (SPField field in migrationItem.Fields)
                //{
                //   WBLogging.Debug("Found field: " + field.Title + " field inner name: " + field.InternalName);
                //}

                subjectTags = AddAdditionalSubjectTags(controlSite, subjectTags, migrationItem.WBxGetAsString(WBColumn.SourceID));
            }


            if (recordsType == null)
            {
                MigrationError(migrationItem, "The records type for this item could not be found. Looked for: " + mappedPath.RecordsTypePath);
                return;
            }

            if (functionalArea == null || functionalArea.Count == 0)
            {
                MigrationError(migrationItem, "The functional area for this item could not be found. Looked for: " + mappedPath.FunctionalAreaPath);
                return;
            }

            // OK so we can start building up our information about the document we are going to declare:
            WBDocument document = new WBDocument();

            document.RecordsType    = recordsType;
            document.FunctionalArea = functionalArea;
            document.SubjectTags    = subjectTags;

            document[WBColumn.SourceFilePath] = sourceFilePath;

            string sourceSystem = migrationItem.WBxGetAsString(WBColumn.SourceSystem);

            if (String.IsNullOrEmpty(sourceSystem))
            {
                sourceSystem = farm.MigrationSourceSystem;
            }
            if (String.IsNullOrEmpty(sourceSystem))
            {
                sourceSystem = farm.MigrationControlListUrl;
            }
            document[WBColumn.SourceSystem] = sourceSystem;

            String sourceID = migrationItem.WBxGetAsString(WBColumn.SourceID);

            if (String.IsNullOrEmpty(sourceID) && MigrationSourceSystem != MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS)
            {
                sourceID = sourceFilePath;
            }
            document[WBColumn.SourceID] = sourceID;

            SPFile     sourceFile = null;
            SPListItem sourceItem = null;

            if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS)
            {
                if (String.IsNullOrEmpty(sourceID))
                {
                    sourceItem = sourceWeb.GetListItem(sourceFilePath);
                    document[WBColumn.SourceID]     = sourceFilePath;
                    document[WBColumn.SourceSystem] = "Initial SharePoint Web Docs";
                }
                else
                {
                    sourceItem = WBUtils.FindItemByColumn(sourceSite, (SPList)sourceLibrary, WBColumn.Source_ID, sourceID);
                }

                if (sourceItem == null)
                {
                    MigrationError(migrationItem, "Could not find the doc with source id = " + sourceFilePath);
                    return;
                }
                sourceFile = sourceItem.File;
            }



            if (migrationItem.WBxIsNotBlank(WBColumn.ReferenceDateString))
            {
                document.ReferenceDate = WBUtils.ParseDate(migrationItem.WBxGetAsString(WBColumn.ReferenceDateString));
            }

            if (migrationItem.WBxIsNotBlank(WBColumn.ModifiedDateString))
            {
                document.Modified = WBUtils.ParseDate(migrationItem.WBxGetAsString(WBColumn.ModifiedDateString));
            }
            else
            {
                if (mappingItem != null)
                {
                    if (mappingItem.WBxIsNotBlank(WBColumn.ModifiedDateString))
                    {
                        document.Modified = WBUtils.ParseDate(mappingItem.WBxGetAsString(WBColumn.ModifiedDateString));
                    }
                }
                else if (subjectItem != null)
                {
                    if (subjectItem.WBxIsNotBlank(WBColumn.ModifiedDateString))
                    {
                        document.Modified = WBUtils.ParseDate(subjectItem.WBxGetAsString(WBColumn.ModifiedDateString));
                    }
                }
                else if (sourceItem != null)
                {
                    if (sourceItem.WBxHasValue(WBColumn.Modified))
                    {
                        document.Modified = (DateTime)sourceItem["Modified"];
                    }
                }
            }

            if (migrationItem.WBxIsNotBlank(WBColumn.DeclaredDateString))
            {
                document.DeclaredRecord = WBUtils.ParseDate(migrationItem.WBxGetAsString(WBColumn.DeclaredDateString));
            }

            if (migrationItem.WBxIsNotBlank(WBColumn.ScanDateString))
            {
                document.ScanDate = WBUtils.ParseDate(migrationItem.WBxGetAsString(WBColumn.ScanDateString));
            }


            if (migrationItem.WBxIsNotBlank(WBColumn.OwningTeamPath) || !String.IsNullOrEmpty(mappedPath.OwningTeamPath))
            {
                WBTaxonomy teamsTaxonomy = mapping.TeamsTaxonomy;

                string owningTeamPath = migrationItem.WBxGetAsString(WBColumn.OwningTeamPath);
                if (owningTeamPath == "")
                {
                    owningTeamPath = mappedPath.OwningTeamPath;
                }
                WBTeam foundTeam = teamsTaxonomy.GetSelectedTeam(WBUtils.NormalisePath(owningTeamPath));

                if (foundTeam != null)
                {
                    WBLogging.Migration.Verbose("Found the owning team: " + foundTeam.Name);
                    document.OwningTeam = foundTeam;
                }
                else
                {
                    MigrationError(migrationItem, "Could not find the owning team at: " + owningTeamPath);
                    return;
                }
            }

            if (migrationItem.WBxIsNotBlank(WBColumn.Title))
            {
                document[WBColumn.Title] = migrationItem.WBxGetAsString(WBColumn.Title);
            }


            if (MigrationSourceSystem == MIGRATION_SOURCE__HFI_INTRANET_DOCUMENTS)
            {
                document.Modified = File.GetLastWriteTime(sourceFilePath);
                WBLogging.Debug("Found the last modified date to be: " + document.Modified);
            }

            // We'll set the reference date for these imported files based on their existing declared date or modified date if it exists.
            if (!document.HasReferenceDate)
            {
                if (document.HasDeclaredRecord)
                {
                    document.ReferenceDate = document.DeclaredRecord;
                }
                else if (document.HasScanDate)
                {
                    document.ReferenceDate = document.ScanDate;
                }
                else if (document.HasModified)
                {
                    document.ReferenceDate = document.Modified;
                }
            }

            if (migrationItem.WBxHasValue(WBColumn.ReferenceID))
            {
                document.ReferenceID = migrationItem.WBxGetAsString(WBColumn.ReferenceID);
            }


            string protectiveZone = migrationItem.WBxGetAsString(WBColumn.ProtectiveZone);

            if (String.IsNullOrEmpty(protectiveZone))
            {
                protectiveZone = mappedPath.ProtectiveZone;
                if (String.IsNullOrEmpty(protectiveZone))
                {
                    protectiveZone = WBRecordsType.PROTECTIVE_ZONE__PROTECTED;
                }
            }
            document[WBColumn.ProtectiveZone] = protectiveZone;

            string liveOrArchived = migrationItem.WBxGetAsString(WBColumn.LiveOrArchived);

            if (String.IsNullOrEmpty(liveOrArchived))
            {
                liveOrArchived = mappedPath.LiveOrArchived;
                if (String.IsNullOrEmpty(liveOrArchived))
                {
                    liveOrArchived = WBColumn.LIVE_OR_ARCHIVED__LIVE;
                }
            }
            document[WBColumn.LiveOrArchived] = liveOrArchived;

            bool downloadFromWebSite = false;

            if (MigrationSourceSystem == MIGRATION_SOURCE__ALFRESCO_RECORDS)
            {
                downloadFromWebSite = true;
            }


            String originalFileName = migrationItem.WBxGetAsString(WBColumn.OriginalFilename).Trim();

            if (String.IsNullOrEmpty(originalFileName))
            {
                originalFileName = Path.GetFileName(sourceFilePath);
            }
            if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS)
            {
                originalFileName = sourceFile.Name;
            }
            if (downloadFromWebSite)
            {
                originalFileName = HttpUtility.UrlDecode(originalFileName);
            }

            document.OriginalFilename = originalFileName;

            //String extension = Path.GetExtension(filename);


            WBItemMessages metadataErrors = recordsType.CheckMetadataIsOK(document);

            if (metadataErrors.Count > 0)
            {
                string message = "There were problems with the prepared metadata. ";
                foreach (WBColumn column in metadataErrors.Keys)
                {
                    message += "Error for column: " + column.DisplayName + " message: " + metadataErrors[column] + "  ";
                }
                MigrationError(migrationItem, message);
                return;
            }

            Stream fileStream = null;

            if (downloadFromWebSite)
            {
                WebClient webClient = new WebClient();

                if (!String.IsNullOrEmpty(farm.MigrationUserName) && !String.IsNullOrEmpty(farm.MigrationPassword))
                {
                    webClient.Credentials = new NetworkCredential(farm.MigrationUserName, farm.MigrationPassword);
                }

                string tempFile = @"C:\Temp\tmp.bin";
                if (farm.FarmInstance == WBFarm.FARM_INSTANCE__PROTECTED_INTERNAL_FARM)
                {
                    tempFile = @"E:\Temp\tmp.bin";
                }

                webClient.DownloadFile(sourceFilePath, tempFile);
                WBLogging.Migration.Verbose("Downloaded to local tmp file using webClient.DownloadFile() successfully");

                fileStream = File.OpenRead(tempFile);
                WBLogging.Migration.Verbose("Opened local tmp file using File.OpenRead() successfully");
            }
            else if (MigrationSourceSystem == MIGRATION_SOURCE__DOCUMENTUM_WEB_DOCUMENTS)
            {
                fileStream = sourceFile.OpenBinaryStream();
                WBLogging.Migration.Verbose("Opened using sourceFile.OpenBinaryStream() successfully");
            }
            else
            {
                fileStream = File.OpenRead(sourceFilePath);
                WBLogging.Migration.Verbose("Opened using File.OpenRead() successfully");
            }

            SPListItem uploadedItem = null;

            try
            {
                uploadedItem = recordsType.PublishDocument(destinationWeb, destinationRootFolder, document, fileStream);
            }
            finally
            {
                fileStream.Close();
                fileStream.Dispose();
            }

            if (uploadedItem == null)
            {
                MigrationError(migrationItem, "There was a problem in the call to recordsType.PublishDocument() as the uploaded item is null.");
                return;
            }

            migrationItem.WBxSet(WBColumn.DateMigrated, DateTime.Now);
            migrationItem.WBxSet(WBColumn.MigratedToUrl, uploadedItem.WBxGet(WBColumn.EncodedAbsoluteURL));
            migrationItem.WBxSet(WBColumn.RecordID, uploadedItem.WBxGet(WBColumn.RecordID));
            migrationItem.WBxSet(WBColumn.MigrationStatus, WBColumn.MIGRATION_STATUS__DONE);

            migrationItem.Update();
        }
コード例 #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // First we're going to check membership of the records management group:
            String  rmGroupName = WBFarm.Local.RecordsManagersGroupName;
            SPGroup rmGroup     = null;

            if (!String.IsNullOrEmpty(rmGroupName))
            {
                try
                {
                    rmGroup = SPContext.Current.Web.SiteGroups[rmGroupName];
                }
                catch (Exception exception)
                {
                    // Probably the group hasn't been created or setup here yet
                }
            }

            if (rmGroup == null || !rmGroup.ContainsCurrentUser)
            {
                AccessDeniedPanel.Visible          = true;
                UpdateRecordsMetadataPanel.Visible = false;
                return;
            }

            currentUserLoginName = SPContext.Current.Web.CurrentUser.LoginName;


            String listIDString   = "";
            String itemIDString   = "";
            String recordIDString = "";

            recordsTypesTaxonomy = WBTaxonomy.GetRecordsTypes(SPContext.Current.Site);
            subjectTagsTaxonomy  = WBTaxonomy.GetSubjectTags(recordsTypesTaxonomy);

            librarySite = new SPSite(WBFarm.Local.ProtectedRecordsLibraryUrl);
            libraryWeb  = librarySite.OpenWeb();

            libraryList = libraryWeb.GetList(WBFarm.Local.ProtectedRecordsLibraryUrl);


            if (!IsPostBack)
            {
                recordIDString = Request.QueryString["RecordID"];

                if (String.IsNullOrEmpty(recordIDString))
                {
                    listIDString = Request.QueryString["ListID"];
                    itemIDString = Request.QueryString["ItemID"];
                }
                else
                {
                    listIDString = libraryList.ID.ToString();
                }

                ListID.Value = listIDString;
                ItemID.Value = itemIDString;
            }
            else
            {
                recordIDString = RecordID.Text;
                listIDString   = ListID.Value;
                itemIDString   = ItemID.Value;
            }

            if (!String.IsNullOrEmpty(itemIDString))
            {
                int itemID = Convert.ToInt32(itemIDString);

                recordItem = libraryList.GetItemById(itemID);
            }
            else
            {
                recordItem = WBUtils.FindItemByColumn(SPContext.Current.Site, libraryList, WBColumn.RecordID, recordIDString);

                if (recordItem != null)
                {
                    itemIDString = recordItem.ID.ToString();
                    ItemID.Value = itemIDString;
                }
            }

            if (recordItem != null)
            {
                record = new WBDocument(recordItem);

                FunctionalArea.Text = record.FunctionalArea.Names();

                WBRecordsType recordsType = record.RecordsType;

                recordsType.Taxonomy = recordsTypesTaxonomy;

                RecordsType.Text = recordsType.FullPath.Replace("/", " / ");


                if (!IsPostBack)
                {
                    Filename.Text = recordItem.Name;
                    Title.Text    = recordItem.Title;
                    RecordID.Text = record[WBColumn.RecordID].WBxToString();

                    LiveOrArchived.DataSource = new String[] { "Live", "Archived" };
                    LiveOrArchived.DataBind();
                    LiveOrArchived.SelectedValue = record[WBColumn.LiveOrArchived].WBxToString();

                    ProtectiveZone.DataSource = WBRecordsType.getProtectiveZones();
                    ProtectiveZone.DataBind();
                    ProtectiveZone.SelectedValue = record.ProtectiveZone;

                    subjectTagsTaxonomy.InitialiseTaxonomyControl(SubjectTags, WBColumn.SubjectTags.DisplayName, true);
                    SubjectTags.Text = record.SubjectTags.UIControlValue;
                }
            }

            if (!IsPostBack)
            {
                libraryWeb.Dispose();
                librarySite.Dispose();

                LiveOrArchived.Focus();
            }
        }