예제 #1
0
        private void GetspPath(tblPath rec)
        {
            var spPath = rec.serverPath.Substring(rec.serverDrev.Length).Replace(@"\", @"/");

            if (spPath.Contains(@"#"))
            {
                rec.spPathRenamed = true;
            }
            else
            {
                rec.spPathRenamed = false;
            }

            spPath = spPath.Replace(@"#", @"_");

            var spDirectory = Path.GetDirectoryName(spPath);

            if ((spPath.Length < 260) && (spDirectory.Length < 248))
            {
                rec.spPath = spPath;
                return;
            }

            if (spDirectory.Length < 248)
            {
                var spFile = Path.GetFileNameWithoutExtension(spPath);
                var spExt  = Path.GetExtension(spPath);
                int maxLen = 259 - spDirectory.Length - spExt.Length - 1;
                rec.spPath        = spDirectory + "/" + spFile.Substring(0, maxLen) + "." + spExt;
                rec.spPathRenamed = true;
                return;
            }

            rec.spPath = spPath;
        }
예제 #2
0
        public void load(string pServerPathType, clsServer recServer)
        {
            dbSharePointEntities db = new dbSharePointEntities();

            db.tblPath.Load();


            string[] files;
            if (recServer.topFoldersExclude == null)
            {
                if (pServerPathType == "File")
                {
                    files = System.IO.Directory.GetFiles(recServer.serverDrev, "*", System.IO.SearchOption.AllDirectories);
                }
                else // == "Folder"
                {
                    files = System.IO.Directory.GetDirectories(recServer.serverDrev, "*", System.IO.SearchOption.AllDirectories);
                }
            }
            else
            {
                string[]      tffiles;
                List <string> filesList         = new List <string>();
                var           topFoldersExclude = recServer.topFoldersExclude;

                var topFolders = System.IO.Directory.GetDirectories(recServer.serverDrev, "*", System.IO.SearchOption.TopDirectoryOnly);
                var topFiles   = System.IO.Directory.GetFiles(recServer.serverDrev, "*", System.IO.SearchOption.TopDirectoryOnly);

                foreach (var tf in topFolders)
                {
                    var bfilter = false;
                    foreach (var f in topFoldersExclude)
                    {
                        if (tf.ToUpperInvariant().Contains(f.ToUpperInvariant()))
                        {
                            bfilter = true;
                            break;
                        }
                    }
                    if (bfilter)
                    {
                        continue;
                    }

                    if (pServerPathType == "File")
                    {
                        tffiles = System.IO.Directory.GetFiles(tf, "*", System.IO.SearchOption.AllDirectories);
                        filesList.AddRange(topFiles);
                    }
                    else // == "Folder"
                    {
                        tffiles = System.IO.Directory.GetDirectories(tf, "*", System.IO.SearchOption.AllDirectories);
                        filesList.Add(tf);
                    }
                    filesList.AddRange(tffiles);
                }
                files = filesList.ToArray();
            }

            var files1 = files.ToList();

            files1.Sort();
            int i = 0;

            foreach (var file in files1)
            {
                var bfilter = false;
                foreach (var f in filter)
                {
                    if (file.ToUpperInvariant().Contains(f.ToUpperInvariant()))
                    {
                        bfilter = true;
                        break;
                    }
                }
                if (bfilter)
                {
                    continue;
                }

                Console.WriteLine((++i).ToString());
                var qryfile = db.tblPath.Local.Where(f => f.serverPath == file);
                if (qryfile.Count() == 0)
                {
                    tblPath rec = new tblPath()
                    {
                        serverDrev      = recServer.serverDrev,
                        localDrevLetter = recServer.localDrevLetter,
                        serverPath      = file,
                        spSite          = recServer.spSite,
                        spSiteType      = recServer.spSiteType,
                        build           = true,
                        serverPathType  = pServerPathType
                    };
                    try
                    {
                        db.tblPath.Local.Add(rec);
                        db.SaveChanges();
                        Console.WriteLine(file);
                    }
                    catch (Exception e)
                    {
                        int x = 1;
                        //duplicate
                    }
                }
            }
        }
예제 #3
0
        public async Task CreateFileAsyncOLD(KeyValuePair <string, string> f)
        {
            var sPath = f.Key;
            var tPath = f.Value;
            var tt    = (int)DateTime.Now.Subtract(clsContent.TokenAcquired).TotalSeconds;

            tblPath rec = new tblPath()
            {
                serverDrev = m_sourceStartDir,
                serverPath = sPath,
                spSite     = "/klient",
                spPath     = tPath,
            };

            try
            {
                var item = await clsContent.graphClient.Sites[m_targetSiteId].Drive.Root.ItemWithPath(tPath).Request().GetAsync();
                Console.WriteLine(string.Format("{0}-{1}/{2} Exists: {3}", tt, m_ifile, m_totfiles, tPath));
                rec.spPathExists = true;
            }
            catch (ServiceException e)
            {
                Console.WriteLine(string.Format("{0}-{1}/{2} {3}", tt, m_ifile, m_totfiles, tPath));
                UploadSession uploadSession = null;
                try
                {
                    using (FileStream stream = System.IO.File.Open(sPath, FileMode.Open, FileAccess.Read))
                    {
                        try
                        {
                            uploadSession = await clsContent.graphClient.Sites[m_targetSiteId].Drive.Root.ItemWithPath(tPath).CreateUploadSession().Request().PostAsync();

                            var maxChunkSize = 32 * 320 * 1024; // 10 MB - Change this to your chunk size. 5MB is the default.
                            var provider     = new ChunkedUploadProvider(uploadSession, clsContent.graphClient, stream, maxChunkSize);

                            // Setup the chunk request necessities
                            var       chunkRequests     = provider.GetUploadChunkRequests();
                            var       readBuffer        = new byte[maxChunkSize];
                            var       trackedExceptions = new List <Exception>();
                            DriveItem itemResult        = null;

                            //upload the chunks
                            foreach (var request in chunkRequests)
                            {
                                // Do your updates here: update progress bar, etc.
                                // ...
                                // Send chunk request
                                var result = await provider.GetChunkRequestResponseAsync(request, readBuffer, trackedExceptions);

                                if (result.UploadSucceeded)
                                {
                                    itemResult       = result.ItemResponse;
                                    rec.spPathExists = true;
                                }
                            }

                            // Check that upload succeeded
                            if (itemResult == null)
                            {
                                Console.WriteLine("Upload failed: " + tPath);
                                clsContent.logger.Error("Upload failed: " + tPath);
                                rec.spPathExists = false;
                                rec.error        = "Upload failed";
                            }
                        }
                        catch (ServiceException ex)
                        {
                            Console.WriteLine(ex.Message);
                            clsContent.logger.Error(tPath);
                            clsContent.logger.Error(ex.Message);
                            rec.spPathExists = false;
                            rec.error        = ex.Message;
                        }
                    }
                }
                catch (Exception ez)
                {
                    Console.WriteLine(ez.Message);
                    clsContent.logger.Error(tPath);
                    clsContent.logger.Error(ez.Message);
                    rec.spPathExists = false;
                    rec.error        = ez.Message;
                }
            }
            clsContent.m_db.tblPath.Local.Add(rec);
            clsContent.m_db.SaveChanges();
        }