Exemplo n.º 1
0
        public void GetDataFromDisk()
        {
            CreateCollectionsIfNeeded();

            var directory = FileOperations.GetConnectionIntellisenseDataFolderPathEntities(this.ConnectionId);

            var directoryInfo = new DirectoryInfo(directory);

            if (directoryInfo.Exists)
            {
                var files = directoryInfo.GetFiles("*.xml");

                Parallel.ForEach(files, file =>
                {
                    var entityData = EntityIntellisenseData.Get(file.FullName);

                    if (entityData != null)
                    {
                        if (!this.Entities.ContainsKey(entityData.EntityLogicalName))
                        {
                            this.Entities.TryAdd(entityData.EntityLogicalName, entityData);
                        }
                        else
                        {
                            this.Entities[entityData.EntityLogicalName].MergeDataFromDisk(entityData);
                        }
                    }
                });
            }
        }
Exemplo n.º 2
0
        public static EntityIntellisenseData Get(string filePath)
        {
            EntityIntellisenseData result = null;

            if (File.Exists(filePath))
            {
                DataContractSerializer ser = new DataContractSerializer(typeof(EntityIntellisenseData));

                using (Mutex mutex = new Mutex(false, FileOperations.GetMutexName(filePath)))
                {
                    try
                    {
                        mutex.WaitOne();

                        using (var sr = File.OpenRead(filePath))
                        {
                            result = ser.ReadObject(sr) as EntityIntellisenseData;
                        }
                    }
                    catch (Exception ex)
                    {
                        DTEHelper.WriteExceptionToLog(ex);

                        FileOperations.CreateBackUpFile(filePath, ex);
                    }
                    finally
                    {
                        mutex.ReleaseMutex();
                    }
                }
            }

            return(result);
        }
        private static void AddReferencingEntities(HashSet <string> result, EntityIntellisenseData entityData, bool all)
        {
            if (entityData.ManyToManyRelationships != null)
            {
                foreach (var item in entityData.ManyToManyRelationships.Values.ToList())
                {
                    if (entityData.IsIntersectEntity)
                    {
                        if (!string.IsNullOrEmpty(item.Entity1Name))
                        {
                            result.Add(item.Entity1Name);
                        }

                        if (!string.IsNullOrEmpty(item.Entity2Name))
                        {
                            result.Add(item.Entity2Name);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(item.IntersectEntityName))
                        {
                            result.Add(item.IntersectEntityName);
                        }
                    }
                }
            }

            if (entityData.OneToManyRelationships != null)
            {
                foreach (var item in entityData.OneToManyRelationships.Values.ToList())
                {
                    if (!string.IsNullOrEmpty(item.ChildEntityName))
                    {
                        if (all || !IsCommonAttribute(item.ChildEntityAttributeName))
                        {
                            result.Add(item.ChildEntityName);
                        }
                    }
                }
            }
        }
        public void MergeDataFromDisk(EntityIntellisenseData entityData)
        {
            if (entityData == null)
            {
                return;
            }

            if (!this.MetadataId.HasValue &&
                entityData.MetadataId.HasValue)
            {
                this.MetadataId = entityData.MetadataId;
            }

            if (string.IsNullOrEmpty(this.EntityLogicalName) &&
                !string.IsNullOrEmpty(entityData.EntityLogicalName))
            {
                this.EntityLogicalName = entityData.EntityLogicalName;
            }

            if (!this.ObjectTypeCode.HasValue &&
                entityData.ObjectTypeCode.HasValue)
            {
                this.ObjectTypeCode = entityData.ObjectTypeCode;
            }

            if (string.IsNullOrEmpty(this.EntityPrimaryIdAttribute) &&
                !string.IsNullOrEmpty(entityData.EntityPrimaryIdAttribute))
            {
                this.EntityPrimaryIdAttribute = entityData.EntityPrimaryIdAttribute;
            }

            if (string.IsNullOrEmpty(this.EntityPrimaryNameAttribute) &&
                !string.IsNullOrEmpty(entityData.EntityPrimaryNameAttribute))
            {
                this.EntityPrimaryNameAttribute = entityData.EntityPrimaryNameAttribute;
            }

            if (this.DisplayName == null &&
                entityData.DisplayName != null)
            {
                this.DisplayName = entityData.DisplayName;
            }

            if (this.Description == null &&
                entityData.Description != null)
            {
                this.Description = entityData.Description;
            }

            if (this.DisplayCollectionName == null &&
                entityData.DisplayCollectionName != null)
            {
                this.DisplayCollectionName = entityData.DisplayCollectionName;
            }

            if (entityData.IsIntersectEntity)
            {
                this.IsIntersectEntity = entityData.IsIntersectEntity;
            }

            if (entityData.Attributes != null)
            {
                if (this.Attributes == null)
                {
                    this.Attributes = new ConcurrentDictionary <string, AttributeIntellisenseData>(StringComparer.InvariantCultureIgnoreCase);
                }

                foreach (var attr in entityData.Attributes.Values)
                {
                    if (!this.Attributes.ContainsKey(attr.LogicalName))
                    {
                        this.Attributes.TryAdd(attr.LogicalName, attr);
                    }
                    else
                    {
                        this.Attributes[attr.LogicalName].MergeDataFromDisk(attr);
                    }
                }
            }

            if (entityData.OneToManyRelationships != null)
            {
                if (this.OneToManyRelationships == null)
                {
                    this.OneToManyRelationships = new ConcurrentDictionary <string, OneToManyRelationshipIntellisenseData>(StringComparer.InvariantCultureIgnoreCase);
                }

                foreach (var item in entityData.OneToManyRelationships.Values)
                {
                    if (!this.OneToManyRelationships.ContainsKey(item.SchemaName))
                    {
                        this.OneToManyRelationships.TryAdd(item.SchemaName, item);
                    }
                    else
                    {
                        this.OneToManyRelationships[item.SchemaName].MergeDataFromDisk(item);
                    }
                }
            }

            if (entityData.ManyToOneRelationships != null)
            {
                if (this.ManyToOneRelationships == null)
                {
                    this.ManyToOneRelationships = new ConcurrentDictionary <string, ManyToOneRelationshipIntellisenseData>(StringComparer.InvariantCultureIgnoreCase);
                }

                foreach (var item in entityData.ManyToOneRelationships.Values)
                {
                    if (!this.ManyToOneRelationships.ContainsKey(item.SchemaName))
                    {
                        this.ManyToOneRelationships.TryAdd(item.SchemaName, item);
                    }
                    else
                    {
                        this.ManyToOneRelationships[item.SchemaName].MergeDataFromDisk(item);
                    }
                }
            }

            if (entityData.ManyToManyRelationships != null)
            {
                if (this.ManyToManyRelationships == null)
                {
                    this.ManyToManyRelationships = new ConcurrentDictionary <string, ManyToManyRelationshipIntellisenseData>(StringComparer.InvariantCultureIgnoreCase);
                }

                foreach (var item in entityData.ManyToManyRelationships.Values)
                {
                    if (!this.ManyToManyRelationships.ContainsKey(item.SchemaName))
                    {
                        this.ManyToManyRelationships.TryAdd(item.SchemaName, item);
                    }
                    else
                    {
                        this.ManyToManyRelationships[item.SchemaName].MergeDataFromDisk(item);
                    }
                }
            }

            if (entityData.Keys != null)
            {
                if (this.Keys == null)
                {
                    this.Keys = new ConcurrentDictionary <string, EntityKeyIntellisenseData>(StringComparer.InvariantCultureIgnoreCase);
                }

                foreach (var item in entityData.Keys.Values)
                {
                    if (!this.Keys.ContainsKey(item.LogicalName))
                    {
                        this.Keys.TryAdd(item.LogicalName, item);
                    }
                    else
                    {
                        this.Keys[item.LogicalName].MergeDataFromDisk(item);
                    }
                }
            }
        }