Ejemplo n.º 1
0
        /// <summary>
        /// Start a run using the information info
        /// </summary>
        /// <param name="configInfo">configuration info</param>
        /// <param name="credentials">SharePoint Online credentials</param>
        public static void Run(ConfigFileInfo configInfo, SharePointOnlineCredentials credentials = null)
        {
            // Instanciate and feed running manager
            RunningManager runningManager = GetRunningManagerFromConfigFile(configInfo, credentials);

            // Start the process
            runningManager?.Run();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="web">Site</param>
 /// <param name="isSubSite">True if the site is a sub site, False if not</param>
 public SiteRunner(RunningManager runningManager, ClientContext context, Web web, bool isSubSite = false) : base(runningManager, context, web, RunningLevel.Site)
 {
     IsSubSite = isSubSite;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the running manager from the configuration file info
        /// </summary>
        /// <param name="configFileInfo">Configuration information from the file</param>
        /// <param name="credentials">SharePoint Online credentials</param>
        /// <returns>Running manager</returns>
        private static RunningManager GetRunningManagerFromConfigFile(ConfigFileInfo configFileInfo, SharePointOnlineCredentials credentials = null)
        {
            RunningManager runningManager = new RunningManager();
            string         executablePath = Directory.GetCurrentDirectory();

            // Get DLLs classes from assemblies
            foreach (ReceiverAssembly receiverAssembly in configFileInfo.Receivers)
            {
                // Check if the dll file exists
                if (!IO.File.Exists($"{receiverAssembly.AssemblyName}.dll"))
                {
                    Exception ex = new Exception($"The '{receiverAssembly.AssemblyName}.dll' file does not exist");
                    Logger.Warn(ex.Message, ex);
                    continue;
                }

                // Load the assembly
                Assembly assembly = Assembly.LoadFile(Path.Combine(executablePath, configFileInfo.PathToDLL, $"{receiverAssembly.AssemblyName}.dll"));

                // Check if the assembly is null
                if (assembly == null)
                {
                    Exception ex = new Exception($"The '{receiverAssembly.AssemblyName}' assembly is not loaded");
                    Logger.Warn(ex.Message, ex);
                    continue;
                }

                // Get the type of the class
                Type receiverClass = assembly.GetType($"{receiverAssembly.AssemblyName}.{receiverAssembly.ClassName}");

                // Check if the type exists
                if (receiverClass == null)
                {
                    Exception ex = new Exception($"The '{receiverAssembly.ClassName}' type does not exist");
                    Logger.Warn(ex.Message, ex);
                    continue;
                }

                // Instantiate the class
                Receiver receiver = (Receiver)Activator.CreateInstance(receiverClass);

                // Check if the class is instantiated
                if (receiver == null)
                {
                    Exception ex = new Exception($"The '{receiverAssembly.ClassName}' class is not instantiated");
                    Logger.Warn(ex.Message, ex);
                    continue;
                }

                // Set properties
                receiver.IncludeSubSites    = receiverAssembly.IncludeSubSites;
                receiver.IncludeHiddenLists = receiverAssembly.IncludeHiddenLists;

                // Pass parameters
                List <string> parametersName = receiverAssembly.Parameters.Select(p => p.Name).Distinct().ToList();

                foreach (string parameterName in parametersName)
                {
                    PropertyInfo prop = receiverClass.GetProperty(parameterName);

                    // Check if the property exists
                    if (prop == null)
                    {
                        Exception ex = new Exception($"The '{parameterName}' property does not exist");
                        Logger.Warn(ex.Message, ex);
                        continue;
                    }

                    if (prop.PropertyType == typeof(string))
                    {
                        // Set the string property with the first parameter passed in the configuration file
                        prop.SetValue(receiver, receiverAssembly.Parameters.FirstOrDefault(p => p.Name == parameterName).Value);
                    }
                    else if (prop.PropertyType == typeof(List <string>))
                    {
                        // Set the list of strings properties with the paramters passed in the configuration file
                        prop.SetValue(receiver, receiverAssembly.Parameters.Where(p => p.Name == parameterName).Select(p => p.Value).ToList());
                    }
                    else
                    {
                        Exception ex = new Exception($"The '{parameterName}' property is not a string or a list of strings");
                        Logger.Warn(ex.Message, ex);
                        continue;
                    }
                }

                // Add receiver to receivers list of the running manager
                runningManager.Receivers.Add(receiver);
            }

            // Create the SharePoint Online credentials if none is passed to parameters
            if (credentials == null)
            {
                if (!string.IsNullOrWhiteSpace(configFileInfo.Login) && configFileInfo.SecuredPassword != null)
                {
                    credentials = new SharePointOnlineCredentials(configFileInfo.Login, configFileInfo.SecuredPassword);
                }
                else
                {
                    Exception ex = new Exception("No credentials provided. Please provide SharePoint Online credentials in the configuration file or calling the Run() method");
                    Logger.Error(ex.Message, ex);
                    throw ex;
                }
            }

            // Set credentials
            runningManager.Credentials = credentials;

            // Get the URLs
            runningManager.Urls.AddRange(configFileInfo.Urls);

            // Get the StartingRunningLevel from its string name
            runningManager.StartingRunningLevel = configFileInfo.StartRunningLevel;

            // Return the running manager
            return(runningManager);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="runningLevel">Running level</param>
 public Runner(RunningManager runningManager, RunningLevel runningLevel)
 {
     Manager      = runningManager;
     RunningLevel = runningLevel;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="site">Site collection</param>
 public SiteCollectionRunner(RunningManager runningManager, ClientContext context, Site site) : base(runningManager, context, site, RunningLevel.SiteCollection)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="folder">Folder</param>
 public FolderRunner(RunningManager runningManager, ClientContext context, Folder folder) : base(runningManager, context, folder, RunningLevel.Folder)
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="view">View</param>
 public ViewRunner(RunningManager runningManager, ClientContext context, View view) : base(runningManager, context, view, RunningLevel.View)
 {
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="file">File</param>
 public FileRunner(RunningManager runningManager, ClientContext context, File file) : base(runningManager, context, file, RunningLevel.File)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="tenant">Tenant</param>
 public TenantRunner(RunningManager runningManager, ClientContext context, Tenant tenant) : base(runningManager, context, tenant, RunningLevel.Tenant)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="termGroup">Term group</param>
 public TermGroupRunner(RunningManager runningManager, ClientContext context, TermGroup termGroup) : base(runningManager, context, termGroup, RunningLevel.TermGroup)
 {
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="group">Group</param>
 public GroupRunner(RunningManager runningManager, ClientContext context, Group group) : base(runningManager, context, group, RunningLevel.Group)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="termSet">Term set</param>
 public TermSetRunner(RunningManager runningManager, ClientContext context, TermSet termSet) : base(runningManager, context, termSet, RunningLevel.TermSet)
 {
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="list">List</param>
 public ListRunner(RunningManager runningManager, ClientContext context, List list) : base(runningManager, context, list, RunningLevel.List)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="termStore">Term store</param>
 public TermStoreRunner(RunningManager runningManager, ClientContext context, TermStore termStore) : base(runningManager, context, termStore, RunningLevel.TermStore)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="term">Term</param>
 public TermRunner(RunningManager runningManager, ClientContext context, Term term) : base(runningManager, context, term, RunningLevel.Term)
 {
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="runningManager">Running manager</param>
 /// <param name="context">SharePoint context</param>
 /// <param name="listItem">List item</param>
 public ListItemRunner(RunningManager runningManager, ClientContext context, ListItem listItem) : base(runningManager, context, listItem, RunningLevel.ListItem)
 {
 }