Exemple #1
0
        public void Initialise(WBTaxonomy taxonomy, String name, Guid id)
        {
            if (_taxonomy == null)
            {
                if (name == null || name == "")
                {
                    throw new Exception("You cannot create a WBTerm (or derivative) with a null or blank name");
                }

                WBLogging.Generic.Verbose("Initialising a term with name | id : " + name + " | " + id);

                _taxonomy = taxonomy;
                _name     = name;
                _id       = id;

                _UIControlValue = null;
                _term           = null;

                WBLogging.Generic.Verbose("Right now the UIControlValue comes back as: " + UIControlValue);
            }
            else
            {
                WBUtils.shouldThrowError("You should never call this method on an initialised WBTerm or derived class");
            }
        }
Exemple #2
0
        public static WBTaxonomy GetOrCreate(SPSite site, String termSetName)
        {
            WBFarm     farm     = WBFarm.Local;
            WBTaxonomy taxonomy = new WBTaxonomy(site,
                                                 farm.TermStoreName,
                                                 farm.TermStoreGroupName,
                                                 termSetName);

            TermSet termSet = null;

            try
            {
                termSet = taxonomy.Group.TermSets[termSetName];
            }
            catch (Exception exception)
            {
                WBLogging.Generic.Verbose("Couldn't find a termset of the name so creating one: " + termSetName);

                termSet = taxonomy.Group.CreateTermSet(termSetName);
                taxonomy.CommitAll();
            }

            taxonomy._termSet = termSet;

            return(taxonomy);
        }
Exemple #3
0
 public WBTermCollection(WBTaxonomy taxonomy, T firstTerm)
 {
     _taxonomy = taxonomy;
     _list     = new List <T>();
     _list.Add(firstTerm);
     _UIControlValue = null;
 }
Exemple #4
0
 public void ConnectToSite(SPSite site)
 {
     _site = site;
     _recordsTypesTaxonomy    = WBTaxonomy.GetRecordsTypes(site);
     _functionalAreasTaxonomy = WBTaxonomy.GetFunctionalAreas(_recordsTypesTaxonomy);
     _subjectTagsTaxonomy     = WBTaxonomy.GetSubjectTags(_recordsTypesTaxonomy);
     _teamsTaxonomy           = WBTaxonomy.GetTeams(_recordsTypesTaxonomy);
 }
Exemple #5
0
        public static WBTaxonomy Get(SPSite site, String termSetName)
        {
            WBFarm     farm     = WBFarm.Local;
            WBTaxonomy taxonomy = new WBTaxonomy(site,
                                                 farm.TermStoreName,
                                                 farm.TermStoreGroupName,
                                                 termSetName);

            return(taxonomy);
        }
Exemple #6
0
 public void Initialise(WBTaxonomy taxonomy)
 {
     if (_taxonomy == null && _term == null && !String.IsNullOrEmpty(_UIControlValue))
     {
         _taxonomy = taxonomy;
     }
     else
     {
         WBUtils.shouldThrowError("You can only initialise just the taxonomy if the term and taxonomy are null by the UIControlValue is not empty");
     }
 }
Exemple #7
0
        internal void PopulateWithFunctionalAreas(WBLocationTreeState treeState, TreeNodeCollection treeNodeCollection, String viewMode, WBTermCollection <WBTerm> teamFunctionalAreas)
        {
            bool expandNodes = true;

            if (teamFunctionalAreas.Count > 2)
            {
                expandNodes = false;
            }

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

            foreach (WBTerm term in teamFunctionalAreas)
            {
                sortedTerms.Add(term);
            }
            sortedTerms = sortedTerms.OrderBy(o => o.Name).ToList();

            foreach (WBTerm functionalArea in sortedTerms)
            {
                SPFolder folder = null;

                if (viewMode != VIEW_MODE__NEW)
                {
                    folder = this.Libraries.GetMasterFolderByPath(functionalArea.Name);

                    if (folder == null)
                    {
                        WBLogging.Debug("Couldn't find folder for functional area: " + functionalArea.Name);
                        continue;
                    }
                }
                else
                {
                    WBLogging.Debug("View mode = " + viewMode);
                }


                WBFunctionalAreaTreeNode functionalAreaTreeNode = new WBFunctionalAreaTreeNode(functionalArea, folder);
                TreeNode node = functionalAreaTreeNode.AsTreeNode();

                node.Expanded         = expandNodes;
                node.PopulateOnDemand = false;
                node.SelectAction     = TreeNodeSelectAction.Expand;

                treeNodeCollection.Add(node);

                WBTaxonomy     recordsTypes = this.RecordsTypesTaxonomy;
                TermCollection terms        = recordsTypes.TermSet.Terms;

                PopulateWithRecordsTypes(treeState, node.ChildNodes, viewMode, folder, functionalArea, recordsTypes, terms);
            }
        }
Exemple #8
0
        public static void SyncAllTeams(SPSite site)
        {
            WBTaxonomy teams = WBTaxonomy.GetTeams(site);

            WBLogging.Teams.Verbose("Syncing all teams within the TermSet: " + teams.TermSet.Name);

            WBFarm farm = WBFarm.Local;

            using (SPSite teamsSite = new SPSite(farm.TeamSitesSiteCollectionUrl))
            {
                SyncAllSubTeams(teams, teams.TermSet.Terms, teamsSite, site);
            }
        }
Exemple #9
0
        public WBTaxonomy(WBTaxonomy taxonomy, String termSetName)
        {
            _session = taxonomy._session;

            _termStore     = taxonomy._termStore;
            _termStoreName = taxonomy._termStoreName;

            _group     = taxonomy._group;
            _groupName = taxonomy._groupName;

            _termSet     = null;
            _termSetName = termSetName;
        }
Exemple #10
0
        public WBSubjectTagsRecordsRoutings(WBTaxonomy subjectTags, String values)
        {
            String[] routingsStrings = values.Split(';');

            foreach (String routingString in routingsStrings)
            {
                WBSubjectTagRecordsRoutings routing = new WBSubjectTagRecordsRoutings(subjectTags, routingString);

                if (routing.IsOK)
                {
                    Routings.Add(routing);
                }
            }
        }
Exemple #11
0
        public static WBTeam GetFromTeamSite(WBTaxonomy teams, SPWeb web)
        {
            if (teams == null || web == null)
            {
                return(null);
            }

            String guidString = web.WBxGetProperty(TEAM_SITE_PROPERTY__TERM_GUID);

            if (guidString == "")
            {
                return(null);
            }
            Guid termGuid = new Guid(guidString);

            return(teams.GetTeam(termGuid));
        }
Exemple #12
0
        public void Initialise(WBTaxonomy taxonomy, String UIControlValue)
        {
            if (_taxonomy == null)
            {
                if (UIControlValue == null || UIControlValue == "")
                {
                    throw new Exception("You cannot create a WBTerm (or derivative) with a null or blank UIControlValue");
                }

                _taxonomy       = taxonomy;
                _UIControlValue = UIControlValue;

                _term = null;
            }
            else
            {
                WBUtils.shouldThrowError("You should never call this method on an initialised WBTerm or derived class");
            }
        }
Exemple #13
0
        public void Initialise(WBTaxonomy taxonomy, Term term)
        {
            if (_taxonomy == null)
            {
                if (term == null)
                {
                    throw new Exception("You cannot create a WBTerm (or derivative) with a null Term object");
                }

                _taxonomy = taxonomy;
                _term     = term;

                _UIControlValue = "";
            }
            else
            {
                WBUtils.shouldThrowError("You should never call this method on an initialised WBTerm or derived class");
            }
        }
Exemple #14
0
        private static void SyncAllSubTeams(WBTaxonomy teams, TermCollection terms, SPSite teamsSite, SPSite site)
        {
            foreach (Term term in terms)
            {
                WBLogging.Teams.Verbose("Trying to sync the team with term name: " + term.Name);

                WBTeam team = new WBTeam(teams, term);
                try
                {
                    team.SyncMembersGroup(teamsSite, site);
                }
                catch (Exception e)
                {
                    WBLogging.Teams.Unexpected("Syncing failed for team: " + team.Name + " to site: " + site.Url);
                }

                WBLogging.Teams.Verbose("Next syncing all sub-teams of team: " + team.Name);
                SyncAllSubTeams(teams, term.Terms, teamsSite, site);
            }
        }
Exemple #15
0
        private WBTermCollection <WBSubjectTag> AddAdditionalSubjectTags(SPSite controlSite, WBTermCollection <WBSubjectTag> subjectTags, String sourceID)
        {
            WBLogging.Migration.Verbose("Adding additional subject tags for item with Source ID = " + sourceID);
            WBQuery query = new WBQuery();

            query.AddFilter(WBColumn.SourceID, WBQueryClause.Comparators.Equals, sourceID);

            SPListItemCollection items = MigrationSubjectsList.WBxGetItems(controlSite, query);

            if (items.Count > 0)
            {
                WBTaxonomy subjectTagsTaxonomy = subjectTags.Taxonomy;

                subjectTags = new WBTermCollection <WBSubjectTag>(subjectTags);

                foreach (SPListItem item in items)
                {
                    String paths = WBUtils.NormalisePaths(item.WBxGetAsString(WBColumn.SubjectTagsPaths));

                    string[] pathsArray = paths.Split(';');
                    foreach (String path in pathsArray)
                    {
                        Term subjectTerm = subjectTagsTaxonomy.GetOrCreateSelectedTermByPath(path);
                        if (subjectTerm != null)
                        {
                            WBLogging.Migration.Verbose("Adding additional subject: " + path);

                            subjectTags.Add(new WBSubjectTag(subjectTagsTaxonomy, subjectTerm));
                        }
                        else
                        {
                            WBLogging.Migration.Unexpected("Could not find or create subject: " + path);
                        }
                    }
                }
            }

//            WBLogging.Migration.Verbose("At this point the subjectTags = " + subjectTags);

            return(subjectTags);
        }
Exemple #16
0
        public WBSubjectTagRecordsRoutings(WBTaxonomy subjectTags, String values)
        {
            if (String.IsNullOrEmpty(values))
            {
                IsOK = false;
                WBLogging.Debug("WBSubjectTagRecordsRoutings being created with blank or null values string:" + values);
                return;
            }

            String[] valueArray = values.Split('|');
            if (valueArray.Length == 3)
            {
                SubjectTag               = new WBSubjectTag(subjectTags, WBUtils.PutBackDelimiterCharacters(valueArray[0]));
                PublicDocumentsLibrary   = WBUtils.PutBackDelimiterCharacters(valueArray[1]);
                ExtranetDocumentsLibrary = WBUtils.PutBackDelimiterCharacters(valueArray[2]);
            }
            else
            {
                IsOK = false;
                WBLogging.Debug("WBSubjectTagRecordsRoutings being created with values string with the wrong number of values: " + values);
                return;
            }
        }
Exemple #17
0
        public WBTermCollection <WBTerm> FunctionalArea(WBTaxonomy functionalAreas)
        {
            if (UseAllFunctionalAreas)
            {
                List <WBTerm> allTerms = new List <WBTerm>();
                foreach (Term term in functionalAreas.TermSet.Terms)
                {
                    WBTerm functionalArea = new WBTerm(functionalAreas, term);
                    allTerms.Add(functionalArea);
                }

                return(new WBTermCollection <WBTerm>(functionalAreas, allTerms));
            }

            // Otherwise if we get here then this team has specific terms set:
            string UIControlValue = FunctionalAreaUIControlValue;

            if ((UIControlValue == null || UIControlValue == "") && Parent != null)
            {
                return(Parent.FunctionalArea(functionalAreas));
            }

            return(new WBTermCollection <WBTerm>(functionalAreas, FunctionalAreaUIControlValue));
        }
        /// <summary>
        /// An item was added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            WBLogging.Teams.Unexpected("In WBTeamSiteCalendarChangeEventReceiver(): Requesting a new team event");

            using (WBCollection collection = new WBCollection("http://workboxportals/projects"))
                using (SPSite teamsSite = new SPSite(properties.WebUrl))
                    using (SPWeb teamsWeb = teamsSite.OpenWeb())
                    {
                        WBTaxonomy teams = WBTaxonomy.GetTeams(collection.Site);
                        WBTeam     team  = WBTeam.GetFromTeamSite(teams, teamsWeb);

                        if (team == null)
                        {
                            WBLogging.Teams.Unexpected("Didn't find a team for this calender creation event!!!");
                        }
                        else
                        {
                            WBLogging.Teams.Unexpected("Found team: " + team.Name + " | " + team.TeamSiteUrl);
                        }


                        DateTime eventDate = DateTime.Now;
                        if (properties.ListItem["EventDate"] == null)
                        {
                            if (properties.AfterProperties["EventDate"] == null)
                            {
                                WBLogging.Teams.Unexpected("Both ListItem and AfterProperties have null for 'EventDate' !!");
                            }
                            else
                            {
                                eventDate = (DateTime)properties.AfterProperties["EventDate"];
                            }
                        }
                        else
                        {
                            eventDate = (DateTime)properties.ListItem["EventDate"];
                        }

                        DateTime endDate = DateTime.Now.AddHours(1);
                        if (properties.ListItem["EndDate"] == null)
                        {
                            if (properties.AfterProperties["EndDate"] == null)
                            {
                                WBLogging.Teams.Unexpected("Both ListItem and AfterProperties have null for 'EndDate' !!");
                            }
                            else
                            {
                                endDate = (DateTime)properties.AfterProperties["EndDate"];
                            }
                        }
                        else
                        {
                            endDate = (DateTime)properties.ListItem["EndDate"];
                        }

                        WBLogging.Teams.Unexpected(" Start End times are: " + eventDate + " and " + endDate);

                        String title = properties.ListItem["Title"].WBxToString();

                        WBLogging.Teams.Unexpected(" Title is: " + title);

                        String description = "Changed"; // properties.ListItem["Description"].WBxToString();

                        WBLogging.Teams.Unexpected(" description is: " + description);

                        WorkBox workBox = collection.RequestNewEventWorkBox(
                            properties.List.DefaultViewUrl,
                            properties.List.ID,
                            properties.ListItemId,
                            title,
                            description,
                            eventDate,
                            endDate,
                            team,
                            null,
                            "Meeting");

                        workBox.Open("Opening work box triggered by new event in a calendar.");

                        workBox.Dispose();
                    }

            base.ItemAdded(properties);
        }
Exemple #19
0
 public WBSubjectTagRecordsRoutings(WBTaxonomy subjectTags, String subjectTagUIControlValue, String publicLibrary, String extranetLibrary)
 {
     SubjectTag               = new WBSubjectTag(subjectTags, subjectTagUIControlValue);
     PublicDocumentsLibrary   = publicLibrary;
     ExtranetDocumentsLibrary = extranetLibrary;
 }
Exemple #20
0
 public WBTerm(WBTaxonomy taxonomy, String UIControlValue)
 {
     Initialise(taxonomy, UIControlValue);
 }
Exemple #21
0
 public WBTerm(WBTaxonomy taxonomy, Guid guid)
 {
     Initialise(taxonomy, taxonomy.TermSet.GetTerm(guid));
 }
Exemple #22
0
 public WBTerm(WBTaxonomy taxonomy, Term term)
 {
     Initialise(taxonomy, term);
 }
Exemple #23
0
 public WBTeam(WBTaxonomy taxonomy, Term teamsTerm) : base(taxonomy, teamsTerm)
 {
     _individualCommit = true;
 }
Exemple #24
0
 public WBTeam(WBTaxonomy taxonomy, Guid teamsGuid)
     : base(taxonomy, teamsGuid)
 {
     _individualCommit = true;
 }
Exemple #25
0
 public WBTeam(WBTaxonomy taxonomy, String UIControlValue)
     : base(taxonomy, UIControlValue)
 {
     _individualCommit = true;
 }
Exemple #26
0
        public IHierarchicalEnumerable GetChildren()
        {
            if (_children == null)
            {
                _children = new TreeViewLocationCollection();

                switch (_type)
                {
                case LOCATION_TYPE__FUNCTIONAL_AREA: {
                    WBLogging.Debug("In GetChildren() for type Functional Area");
                    WBTaxonomy     recordsTypes = _manager.RecordsTypesTaxonomy;
                    TermCollection terms        = recordsTypes.TermSet.Terms;

                    foreach (Term childTerm in terms)
                    {
                        WBRecordsType recordsType      = new WBRecordsType(recordsTypes, childTerm);
                        bool          protectiveZoneOK = true;
                        //if (!String.IsNullOrEmpty(_minimumProtectiveZone))
                        //{
                        //   protectiveZoneOK = (recordsType.IsZoneAtLeastMinimum(_minimumProtectiveZone));
                        // }

                        if (recordsType.BranchCanHaveDocuments() && recordsType.IsRelevantToFunctionalArea(_functionalArea) && protectiveZoneOK)
                        {
                            TreeViewLocation newLocation = new TreeViewLocation(this, _manager, _mode, _minimumProtectiveZone, _functionalArea, recordsType);

                            // If we're looking for existing records then we'll only add this location if it has a real folder existing underneath it:
                            if (_mode == VIEW_MODE__NEW || newLocation._folder != null)
                            {
                                _children.Add(newLocation);
                            }
                        }
                        else
                        {
                            WBLogging.Debug("In GetChildren() excluded " + recordsType.Name + " because " + recordsType.BranchCanHaveDocuments() + " && " + protectiveZoneOK);
                        }
                    }

                    break;
                }

                case LOCATION_TYPE__RECORDS_TYPE: {
                    WBLogging.Debug("In GetChildren() for type Records Type");
                    WBTaxonomy recordsTypes = _manager.RecordsTypesTaxonomy;

                    TermCollection terms = _recordsType.Term.Terms;
                    if (terms.Count > 0)
                    {
                        foreach (Term childTerm in terms)
                        {
                            WBRecordsType recordsType      = new WBRecordsType(recordsTypes, childTerm);
                            bool          protectiveZoneOK = true;
                            if (!String.IsNullOrEmpty(_minimumProtectiveZone))
                            {
                                protectiveZoneOK = (recordsType.IsZoneAtLeastMinimum(_minimumProtectiveZone));
                            }

                            if (recordsType.BranchCanHaveDocuments() && recordsType.IsRelevantToFunctionalArea(_functionalArea) && protectiveZoneOK)
                            {
                                TreeViewLocation newLocation = new TreeViewLocation(this, _manager, _mode, _minimumProtectiveZone, _functionalArea, recordsType);

                                // If we're looking for existing records then we'll only add this location if it has a real folder existing underneath it:
                                if (_mode == VIEW_MODE__NEW || newLocation._folder != null)
                                {
                                    _children.Add(newLocation);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (_mode != VIEW_MODE__NEW)
                        {
                            // WBLogging.Debug("In view mode replace switching to folders part of tree");

                            string fullClassPath = WBUtils.NormalisePath(Path);

                            // WBLogging.Debug("Looking for starting folder = " + fullClassPath);

                            SPFolder protectedLibraryRootFolder = _manager.Libraries.ProtectedMasterLibrary.List.RootFolder;

                            // WBLogging.Debug("Got library root folder");

                            SPFolder recordsTypeFolder = protectedLibraryRootFolder.WBxGetFolderPath(fullClassPath);

                            // WBLogging.Debug("Got records type folder - definitely changed .. " + recordsTypeFolder);
                            if (recordsTypeFolder != null)
                            {
                                foreach (SPFolder child in recordsTypeFolder.SubFolders)
                                {
                                    _children.Add(new TreeViewLocation(this, _manager, _mode, _minimumProtectiveZone, child));
                                }
                            }
                            else
                            {
                                WBLogging.Debug("The master library doesn't have a folder with path: " + fullClassPath);
                            }

                            // WBLogging.Debug("Added children folders");
                        }
                    }

                    break;
                }

                case LOCATION_TYPE__FOLDER: {
                    WBLogging.Debug("In GetChildren() for type Folder");

                    if (_folder.SubFolders.Count > 0)
                    {
                        foreach (SPFolder child in _folder.SubFolders)
                        {
                            _children.Add(new TreeViewLocation(this, _manager, _mode, _minimumProtectiveZone, child));
                        }
                    }
                    else
                    {
                        if (_mode == VIEW_MODE__REPLACE)
                        {
                            SPListItemCollection items = GetItemsRecursive(_folder);
                            foreach (SPListItem item in items)
                            {
                                if (ItemCanBePicked(item))
                                {
                                    _children.Add(new TreeViewLocation(this, _manager, _mode, _minimumProtectiveZone, new WBDocument(_manager.Libraries.ProtectedMasterLibrary, item)));
                                }
                            }
                        }
                    }
                    break;
                }

                case LOCATION_TYPE__DOCUMENT: {
                    WBLogging.Debug("In GetChildren() for type Document");

                    break;
                }
                }
            }

            return(_children);
        }
Exemple #27
0
 public static WBTeam getFromTeamSite(WBTaxonomy teams, SPWeb web)
 {
     return(GetFromTeamSite(teams, web));
 }
Exemple #28
0
 public static WBTeam GetFromTeamSite(SPContext context)
 {
     return(GetFromTeamSite(WBTaxonomy.GetTeams(context.Site), context.Web));
 }
Exemple #29
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();
        }
Exemple #30
0
 public static WBTeam GetFromTeamSite(WBTaxonomy teams, SPContext context)
 {
     return(GetFromTeamSite(teams, context.Web));
 }