Пример #1
0
        private void SyncWeb()
        {
            var web = _sp.SpWeb.GetWeb();

            if (web != null)
            {
                var site = new Ent::Site()
                {
                    Title = web.Title,
                    Url   = $"{Settings.SharePoint.ServerIpAddress}"
                };
                _unitOfWork.SiteRepository.Add(site);
                _unitOfWork.Commit();

                SyncDocumentLibrary(site);
            }
        }
Пример #2
0
        private void SyncListItem(Ent::Site site, KeyValuePair <Ent::DocumentLibrary, List> library)
        {
            var documentLibrary = library.Key;
            var folderPath      = documentLibrary.URL;

            var commitedFolders = CommitFolders(site, documentLibrary, folderPath, folder: null);

            CommitFiles(site, documentLibrary, folderPath, folder: null);

            if (commitedFolders != null && commitedFolders.Any())
            {
                // Doküman kütüphanesinin en root dizini artık burada.
                // Recursive bu kırılımda yapılacak.
                foreach (var commitedFolder in commitedFolders)
                {
                    RecursiveCommitItems(site, documentLibrary, commitedFolder);
                }
            }
        }
Пример #3
0
        private List <Ent::Folder> CommitFolders(Ent::Site site, Ent::DocumentLibrary documentLibrary, string folderPath, Ent::Folder folder)
        {
            var commitedFolders = new List <Ent::Folder>();

            try
            {
                var folderListItems = _sp.SpList.GetListItems(documentLibrary.Title, CamlHelper.CamlQueryBuilder(folderPath, DocumentType.Folder));
                if (folderListItems != null)
                {
                    foreach (ListItem listItem in folderListItems)
                    {
                        var folderItem = new Ent::Folder()
                        {
                            SiteID            = site.ID,
                            DocumentLibraryID = documentLibrary.ID,
                            ParentFolderID    = folder?.ID ?? 0,
                            RemoteID          = listItem.Id,
                            FileLeafRef       = SpTypeHelper.GetStringValue(listItem["FileLeafRef"]),
                            FileRef           = SpTypeHelper.GetStringValue(listItem["FileRef"]),
                            Title             = SpTypeHelper.GetStringValue(listItem["Title"]),
                            Created           = SpTypeHelper.GetDateTimeValue(listItem["Created"]),
                            Author            = SpTypeHelper.GetFieldUserValue(listItem["Author"]),
                            Modified          = SpTypeHelper.GetDateTimeValue(listItem["Modified"]),
                            Editor            = SpTypeHelper.GetFieldUserValue(listItem["Editor"]),
                            CopySource        = String.Empty,
                            ItemChildCount    = SpTypeHelper.GetIntValue(listItem["ItemChildCount"]),
                            FolderChildCount  = SpTypeHelper.GetIntValue(listItem["FolderChildCount"])
                        };
                        _unitOfWork.FolderRepository.Add(folderItem);
                        commitedFolders.Add(folderItem);
                    }
                    _unitOfWork.Commit();
                }
            }
            catch
            {
                Thread.Sleep(new TimeSpan(0, 0, 1, 0));
                Initialize();
                commitedFolders = CommitFolders(site, documentLibrary, folderPath, folder);
            }
            return(commitedFolders);
        }
Пример #4
0
            public void AddSite()
            {
                using (var uow = new UnitOfWork(Settings.MsSql.ConnectionString))
                {
                    var site = new Ent::Site()
                    {
                        Title = "Test",
                        Url   = "http://10.1.1.1/"
                    };
                    uow.SiteRepository.Add(site);
                    uow.Commit();
                    Debug.WriteLine(site.ID.ToString());

                    var allSiteList = uow.SiteRepository.All();
                    foreach (var s in allSiteList)
                    {
                        Debug.WriteLine(s.Title);
                    }
                }
            }
Пример #5
0
 private void CommitFiles(Ent::Site site, Ent::DocumentLibrary documentLibrary, string folderPath, Ent::Folder folder)
 {
     try
     {
         var fileListItems = _sp.SpList.GetListItems(documentLibrary.Title, CamlHelper.CamlQueryBuilder(folderPath, DocumentType.File));
         if (fileListItems != null)
         {
             foreach (ListItem listItem in fileListItems)
             {
                 var file = new Ent::File()
                 {
                     SiteID            = site.ID,
                     DocumentLibraryID = documentLibrary.ID,
                     FolderID          = folder?.ID ?? 0,
                     RemoteID          = listItem.Id,
                     FileLeafRef       = SpTypeHelper.GetStringValue(listItem["FileLeafRef"]),
                     FileRef           = SpTypeHelper.GetStringValue(listItem["FileRef"]),
                     FileDirRef        = SpTypeHelper.GetStringValue(listItem["FileDirRef"]),
                     Title             = SpTypeHelper.GetStringValue(listItem["Title"]),
                     Created           = SpTypeHelper.GetDateTimeValue(listItem["Created"]),
                     Author            = SpTypeHelper.GetFieldUserValue(listItem["Author"]),
                     Modified          = SpTypeHelper.GetDateTimeValue(listItem["Modified"]),
                     Editor            = SpTypeHelper.GetFieldUserValue(listItem["Editor"]),
                     CopySource        = String.Empty,
                     FileType          = SpTypeHelper.GetStringValue(listItem["File_x0020_Type"]),
                     FileSize          = SpTypeHelper.GetIntValue(listItem["File_x0020_Size"]),
                     Aktarildimi       = false
                 };
                 _unitOfWork.FileRepository.Add(file);
             }
             _unitOfWork.Commit();
         }
     }
     catch
     {
         Thread.Sleep(new TimeSpan(0, 0, 1, 0));
         Initialize();
         CommitFiles(site, documentLibrary, folderPath, folder);
     }
 }
Пример #6
0
        private void SyncDocumentLibrary(Ent::Site site)
        {
            var siteDocumentLibrary = new Dictionary <Ent::DocumentLibrary, List>();

            #region [DocumentLibrary CommitDb]

            foreach (var d in Settings.SharePoint.RootFolders)
            {
                //Elimizde yalnızca aktarılacak klasörler mevcut. Bu nedenle; bu klasörlerin liste özellikleri gerekli.
                var list = _sp.SpList.GetListByTitle(d, includeRootFolder: true);
                if (list == null)
                {
                    throw new ArgumentNullException(nameof(list));
                }

                var documentLibrary = new Ent::DocumentLibrary()
                {
                    SiteID    = site.ID,
                    Title     = list.Title,
                    URL       = list.RootFolder.ServerRelativeUrl,
                    ItemCount = list.ItemCount
                };
                _unitOfWork.DocumentLibraryRepository.Add(documentLibrary);
                siteDocumentLibrary.Add(documentLibrary, list);
            }
            _unitOfWork.Commit();

            #endregion

            foreach (var dl in siteDocumentLibrary)
            {
                SyncListItem(site, dl);
            }

            //Parallel.ForEach(siteDocumentLibrary, new ParallelOptions { MaxDegreeOfParallelism = 4 }, keyValuePair =>
            //  {
            //      SyncListItem(site, keyValuePair);
            //  });
        }
Пример #7
0
        private void RecursiveCommitItems(Ent::Site site, Ent::DocumentLibrary documentLibrary, Ent::Folder commitedFolder)
        {
            var commitedFolders = new List <Ent::Folder>();
            //{ documentLibrary.URL}
            string folderPath = $"{commitedFolder.FileRef}";

            if (commitedFolder.FolderChildCount > 0)
            {
                commitedFolders = CommitFolders(site, documentLibrary, folderPath, commitedFolder);
            }

            if (commitedFolder.ItemChildCount > 0)
            {
                CommitFiles(site, documentLibrary, folderPath, commitedFolder);
            }

            if (commitedFolders != null && commitedFolders.Any())
            {
                foreach (var folder in commitedFolders)
                {
                    RecursiveCommitItems(site, documentLibrary, folder);
                }
            }
        }