public void SaveMap(string filePath)
        {
            if (_map == null)
            {
                return;
            }

            _map.WriteXml(filePath);
            _map.AcceptChanges();
        }
        public void LoadMap(string filePath)
        {
            if (_map != null)
            {
                return;
            }
            if (filePath == null || filePath == "")
            {
                throw new ArgumentException("Invalid path");
            }

            try
            {
                // load schema from file
                _map = new SourceSchemaMap();
                _map.BeginInit();
                if (File.Exists(filePath))
                {
                    _map.ReadXml(filePath);
                }
                _map.AcceptChanges();

                // remove unmatched members from source schema
                for (int i = _map.Map.Rows.Count - 1; i >= 0; i--)
                {
                    if (SourceSchemaMap.LookupAdomdSchemaObject(_srcCube, _map.Map[i]) == null)
                    {
                        _map.Map.Rows.RemoveAt(i);
                    }
                }

                // add or validate existing memebrs
                foreach (Dimension dim in _srcCube.Dimensions)
                {
                    if (_map.Map.FindBySourceUniqueName("Dimension:" + dim.UniqueName) == null)
                    {
                        _map.Map.AddMapRow("Dimension:" + dim.UniqueName, "");
                    }

                    foreach (Hierarchy hier in dim.Hierarchies)
                    {
                        if (_map.Map.FindBySourceUniqueName("Hierarchy:" + hier.UniqueName) == null)
                        {
                            _map.Map.AddMapRow("Hierarchy:" + hier.UniqueName, "");
                        }

                        foreach (Level lev in hier.Levels)
                        {
                            if (_map.Map.FindBySourceUniqueName("Level:" + lev.UniqueName) == null)
                            {
                                _map.Map.AddMapRow("Level:" + lev.UniqueName, "");
                            }
                        }

                        // measures handled separately
                        if (dim.DimensionType != DimensionTypeEnum.Measure)
                        {
                            // default member or first member in first level
                            Member defMem = (Member)SourceSchemaMap.LookupAdomdSchemaObject(_srcCube, "Member", hier.DefaultMember);
                            if (defMem == null)
                            {
                                defMem = hier.Levels[0].GetMembers(0, 1)[0];
                            }
                            if (_map.Map.FindBySourceUniqueName("Member:" + defMem.UniqueName) == null)
                            {
                                _map.Map.AddMapRow("Member:" + defMem.UniqueName, "");
                            }

                            // calculated members
                            MemberCollection mems =
                                (hier.Levels[0].LevelType == LevelTypeEnum.All ?
                                 hier.Levels[1].GetMembers() : hier.Levels[0].GetMembers());
                            foreach (Member mem in mems)
                            {
                                if (mem.Type != MemberTypeEnum.Formula)
                                {
                                    continue;
                                }

                                if (_map.Map.FindBySourceUniqueName("Member:" + mem.UniqueName) == null)
                                {
                                    _map.Map.AddMapRow("Member:" + mem.UniqueName, "");
                                }
                            }
                        }
                    }

                    // measures
                    if (dim.DimensionType == DimensionTypeEnum.Measure)
                    {
                        foreach (Measure mea in _srcCube.Measures)
                        {
                            if (_map.Map.FindBySourceUniqueName("Measure:" + mea.UniqueName) == null)
                            {
                                _map.Map.AddMapRow("Measure:" + mea.UniqueName, "");
                            }
                        }
                    }
                }

                // load dest schema
                _destSchema.BeginInit();

                // empty member
                _destSchema.Schema.AddSchemaRow("");

                // dimension hierarchies
                foreach (Dimension dim in _destCube.Dimensions)
                {
                    if (_destSchema.Schema.FindByUniqueName("Dimension:" + dim.UniqueName) == null)
                    {
                        _destSchema.Schema.AddSchemaRow("Dimension:" + dim.UniqueName);
                    }

                    foreach (Hierarchy hier in dim.Hierarchies)
                    {
                        if (_destSchema.Schema.FindByUniqueName("Hierarchy:" + hier.UniqueName) == null)
                        {
                            _destSchema.Schema.AddSchemaRow("Hierarchy:" + hier.UniqueName);
                        }

                        foreach (Level lev in hier.Levels)
                        {
                            if (_destSchema.Schema.FindByUniqueName("Level:" + lev.UniqueName) == null)
                            {
                                _destSchema.Schema.AddSchemaRow("Level:" + lev.UniqueName);
                            }
                        }

                        // measures handeled separately
                        if (dim.DimensionType != DimensionTypeEnum.Measure)
                        {
                            // default member or first member in first level
                            Member defMem = (Member)SourceSchemaMap.LookupAdomdSchemaObject(_destCube, "Member", hier.DefaultMember);
                            if (defMem == null)
                            {
                                defMem = hier.Levels[0].GetMembers(0, 1)[0];
                            }
                            if (_destSchema.Schema.FindByUniqueName("Member:" + defMem.UniqueName) == null)
                            {
                                _destSchema.Schema.AddSchemaRow("Member:" + defMem.UniqueName);
                            }

                            // calculated members
                            MemberCollection mems =
                                (hier.Levels[0].LevelType == LevelTypeEnum.All ?
                                 hier.Levels[1].GetMembers() : hier.Levels[0].GetMembers());
                            foreach (Member mem in mems)
                            {
                                if (mem.Type != MemberTypeEnum.Formula)
                                {
                                    continue;
                                }

                                if (_destSchema.Schema.FindByUniqueName("Member:" + mem.UniqueName) == null)
                                {
                                    _destSchema.Schema.AddSchemaRow("Member:" + mem.UniqueName);
                                }
                            }
                        }
                    }

                    // measures
                    if (dim.DimensionType == DimensionTypeEnum.Measure)
                    {
                        foreach (Measure mea in _destCube.Measures)
                        {
                            if (_destSchema.Schema.FindByUniqueName("Measure:" + mea.UniqueName) == null)
                            {
                                _destSchema.Schema.AddSchemaRow("Measure:" + mea.UniqueName);
                            }
                        }
                    }
                }


                // merge dest schema to file
                foreach (SourceSchemaMap.MapRow srcRow in _map.Map.Rows)
                {
                    // assign is empty and exact match
                    if (srcRow.IsDestUniqueNameNull() || srcRow.DestUniqueName == "")
                    {
                        DestSchema.SchemaRow destRow = _destSchema.Schema.FindByUniqueName(srcRow.SourceUniqueName);
                        srcRow.DestUniqueName = (destRow == null ? "" : destRow.UniqueName);
                    }
                    else // check assigned
                    {
                        DestSchema.SchemaRow destRow = _destSchema.Schema.FindByUniqueName(srcRow.DestUniqueName);
                        if (destRow == null)
                        {
                            srcRow.DestUniqueName = "";
                        }
                    }
                }
            }
            finally
            {
                if (_map != null)
                {
                    _map.EndInit();
                }

                if (_destSchema != null)
                {
                    _destSchema.AcceptChanges();
                    _destSchema.EndInit();
                }
            }
        }