E:\TrabalhoSuely\RoboDescompilado\Redistribuir\ZionRobot\ZionExchangeManagement\ZionSharePointManager.cs E:\TrabalhoSuely\RoboDescompilado\CriarVerificar\ZionRobot\ZionExchangeManagement\ZionSharePointManager.cs
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Security; using System.Security;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client;
   
namespace ZionRobot.ZionExchangeManagement namespace ZionRobot.ZionExchangeManagement
{ {
    // Token: 0x02000016 RID: 22     // Token: 0x02000011 RID: 17
    internal class ZionSharePointManager     internal class ZionSharePointManager
    {     {
        // Token: 0x0600007F RID: 127 RVA: 0x00004B2B File Offset: 0x00002D2B         // Token: 0x06000059 RID: 89 RVA: 0x000041AB File Offset: 0x000023AB
        public ZionSharePointManager(string userName, string userPassword)         public ZionSharePointManager(string userName, string userPassword)
        {         {
            this.UserName = userName;             this.UserName = userName;
            this.UserPassword = userPassword;             this.UserPassword = userPassword;
        }         }
   
        // Token: 0x06000080 RID: 128 RVA: 0x00004B44 File Offset: 0x00002D44         // Token: 0x0600005A RID: 90 RVA: 0x000041C4 File Offset: 0x000023C4
        public void ConnectToSharePointOnline(string siteUrl)         public void ConnectToSharePointOnline(string siteUrl)
        {         {
            try             try
            {             {
                bool flag = this.context != null;                 bool flag = this.context != null;
                if (flag)                 if (flag)
                {                 {
                    this.context.Dispose();                     this.context.Dispose();
                }                 }
                this.context = new ClientContext(siteUrl);                 this.context = new ClientContext(siteUrl);
                SecureString secureString = new SecureString();                 SecureString secureString = new SecureString();
                this.UserPassword.ToList<char>().ForEach(new Action<char>(secureString.AppendChar));                 this.UserPassword.ToList<char>().ForEach(new Action<char>(secureString.AppendChar));
                this.context.Credentials = new SharePointOnlineCredentials(this.UserName, secureString);                 this.context.Credentials = new SharePointOnlineCredentials(this.UserName, secureString);
                this.site = this.context.Site;                 this.site = this.context.Site;
                this.context.Load<Site>(this.site, Array.Empty<Expression<Func<Site, object>>>());                 this.context.Load<Site>(this.site, Array.Empty<Expression<Func<Site, object>>>());
                this.context.ExecuteQuery();                 this.context.ExecuteQuery();
                Console.ForegroundColor = ConsoleColor.Green;                 Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Connected to " + siteUrl);                 Console.WriteLine("Connected to " + siteUrl);
            }             }
            catch (Exception ex)             catch (Exception ex)
            {             {
                throw;                 throw;
            }             }
        }         }
   
        // Token: 0x06000081 RID: 129 RVA: 0x00004C18 File Offset: 0x00002E18         // Token: 0x0600005B RID: 91 RVA: 0x00004298 File Offset: 0x00002498
        private void CreateFolder(Folder RootFolder, string FolderName)         private void CreateFolder(Folder RootFolder, string FolderName)
        {         {
            this.context.Load<FolderCollection>(RootFolder.Folders, Array.Empty<Expression<Func<FolderCollection, object>>>());             this.context.Load<FolderCollection>(RootFolder.Folders, Array.Empty<Expression<Func<FolderCollection, object>>>());
            RootFolder.Folders.Add(FolderName);             RootFolder.Folders.Add(FolderName);
            RootFolder.Update();             RootFolder.Update();
            this.context.ExecuteQuery();             this.context.ExecuteQuery();
        }         }
   
        // Token: 0x06000082 RID: 130 RVA: 0x00004C52 File Offset: 0x00002E52         // Token: 0x0600005C RID: 92 RVA: 0x000042D2 File Offset: 0x000024D2
        private void LoadFolders(Folder RootFolder)         private void LoadFolders(Folder RootFolder)
        {         {
            this.context.Load<FolderCollection>(RootFolder.Folders, Array.Empty<Expression<Func<FolderCollection, object>>>());             this.context.Load<FolderCollection>(RootFolder.Folders, Array.Empty<Expression<Func<FolderCollection, object>>>());
            this.context.ExecuteQuery();             this.context.ExecuteQuery();
        }         }
   
        // Token: 0x06000083 RID: 131 RVA: 0x00004C78 File Offset: 0x00002E78         // Token: 0x0600005D RID: 93 RVA: 0x000042F8 File Offset: 0x000024F8
        public List<List> GetCollections()         public List<List> GetCollections()
        {         {
            this.context.Load<ListCollection>(this.context.Web.Lists, Array.Empty<Expression<Func<ListCollection, object>>>());             this.context.Load<ListCollection>(this.context.Web.Lists, Array.Empty<Expression<Func<ListCollection, object>>>());
            this.context.ExecuteQuery();             this.context.ExecuteQuery();
            return this.context.Web.Lists.ToList<List>();             return this.context.Web.Lists.ToList<List>();
        }         }
   
        // Token: 0x06000084 RID: 132 RVA: 0x00004CCC File Offset: 0x00002ECC         // Token: 0x0600005E RID: 94 RVA: 0x0000434C File Offset: 0x0000254C
        public List GetCollection(string title)         public List GetCollection(string title)
        {         {
            this.context.Load<ListCollection>(this.context.Web.Lists, Array.Empty<Expression<Func<ListCollection, object>>>());             this.context.Load<ListCollection>(this.context.Web.Lists, Array.Empty<Expression<Func<ListCollection, object>>>());
            this.context.ExecuteQuery();             this.context.ExecuteQuery();
            return (from item in this.context.Web.Lists.ToList<List>()             return (from item in this.context.Web.Lists.ToList<List>()
            where item.Title == title             where item.Title == title
            select item).FirstOrDefault<List>();             select item).FirstOrDefault<List>();
        }         }
   
        // Token: 0x06000085 RID: 133 RVA: 0x00004D44 File Offset: 0x00002F44         // Token: 0x0600005F RID: 95 RVA: 0x000043C4 File Offset: 0x000025C4
        public Folder GetFolder(List list, string folder)         public Folder GetFolder(List list, string folder)
        {         {
            List<string> folders = folder.Split(new char[]             List<string> folders = folder.Split(new char[]
            {             {
                '/'                  '/' 
            }).ToList<string>();             }).ToList<string>();
            Folder currentFolder = null;             Folder currentFolder = null;
            using (List<string>.Enumerator enumerator = folders.GetEnumerator())             using (List<string>.Enumerator enumerator = folders.GetEnumerator())
            {             {
                while (enumerator.MoveNext())                 while (enumerator.MoveNext())
                {                 {
                    string current = enumerator.Current;                     string current = enumerator.Current;
                    bool flag = currentFolder == null;                     bool flag = currentFolder == null;
                    if (flag)                     if (flag)
                    {                     {
                        this.context.Load<FolderCollection>(list.RootFolder.Folders, Array.Empty<Expression<Func<FolderCollection, object>>>());                         this.context.Load<FolderCollection>(list.RootFolder.Folders, Array.Empty<Expression<Func<FolderCollection, object>>>());
                        this.context.ExecuteQuery();                         this.context.ExecuteQuery();
                        currentFolder = (from f in list.RootFolder.Folders                         currentFolder = (from f in list.RootFolder.Folders
                        where Regex.IsMatch(f.Name, current)                         where Regex.IsMatch(f.Name, current)
                        select f).FirstOrDefault<Folder>();                         select f).FirstOrDefault<Folder>();
                        this.LoadFolders(currentFolder);                         this.LoadFolders(currentFolder);
                    }                     }
                    else                     else
                    {                     {
                        Folder x = null;                         Folder x = null;
                        currentFolder.Folders.ToList<Folder>().ForEach(delegate(Folder f)                         currentFolder.Folders.ToList<Folder>().ForEach(delegate(Folder f)
                        {                         {
                            bool flag3 = Regex.IsMatch(f.Name, current);                             bool flag3 = Regex.IsMatch(f.Name, current);
                            if (flag3)                             if (flag3)
                            {                             {
                                x = f;                                 x = f;
                            }                             }
                        });                         });
                        Folder temp = (from f in currentFolder.Folders                         Folder temp = (from f in currentFolder.Folders
                        where Regex.IsMatch(f.Name, current) || f.Name.StartsWith(current)                         where Regex.IsMatch(f.Name, current) || f.Name.StartsWith(current)
                        select f).FirstOrDefault<Folder>();                         select f).FirstOrDefault<Folder>();
                        bool flag2 = temp != null;                         bool flag2 = temp != null;
                        if (!flag2)                         if (!flag2)
                        {                         {
                            break;                             break;
                        }                         }
                        currentFolder = temp;                         currentFolder = temp;
                        this.LoadFolders(currentFolder);                         this.LoadFolders(currentFolder);
                    }                     }
                }                 }
            }             }
            return currentFolder;             return currentFolder;
        }         }
   
        // Token: 0x06000086 RID: 134 RVA: 0x00004FFC File Offset: 0x000031FC         // Token: 0x06000060 RID: 96 RVA: 0x0000467C File Offset: 0x0000287C
        public Folder BuildFolder(List list, string folder)         public Folder BuildFolder(List list, string folder)
        {         {
            List<string> folders = folder.Split(new char[]             List<string> folders = folder.Split(new char[]
            {             {
                '/'                  '/' 
            }).ToList<string>();             }).ToList<string>();
            Folder currentFolder = null;             Folder currentFolder = null;
            for (int i = 0; i < folders.Count; i++)             for (int i = 0; i < folders.Count; i++)
            {             {
                char[] charsToTrim = new char[]                 char[] charsToTrim = new char[]
                {                 {
                    ',',                     ',',
                    '.',                     '.',
                    ' ',                     ' ',
                    '#',                     '#',
                    '%',                     '%',
                    '*',                     '*',
                    ':',                     ':',
                    '<',                     '<',
                    '>',                     '>',
                    '?',                     '?',
                    '/',                     '/',
                    '|'                      '|' 
                };                 };
                string current = folders[i].TrimEnd(charsToTrim);                 string current = folders[i].TrimEnd(charsToTrim);
                bool flag = currentFolder == null;                 bool flag = currentFolder == null;
                if (flag)                 if (flag)
                {                 {
                    this.context.Load<FolderCollection>(list.RootFolder.Folders, Array.Empty<Expression<Func<FolderCollection, object>>>());                     this.context.Load<FolderCollection>(list.RootFolder.Folders, Array.Empty<Expression<Func<FolderCollection, object>>>());
                    this.context.ExecuteQuery();                     this.context.ExecuteQuery();
                    currentFolder = (from f in list.RootFolder.Folders                     currentFolder = (from f in list.RootFolder.Folders
                    where Regex.IsMatch(f.Name, current)                     where Regex.IsMatch(f.Name, current)
                    select f).FirstOrDefault<Folder>();                     select f).FirstOrDefault<Folder>();
                    this.LoadFolders(currentFolder);                     this.LoadFolders(currentFolder);
                }                 }
                else                 else
                {                 {
                    Folder temp = (from f in currentFolder.Folders                     Folder temp = (from f in currentFolder.Folders
                    where Regex.IsMatch(f.Name, current) || f.Name.StartsWith(current)                     where Regex.IsMatch(f.Name, current) || f.Name.StartsWith(current)
                    select f).FirstOrDefault<Folder>();                     select f).FirstOrDefault<Folder>();
                    bool flag2 = temp != null;                     bool flag2 = temp != null;
                    if (flag2)                     if (flag2)
                    {                     {
                        currentFolder = temp;                         currentFolder = temp;
                        this.LoadFolders(currentFolder);                         this.LoadFolders(currentFolder);
                    }                     }
                    else                     else
                    {                     {
                        string tmp = current;                         string tmp = current;
                        bool flag3 = folders.Last<string>() == current;                         bool flag3 = folders.Last<string>() == current;
                        if (flag3)                         if (flag3)
                        {                         {
                            tmp = current;                             tmp = current;
                        }                         }
.                        this.CreateFolder(currentFolder, tmp.Trim());                         this.CreateFolder(currentFolder, tmp);
                        this.LoadFolders(currentFolder);                         this.LoadFolders(currentFolder);
                        i--;                         i--;
                    }                     }
                }                 }
            }             }
            return currentFolder;             return currentFolder;
        }         }
   
        // Token: 0x06000087 RID: 135 RVA: 0x00005294 File Offset: 0x00003494         // Token: 0x06000061 RID: 97 RVA: 0x00004910 File Offset: 0x00002B10
        public Microsoft.SharePoint.Client.File UploadFile(Folder folder, string fileName, string path)         public Microsoft.SharePoint.Client.File UploadFile(Folder folder, string fileName, string path)
        {         {
            Microsoft.SharePoint.Client.File result;             Microsoft.SharePoint.Client.File result;
            try             try
            {             {
                this.context.Load<FileCollection>(folder.Files, Array.Empty<Expression<Func<FileCollection, object>>>());                 this.context.Load<FileCollection>(folder.Files, Array.Empty<Expression<Func<FileCollection, object>>>());
                this.context.ExecuteQuery();                 this.context.ExecuteQuery();
                fileName = Regex.Replace(fileName, "[^0-9a-zA-Z._ ]", string.Empty);                 fileName = Regex.Replace(fileName, "[^0-9a-zA-Z._ ]", string.Empty);
                string uploadedFileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);                 string uploadedFileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
                string uploadedFileExtension = Path.GetExtension(fileName);                 string uploadedFileExtension = Path.GetExtension(fileName);
                int index = 1;                 int index = 1;
                string newFileName = uploadedFileNameWithoutExtension;                 string newFileName = uploadedFileNameWithoutExtension;
                while ((from f in folder.Files                 while ((from f in folder.Files
                where f.Name == newFileName + uploadedFileExtension                 where f.Name == newFileName + uploadedFileExtension
                select f).Count<Microsoft.SharePoint.Client.File>() > 0)                 select f).Count<Microsoft.SharePoint.Client.File>() > 0)
                {                 {
                    newFileName = uploadedFileNameWithoutExtension + string.Format(" ({0})", index);                     newFileName = uploadedFileNameWithoutExtension + string.Format(" ({0})", index);
                    index++;                     index++;
                }                 }
                newFileName += uploadedFileExtension;                 newFileName += uploadedFileExtension;
                bool flag = System.IO.File.Exists(path);                 bool flag = System.IO.File.Exists(path);
                byte[] FileContent;                 byte[] FileContent;
                if (flag)                 if (flag)
                {                 {
                    FileContent = System.IO.File.ReadAllBytes(path);                     FileContent = System.IO.File.ReadAllBytes(path);
                }                 }
                else                 else
                {                 {
                    FileContent = Convert.FromBase64String(path);                     FileContent = Convert.FromBase64String(path);
                }                 }
                FileCreationInformation fileCreationInformation = new FileCreationInformation();                 FileCreationInformation fileCreationInformation = new FileCreationInformation();
                fileCreationInformation.ContentStream = new MemoryStream(FileContent);                 fileCreationInformation.ContentStream = new MemoryStream(FileContent);
                fileCreationInformation.Url = newFileName;                 fileCreationInformation.Url = newFileName;
                Microsoft.SharePoint.Client.File file = folder.Files.Add(fileCreationInformation);                 Microsoft.SharePoint.Client.File file = folder.Files.Add(fileCreationInformation);
                this.context.Load<Microsoft.SharePoint.Client.File>(file, Array.Empty<Expression<Func<Microsoft.SharePoint.Client.File, object>>>());                 this.context.Load<Microsoft.SharePoint.Client.File>(file, Array.Empty<Expression<Func<Microsoft.SharePoint.Client.File, object>>>());
                this.context.ExecuteQuery();                 this.context.ExecuteQuery();
                result = file;                 result = file;
            }             }
            catch (Exception ex)             catch (Exception ex)
            {             {
                result = null;                 result = null;
            }             }
            return result;             return result;
        }         }
   
        // Token: 0x06000088 RID: 136 RVA: 0x00005490 File Offset: 0x00003690         // Token: 0x06000062 RID: 98 RVA: 0x00004B0C File Offset: 0x00002D0C
        public string DownloadFile(Folder folder, string name, string downloadTo = "./")         public string DownloadFile(Folder folder, string name, string downloadTo = "./")
        {         {
            string result;             string result;
            try             try
            {             {
                this.context.Load<FileCollection>(folder.Files, Array.Empty<Expression<Func<FileCollection, object>>>());                 this.context.Load<FileCollection>(folder.Files, Array.Empty<Expression<Func<FileCollection, object>>>());
                this.context.ExecuteQuery();                 this.context.ExecuteQuery();
                Microsoft.SharePoint.Client.File file = (from f in folder.Files                 Microsoft.SharePoint.Client.File file = (from f in folder.Files
                where f.Name == name                 where f.Name == name
                select f).FirstOrDefault<Microsoft.SharePoint.Client.File>();                 select f).FirstOrDefault<Microsoft.SharePoint.Client.File>();
                Console.ForegroundColor = ConsoleColor.Yellow;                 Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(file.ServerRelativeUrl);                 Console.WriteLine(file.ServerRelativeUrl);
                FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(this.context, file.ServerRelativeUrl);                 FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(this.context, file.ServerRelativeUrl);
                string fileName = Path.Combine("./", file.Name);                 string fileName = Path.Combine("./", file.Name);
                using (FileStream fileStream = System.IO.File.Create(fileName))                 using (FileStream fileStream = System.IO.File.Create(fileName))
                {                 {
                    fileInfo.Stream.CopyTo(fileStream);                     fileInfo.Stream.CopyTo(fileStream);
                }                 }
                result = fileName;                 result = fileName;
            }             }
            catch             catch
            {             {
                result = string.Empty;                 result = string.Empty;
            }             }
            return result;             return result;
        }         }
   
        // Token: 0x0400002F RID: 47         // Token: 0x0400001D RID: 29
        private ClientContext context;         private ClientContext context;
   
        // Token: 0x04000030 RID: 48         // Token: 0x0400001E RID: 30
        private Site site;         private Site site;
   
        // Token: 0x04000031 RID: 49         // Token: 0x0400001F RID: 31
        public string UserName;         public string UserName;
   
        // Token: 0x04000032 RID: 50         // Token: 0x04000020 RID: 32
        public string UserPassword;         public string UserPassword;
    }     }
} }