public void UpgradeInPath(DirectoryInfo dir, IEnumerable <IUpgrader> upgraders, bool recursive = true) { var backupFile = FuncEx.Create((string p) => { string date = DateTime.Now.ToString("yyyy-MMM-dd-H-mm-ss"); string backupPath = String.Format("{0}-{1}.bak", p, date); if (File.Exists(backupPath)) { File.Delete(backupPath); } File.Copy(p, backupPath); return(true); }); if (recursive == true) { foreach (var d in dir.GetDirectories()) { UpgradeInPath(d, upgraders); } } var searchPatterns = upgraders.SelectMany(u => u.SearchPattern).Distinct().ToArray(); // Search patterns are defined by the upgrader var files = dir.GetFiles(searchPatterns); foreach (var f in files) { backupFile(f.FullName); // http://stackoverflow.com/questions/9213720/most-efficient-way-of-reading-file IEnumerable <string> lines = new List <string>(System.IO.File.ReadAllLines(f.FullName)); var upgradedTypes = new Dictionary <IUpgrader, bool>(); foreach (var upgrader in upgraders) { bool didUpgrade; lines = upgrader.Upgrade(f.FullName, lines, out didUpgrade); upgradedTypes.Add(upgrader, didUpgrade); } if (upgradedTypes.Values.Any(u => u == true)) { File.WriteAllText(f.FullName, String.Join(Environment.NewLine, lines)); Console.WriteLine(String.Format("Upgraded {0}", f.FullName)); } else { Console.WriteLine(String.Format("Skipped {0}", f.FullName)); } } }
public async Task <IEnumerable <Article> > GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = new CancellationToken()) { using (pageIndex == 0 ? _progressService.BeginUiOperation(true) : _progressService.BeginBackgroundOperation(true)) { try { var paginationResponse = await FuncEx.Make(() => _shopApiService.GetArticles(new PaginationRequest <ArticlesSearchRequest> { Page = pageIndex + 1, PageSize = pageSize, Request = _searchRequest }) ).RetryWhenException <PaginationResponse <Article>, ApiException>().ConfigureAwait(false); return(paginationResponse.Content); } catch (ApiException e) { Logger.Error($"Failed to load article items. Page {pageIndex}, pageSize {pageSize}", e); throw; } } }
public static void ItemAdded(ProjectItem projectItem) { if (projectItem.Properties == null) { return; } // Troubles loading F# projects. if (projectItem.GetType().ToString().Equals("Microsoft.VisualStudio.FSharp.ProjectSystem.Automation.OAFileItem", StringComparison.InvariantCultureIgnoreCase)) { return; } // Only try and copy physical files (ignore folders, sub projects, virtual files. if (Guid.Parse(projectItem.Kind) != Guid.Parse("6bb5f8ee-4483-11d3-8bcf-00c04f8ec28c")) // GUID_ItemType_PhysicalFile { return; } var isPermittedFileType = FuncEx.Create((List <string> fileTypes, ProjectItemBuildAction action) => { if (!fileTypes.Contains(Path.GetExtension(projectItem.Name).TrimStart('.'))) { return(false); } var buildAction = (ProjectItemBuildAction)projectItem.Properties.Item("BuildAction").Value; if (buildAction != action) { return(false); } return(true); }); if (!(isPermittedFileType(EmbeddedResourceFileTypes, ProjectItemBuildAction.EmbeddedResource) || isPermittedFileType(ContentFileTypes, ProjectItemBuildAction.Content))) { return; } // If this is a cshtml file then check to see if it has a customtool property value. If there's no value then the cshtml file // is probably coming from a theme and shouldn't be copied at all. if (Path.GetExtension(projectItem.Name).Equals(".cshtml", StringComparison.InvariantCultureIgnoreCase)) { if (projectItem.FileNames[0].ToLower().Contains("app_code")) { return; } string customTool = projectItem.Properties.Item("CustomTool").Value.ToString(); if (String.IsNullOrEmpty(customTool)) { return; } } // If the file belongs to the start up application don't copy it anywhere var startupProject = Infrastructure.Core.Instance.StartupProject; if (projectItem.ContainingProject.Equals(startupProject)) { return; } CopiedFiles.Add(startupProject, projectItem); var ie = projectItem.ProjectItems.GetEnumerator(); while (ie.MoveNext()) { ProjectItem subProjectItem = projectItem.ProjectItems.Item(((dynamic)ie.Current).Name); ItemAdded(subProjectItem); } // Copy the file from the project into the same folder structure under the Startup Application // Have to be careful to keep folders like /content/styles/cool.css //var saveTo = startupProject.Combine(projectItem.FilenameAsRelativePath()); //if (!Directory.Exists(Path.GetDirectoryName(saveTo))) // Directory.CreateDirectory(Path.GetDirectoryName(saveTo)); //File.Copy(projectItem.FileNames[0], saveTo, true); //Infrastructure.Core.Instance.Notity("Embedded resource exported to " + saveTo); }