Beispiel #1
0
        public static bool HasFolderUriChanged(Folder folder, Uri newFolderUri)
        {
            string valueOrDefault = folder.PropertyBag.GetValueOrDefault <string>(FolderSchema.LinkedUrl, string.Empty);

            if (string.IsNullOrEmpty(valueOrDefault))
            {
                return(true);
            }
            Uri x = new Uri(valueOrDefault);

            return(!UriComparer.IsEqual(x, newFolderUri));
        }
        protected virtual void OnGetDocumentLibraryListsComplete(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new InvalidOperationException("OnGetDocumentLibraryListsComplete: asyncResult cannot be null here.");
            }
            ProtocolLog.LogInformation(this.loggingComponent, this.loggingContext, string.Format("SiteSynchronizer.BeginExecute", new object[0]));
            bool flag = (base.SyncOption & SyncOption.CurrentDocumentLibsOnly) == SyncOption.CurrentDocumentLibsOnly;
            Dictionary <Guid, List> dictionary = new Dictionary <Guid, List>();

            if (!flag)
            {
                try
                {
                    this.InitializeDocumentLibraryList(dictionary);
                    if (base.HandleShutDown())
                    {
                        return;
                    }
                }
                catch (WebException e)
                {
                    SharePointException value = new SharePointException(this.siteUri.AbsoluteUri, e, false);
                    this.executionAsyncResult.InvokeCallback(value);
                    return;
                }
                catch (IOException value2)
                {
                    this.executionAsyncResult.InvokeCallback(value2);
                    return;
                }
                catch (ClientRequestException value3)
                {
                    this.executionAsyncResult.InvokeCallback(value3);
                    return;
                }
                catch (ServerException value4)
                {
                    this.executionAsyncResult.InvokeCallback(value4);
                    return;
                }
            }
            List <StoreObjectId>             list        = new List <StoreObjectId>();
            List <List>                      list2       = new List <List>();
            Dictionary <StoreObjectId, List> dictionary2 = new Dictionary <StoreObjectId, List>();

            try
            {
                using (Folder folder = Folder.Bind(this.mailboxSession, DefaultFolderType.Root))
                {
                    using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, new ExistsFilter(FolderSchema.LinkedId), null, new PropertyDefinition[]
                    {
                        FolderSchema.LinkedId,
                        FolderSchema.Id,
                        FolderSchema.DisplayName,
                        FolderSchema.LinkedUrl,
                        FolderSchema.LinkedSiteAuthorityUrl
                    }))
                    {
                        object[][] rows;
                        do
                        {
                            rows = queryResult.GetRows(10000);
                            for (int i = 0; i < rows.Length; i++)
                            {
                                Guid          guid     = (Guid)rows[i][0];
                                StoreObjectId objectId = ((VersionedId)rows[i][1]).ObjectId;
                                string        a        = rows[i][2] as string;
                                string        text     = rows[i][3] as string;
                                string        text2    = rows[i][4] as string;
                                Uri           uri      = null;
                                if (!string.IsNullOrEmpty(text2))
                                {
                                    uri = new Uri(text2);
                                }
                                if (string.IsNullOrEmpty(text))
                                {
                                    this.executionAsyncResult.InvokeCallback(new ArgumentNullException("LinkedUrl is null for folder " + objectId.ToString()));
                                }
                                if (!flag)
                                {
                                    List list3 = null;
                                    if (dictionary.TryGetValue(guid, out list3))
                                    {
                                        if (!string.Equals(a, list3.Title, StringComparison.Ordinal) || (uri != null && !UriComparer.IsEqual(uri, this.siteUri)) || (this.Job.SyncOption & SyncOption.FullSync) == SyncOption.FullSync)
                                        {
                                            dictionary2[objectId] = dictionary[guid];
                                        }
                                        this.documentLibraryInfos.Enqueue(new DocumentLibraryInfo(objectId, list3.Id, list3.RootFolder.ServerRelativeUrl));
                                        dictionary.Remove(guid);
                                    }
                                    else
                                    {
                                        list.Add(objectId);
                                    }
                                }
                                else
                                {
                                    this.documentLibraryInfos.Enqueue(new DocumentLibraryInfo(objectId, guid, new Uri(text).AbsolutePath));
                                }
                            }
                        }while (rows.Length != 0);
                        list2.AddRange(dictionary.Values);
                    }
                    if (list.Count > 0)
                    {
                        folder.DeleteObjects(DeleteItemFlags.HardDelete, list.ToArray());
                    }
                    foreach (KeyValuePair <StoreObjectId, List> keyValuePair in dictionary2)
                    {
                        if (base.HandleShutDown())
                        {
                            return;
                        }
                        using (Folder folder2 = Folder.Bind(this.mailboxSession, keyValuePair.Key))
                        {
                            Uri  uri2  = new Uri(new Uri(this.siteUri.GetLeftPart(UriPartial.Authority)), keyValuePair.Value.RootFolder.ServerRelativeUrl);
                            bool flag2 = Utils.HasFolderUriChanged(folder2, uri2);
                            if (flag2)
                            {
                                folder2[FolderSchema.SharePointChangeToken] = string.Empty;
                                folder2[FolderSchema.LinkedUrl]             = uri2.AbsoluteUri;
                                folder2[FolderSchema.LinkedSiteUrl]         = this.siteUri.AbsoluteUri;
                                string valueOrDefault = folder2.PropertyBag.GetValueOrDefault <string>(FolderSchema.LinkedUrl, string.Empty);
                                ProtocolLog.LogInformation(this.loggingComponent, this.loggingContext, string.Format("SiteSynchronizer: Document Library URL has changed from {0} to {1}", valueOrDefault, uri2.AbsoluteUri));
                            }
                            folder2.DisplayName = keyValuePair.Value.Title;
                            folder2[FolderSchema.LinkedSiteAuthorityUrl] = this.siteUri.AbsoluteUri;
                            folder2.Save();
                        }
                    }
                    foreach (List list4 in list2)
                    {
                        if (base.HandleShutDown())
                        {
                            return;
                        }
                        using (Folder folder3 = Folder.Create(this.mailboxSession, folder.Id.ObjectId, StoreObjectType.ShortcutFolder, list4.Title, CreateMode.OpenIfExists))
                        {
                            folder3[FolderSchema.LinkedId] = list4.Id;
                            Uri uri3 = new Uri(new Uri(this.siteUri.GetLeftPart(UriPartial.Authority)), list4.RootFolder.ServerRelativeUrl);
                            folder3[FolderSchema.LinkedUrl]               = uri3.AbsoluteUri;
                            folder3[FolderSchema.LinkedSiteUrl]           = this.siteUri.AbsoluteUri;
                            folder3[FolderSchema.LinkedListId]            = list4.Id;
                            folder3[FolderSchema.IsDocumentLibraryFolder] = true;
                            folder3[FolderSchema.LinkedSiteAuthorityUrl]  = this.siteUri.AbsoluteUri;
                            folder3.Save();
                            folder3.Load();
                            ProtocolLog.LogInformation(this.loggingComponent, this.loggingContext, string.Format("SiteSynchronizer: Create or update top level document library Name:{0}, LinkedUrl: {1}, LinkedId {2}, ListId {3}", new object[]
                            {
                                folder3.DisplayName,
                                folder3[FolderSchema.LinkedUrl],
                                folder3[FolderSchema.LinkedId],
                                folder3[FolderSchema.LinkedListId]
                            }));
                            this.documentLibraryInfos.Enqueue(new DocumentLibraryInfo(folder3.Id.ObjectId, list4.Id, list4.RootFolder.ServerRelativeUrl));
                        }
                    }
                }
                base.SyncResult = this.documentLibraryInfos;
                this.executionAsyncResult.InvokeCallback(null);
            }
            catch (StorageTransientException value5)
            {
                this.executionAsyncResult.InvokeCallback(value5);
            }
            catch (StoragePermanentException value6)
            {
                this.executionAsyncResult.InvokeCallback(value6);
            }
        }
        public override IAsyncResult BeginExecute(AsyncCallback executeCallback, object state)
        {
            this.executionAsyncResult = new LazyAsyncResult(null, state, executeCallback);
            this.performanceCounter.Start(OperationType.EndToEnd);
            try
            {
                this.InitializeSyncMetadata();
                base.UpdateSyncMetadataOnBeginSync();
            }
            catch (StorageTransientException ex)
            {
                ProtocolLog.LogError(this.loggingComponent, this.loggingContext, "MaintenanceSynchronizer.BeginExecute: failed with StorageTransientException", ex);
                this.executionAsyncResult.InvokeCallback(ex);
                return(this.executionAsyncResult);
            }
            catch (StoragePermanentException ex2)
            {
                ProtocolLog.LogError(this.loggingComponent, this.loggingContext, "MaintenanceSynchronizer.BeginExecute: failed with StoragePermanentException", ex2);
                this.executionAsyncResult.InvokeCallback(ex2);
                return(this.executionAsyncResult);
            }
            ProtocolLog.LogInformation(this.loggingComponent, this.loggingContext, "MaintenanceSynchronizer.BeginExecute");
            Exception value = null;
            Uri       uri;
            string    b;

            if (this.recordedSiteUrl != null && this.webCollectionUrl != null && this.TryGetSharePointSiteUrlAndTitle(this.webCollectionUrl, this.webId, out uri, out b, out value))
            {
                if (UriComparer.IsEqual(this.recordedSiteUrl, uri))
                {
                    if (string.Equals(this.displayName, b))
                    {
                        goto IL_286;
                    }
                }
                try
                {
                    IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, null, CultureInfo.InvariantCulture.LCID, false, ConsistencyMode.IgnoreInvalid, null, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(this.orgId), 189, "BeginExecute", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\LinkedFolder\\MaintenanceSynchronizer.cs");
                    ADUser            aduser = tenantOrRootOrgRecipientSession.FindByExchangeGuid(this.TeamMailboxGuid) as ADUser;
                    if (aduser == null)
                    {
                        value = new ObjectNotFoundException(new LocalizedString("Cannot find the team mailbox by mailbox guid " + this.TeamMailboxGuid));
                    }
                    else
                    {
                        aduser.SharePointUrl = uri;
                        aduser.DisplayName   = b;
                        tenantOrRootOrgRecipientSession.Save(aduser);
                        ProtocolLog.LogInformation(this.loggingComponent, this.loggingContext, "MaintenanceSynchronizer.BeginExecute: updated new SharePoint site URL: " + uri);
                        if (!UriComparer.IsEqual(this.recordedSiteUrl, uri))
                        {
                            RpcClientWrapper.EnqueueTeamMailboxSyncRequest(this.mailboxSession.MailboxOwner.MailboxInfo.Location.ServerFqdn, this.mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, QueueType.TeamMailboxDocumentSync, this.mailboxSession.MailboxOwner.MailboxInfo.OrganizationId, "Maintenance Synchronizer", tenantOrRootOrgRecipientSession.LastUsedDc, SyncOption.Default);
                            RpcClientWrapper.EnqueueTeamMailboxSyncRequest(this.mailboxSession.MailboxOwner.MailboxInfo.Location.ServerFqdn, this.mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, QueueType.TeamMailboxMembershipSync, this.mailboxSession.MailboxOwner.MailboxInfo.OrganizationId, "Maintenance Synchronizer", tenantOrRootOrgRecipientSession.LastUsedDc, SyncOption.Default);
                        }
                    }
                }
                catch (DataSourceOperationException ex3)
                {
                    value = ex3;
                }
                catch (DataValidationException ex4)
                {
                    value = ex4;
                }
                catch (TransientException ex5)
                {
                    value = ex5;
                }
            }
IL_286:
            this.executionAsyncResult.InvokeCallback(value);
            return(this.executionAsyncResult);
        }
Beispiel #4
0
        public static LinkedItemProps FindFolderBySharePointUri(MailboxSession session, Folder rootFolder, Uri sharePointUri, PerformanceCounter performanceCounter)
        {
            performanceCounter.Start(OperationType.FolderLookupByUri);
            string text = rootFolder.PropertyBag.GetValueOrDefault <string>(FolderSchema.LinkedUrl, null);

            if (!string.IsNullOrEmpty(text))
            {
                Uri uri = null;
                try
                {
                    uri = new Uri(text);
                }
                catch (UriFormatException)
                {
                }
                if (uri != null && UriComparer.IsEqual(uri, sharePointUri))
                {
                    performanceCounter.Stop(OperationType.FolderLookupByUri, 1);
                    return(new LinkedItemProps(rootFolder.Id.ObjectId, rootFolder.ParentId));
                }
            }
            using (QueryResult queryResult = rootFolder.FolderQuery(FolderQueryFlags.DeepTraversal, null, null, new PropertyDefinition[]
            {
                FolderSchema.LinkedUrl,
                FolderSchema.Id,
                StoreObjectSchema.ParentItemId
            }))
            {
                object[][] array = null;
                int        i;
                for (;;)
                {
                    array = queryResult.GetRows(10000);
                    for (i = 0; i < array.Length; i++)
                    {
                        text = (array[i][0] as string);
                        if (!string.IsNullOrEmpty(text))
                        {
                            Uri x = null;
                            try
                            {
                                x = new Uri(text);
                            }
                            catch (UriFormatException)
                            {
                                goto IL_FF;
                            }
                            if (UriComparer.IsEqual(x, sharePointUri))
                            {
                                goto Block_11;
                            }
                        }
                        IL_FF :;
                    }
                    if (array.Length == 0)
                    {
                        goto Block_13;
                    }
                }
Block_11:
                performanceCounter.Stop(OperationType.FolderLookupByUri, 1);
                return(new LinkedItemProps(((VersionedId)array[i][1]).ObjectId, (StoreObjectId)array[i][2]));

                Block_13 :;
            }
            performanceCounter.Stop(OperationType.FolderLookupByUri, 1);
            return(null);
        }