/// <summary> /// Parses the revit. /// </summary> /// <param name="revitFileInfo">The revit file information.</param> /// <param name="properties">The properties.</param> /// <exception cref="T:System.ArgumentNullException">properties</exception> public static void ParseRevit(this RevitFileInfo revitFileInfo, Dictionary <string, string> properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } // Parse Revit Build string if (!properties.ContainsKey(KnownRevitInfoProps.REVIT_BUILD)) { return; } var versionObj = versionExtractor.Match(properties[KnownRevitInfoProps.REVIT_BUILD]); if (!versionObj.Success) { return; } revitFileInfo.Vendor = versionObj?.Groups["vendor"]?.Value; revitFileInfo.Name = versionObj?.Groups["software"]?.Value; revitFileInfo.Is64Bit = versionObj.Groups["arch"]?.Value?.Contains("x64") ?? false; var versionString = string.Format("{0}.{1}.{2}", versionObj.Groups["version"].Value, versionObj.Groups["build"].Value, versionObj.Groups["revision"].Value); revitFileInfo.Version = new Version(versionString); }
/// <summary> /// Parses the revit. /// </summary> /// <param name="revitFileInfo">The revit file information.</param> /// <param name="properties">The properties.</param> /// <exception cref="T:System.ArgumentNullException">properties.</exception> public static void ParseRevit(this RevitFileInfo revitFileInfo, Dictionary <string, string> properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } // Parse Revit Build string var versionObj = GetBuildMatch(properties); if (!versionObj?.Success ?? false) { return; } revitFileInfo.Is64Bit = versionObj.Groups["arch"]?.Value?.Contains("x64") ?? false; revitFileInfo.ProductVersion = $"{versionObj.Groups["build"].Value}_{versionObj.Groups["revision"].Value}"; if (!string.IsNullOrWhiteSpace(versionObj?.Groups["vendor"]?.Value)) { revitFileInfo.ProductVendor = versionObj?.Groups["vendor"]?.Value; } if (!string.IsNullOrWhiteSpace(versionObj?.Groups["software"]?.Value)) { revitFileInfo.ProductName = versionObj?.Groups["software"]?.Value; } }
/// <summary> /// Parses the username. /// </summary> /// <param name="revitFileInfo">The revit file information.</param> /// <param name="properties">The properties.</param> /// <exception cref="T:System.ArgumentNullException">properties</exception> public static void ParseUsername(this RevitFileInfo revitFileInfo, Dictionary <string, string> properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } // Parse username field if (!properties.ContainsKey(KnownRevitInfoProps.USERNAME)) { return; } revitFileInfo.Username = properties[KnownRevitInfoProps.USERNAME]; }
/// <summary> /// Parses the document information. /// </summary> /// <param name="revitFileInfo">The revit file information.</param> /// <param name="properties">The properties.</param> /// <exception cref="T:System.ArgumentNullException">properties</exception> public static void ParseDocumentInfo(this RevitFileInfo revitFileInfo, Dictionary <string, string> properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } // Parse document unique id if (!properties.ContainsKey(KnownRevitInfoProps.UNIQUE_DOCUMENT_GUID)) { return; } var guidRaw = properties[KnownRevitInfoProps.UNIQUE_DOCUMENT_GUID]; revitFileInfo.Guid = new Guid(guidRaw); }
/// <summary> /// Parses the revit. /// </summary> /// <param name="revitFileInfo">The revit file information.</param> /// <param name="properties">The properties.</param> /// <exception cref="T:System.ArgumentNullException">properties</exception> public static void ParseRevit(this RevitFileInfo revitFileInfo, Dictionary <string, string> properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } if (properties.TryGetValue(KnownRevitInfoProps.FORMAT, out var formatRaw) && int.TryParse(formatRaw, out var format)) { revitFileInfo.Format = format; } // Parse Revit Build string var versionObj = default(Match); if (properties.TryGetValue(KnownRevitInfoProps.REVIT_BUILD, out var buildInfo)) { versionObj = versionExtractor.Match(buildInfo); } if (properties.TryGetValue(KnownRevitInfoProps.BUILD, out buildInfo)) { versionObj = versionExtractorSimple.Match(buildInfo); } if (!versionObj?.Success ?? false) { return; } revitFileInfo.Is64Bit = versionObj.Groups["arch"]?.Value?.Contains("x64") ?? false; revitFileInfo.ProductVersion = $"{versionObj.Groups["build"].Value}_{versionObj.Groups["revision"].Value}"; if (!string.IsNullOrWhiteSpace(versionObj?.Groups["vendor"]?.Value)) { revitFileInfo.ProductVendor = versionObj?.Groups["vendor"]?.Value; } if (!string.IsNullOrWhiteSpace(versionObj?.Groups["software"]?.Value)) { revitFileInfo.ProductName = versionObj?.Groups["software"]?.Value; } }
/// <summary> /// Parses the locale. /// </summary> /// <param name="revitFileInfo">The revit file information.</param> /// <param name="properties">The properties.</param> /// <exception cref="T:System.ArgumentNullException">properties</exception> public static void ParseLocale(this RevitFileInfo revitFileInfo, Dictionary <string, string> properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } // Parse last saved locale if (!properties.ContainsKey(KnownRevitInfoProps.LOCALE)) { return; } var localeRaw = properties[KnownRevitInfoProps.LOCALE]; revitFileInfo.Locale = CultureInfo .GetCultures(CultureTypes.NeutralCultures) .FirstOrDefault(c => c.ThreeLetterWindowsLanguageName == localeRaw); }
/// <summary> /// Gets a <see cref="RevitFileInfo" /> instance from the given file path. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="readProperties">if set to <c>true</c> [read properties].</param> /// <param name="readTypes">if set to <c>true</c> [read types].</param> /// <returns></returns> /// <exception cref="T:System.ArgumentException">filePath is invalid</exception> public static RevitFileInfo GetFromFile(string filePath) { if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentException("filePath is invalid"); } var rfi = new RevitFileInfo { FilePath = filePath }; // Read basic file info from metadata try { var properties = GetProperties(filePath); rfi.ParseDocumentInfo(properties); rfi.ParseLocale(properties); rfi.ParseRevit(properties); rfi.ParseUsername(properties); } catch (Exception) { // TODO log the error } // Read family types from part atom try { rfi.PartAtom = PartAtom.GetFromFile(filePath); } catch (Exception) { // TODO log the error } return(rfi); }