示例#1
0
        public void Associate(DataEntity inSource, DataEntity inAssociate)
        {
            inSource.DontAssociate    = false;
            inAssociate.DontAssociate = false;

            List <DataEntity> confirmed = GetConfirmedAssociations(inSource);

            if (!confirmed.Contains(inAssociate))
            {
                _assocciations.Add(new DataEntity[] { inSource, inAssociate });
            }
            AssociateEntities();
        }
示例#2
0
        public string[] GetTransferables(DataEntity currentEntity)
        {
            List <string> transferables = new List <string>();

            foreach (EntityProperty prop in currentEntity.Properties)
            {
                if (prop.Transferable)
                {
                    transferables.Add(prop.Name);
                }
            }

            string[] transfer = new string[transferables.Count];
            transferables.CopyTo(transfer);

            return(transfer);
        }
示例#3
0
        public Comparison GetSummary(DataEntity comparedEntity, DataEntity dataEntity)
        {
            Dictionary <string, double> comparisons = _comparisons[comparedEntity][dataEntity];

            int propCounter = 0;

            foreach (string propName in comparisons.Keys)
            {
                if (comparedEntity.Properties[propCounter].Mandatory && comparisons[propName] < 1.0)
                {
                    return(Comparison.Differ);
                }
                propCounter++;
            }

            return(Comparison.Equals);
        }
示例#4
0
        public List <DataEntity> GetConfirmedAssociations(DataEntity inEntity)
        {
            List <DataEntity> rslt = new List <DataEntity>();

            foreach (DataEntity[] assoc in _assocciations)
            {
                if (assoc[0] == inEntity)
                {
                    rslt.Add(assoc[1]);
                }
                else if (assoc[1] == inEntity)
                {
                    rslt.Add(assoc[0]);
                }
            }

            return(rslt);
        }
示例#5
0
        public void DeAssociate(string idSource, string idAssociate, bool left)
        {
            DataEntity source = GetEntity(idSource, left);

            if (source == null)
            {
                return;
            }

            DataEntity associate = GetEntity(idAssociate, !left);

            if (associate == null)
            {
                return;
            }

            DeAssociate(source, associate);
        }
示例#6
0
        public List <DataEntity> GetPossibleAssociations(DataEntity inEntity)
        {
            List <DataEntity> rslt = new List <DataEntity>();

            if (!inEntity.DontAssociate)
            {
                ComparableData    otherData = inEntity.Comparable == _leftData ? _rightData : _leftData;
                List <DataEntity> confirmed = GetConfirmedAssociations(inEntity);

                foreach (DataEntity entity in otherData.Entities)
                {
                    if (!confirmed.Contains(entity))
                    {
                        rslt.Add(entity);
                    }
                }
            }

            return(rslt);
        }
示例#7
0
        public string[] GetConfirmedAssociations(string id, bool left)
        {
            string[] rslt = new string[0];

            DataEntity entity = GetEntity(id, left);

            if (entity != null)
            {
                List <DataEntity> entities = GetConfirmedAssociations(entity);
                rslt = new string[entities.Count];

                int counter = 0;
                foreach (DataEntity curEntity in entities)
                {
                    rslt[counter] = curEntity.Id;
                    counter++;
                }
            }

            return(rslt);
        }
示例#8
0
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_currentEntities != null && _currentEntities.Count > 0)
            {
                ToolStripItem item = sender as ToolStripItem;
                foreach (DataEntity entity in _currentEntities)
                {
                    entity.Copy(entity.Comparable == _left ? _right : _left);
                }

                Compare();
            }
            else if (_currentEntity != null)
            {
                ToolStripItem item = sender as ToolStripItem;

                _currentEntity.Copy(_currentEntity.Comparable == _left ? _right : _left);

                _currentEntity = null;
                Compare();
            }
        }
示例#9
0
        public bool transfer(DataEntity entity, string propertyName)
        {
            EntityProperty prop = entity.GetProperty(propertyName);

            if (prop != null)
            {
                if (!prop.Transfer(entity.AssociatedEntity))
                {
                    Logger.Log(string.Format("Can't transfer \"{0}.{1}\" on \"{2}\"", entity.Id, propertyName, entity.AssociatedEntity.Id), LogSeverities.Error);
                }
                else
                {
                    Logger.Log(string.Format("Transfer \"{0}.{1}\" on \"{2}\" successfull", entity.Id, propertyName, entity.AssociatedEntity.Id), LogSeverities.Info);
                    return(true);
                }
            }
            else
            {
                Logger.Log(string.Format("Can't fin property \"{0}\" on \"{1}\"", propertyName, entity.Id), LogSeverities.Error);
            }

            return(false);
        }
示例#10
0
        private void highlightSelectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <string> selEntities = new List <string>();

            foreach (DataGridViewCell cell in ComparisonsDGV.SelectedCells)
            {
                string id = ComparisonsDGV.Rows[cell.RowIndex].Cells[0].Value.ToString() + "|" + (cell.ColumnIndex < _left.Entities[0].Properties.Count ? "0" : "1");
                if (!selEntities.Contains(id))
                {
                    selEntities.Add(id);
                }
            }

            bool       highlighted = false;
            DataEntity entity      = null;

            foreach (string selEntity in selEntities)
            {
                string[] splitId = selEntity.Split('|');
                entity = _comp.GetEntity(splitId[0], splitId[1] == "0");

                if (entity != null)
                {
                    if (!highlighted)
                    {
                        highlighted = true;
                        entity.BeginHighlight();
                    }
                    entity.Highlight();
                }
            }

            if (entity != null)
            {
                entity.EndHighlight();
            }
        }
示例#11
0
 public void DeAssociate(DataEntity inSource, DataEntity inAssociate)
 {
     foreach (DataEntity[] assoc in _assocciations)
     {
         if (inSource == assoc[0])
         {
             if (inAssociate == assoc[1])
             {
                 _assocciations.Remove(assoc);
                 AssociateEntities();
                 return;
             }
         }
         else if (inSource == assoc[1])
         {
             if (inAssociate == assoc[0])
             {
                 _assocciations.Remove(assoc);
                 AssociateEntities();
                 return;
             }
         }
     }
 }
示例#12
0
        public void Transfer_OnClick(object sender, EventArgs e)
        {
            List <string> properties = new List <string>();

            if (_currentEntities != null && _currentEntities.Count > 0)
            {
                ToolStripItem item = sender as ToolStripItem;

                if (item.Text.StartsWith("All sel"))
                {
                    string props = item.Text.Substring(item.Text.IndexOf("(") + 1);
                    props = props.Substring(0, props.Length - 1);

                    properties = new List <string>(props.Split(','));
                }
                else
                {
                    properties.Add(item.Text);
                }

                List <DataEntity> changedEntities = new List <DataEntity>();

                foreach (DataEntity entity in _currentEntities)
                {
                    if (entity.AssociatedEntity != null)
                    {
                        foreach (string currentProp in properties)
                        {
                            if (_comp.Comparisons[entity][entity.AssociatedEntity][currentProp] < 1.0)
                            {
                                if (transfer(entity, currentProp) && !changedEntities.Contains(entity.AssociatedEntity))
                                {
                                    changedEntities.Add(entity.AssociatedEntity);
                                }
                            }
                            else
                            {
                                Logger.Log(string.Format("No need to transfer \"{0}.{1}\" on \"{2}\" already equals", entity.Id, currentProp, entity.AssociatedEntity.Id), LogSeverities.Log);
                            }
                        }
                    }
                }

                if (changedEntities.Count > 0)
                {
                    foreach (DataEntity entity in changedEntities)
                    {
                        entity.CreateProperties();
                    }

                    _comp.Compare();
                    RefreshGrid();
                }
            }
            else if (_currentEntity != null)
            {
                ToolStripItem item    = sender as ToolStripItem;
                bool          changed = false;
                foreach (string currentProp in properties)
                {
                    if (transfer(_currentEntity, currentProp))
                    {
                        changed = true;
                    }
                }

                if (changed)
                {
                    _currentEntity.AssociatedEntity.CreateProperties();
                    _comp.Compare();
                    RefreshGrid();
                }

                _currentEntity = null;
            }
        }
示例#13
0
 public ComparisonScore(DataEntity leftEntity, DataEntity rightEntity, double score)
 {
     _leftEntity  = leftEntity;
     _rightEntity = rightEntity;
     _score       = score;
 }
 public virtual bool Transfer(DataEntity dataEntity)
 {
     return(false);
 }
示例#15
0
        public void LoadMappings(string inPath)
        {
            SaveAbleMapping mappping = new SaveAbleMapping();

            mappping.Load(inPath);
            mappping.Mappings.SyncDic();

            Dictionary <DataEntity, List <DataEntity> > assocs = new Dictionary <DataEntity, List <DataEntity> >();

            foreach (string key in mappping.Mappings.Keys)
            {
                string[] nameSplit  = key.Split('|');
                string   entityName = nameSplit[1];

                DataEntity entity = GetEntity(entityName, true);
                if (entity != null)
                {
                    string[] mappings = ((string)mappping.Mappings.GetValue(key)).Split(';');
                    foreach (string mapping in mappings)
                    {
                        string[]   nameSplit2  = mapping.Split('|');
                        string     entityName2 = nameSplit2[1];
                        DataEntity otherEntity = GetEntity(entityName2, false);
                        if (otherEntity != null)
                        {
                            if (assocs.ContainsKey(entity))
                            {
                                assocs[entity].Add(otherEntity);
                            }
                            else
                            {
                                List <DataEntity> entities = new List <DataEntity>();
                                entities.Add(otherEntity);
                                assocs.Add(entity, entities);
                            }
                        }
                    }
                }
            }

            foreach (DataEntity key in assocs.Keys)
            {
                List <DataEntity> newAssocs = assocs[key];
                List <DataEntity> oldAssocs = GetConfirmedAssociations(key);
                if (oldAssocs.Count > 0)
                {
                    foreach (DataEntity assocEntity in oldAssocs)
                    {
                        if (!newAssocs.Contains(assocEntity))
                        {
                            DeAssociate(key, assocEntity);
                        }
                    }
                }
                else
                {
                    if (newAssocs.Count == 1)
                    {
                        if (key.AssociatedEntity != newAssocs[0])
                        {
                            Associate(key, newAssocs[0]);
                        }
                    }
                    else
                    {
                        if (newAssocs.Count == 0)
                        {
                            if (key.AssociatedEntity != null)
                            {
                                key.DontAssociate = true;
                            }
                        }
                        else
                        {
                            foreach (DataEntity assocEntity in newAssocs)
                            {
                                if (!oldAssocs.Contains(assocEntity))
                                {
                                    Associate(key, assocEntity);
                                }
                            }
                        }
                    }
                }
            }

            AssociateEntities();
        }
示例#16
0
        private void ComparisonsDGV_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                System.Windows.Forms.DataGridView.HitTestInfo hit = ComparisonsDGV.HitTest(e.X, e.Y);

                if (hit.Type == DataGridViewHitTestType.Cell && hit.ColumnIndex != _left.Entities[0].Properties.Count)
                {
                    DataGridViewCell cell = ComparisonsDGV.Rows[hit.RowIndex].Cells[hit.ColumnIndex];

                    associateWithToolStripMenuItem.DropDownItems.Clear();
                    removeAssociationWithToolStripMenuItem.DropDownItems.Clear();
                    transferToolStripMenuItem.DropDownItems.Clear();

                    bool left = hit.ColumnIndex < _left.Entities[0].Properties.Count;
                    _currentEntity = _comp.GetEntity((string)ComparisonsDGV.Rows[hit.RowIndex].Cells[left ? 0 : _left.Entities[0].Properties.Count + 1].Value, left);
                    if (_currentEntity == null)
                    {
                        return;
                    }

                    List <string> entitiesList = new List <string>();
                    _currentEntities = new List <DataEntity>()
                    {
                        _currentEntity
                    };
                    string currentProperty = _left.Entities[0].Properties[left ? hit.ColumnIndex : (hit.ColumnIndex - 1 - _left.Entities[0].Properties.Count)].Name;
                    _currentProperties = new List <string>()
                    {
                        currentProperty
                    };

                    entitiesList.Add((string)_currentEntity.Properties[0].Value);

                    foreach (DataGridViewCell curCell in ComparisonsDGV.SelectedCells)
                    {
                        if ((left && curCell.ColumnIndex < _left.Entities[0].Properties.Count) || (!left && curCell.ColumnIndex > _left.Entities[0].Properties.Count))
                        {
                            DataEntity entity = _comp.GetEntity((string)ComparisonsDGV.Rows[curCell.RowIndex].Cells[left ? 0 : _left.Entities[0].Properties.Count + 1].Value, left);
                            if (!_currentEntities.Contains(entity))
                            {
                                _currentEntities.Add(entity);
                                entitiesList.Add((string)entity.Properties[0].Value);
                            }
                            string propName = _left.Entities[0].Properties[left ? curCell.ColumnIndex : (curCell.ColumnIndex - 1 - _left.Entities[0].Properties.Count)].Name;
                            if (!_currentProperties.Contains(propName))
                            {
                                _currentProperties.Add(propName);
                            }
                        }
                    }

                    Logger.Log(TypesHelper.Join(entitiesList) + " " + TypesHelper.Join(_currentProperties), LogSeverities.Info);

                    string[] confirmedAssocs = _comp.GetConfirmedAssociations(_currentEntity.Id, left);
                    foreach (string assoc in confirmedAssocs)
                    {
                        removeAssociationWithToolStripMenuItem.DropDownItems.Add(assoc, null, new EventHandler(DeAssociate_OnClick));
                    }

                    string[] assocs = _comp.GetPossibleAssociations(_currentEntity.Id, left);

                    foreach (string assoc in assocs)
                    {
                        associateWithToolStripMenuItem.DropDownItems.Add(assoc, null, new EventHandler(Associate_OnClick));
                    }

                    dontAssociateToolStripMenuItem.Checked = _currentEntity.DontAssociate;

                    toolStripMenuItem1.Visible        = false;
                    transferToolStripMenuItem.Visible = false;

                    DataEntity currentAssociatedEntity = _currentEntity.AssociatedEntity;

                    if (currentAssociatedEntity != null)
                    {
                        string[] transferables = _comp.GetTransferables(_currentEntity);

                        if (transferables.Length > 0)
                        {
                            bool canTransfer = false;

                            if (ArrayContains(transferables, currentProperty) && _comp.Comparisons[_currentEntity][currentAssociatedEntity][currentProperty] < 1.0)
                            {
                                transferToolStripMenuItem.DropDownItems.Add(currentProperty, null, new EventHandler(Transfer_OnClick));
                                transferToolStripMenuItem.DropDownItems.Add("-", null, null);
                                transferToolStripMenuItem.DropDownItems.Add("All sel. props (" + TypesHelper.Join(_currentProperties) + ")", null, new EventHandler(Transfer_OnClick));
                                transferToolStripMenuItem.DropDownItems.Add("-", null, null);
                                transferToolStripMenuItem.DropDownItems.Add("All", null, new EventHandler(TransferAll_OnClick));

                                canTransfer = true;
                            }
                            else
                            {
                                foreach (string transferable in transferables)
                                {
                                    foreach (DataEntity currentEntity in _currentEntities)
                                    {
                                        if (_comp.Comparisons[currentEntity][currentEntity.AssociatedEntity][transferable] < 1.0)
                                        {
                                            transferToolStripMenuItem.DropDownItems.Add("All sel. props (" + TypesHelper.Join(_currentProperties) + ")", null, new EventHandler(Transfer_OnClick));
                                            transferToolStripMenuItem.DropDownItems.Add("-", null, null);
                                            transferToolStripMenuItem.DropDownItems.Add("All", null, new EventHandler(TransferAll_OnClick));
                                            canTransfer = true;
                                            break;
                                        }
                                    }
                                    if (canTransfer)
                                    {
                                        break;
                                    }
                                }
                            }

                            if (canTransfer)
                            {
                                toolStripMenuItem1.Visible        = true;
                                transferToolStripMenuItem.Visible = true;
                            }
                        }
                    }

                    comparisonCtxt.Show(ComparisonsDGV.PointToScreen(new Point(e.X, e.Y)));
                }
            }
        }
 public void AddEntity(DataEntity inEntity)
 {
     _entities.Add(inEntity);
     inEntity.Comparable = this;
 }