/// <summary> /// Reads a BCFv2 zip archive /// </summary> /// <param name="zipFileStream">The zip archive of the physical file</param> /// <returns></returns> public static BCFv2Container ReadStream(Stream zipFileStream) { var container = new BCFv2Container(); var bcfZipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Read); // Check if version info is compliant with this implementation (2.0) var versionEntry = bcfZipArchive.Entries.FirstOrDefault(e => string.Equals(e.FullName, "bcf.version", StringComparison.OrdinalIgnoreCase)); if (versionEntry != null) { var fileVersionInfo = Version.Deserialize(versionEntry.Open()); if (fileVersionInfo.VersionId != "2.0" || !fileVersionInfo.DetailedVersion.Contains("2.0")) { throw new NotSupportedException("BCFzip version"); } } // Get project info if present if (bcfZipArchive.Entries.Any(e => e.FullName == "project.bcfp")) { var deserializedProject = ProjectExtension.Deserialize(bcfZipArchive.Entries.First(Entry => Entry.FullName == "project.bcfp").Open()); if (!(string.IsNullOrWhiteSpace(deserializedProject.ExtensionSchema) && (deserializedProject.Project == null || string.IsNullOrWhiteSpace(deserializedProject.Project.Name) && string.IsNullOrWhiteSpace(deserializedProject.Project.ProjectId)))) { if (string.IsNullOrWhiteSpace(deserializedProject.ExtensionSchema)) { deserializedProject.ExtensionSchema = null; } container.BcfProject = deserializedProject; if (!string.IsNullOrWhiteSpace(container.BcfProject.ExtensionSchema) && bcfZipArchive.Entries.Any(e => e.FullName == container.BcfProject.ExtensionSchema)) { using (var extensionsReader = new StreamReader(bcfZipArchive.Entries.First(e => e.FullName == container.BcfProject.ExtensionSchema).Open())) { container.ProjectExtensions = new ProjectExtensions(extensionsReader.ReadToEnd()); } } } } // Get each topic's GUID and read the topic var topicIds = new List <string>(); foreach (var entry in bcfZipArchive.Entries) { var topicId = entry.FullName; if (Regex.IsMatch(topicId, @"^\b[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}/markup.bcf\b")) { if (!topicIds.Contains(Regex.Match(topicId, @"^\b[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}\b").Value)) { container.Topics.Add(ReadSingleTopic(bcfZipArchive, Regex.Match(topicId, @"^\b[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}\b").Value, container)); } topicIds.Add(Regex.Match(topicId, @"^\b[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}\b").Value); } } // Check if there is no extension but a reference to it; delete the reference then if (container.ProjectExtensions == null && !string.IsNullOrWhiteSpace(container.BcfProject?.ExtensionSchema)) { container.BcfProject.ExtensionSchema = null; } return(container); }
private static ProjectExtension DeserializeProject(string path) { ProjectExtension output = null; try { using (var markupFile = new FileStream(path, FileMode.Open)) { var serializerM = new XmlSerializer(typeof(ProjectExtension)); output = serializerM.Deserialize(markupFile) as ProjectExtension; } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } return(output); }
private List <CorporateTravelWeeklyReportModel> BuildCorporateTravelWeeklyReportModel(DateTime startDate, DateTime endDate) { var userId = this.GetUserId(); var departmentService = GetService <DepartmentService>(); var projectService = GetService <ProjectService>(); var timeSheetService = GetService <TimeSheetService>(); var userService = GetService <UserService>(); var userGroups = departmentService.GetUserGroupsByUserId(userId); var models = new List <CorporateTravelWeeklyReportModel>(); if (userGroups.Count > 0) { foreach (var userGroup in userGroups) { var projectIds = timeSheetService.GetWorkingProjectIds(userGroup.UserIds, startDate, endDate); var projects = projectService.GetByIds(projectIds); if (projects != null) { //过滤公共项目 projects = projects.Where(p => !p.IsPublic && !p.IsCr).ToList(); foreach (var project in projects) { //Manager拥有多个组,过滤重复项目 if (models.Exists(p => p.ProjectID == project.Id)) { continue; } //计算开发、测试完成百分比 double devPercentage = ProjectExtension.GetDevPercentage(project); double testPercentage = ProjectExtension.GetTestPercentage(project); bool isDone = project.Status != Status.Done ? false : true; //遍历参与开发、测试人员 List <string> devNames = new List <string>(); List <string> testNames = new List <string>(); foreach (var usrId in project.UserIds) { var usr = userService.Get(usrId); if (departmentService.IsTester(usrId)) { testNames.Add(usr.Name); } else { devNames.Add(usr.Name); } } List <string> devManagers = new List <string>(); List <string> testManagers = new List <string>(); foreach (var ownerId in project.OwnerIds) { var usr = userService.Get(ownerId); if (departmentService.IsTester(ownerId)) { testManagers.Add(usr.Name); } else { devManagers.Add(usr.Name); } } string progressText = ReportHelper.GetFlightProgressText(isDone, devPercentage, testPercentage); string percentageCompletion = ReportHelper.GetPercentageCompletion(devNames, testNames, devPercentage, testPercentage); models.Add(new CorporateTravelWeeklyReportModel(project, GetAllUserGroupNamesByProject(project), percentageCompletion, progressText, ReportHelper.GetProjectStatus(project), devManagers, testManagers, devNames, testNames)); } } } models = models.OrderByDescending(o => o.Project.Level).ThenBy(o => o.Project.GetEndDate()).ToList(); } return(models); }
/// <summary> /// Serializes to a bcfzip and saves it to disk /// </summary> /// <param name="bcffile"></param> /// <returns></returns> private static bool SaveBcfFile(BcfFile bcffile) { try { if (bcffile.Issues.Count == 0) { MessageBox.Show("The current BCF Report is empty.", "No Issue", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!Directory.Exists(bcffile.TempPath)) { Directory.CreateDirectory(bcffile.TempPath); } // Show save file dialog box string name = !string.IsNullOrEmpty(bcffile.Filename) ? bcffile.Filename : "New BCF Report"; string filename = SaveBcfDialog(name); // Process save file dialog box results if (string.IsNullOrWhiteSpace(filename)) { return(false); } var bcfProject = new ProjectExtension { Project = new Project { Name = string.IsNullOrEmpty(bcffile.ProjectName) ? bcffile.Filename : bcffile.ProjectName, ProjectId = bcffile.ProjectId.Equals(Guid.Empty) ? Guid.NewGuid().ToString() : bcffile.ProjectId.ToString() }, ExtensionSchema = "" }; var bcfVersion = new Bcf2.Version { VersionId = "2.0", DetailedVersion = "2.0" }; var serializerP = new XmlSerializer(typeof(ProjectExtension)); Stream writerP = new FileStream(Path.Combine(bcffile.TempPath, "project.bcfp"), FileMode.Create); serializerP.Serialize(writerP, bcfProject); writerP.Close(); var serializerVers = new XmlSerializer(typeof(Bcf2.Version)); Stream writerVers = new FileStream(Path.Combine(bcffile.TempPath, "bcf.version"), FileMode.Create); serializerVers.Serialize(writerVers, bcfVersion); writerVers.Close(); var serializerV = new XmlSerializer(typeof(VisualizationInfo)); var serializerM = new XmlSerializer(typeof(Markup)); foreach (var issue in bcffile.Issues) { // Serialize the object, and close the TextWriter string issuePath = Path.Combine(bcffile.TempPath, issue.Topic.Guid); if (!Directory.Exists(issuePath)) { Directory.CreateDirectory(issuePath); } //BCF 1 compatibility //there needs to be a view whose viewpoint and snapshot are named as follows and not with a guid //uniqueness is still guarenteed by the guid field if (issue.Viewpoints.Any() && (issue.Viewpoints.Count == 1 || issue.Viewpoints.All(o => o.Viewpoint != "viewpoint.bcfv"))) { if (File.Exists(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint))) { File.Delete(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint)); } issue.Viewpoints[0].Viewpoint = "viewpoint.bcfv"; if (File.Exists(Path.Combine(issuePath, issue.Viewpoints[0].Snapshot))) { File.Move(Path.Combine(issuePath, issue.Viewpoints[0].Snapshot), Path.Combine(issuePath, "snapshot.png")); } issue.Viewpoints[0].Snapshot = "snapshot.png"; } //serialize markup with updated content Stream writerM = new FileStream(Path.Combine(issuePath, "markup.bcf"), FileMode.Create); serializerM.Serialize(writerM, issue); writerM.Close(); //serialize views foreach (var bcfViewpoint in issue.Viewpoints) { Stream writerV = new FileStream(Path.Combine(issuePath, bcfViewpoint.Viewpoint), FileMode.Create); serializerV.Serialize(writerV, bcfViewpoint.VisInfo); writerV.Close(); } } //overwrite, without doubts if (File.Exists(filename)) { File.Delete(filename); } ZipFile.CreateFromDirectory(bcffile.TempPath, filename, CompressionLevel.Optimal, false); //Open browser at location Uri uri2 = new Uri(filename); string reportname = Path.GetFileName(uri2.LocalPath); if (File.Exists(filename)) { string argument = @"/select, " + filename; System.Diagnostics.Process.Start("explorer.exe", argument); } bcffile.HasBeenSaved = true; bcffile.Filename = reportname; } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } return(true); }
private ProjectItem GetResourceFile() { ProjectItem resourceFilePrjItem = null; string resourceFileName = null, resourceFileDir = null; if (!Settings.IsUseGlobalResourceFile) { resourceFileName = System.IO.Path.ChangeExtension(Window.ProjectItem.Name, "Resources.resx"); //file name only resourceFileDir = System.IO.Path.GetDirectoryName(Window.ProjectItem.FileNames[0]); } else { resourceFileName = ProjectExtension.StartsWith("cs", StringComparison.OrdinalIgnoreCase) ? "Properties" : "My Project"; resourceFileDir = System.IO.Path.GetDirectoryName(Window.ProjectItem.ContainingProject.FullName); } //get the projects project-items collection ProjectItems prjItems = Window.Project.ProjectItems; if (!Settings.IsUseGlobalResourceFile) { try { //try to get the parent project-items collection (if in a sub folder) prjItems = ((ProjectItem)Window.ProjectItem.Collection.Parent).ProjectItems; } catch { } } try { resourceFilePrjItem = prjItems?.Item(resourceFileName); } catch { } if (Settings.IsUseGlobalResourceFile) { bool isPropertiesItem = (resourceFilePrjItem != null); if (isPropertiesItem) { prjItems = resourceFilePrjItem.ProjectItems; resourceFilePrjItem = null; resourceFileDir = System.IO.Path.Combine(resourceFileDir, resourceFileName); //append "Properties"/"My Project" because it exists } if (prjItems == null) { return(null); //something went terribly wrong that never should have been possible } if (string.IsNullOrEmpty(Settings.GlobalResourceFileName)) { resourceFileName = "Resources.resx"; //standard global resource file } else { resourceFileName = System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(Settings.GlobalResourceFileName), "Resources.resx"); } try { //searches for the global resource resourceFilePrjItem = prjItems.Item(resourceFileName); } catch { } } if (resourceFilePrjItem == null) { #region not in project but file exists? -> ask user if delete string projectPath = System.IO.Path.GetDirectoryName(Window.ProjectItem.ContainingProject.FullName), resourceFile = System.IO.Path.Combine(resourceFileDir, resourceFileName), designerFile = System.IO.Path.ChangeExtension(resourceFile, ".Designer." + ProjectExtension.Substring(0, 2) /*((m_IsCSharp) ? "cs" : "vb")*/); if (System.IO.File.Exists(resourceFile) || System.IO.File.Exists(designerFile)) { string msg = string.Format( "The resource file already exists though it is not included in the project: '{0}'. Overriding file.", resourceFile.Substring(projectPath.Length).TrimStart('\\')); TryToSilentlyDeleteIfExistsEvenIfReadOnly(resourceFile); TryToSilentlyDeleteIfExistsEvenIfReadOnly(designerFile); } #endregion try { // Retrieve the path to the resource template. string itemPath = ((Solution2)Dte.Solution).GetProjectItemTemplate("Resource.zip", ProjectExtension); //create a new project item based on the template /*prjItem =*/ prjItems.AddFromTemplate(itemPath, resourceFileName); //returns always null ... resourceFilePrjItem = prjItems.Item(resourceFileName); } catch (Exception ex) { return(null); } } if (resourceFilePrjItem == null) { return(null); } //open the ResX file if (!resourceFilePrjItem.IsOpen[EnvDTE.Constants.vsViewKindAny]) { resourceFilePrjItem.Open(EnvDTE.Constants.vsViewKindDesigner); } return(resourceFilePrjItem); }
/// <summary> /// Initializes a new instance of the <see cref="ExtensionItemTreeNode"/> class. /// </summary> /// <param name="extension">The extension.</param> /// <param name="imgIndex">Index of the img.</param> public ExtensionItemTreeNode(ProjectExtension extension, int imgIndex) : base(extension.ToString(), imgIndex, imgIndex) { this.extension = extension; }
/// <summary> /// Creates a BCFv2 zip archive /// </summary> /// <param name="streamToWrite"></param> public void WriteStream(Stream streamToWrite) { using (var bcfZip = new ZipArchive(streamToWrite, ZipArchiveMode.Create, true)) { // Write the version information var versionInformation = bcfZip.CreateEntry("bcf.version"); using (var versionWriter = new StreamWriter(versionInformation.Open())) { var serializedVersionInfo = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(BcfVersionInfo.Serialize()); versionWriter.Write(serializedVersionInfo); } if (ProjectExtensions != null && !ProjectExtensions.IsEmpty()) { var projectInformation = bcfZip.CreateEntry("extensions.xsd"); using (var projectInfoWriter = new StreamWriter(projectInformation.Open())) { var serializedExtensions = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(ProjectExtensions.WriteExtension()); projectInfoWriter.Write(serializedExtensions); } if (BcfProject == null) { BcfProject = new ProjectExtension(); } BcfProject.ExtensionSchema = "extensions.xsd"; } // Write the project info if it is present if (BcfProject != null) { var projectEntry = bcfZip.CreateEntry("project.bcfp"); using (var projectInfoWriter = new StreamWriter(projectEntry.Open())) { var serializedProjectInfo = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(BcfProject.Serialize()); projectInfoWriter.Write(serializedProjectInfo); } } // Write file attachments if (FileAttachments.Any()) { foreach (var attachment in FileAttachments) { var attachmentEntry = bcfZip.CreateEntry(attachment.Key); using (var attachmentWriter = new BinaryWriter(attachmentEntry.Open())) { attachmentWriter.Write(attachment.Value); } } } // Write an entry for each topic foreach (var topic in Topics) { if (!topic.Markup.Topic.CreationDateSpecified) { topic.Markup.Topic.CreationDate = DateTime.UtcNow; } if (string.IsNullOrWhiteSpace(topic.Markup.Topic.Guid)) { topic.Markup.Topic.Guid = Guid.NewGuid().ToString(); } if (topic.Markup.Topic.ShouldSerializeBimSnippet()) { // Write BIM Snippet if present in the file and internal if (!topic.Markup.Topic.BimSnippet.isExternal) { topic.Markup.Topic.BimSnippet.isExternal = false; var bimSnippetBinaryEntry = bcfZip.CreateEntry(topic.Markup.Topic.Guid + "/" + topic.Markup.Topic.BimSnippet.Reference); using (var snippetWriter = new BinaryWriter(bimSnippetBinaryEntry.Open())) { if (topic.SnippetData != null) { snippetWriter.Write(topic.SnippetData); } } } } var topicEntry = bcfZip.CreateEntry(topic.Markup.Topic.Guid + "/" + "markup.bcf"); for (var i = 0; i < topic.Viewpoints.Count; i++) { if (topic.ViewpointSnapshots.ContainsKey(topic.Viewpoints[i].GUID)) { topic.Markup.Viewpoints[i].Snapshot = "Snapshot_" + topic.Viewpoints[i].GUID + ".png"; } } using (var topicWriter = new StreamWriter(topicEntry.Open())) { var serializedTopic = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(topic.Markup.Serialize()); topicWriter.Write(serializedTopic); } // Write viewpoints if present for (var i = 0; i < topic.Viewpoints.Count; i++) { var entryName = topic.Markup.Topic.Guid + "/" + topic.Markup.Viewpoints[i].Viewpoint; var viewpoint = bcfZip.CreateEntry(entryName); using (var viewpointWriter = new StreamWriter(viewpoint.Open())) { if (topic.Viewpoints[i].Bitmaps.Count > 0) { foreach (var bitmap in topic.Viewpoints[i].Bitmaps) { bitmap.Reference = "Bitmap_" + Guid.NewGuid() + "." + (bitmap.Bitmap == BitmapFormat.JPG ? "jpg" : "png"); } } var serializedViewpoint = BrandingCommentFactory.AppendBrandingCommentToTopLevelXml(topic.Viewpoints[i].Serialize()); viewpointWriter.Write(serializedViewpoint); } // Write snapshot if present if (topic.ViewpointSnapshots.ContainsKey(topic.Viewpoints[i].GUID)) { var snapshotEntryName = topic.Markup.Topic.Guid + "/" + topic.Markup.Viewpoints[i].Snapshot; var viewpointSnapshot = bcfZip.CreateEntry(snapshotEntryName); using (var CurrentViewpointSnapshotWriter = new BinaryWriter(viewpointSnapshot.Open())) { CurrentViewpointSnapshotWriter.Write(topic.ViewpointSnapshots[topic.Markup.Viewpoints[i].Guid]); } } // Write bitmaps if present if (topic.ViewpointBitmaps.ContainsKey(topic.Viewpoints[i])) { for (var j = 0; j < topic.ViewpointBitmaps[topic.Viewpoints[i]].Count; j++) { // It's a little bit hacky still.... var bitmapEntryName = topic.Markup.Topic.Guid + "/" + topic.Viewpoints[i].Bitmaps[j].Reference; var viewpointBitmapEntry = bcfZip.CreateEntry(bitmapEntryName); using (var viewpointBitmapWriter = new BinaryWriter(viewpointBitmapEntry.Open())) { viewpointBitmapWriter.Write(topic.ViewpointBitmaps[topic.Viewpoints[i]][j]); } } } } } } }