示例#1
0
 /// <summary>
 /// Convert back to an bcfzip file from SQLite database
 /// </summary>
 /// <param name="param"></param>
 public void ConvertBCFExecuted(object param)
 {
     try
     {
         if (bcfFiles.Count > 0)
         {
             //select primary file info
             BCFZIP combinedBCF = CombineBCF(bcfFiles, 0);
             if (null != combinedBCF)
             {
                 SaveFileDialog saveDialog = new SaveFileDialog();
                 saveDialog.Title           = "Save BCF";
                 saveDialog.DefaultExt      = ".bcfzip";
                 saveDialog.Filter          = "BCF (.bcfzip)|*.bcfzip";
                 saveDialog.OverwritePrompt = true;
                 if ((bool)saveDialog.ShowDialog())
                 {
                     string bcfPath = saveDialog.FileName;
                     bool   saved   = BCFWriter.BCFWriter.Write(bcfPath, combinedBCF);
                     if (saved)
                     {
                         MessageBox.Show(bcfPath + "\n has been successfully saved!!", "BCF Saved", MessageBoxButton.OK, MessageBoxImage.Information);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         string message = ex.Message;
     }
 }
示例#2
0
        /// <summary>
        /// Combine bcf info into the existing database
        /// </summary>
        /// <param name="bcfFiles"></param>
        /// <param name="primaryIndex"></param>
        /// <returns></returns>
        private BCFZIP CombineBCF(ObservableCollection <BCFZIP> bcfFiles, int primaryIndex)
        {
            BCFZIP combinedBCF = null;

            try
            {
                //Set Primary BCF
                BCFZIP primaryBCF = bcfFiles[primaryIndex];
                for (int i = 0; i < bcfFiles.Count; i++)
                {
                    if (i == primaryIndex)
                    {
                        continue;
                    }
                    BCFZIP bcf = bcfFiles[i];
                    foreach (Markup markup in bcf.Markups)
                    {
                        primaryBCF.Markups.Add(markup);
                    }
                }
                primaryBCF.Markups = new ObservableCollection <Markup>(primaryBCF.Markups.OrderBy(o => o.Topic.Index));
                for (int i = 0; i < primaryBCF.Markups.Count; i++)
                {
                    primaryBCF.Markups[i].Topic.Index = i;
                }
                combinedBCF = primaryBCF;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to combine multiple bcf files.\n" + ex.Message, "Combine BCF Files", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(combinedBCF);
        }
示例#3
0
        /// <summary>
        /// Read a bcfzip file and store the info into BCFZIP class
        /// </summary>
        /// <param name="bcfPath"></param>
        /// <returns></returns>
        public static BCFZIP Read(string bcfPath)
        {
            BCFZIP bcfZip = new BCFZIP(bcfPath);

            try
            {
                Dictionary <string /*topicId*/, Dictionary <string /*fileName*/, VisualizationInfo> >      tempVisInfoHolder = new Dictionary <string, Dictionary <string, VisualizationInfo> >();
                Dictionary <string /*topicId*/, Dictionary <string /*fileName*/, ComponentExtensionInfo> > tempExtInfoHolder = new Dictionary <string, Dictionary <string, ComponentExtensionInfo> >();
                Dictionary <string /*topicId*/, Dictionary <string /*fileName*/, byte[]> > tempFileContentHoder = new Dictionary <string, Dictionary <string, byte[]> >();

                bcfZip = ReadRawData(bcfPath, out tempVisInfoHolder, out tempFileContentHoder, out tempExtInfoHolder);

                bcfZip = MapContents(bcfZip, tempVisInfoHolder, tempFileContentHoder, tempExtInfoHolder);

                bcfZip.Markups = new ObservableCollection <Markup>(bcfZip.Markups.OrderBy(o => o.Topic.Index).ToList());
                if (bcfZip.Markups.Count > 0)
                {
                    bcfZip.SelectedMarkup = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to read BCF.\n" + ex.Message, "Read BCF", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(bcfZip);
        }
示例#4
0
        /// <summary>
        /// Add additional bcf info into the existing database
        /// </summary>
        /// <param name="bcfPath"></param>
        /// <returns></returns>
        public bool AddBCF(string bcfPath)
        {
            bool added = false;

            try
            {
                TaskDialogOption selectedOption = TaskDialogOption.NONE;
                var bcfExisting = from bcf in bcfFiles where bcf.ZipFilePath == bcfPath select bcf;
                if (bcfExisting.Count() > 0)
                {
                    TaskDialogWindow dialogWindow = new TaskDialogWindow("\"" + bcfPath + "\" already exists in the database.\nDo you want to replace it?");
                    if ((bool)dialogWindow.ShowDialog())
                    {
                        selectedOption = dialogWindow.SelectedOption;
                        switch (selectedOption)
                        {
                        case TaskDialogOption.REPLACE:
                            BCFZIP existingBCF = bcfExisting.First();
                            bool   deleted     = BCFDBWriter.BCFDBWriter.DeleteBCF(existingBCF);
                            if (deleted)
                            {
                                this.BCFFiles.Remove(existingBCF);
                            }
                            break;

                        case TaskDialogOption.MERGE:
                            break;

                        case TaskDialogOption.IGNORE:
                            return(false);

                        case TaskDialogOption.NONE:
                            return(false);
                        }
                    }
                }

                BCFZIP bcfzip = BCFReader.BCFReader.Read(bcfPath);
                if (bcfzip.Markups.Count > 0)
                {
                    ConflictMode mode = ConflictMode.IGNORE;
                    if (selectedOption == TaskDialogOption.MERGE)
                    {
                        int index = bcfFiles.IndexOf(bcfExisting.First());
                        if (index > -1)
                        {
                            BCFZIP mergedBCF = BCFDBWriter.BCFDBWriter.MergeDatabase(bcfzip, bcfFiles[index]);
                            if (null != mergedBCF)
                            {
                                this.BCFFiles[index] = mergedBCF;
                            }
                        }
                    }
                    else
                    {
                        bool written = BCFDBWriter.BCFDBWriter.WriteDatabase(bcfzip, mode);
                        if (written)
                        {
                            bcfzip.IsPrimary = false;
                            this.BCFFiles.Add(bcfzip);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add BCF into the connected database.\n" + ex.Message, "Add BCF", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(added);
        }
示例#5
0
        /// <summary>
        /// Save changes into the database
        /// </summary>
        /// <param name="bcfPath"></param>
        /// <returns></returns>
        public bool SaveDatabase(string bcfPath)
        {
            bool savedDB = false;

            try
            {
                this.BCFFiles.Clear();

                SaveFileDialog saveDialog = new SaveFileDialog();
                saveDialog.Title           = "Specify a Database File Location";
                saveDialog.DefaultExt      = ".sqlite";
                saveDialog.Filter          = "SQLITE File (.sqlite)|*.sqlite";
                saveDialog.FileName        = System.IO.Path.GetFileNameWithoutExtension(bcfPath);
                saveDialog.OverwritePrompt = false;
                if ((bool)saveDialog.ShowDialog())
                {
                    this.DatabaseFile = saveDialog.FileName;
                    if (File.Exists(databaseFile))
                    {
                        MessageBoxResult msgResult = MessageBox.Show("\"" + databaseFile + "\" already exists.\nDo you want to replace it?",
                                                                     "File Exists", MessageBoxButton.YesNo, MessageBoxImage.Question);
                        if (msgResult == MessageBoxResult.Yes)
                        {
                            File.Delete(databaseFile);
                        }
                        else if (msgResult == MessageBoxResult.No)
                        {
                            return(false);
                        }
                    }

                    BCFZIP bcfzip = BCFReader.BCFReader.Read(bcfPath);
                    bcfzip.IsPrimary = true;
                    if (bcfzip.Markups.Count > 0)
                    {
                        bool connected = BCFDBWriter.BCFDBWriter.ConnectDatabase(databaseFile);
                        if (connected)
                        {
                            bool created = BCFDBWriter.BCFDBWriter.CreateTables();
                            bool written = BCFDBWriter.BCFDBWriter.WriteDatabase(bcfzip, ConflictMode.IGNORE);

                            if (created && written)
                            {
                                //MessageBox.Show("The database file has been successfully created!!\n" + dbFile, "Database Created", MessageBoxButton.OK, MessageBoxImage.Information);
                                this.BCFFiles.Add(bcfzip);
                                this.DatabaseOpened = true;
                                //if (addInMode) { this.ComponentEnabled = true; }
                                this.SelectedIndex = bcfFiles.Count - 1;
                            }
                            else
                            {
                                MessageBox.Show("The datbase file has not been successfully created.\nPlease check the log file.", "Database Error", MessageBoxButton.OK, MessageBoxImage.Information);
                                savedDB = false;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("An invalid BCFZip file has been selected.\n Please select another BCFZip file to create a database file.", "Invalid BCFZip", MessageBoxButton.OK, MessageBoxImage.Information);
                        savedDB = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save BCF data into the database.\n" + ex.Message, "Import BCF", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(savedDB);
        }
示例#6
0
        public static bool Write(string bcfPath, BCFZIP bcf)
        {
            bool written = false;

            try
            {
                ProgressManager.InitializeProgress("Writing BCF..", bcf.Markups.Count);

                string tempDirectory = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "SmartBCF", bcf.FileId);
                if (Directory.Exists(tempDirectory))
                {
                    Directory.Delete(tempDirectory, true);
                }

                //Create root directory
                Directory.CreateDirectory(tempDirectory);

                //Project File
                string projectFilePath = System.IO.Path.Combine(tempDirectory, "project.bcfp");
                using (FileStream stream = new FileStream(projectFilePath, FileMode.Create))
                {
                    XmlSerializer projectSerializer = new XmlSerializer(typeof(ProjectExtension));
                    projectSerializer.Serialize(stream, bcf.ProjectFile);
                    stream.Close();
                }

                //Version File
                string versionFilePath = System.IO.Path.Combine(tempDirectory, "bcf.version");
                using (FileStream stream = new FileStream(versionFilePath, FileMode.Create))
                {
                    XmlSerializer versionSerializer = new XmlSerializer(typeof(Version));
                    versionSerializer.Serialize(stream, bcf.VersionFile);
                    stream.Close();
                }

                //Color File
                string colorFilePath = System.IO.Path.Combine(tempDirectory, "extension.color");
                using (FileStream stream = new FileStream(colorFilePath, FileMode.Create))
                {
                    XmlSerializer colorSerializer = new XmlSerializer(typeof(RevitExtensionInfo));
                    colorSerializer.Serialize(stream, bcf.ExtensionColor);
                    stream.Close();
                }

                //Markup and Viewpoint
                XmlSerializer markupSerializer  = new XmlSerializer(typeof(Markup));
                XmlSerializer visInfoSerializer = new XmlSerializer(typeof(VisualizationInfo));
                XmlSerializer extInfoSerializer = new XmlSerializer(typeof(ComponentExtensionInfo));
                foreach (Markup markup in bcf.Markups)
                {
                    ProgressManager.StepForward();

                    string topicDirectory = System.IO.Path.Combine(tempDirectory, markup.Topic.Guid);
                    Directory.CreateDirectory(topicDirectory);

                    string markupFilePath = System.IO.Path.Combine(topicDirectory, "markup.bcf");
                    using (FileStream stream = new FileStream(markupFilePath, FileMode.Create))
                    {
                        markupSerializer.Serialize(stream, markup);
                        stream.Close();
                    }

                    //Viewpoint
                    foreach (ViewPoint vp in markup.Viewpoints)
                    {
                        //Snapshot
                        if (!string.IsNullOrEmpty(vp.Snapshot) && null != vp.SnapshotImage)
                        {
                            string snapshotPath = System.IO.Path.Combine(topicDirectory, vp.Snapshot);
                            using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(vp.SnapshotImage)))
                            {
                                image.Save(snapshotPath, System.Drawing.Imaging.ImageFormat.Png);
                            }
                        }

                        if (!string.IsNullOrEmpty(vp.Viewpoint))
                        {
                            //Visinfo
                            string visInfoPath = System.IO.Path.Combine(topicDirectory, vp.Viewpoint);
                            if (null != vp.VisInfo)
                            {
                                VisualizationInfo visInfo = vp.VisInfo;
                                using (FileStream stream = new FileStream(visInfoPath, FileMode.Create))
                                {
                                    visInfoSerializer.Serialize(stream, visInfo);
                                    stream.Close();
                                }

                                string extensionPath           = visInfoPath.Replace(".bcfv", ".bcfvx");
                                ComponentExtensionInfo extInfo = new ComponentExtensionInfo();
                                extInfo.ViewpointGuid = vp.Guid;
                                var revitComponents = from comp in visInfo.Components
                                                      where (null != comp.Action) && (null != comp.Responsibility)
                                                      select comp;
                                if (revitComponents.Count() > 0)
                                {
                                    var componentsToWrite = from comp in revitComponents
                                                            where (comp.Action.Guid != Guid.Empty.ToString()) || (comp.Responsibility.Guid != Guid.Empty.ToString()) || (!string.IsNullOrEmpty(comp.ElementName))
                                                            select comp;
                                    if (componentsToWrite.Count() > 0)
                                    {
                                        ObservableCollection <ComponentExtension> compExtensions = new ObservableCollection <ComponentExtension>();
                                        List <Component> componentList = revitComponents.ToList();
                                        foreach (Component comp in componentList)
                                        {
                                            compExtensions.Add(new ComponentExtension(comp));
                                        }
                                        extInfo.Extensions = compExtensions;
                                        using (FileStream stream = new FileStream(extensionPath, FileMode.Create))
                                        {
                                            extInfoSerializer.Serialize(stream, extInfo);
                                            stream.Close();
                                        }
                                    }
                                }

                                //Bitmap
                                if (vp.VisInfo.Bitmaps.Count > 0)
                                {
                                    foreach (VisualizationInfoBitmaps bitmap in visInfo.Bitmaps)
                                    {
                                        if (!string.IsNullOrEmpty(bitmap.Reference) && null != bitmap.BitmapImage)
                                        {
                                            string bitmapPath = System.IO.Path.Combine(topicDirectory, bitmap.Reference);
                                            using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bitmap.BitmapImage)))
                                            {
                                                if (bitmap.Bitmap == BitmapFormat.JPG)
                                                {
                                                    image.Save(bitmapPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                                                }
                                                else if (bitmap.Bitmap == BitmapFormat.PNG)
                                                {
                                                    image.Save(bitmapPath, System.Drawing.Imaging.ImageFormat.Png);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                ZipFile.CreateFromDirectory(tempDirectory, bcfPath, CompressionLevel.Fastest, false);
                if (File.Exists(bcfPath))
                {
                    written = true;
                }
                ProgressManager.FinalizeProgress();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to write the BCF file.\n" + ex.Message, "Write BCF", MessageBoxButton.OK, MessageBoxImage.Warning);
                ProgressManager.FinalizeProgress();
            }
            return(written);
        }
示例#7
0
        /// <summary>
        /// Read files and serialize xml files into class structure
        /// </summary>
        /// <param name="bcfPath">the name of bcfzip</param>
        /// <param name="tempVisInfoHolder"></param>
        /// <param name="tempFileContentHoder"></param>
        /// <param name="tempExtInfoHolder"></param>
        /// <returns></returns>
        private static BCFZIP ReadRawData(string bcfPath, out Dictionary <string, Dictionary <string, VisualizationInfo> > tempVisInfoHolder,
                                          out Dictionary <string, Dictionary <string, byte[]> > tempFileContentHoder, out Dictionary <string, Dictionary <string, ComponentExtensionInfo> > tempExtInfoHolder)
        {
            BCFZIP bcfZip = new BCFZIP(bcfPath);

            tempVisInfoHolder    = new Dictionary <string, Dictionary <string, VisualizationInfo> >();
            tempFileContentHoder = new Dictionary <string, Dictionary <string, byte[]> >();
            tempExtInfoHolder    = new Dictionary <string, Dictionary <string, ComponentExtensionInfo> >();
            try
            {
                using (ZipArchive archive = ZipFile.OpenRead(bcfPath))
                {
                    ProgressManager.InitializeProgress("Gathering information from the BCF file...", archive.Entries.Count);
                    double value = 0;

                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        value++;
                        ProgressManager.StepForward();
                        string topicId = entry.ExtractGuidFolderName();

                        if (entry.FullName.EndsWith(".bcfp", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize project file
                            XmlSerializer serializer = new XmlSerializer(typeof(ProjectExtension));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                bcfZip.ProjectFile = (ProjectExtension)serializer.Deserialize(reader);
                                continue;
                            }
                        }
                        else if (entry.FullName.EndsWith(".version", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize version file
                            XmlSerializer serializer = new XmlSerializer(typeof(Version));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                bcfZip.VersionFile = (Version)serializer.Deserialize(reader);
                                continue;
                            }
                        }
                        else if (entry.FullName.EndsWith(".color", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize color file
                            XmlSerializer serializer = new XmlSerializer(typeof(RevitExtensionInfo));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                bcfZip.ExtensionColor = (RevitExtensionInfo)serializer.Deserialize(reader);
                                continue;
                            }
                        }
                        else if (!string.IsNullOrEmpty(topicId) && entry.FullName.EndsWith(".bcf", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize markup file
                            XmlSerializer serializer = new XmlSerializer(typeof(Markup));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                Markup markup = (Markup)serializer.Deserialize(reader);
                                bcfZip.Markups.Add(markup);
                            }
                        }
                        else if (!string.IsNullOrEmpty(topicId) && entry.FullName.EndsWith(".bcfv", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize viewpoint file
                            XmlSerializer serializer = new XmlSerializer(typeof(VisualizationInfo));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                VisualizationInfo visInfo = (VisualizationInfo)serializer.Deserialize(reader);
                                if (tempVisInfoHolder.ContainsKey(topicId))
                                {
                                    if (!tempVisInfoHolder[topicId].ContainsKey(entry.Name))
                                    {
                                        tempVisInfoHolder[topicId].Add(entry.Name, visInfo);
                                    }
                                }
                                else
                                {
                                    Dictionary <string, VisualizationInfo> visInfoDictionary = new Dictionary <string, VisualizationInfo>();
                                    visInfoDictionary.Add(entry.Name, visInfo);
                                    tempVisInfoHolder.Add(topicId, visInfoDictionary);
                                }
                            }
                        }
                        else if (!string.IsNullOrEmpty(topicId) && entry.FullName.EndsWith(".bcfvx", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize extension file
                            XmlSerializer serializer = new XmlSerializer(typeof(ComponentExtensionInfo));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                ComponentExtensionInfo extInfo = (ComponentExtensionInfo)serializer.Deserialize(reader);
                                if (tempExtInfoHolder.ContainsKey(topicId))
                                {
                                    if (!tempExtInfoHolder[topicId].ContainsKey(entry.Name))
                                    {
                                        tempExtInfoHolder[topicId].Add(entry.Name, extInfo);
                                    }
                                }
                                else
                                {
                                    Dictionary <string, ComponentExtensionInfo> extInfoDictionary = new Dictionary <string, ComponentExtensionInfo>();
                                    extInfoDictionary.Add(entry.Name, extInfo);
                                    tempExtInfoHolder.Add(topicId, extInfoDictionary);
                                }
                            }
                        }
                        else
                        {
                            //obtain bytearray of miscellaneous files including images
                            using (MemoryStream ms = new MemoryStream())
                            {
                                entry.Open().CopyTo(ms);
                                byte[] byteArray = ms.ToArray();
                                if (tempFileContentHoder.ContainsKey(topicId))
                                {
                                    if (!tempFileContentHoder[topicId].ContainsKey(entry.Name))
                                    {
                                        tempFileContentHoder[topicId].Add(entry.Name, byteArray);
                                    }
                                }
                                else
                                {
                                    Dictionary <string, byte[]> fileContents = new Dictionary <string, byte[]>();
                                    fileContents.Add(entry.Name, byteArray);
                                    tempFileContentHoder.Add(topicId, fileContents);
                                }
                            }
                        }
                    }
                    ProgressManager.FinalizeProgress();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to read data from BCF.\n" + ex.Message, "Read Raw Data", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(bcfZip);
        }
示例#8
0
        /// <summary>
        /// Organize raw data into BCFZIP class structure
        /// </summary>
        /// <param name="bcfzip"></param>
        /// <param name="tempVisInfoHolder"></param>
        /// <param name="tempFileContentHolder"></param>
        /// <param name="tempExtInfoHolder"></param>
        /// <returns></returns>
        private static BCFZIP MapContents(BCFZIP bcfzip, Dictionary <string, Dictionary <string, VisualizationInfo> > tempVisInfoHolder,
                                          Dictionary <string, Dictionary <string, byte[]> > tempFileContentHolder, Dictionary <string, Dictionary <string, ComponentExtensionInfo> > tempExtInfoHolder)
        {
            BCFZIP mappedBCF = null;

            try
            {
                Dictionary <string /*guid*/, RevitExtension> extensions = new Dictionary <string, RevitExtension>();
                foreach (RevitExtension ext in bcfzip.ExtensionColor.Extensions)
                {
                    if (!extensions.ContainsKey(ext.Guid))
                    {
                        extensions.Add(ext.Guid, ext);
                    }
                }

                for (int i = 0; i < bcfzip.Markups.Count; i++)
                {
                    Markup markup  = bcfzip.Markups[i];
                    string topicId = markup.Topic.Guid;

                    //BimSnippet
                    BimSnippet bimSnippet = markup.Topic.BimSnippet;
                    if (!string.IsNullOrEmpty(bimSnippet.Reference) && !bimSnippet.isExternal)
                    {
                        if (tempFileContentHolder.ContainsKey(topicId))
                        {
                            if (tempFileContentHolder[topicId].ContainsKey(bimSnippet.Reference))
                            {
                                bimSnippet.FileContent = tempFileContentHolder[topicId][bimSnippet.Reference];
                            }
                        }
                    }
                    bimSnippet.TopicGuid    = topicId;
                    markup.Topic.BimSnippet = bimSnippet;

                    //DocumentReferences
                    List <TopicDocumentReferences> docList = new List <TopicDocumentReferences>();
                    foreach (TopicDocumentReferences doc in markup.Topic.DocumentReferences)
                    {
                        TopicDocumentReferences docRef = doc;
                        docRef.TopicGuid = topicId;
                        if (!string.IsNullOrEmpty(docRef.ReferencedDocument) && !docRef.isExternal)
                        {
                            if (tempFileContentHolder.ContainsKey(topicId))
                            {
                                if (tempFileContentHolder[topicId].ContainsKey(docRef.ReferencedDocument))
                                {
                                    docRef.FileContent = tempFileContentHolder[topicId][docRef.ReferencedDocument];
                                }
                            }
                        }
                        docList.Add(docRef);
                    }
                    markup.Topic.DocumentReferences = docList;

                    if (markup.Viewpoints.Count > 0)
                    {
                        ViewPoint firstViewpoint = markup.Viewpoints.First();

                        for (int j = 0; j < markup.Comment.Count; j++)
                        {
                            string viewPointGuid = markup.Comment[j].Viewpoint.Guid;
                            if (string.IsNullOrEmpty(viewPointGuid))
                            {
                                markup.Comment[j].Viewpoint.Guid = firstViewpoint.Guid;
                            }
                        }
                    }

                    //viewpoints
                    for (int j = 0; j < markup.Viewpoints.Count; j++)
                    {
                        ViewPoint viewpoint = markup.Viewpoints[j];
                        //bitmap
                        if (tempVisInfoHolder.ContainsKey(topicId))
                        {
                            if (tempVisInfoHolder[topicId].ContainsKey(viewpoint.Viewpoint))
                            {
                                VisualizationInfo visInfo = tempVisInfoHolder[topicId][viewpoint.Viewpoint];
                                visInfo.ViewPointGuid = viewpoint.Guid;
                                List <VisualizationInfoBitmaps> bitmapList = new List <VisualizationInfoBitmaps>();
                                foreach (VisualizationInfoBitmaps bitmap in visInfo.Bitmaps)
                                {
                                    VisualizationInfoBitmaps visBitmap = bitmap;
                                    if (!string.IsNullOrEmpty(bitmap.Reference))
                                    {
                                        if (tempFileContentHolder.ContainsKey(topicId))
                                        {
                                            if (tempFileContentHolder[topicId].ContainsKey(bitmap.Reference))
                                            {
                                                visBitmap.BitmapImage = tempFileContentHolder[topicId][bitmap.Reference];
                                            }
                                        }
                                    }
                                    visBitmap.ViewPointGuid = viewpoint.Guid;
                                    bitmapList.Add(visBitmap);
                                }
                                visInfo.Bitmaps = bitmapList;

                                string viewpointExt = viewpoint.Viewpoint.Replace(".bcfv", ".bcfvx");
                                if (tempExtInfoHolder.ContainsKey(topicId))
                                {
                                    if (tempExtInfoHolder[topicId].ContainsKey(viewpointExt))
                                    {
                                        ComponentExtensionInfo extInfo = tempExtInfoHolder[topicId][viewpointExt];
                                        if (visInfo.Components.Count > 0)
                                        {
                                            foreach (ComponentExtension compExt in extInfo.Extensions)
                                            {
                                                var compFound = from comp in visInfo.Components where comp.IfcGuid == compExt.IfcGuid select comp;
                                                if (compFound.Count() > 0)
                                                {
                                                    int compIndex = visInfo.Components.IndexOf(compFound.First());
                                                    visInfo.Components[compIndex].ElementName    = compExt.ElementName;
                                                    visInfo.Components[compIndex].Action         = (extensions.ContainsKey(compExt.ActionGuid)) ? extensions[compExt.ActionGuid] : new RevitExtension();
                                                    visInfo.Components[compIndex].Responsibility = (extensions.ContainsKey(compExt.ResponsibilityGuid)) ? extensions[compExt.ResponsibilityGuid] : new RevitExtension();
                                                }
                                            }
                                        }
                                    }
                                }

                                markup.Viewpoints[j].VisInfo = visInfo;
                            }
                        }
                        //snapshot
                        if (tempFileContentHolder.ContainsKey(topicId))
                        {
                            if (tempFileContentHolder[topicId].ContainsKey(viewpoint.Snapshot))
                            {
                                markup.Viewpoints[j].SnapshotImage = tempFileContentHolder[topicId][viewpoint.Snapshot];
                                if (null == markup.TopicImage && null != markup.Viewpoints[j].SnapshotImage)
                                {
                                    markup.TopicImage = markup.Viewpoints[j].SnapshotImage;
                                }
                            }
                        }
                    }

                    if (markup.Viewpoints.Count > 0)
                    {
                        markup.SelectedViewpoint = markup.Viewpoints.First();
                    }
                    bcfzip.Markups[i] = markup;
                }
                mappedBCF = bcfzip;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create maps from BCF contents.\n" + ex.Message, "Mapping BCF Contents", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(mappedBCF);
        }
示例#9
0
        private void buttonImport_Click(object sender, RoutedEventArgs e)
        {
            UpdateLableDelegate    updateLabelDelegate    = new UpdateLableDelegate(statusLable.SetValue);
            UpdateProgressDelegate updateProgressDelegate = new UpdateProgressDelegate(progressBar.SetValue);

            try
            {
                double progressValue = 0;
                progressBar.Maximum    = 3;
                progressBar.Value      = progressValue;
                progressBar.Visibility = Visibility.Visible;
                bcfPath    = textBoxBCF.Text;
                sharedLink = textBoxFolder.Text;
                string folderId = "";
                if (sharedLink.Contains("id="))
                {
                    folderId = FileManager.GetFolderId(sharedLink);
                }

                if (!string.IsNullOrEmpty(bcfProjectId))
                {
                    if (folderId != bcfProjectId)
                    {
                        bcfProjectId  = folderId;
                        googleFolders = FileManager.FindGoogleFolders(bcfProjectId);
                    }
                }
                else
                {
                    bcfProjectId  = folderId;
                    googleFolders = FileManager.FindGoogleFolders(bcfProjectId);
                }

                if (AbortFlag.GetAbortFlag())
                {
                    this.DialogResult = false; return;
                }

                File        colorSheet     = null;
                File        uploadedBCF    = null;
                File        markupSheet    = null;
                File        viewpointSheet = null;
                List <File> uploadedImages = null;

                if (!string.IsNullOrEmpty(bcfPath) && null != googleFolders)
                {
                    if (null != googleFolders)
                    {
                        progressValue += 1;
                        Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Searching default folders..." });
                        Dispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue });

                        colorSheet       = googleFolders.ColorSheet;
                        bcfColorSchemeId = colorSheet.Id;

                        string bcfName = System.IO.Path.GetFileNameWithoutExtension(bcfPath);
                        if (FileManager.CheckExistingFiles(bcfName, googleFolders))
                        {
                            string uploadId = Guid.NewGuid().ToString();

                            if (null != googleFolders.ArchiveBCFFolder)
                            {
                                if (AbortFlag.GetAbortFlag())
                                {
                                    this.DialogResult = false; return;
                                }

                                progressValue += 1;
                                Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Uploading bcfzip to an archive folder..." });
                                Dispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue });

                                string parentId = googleFolders.ArchiveBCFFolder.Id;
                                uploadedBCF = FileManager.UploadBCF(bcfPath, parentId, uploadId);
                            }
                            if (null != googleFolders.ActiveBCFFolder && null != googleFolders.ArchiveImgFolder)
                            {
                                if (AbortFlag.GetAbortFlag())
                                {
                                    this.DialogResult = false; return;
                                }

                                BCFUtil bcfUtil = new BCFUtil();
                                bcfzip = bcfUtil.ReadBCF(bcfPath);

                                progressValue += 1;
                                Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Creating Google spreadsheet..." });
                                Dispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue });

                                if (AbortFlag.GetAbortFlag())
                                {
                                    this.DialogResult = false; return;
                                }

                                string parentId = googleFolders.ActiveBCFFolder.Id;
                                System.IO.MemoryStream markupStream = BCFParser.CreateMarkupStream(bcfzip);
                                if (null != markupStream)
                                {
                                    string title = bcfName + "_Markup.csv";
                                    markupSheet = FileManager.UploadSpreadsheet(markupStream, title, parentId, uploadId);
                                }

                                System.IO.MemoryStream viewpointStream = BCFParser.CreateViewpointStream(bcfzip);
                                if (null != viewpointStream)
                                {
                                    string title = bcfName + "_Viewpoint.csv";
                                    viewpointSheet = FileManager.UploadSpreadsheet(viewpointStream, title, parentId, uploadId);
                                }

                                if (AbortFlag.GetAbortFlag())
                                {
                                    this.DialogResult = false; return;
                                }

                                if (null != bcfzip)
                                {
                                    Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Uploading BCF images..." });
                                    Dispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue });
                                    parentId       = googleFolders.ActiveImgFolder.Id;
                                    uploadedImages = FileManager.UploadBCFImages(bcfzip, parentId, uploadId, progressBar);
                                }

                                if (AbortFlag.GetAbortFlag())
                                {
                                    this.DialogResult = false; return;
                                }

                                if (null != uploadedBCF && null != markupSheet && null != viewpointSheet && null != uploadedImages)
                                {
                                    Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Completed." });
                                    progressBar.Visibility = Visibility.Hidden;

                                    bcfFileInfo       = new LinkedBcfFileInfo(bcfName, markupSheet.Id, viewpointSheet.Id, sharedLink, googleFolders.RootTitle, bcfProjectId);
                                    this.DialogResult = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Folder Id cannot be identified.\n Please enter a valid shared link.\n", "Invalid Shared Link", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a correct form of the file path of bcf or the address of shared link.\n", "Invalid Path", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to import BCF.\n" + ex.Message, "Import BCF", MessageBoxButton.OK, MessageBoxImage.Warning);
                Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Ready." });
            }
            progressBar.Visibility = Visibility.Hidden;
        }