Ejemplo n.º 1
0
        public void MergeBcfFile(IEnumerable <BcfFile> bcfFiles)
        {
            try
            {
                foreach (var bcf in bcfFiles)
                {
                    foreach (var mergedIssue in bcf.Issues)
                    {
                        //it's a new issue
                        if (!Issues.Any(x => x.Topic != null && mergedIssue.Topic != null && x.Topic.Guid == mergedIssue.Topic.Guid))
                        {
                            string sourceDir = Path.Combine(bcf.TempPath, mergedIssue.Topic.Guid);
                            string destDir   = Path.Combine(TempPath, mergedIssue.Topic.Guid);

                            Directory.Move(sourceDir, destDir);
                            //update path set for binding
                            foreach (var view in mergedIssue.Viewpoints)
                            {
                                view.SnapshotPath = Path.Combine(TempPath, mergedIssue.Topic.Guid, view.Snapshot);
                            }
                            Issues.Add(mergedIssue);
                        }
                        //it exists, let's loop comments and views
                        else
                        {
                            var issue       = Issues.First(x => x.Topic.Guid == mergedIssue.Topic.Guid);
                            var newComments = mergedIssue.Comment.Where(x => issue.Comment.All(y => y.Guid != x.Guid)).ToList();
                            if (newComments.Any())
                            {
                                foreach (var newComment in newComments)
                                {
                                    issue.Comment.Add(newComment);
                                }
                            }
                            //sort comments
                            issue.Comment = new ObservableCollection <Comment>(issue.Comment.OrderByDescending(x => x.Date));

                            var newViews = mergedIssue.Viewpoints.Where(x => issue.Viewpoints.All(y => y.Guid != x.Guid)).ToList();
                            if (newViews.Any())
                            {
                                foreach (var newView in newViews)
                                {
                                    //to avoid conflicts in case both contain a snapshot.png or viewpoint.bcfv
                                    //img to be merged
                                    string sourceFile = newView.SnapshotPath;
                                    //assign new safe name based on guid
                                    newView.Snapshot = newView.Guid + ".png";
                                    //set new temp path for binding
                                    newView.SnapshotPath = Path.Combine(TempPath, issue.Topic.Guid, newView.Snapshot);
                                    //assign new safe name based on guid
                                    newView.Viewpoint = newView.Guid + ".bcfv";
                                    File.Move(sourceFile, newView.SnapshotPath);
                                    issue.Viewpoints.Add(newView);
                                }
                            }
                        }
                    }
                    Utils.DeleteDirectory(bcf.TempPath);
                }
                HasBeenSaved = false;
            }
            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }
        }