/// <summary> /// Process the request /// </summary> public override void ExecuteCmdlet() { base.ExecuteCmdlet(); // obtain CSOM object for host web Web hostWeb = this.ClientContext.Web; if (!CompareDatetime.HasValue) { _LastWriteTime = DateTime.Now; } else { _LastWriteTime = CompareDatetime.Value; } // check to see if library exists var siteLibrary = TargetList.GetList(this.ClientContext.Web); if (siteLibrary == null) { LogWarning("Failed to find site list/library {0}", TargetList.ToString()); return; } if (Watch) { try { siteLibrary.EnsureProperties(sl => sl.RootFolder, sl => sl.RootFolder.ServerRelativeUrl); var watcherFilters = (FileNameFilters == null || !FileNameFilters.Any()) ? new string[] { "*.*" } : FileNameFilters; var watcherFiles = watcherFilters.SelectMany(sm => System.IO.Directory.GetFiles(this.SiteContentDirectory.FullName, sm, System.IO.SearchOption.AllDirectories)); while (true) { System.Threading.Thread.Sleep(new TimeSpan(0, 0, TestSeconds)); if (this.Stopping) { LogWarning("Stopping the process and discontinuing the watcher"); break; } var changedItems = watcherFiles .Select(sf => new System.IO.FileInfo(sf)) .Where(wf => { return((wf.LastWriteTime.Subtract(_LastWriteTime)).TotalSeconds >= WaitSeconds); }) .OrderBy(ob => ob.DirectoryName) .ThenBy(tb => tb.LastWriteTime) .ToList(); if (changedItems != null && changedItems.Any()) { _LastWriteTime = DateTime.Now; var parentName = string.Empty; var tmpParentname = string.Empty; var sitecontentfullname = SiteContentDirectory.FullName; Folder directoryPath = null; foreach (var change in changedItems) { parentName = change.Directory.Name; if (parentName != tmpParentname) { var filedirectorypath = change.Directory.FullName.Replace(sitecontentfullname, "").Replace("\\", "/"); directoryPath = siteLibrary.RootFolder.ListEnsureFolder(filedirectorypath); tmpParentname = parentName; } OnChanged(siteLibrary, directoryPath, change); } } } } catch (Exception tex) { LogWarning("Terminating watch command {0}", tex.Message); } } else { var searchPattern = "*"; if (!string.IsNullOrEmpty(this.SiteActionFile)) { searchPattern = this.SiteActionFile; if (this.SiteActionFile.IndexOf(@"\") > -1) { searchPattern = this.SiteActionFile.Substring(0, this.SiteActionFile.IndexOf(@"\")); } } var appDirectories = System.IO.Directory.GetDirectories(this.SiteContent, searchPattern, System.IO.SearchOption.TopDirectoryOnly); foreach (var appDirectory in appDirectories) { var appDirectoryInfo = new System.IO.DirectoryInfo(appDirectory); UploadSiteAssetFilesToWeb(siteLibrary, siteLibrary.RootFolder, appDirectoryInfo); } } }