private bool ConfigExists(string name) { if (!Configurations.Any(x => x.Name == name)) { Program.Logger.Error("Unknown config \"" + name + "\""); return(false); } return(true); }
private void ValidateConfigurationAggregate(Configuration cfg) { if (Configurations.Any(c => c.Group == cfg.Group && c.Name == cfg.Name)) { throw new ApplicationException("DUP_CONFIGURATION"); } // More validations... }
public void Seed() { if (!Configurations.Any()) { var config = new List <ApiConfiguration> { new ApiConfiguration() { AcceptedSpeed = 2, LimitSpeed = 5, PriceThreshold = 0.04, LastNotification = DateTime.UtcNow.AddMinutes(-15), MinimalAcceptedSpeed = 0.4, AcceptedPercentThreshold = 0.1, EnableAudit = true, TotalHashThreshold = 0.8, } }; AddRange(config); } foreach (var condition in Registry.GetConditions()) { var name = condition.Name; var priority = Registry.GetPriority(condition); var dbCondition = ConditionSettings.FirstOrDefault(c => c.ConditionName == name); if (dbCondition == null) { var setting = new ConditionSetting() { ConditionID = priority, ConditionName = name, Enabled = true }; Add(setting); } else if (dbCondition.ConditionID != priority) { dbCondition.ConditionID = priority; } } SaveChanges(); }
/// <summary> /// Saves the Visual Studio solution to a file. /// </summary> /// <param name="rootPath">A root path for the solution to make other paths relative to.</param> /// <param name="writer">The <see cref="TextWriter" /> to save the solution file to.</param> /// <param name="useFolders">Specifies if folders should be created.</param> /// <param name="collapseFolders">An optional value indicating whether or not folders containing a single item should be collapsed into their parent folder.</param> internal void Save(string rootPath, TextWriter writer, bool useFolders, bool collapseFolders = false) { writer.WriteLine(Header, _fileFormatVersion); if (SolutionItems.Count > 0) { writer.WriteLine($@"Project(""{SlnFolder.FolderProjectTypeGuid}"") = ""Solution Items"", ""Solution Items"", ""{Guid.NewGuid().ToSolutionString()}"" "); writer.WriteLine(" ProjectSection(SolutionItems) = preProject"); foreach (string solutionItem in SolutionItems.Select(i => i.ToRelativePath(rootPath))) { writer.WriteLine($" {solutionItem} = {solutionItem}"); } writer.WriteLine(" EndProjectSection"); writer.WriteLine("EndProject"); } foreach (SlnProject project in _projects.OrderBy(i => i.FullPath)) { writer.WriteLine($@"Project(""{project.ProjectTypeGuid.ToSolutionString()}"") = ""{project.Name}"", ""{project.FullPath.ToRelativePath(rootPath)}"", ""{project.ProjectGuid.ToSolutionString()}"""); writer.WriteLine("EndProject"); } SlnHierarchy hierarchy = null; if (useFolders && _projects.Any(i => !i.IsMainProject)) { hierarchy = new SlnHierarchy(_projects, collapseFolders); foreach (SlnFolder folder in hierarchy.Folders) { writer.WriteLine($@"Project(""{folder.ProjectTypeGuid}"") = ""{folder.Name}"", ""{folder.FullPath.ToRelativePath(rootPath)}"", ""{folder.FolderGuid.ToSolutionString()}"""); writer.WriteLine("EndProject"); } } writer.WriteLine("Global"); if (useFolders && _projects.Count > 1 && hierarchy != null) { writer.WriteLine(@" GlobalSection(NestedProjects) = preSolution"); foreach (SlnFolder folder in hierarchy.Folders.Where(i => i.Parent != null)) { foreach (SlnProject project in folder.Projects) { writer.WriteLine($@" {project.ProjectGuid.ToSolutionString()} = {folder.FolderGuid.ToSolutionString()}"); } writer.WriteLine($@" {folder.FolderGuid.ToSolutionString()} = {folder.Parent.FolderGuid.ToSolutionString()}"); } writer.WriteLine(" EndGlobalSection"); } writer.WriteLine(" GlobalSection(SolutionConfigurationPlatforms) = preSolution"); HashSet <string> solutionPlatforms = Platforms != null && Platforms.Any() ? new HashSet <string>(GetValidSolutionPlatforms(Platforms), StringComparer.OrdinalIgnoreCase) : new HashSet <string>(GetValidSolutionPlatforms(_projects.SelectMany(i => i.Platforms)), StringComparer.OrdinalIgnoreCase); HashSet <string> solutionConfigurations = Configurations != null && Configurations.Any() ? new HashSet <string>(Configurations, StringComparer.OrdinalIgnoreCase) : new HashSet <string>(_projects.SelectMany(i => i.Configurations).Where(i => !i.IsNullOrWhiteSpace()), StringComparer.OrdinalIgnoreCase); foreach (string configuration in solutionConfigurations) { foreach (string platform in solutionPlatforms) { if (!string.IsNullOrWhiteSpace(configuration) && !string.IsNullOrWhiteSpace(platform)) { writer.WriteLine($" {configuration}|{platform} = {configuration}|{platform}"); } } } writer.WriteLine(" EndGlobalSection"); writer.WriteLine(" GlobalSection(ProjectConfigurationPlatforms) = postSolution"); foreach (SlnProject project in _projects) { string projectGuid = project.ProjectGuid.ToSolutionString(); foreach (string configuration in solutionConfigurations) { bool foundConfiguration = TryGetProjectSolutionConfiguration(configuration, project, out string projectSolutionConfiguration); foreach (string platform in solutionPlatforms) { bool foundPlatform = TryGetProjectSolutionPlatform(platform, project, out string projectSolutionPlatform, out string projectBuildPlatform); writer.WriteLine($@" {projectGuid}.{configuration}|{platform}.ActiveCfg = {projectSolutionConfiguration}|{projectSolutionPlatform}"); if (foundPlatform && foundConfiguration) { writer.WriteLine($@" {projectGuid}.{configuration}|{platform}.Build.0 = {projectSolutionConfiguration}|{projectBuildPlatform}"); } if (project.IsDeployable) { writer.WriteLine($@" {projectGuid}.{configuration}|{platform}.Deploy.0 = {projectSolutionConfiguration}|{projectSolutionPlatform}"); } } } } writer.WriteLine(" EndGlobalSection"); writer.WriteLine(" GlobalSection(SolutionProperties) = preSolution"); writer.WriteLine(" HideSolutionNode = FALSE"); writer.WriteLine(" EndGlobalSection"); writer.WriteLine(" GlobalSection(ExtensibilityGlobals) = postSolution"); writer.WriteLine($" SolutionGuid = {SolutionGuid.ToSolutionString()}"); writer.WriteLine(" EndGlobalSection"); writer.WriteLine("EndGlobal"); }
public void Save(Stream stream) { var packageXml = new XDocument(new XElement("PartPackage")); packageXml.Root.Add(new XElement("Info", new XElement("Part", PartID), new XElement("Description", Description) )); if (Meshes.Any()) { var meshesElem = new XElement("Meshes"); packageXml.Root.Add(meshesElem); foreach (var partMesh in Meshes) { meshesElem.Add(partMesh.Serialize()); } } if (DecorationImages.Any()) { var decoElem = packageXml.Root.AddElement("Decorations"); foreach (var decImg in DecorationImages) { decoElem.Add(decImg.Serialize()); } } if (Configurations.Any()) { var brickElem = packageXml.Root.AddElement("Configurations"); foreach (var brick in Configurations) { var elem = new XElement("Brick", new XAttribute("ElementID", brick.ElementID), new XAttribute("MaterialID", brick.MaterialID)); foreach (var dec in brick.Decorations) { elem.Add(XmlHelper.DefaultSerialize(dec)); } foreach (var subMat in brick.SubMaterials) { elem.Add(XmlHelper.DefaultSerialize(subMat)); } brickElem.Add(elem); } } using (var zipStream = new ZipOutputStream(stream)) { zipStream.SetLevel(1); zipStream.PutNextEntry(new ZipEntry(PACKAGE_XML_FILENAME)); packageXml.Save(zipStream); zipStream.CloseEntry(); if (Primitive != null) { zipStream.PutNextEntry(new ZipEntry("primitive.xml")); Primitive.Save(zipStream); zipStream.CloseEntry(); } foreach (var partMesh in Meshes) { zipStream.PutNextEntry(new ZipEntry($"{MESH_FOLDER}{partMesh.GetFileName()}")); using (var ms = new MemoryStream()) { partMesh.Mesh.Save(ms); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(zipStream); } zipStream.CloseEntry(); } foreach (var decImg in DecorationImages) { zipStream.PutNextEntry(new ZipEntry($"{DECO_FOLDER}{decImg.GetFileName()}")); decImg.Image.Save(zipStream, decImg.Image.RawFormat); zipStream.CloseEntry(); } } }