示例#1
0
        private void BuildAllInterfaces()
        {
            FAASModel _context = new FAASModel();
            log.Log("Build bucket to bucket Interfaces - start");

            //get target id & unit for each relationship
            var f = (from r in _context.EntityRelationships
                     select new
                     {
                         RelationshipId = r.Id,
                         TargetEntityId = r.CalledEntityId,
                         SourceEntityId = r.CallingEntityId,
                         TargetUnit = (from t in _context.Entities
                                       where t.Id == r.CalledEntityId
                                       select new { t.NormalisedUnit }).FirstOrDefault(),
                         SourceUnit = (from t in _context.Entities
                                       where t.Id == r.CallingEntityId
                                       select new { t.NormalisedUnit }).FirstOrDefault()
                     });

            foreach (var a in f)
            {
                try
                {
                    if (a.SourceUnit.NormalisedUnit != a.TargetUnit.NormalisedUnit)
                    {
                        bool exists = CheckInterface(a.TargetEntityId, a.TargetUnit.NormalisedUnit, a.SourceEntityId);
                        if (!exists)
                        {
                            //create new interface
                            Interface newInterface = new Interface();
                            newInterface.TargetEntityId = a.TargetEntityId;
                            newInterface.TargetUnit = a.TargetUnit.NormalisedUnit.ToString();
                            newInterface.EntityRelationshipIds = a.RelationshipId.ToString();
                            //write processing output to same line
                            Console.Write("Creating interface for {0}          \r", newInterface.TargetUnit);
                            _interfaces.Add(newInterface);
                        }
                    }
                }
                catch (Exception e)
                {
                    log.Log(String.Format("Error: {0}", e));
                }
            }
            log.Log("Build bucket to bucket Interfaces - complete");
        }
示例#2
0
        public virtual void PopulateEntities()
        {
            FAASModel _context = new FAASModel();

            log.Log("Extract Entities to DB - start");
            try
            {
                foreach (Entity item in _entity)
                {
                    _context.Entities.Add(item);
                }
                _context.SaveChanges();
                log.Log("Extract Entities to DB - complete");
            }
            catch (Exception e)
            {
                log.Log(string.Format("Erorr extracting Entities to DB: {0}", e.Message));
            }
        }
示例#3
0
        private void BeginReferentialWeighting(ConsoleLog log)
        {
            log.Log("Assess entity residence - start");

            FAASModel _context = new FAASModel();
            _entities = _context.Entities.ToList();
            _internalInterfaces = _context.InternalInterfaces.ToList();
            _externalInterfaces = _context.Interfaces.ToList();

            foreach (Entity entity in _entities)
            {
                //write processing output to same line
                Console.Write("Assessing {0}            \r", entity.Name);

                EntityResidence entStr = new EntityResidence();
                entStr.EntityId = entity.Id;
                entStr.InternalWeight = GetStrength(entity, "internal");
                entStr.ExternalWeight = GetStrength(entity, "external");
                entStr.ExternalSources = InterfaceSources(entity, "external").Count;
                _entStr.Add(entStr);
            }
            log.Log("Assess entity residence - start");
        }
        private void BuildRuleRuleCalls(ConsoleLog log, string[] input)
        {
            log.Log("************** BUILD ******************");

            ClearTables();

            //write processing output to same line
            Console.Write("Preparing global data...");
            FAASModel _context = new FAASModel();
            _entities = _context.Entities.ToList();
            _ruleDefinitions = _context.RuleDefinitions.ToList();
            _tableDefinitions = _context.TableDefinitions.ToList();
            _triggers = _context.TriggerDefinitions.ToList();

            var uniqueRules = ListOfNames("rule");
            var uniqueTables = ListOfNames("TABLE");
            var uniqueTriggers = ListOfNames("TRIGGER");
            Console.WriteLine("done");

            //Get calls in rules to rules, screens, tables, reports, job cards, NEED TO ADD TRIGGERS
            GetRuleEntityCalls(_ruleDefinitions, uniqueRules, uniqueTables, uniqueTriggers, input);

            CreateMasterList();
            ConvertEntityCallsToInt();
            PopulateEntityRelationships();

            log.Log("************ BUILD END ****************");
        }
 private static List<string> ListOfNames(string type)
 {
     FAASModel _context = new FAASModel();
     //create entity (of object type) object
     var uniqueNames = (from e in _context.Entities
                               where e.Type.Equals(type)
                               select e.Name).Distinct().ToList();
     return uniqueNames;
 }
示例#6
0
        private void BuildInterfaceReporting(ConsoleLog log)
        {
            log.Log("Build Interface Reports - start");
            FAASModel _context = new FAASModel();
            _entities = _context.Entities.ToList();

            foreach (Interface i in _externalInterfaces)
            {
                _interfaceReports.Add(CreateExternalInterfaceReport(i, "external"));
            }
            foreach (InternalInterface i in _internalInterfaces)
            {
                _interfaceReports.Add(CreateInternalInterfaceReport(i, "internal"));
            }
            log.Log("Build Interface Reports - complete");
        }
示例#7
0
        private void UpdateUnmappedEntities()
        {
            FAASModel _context = new FAASModel();
            log.Log("Persist unmapped entity units to DB - start");
            _entities = _context.Entities.ToList();

            foreach (Entity entity in _entities)
            {
                if (entity.NormalisedUnit.ToString().Equals("N/A"))
                {
                    entity.NormalisedUnit = "LONELY";
                }
            }

            //need to persist to DB
            _context.SaveChanges();
            log.Log("Persist unmapped entity units to DB - complete");

            var count = (from x in _context.Entities
                         where x.NormalisedUnit == "LONELY"
                         select x).Count();

            log.Log(string.Format("{0} entities Unallocated", count));
        }
示例#8
0
        /// <summary>
        /// Get the distinct units that interface with the current entity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        private HashSet<string> InterfaceSources(Entity entity, string type)
        {
            FAASModel _context = new FAASModel();
            List<string> _units = new List<string>();
            List<int> _relationIds = new List<int>();
            List<int> _sourceIds = new List<int>();
            int value = 0;

            //get list of relIds for the interface
            if (type.Equals("external"))
            {
                foreach (Interface extInterface in _externalInterfaces)
                {
                    if (extInterface.TargetEntityId.Equals(entity.Id))
                    {
                        _relationIds = RetreiveIds(extInterface.EntityRelationshipIds.ToString());
                    }

                }
            }

            //get list of relIds for the interface
            else if (type.Equals("internal"))
            {
                foreach (InternalInterface intInterface in _internalInterfaces)
                {
                    if (intInterface.TargetEntityId.Equals(entity.Id))
                    {
                        _relationIds = RetreiveIds(intInterface.EntityRelationshipIds.ToString());
                    }

                }
            }
            //get the source (caller) id for each relationship
            //get unique source Unit ids
                foreach (int i in _relationIds)
                {
                    int d = (from q in _context.EntityRelationships
                             where q.Id == i
                             select q.CallingEntityId).SingleOrDefault();

                    foreach (Entity e in _entities)
                    {
                        if (d.Equals(e.Id))
                        {
                            _units.Add(e.NormalisedUnit);
                        }
                    }
                }

                var uniqueUnits = new HashSet<string>(_units);
                value = uniqueUnits.Count;

                return uniqueUnits;
        }
示例#9
0
        private void AddInternalEntityLinks()
        {
            FAASModel _context = new FAASModel();

            var f = (from r in _context.EntityRelationships
                     select new
                     {
                         RelationshipId = r.Id,
                         TargetEntityId = r.CalledEntityId,
                         SourceEntityId = r.CallingEntityId,
                         TargetUnit = (from t in _context.Entities
                                       where t.Id == r.CalledEntityId
                                       select new { t.NormalisedUnit }).FirstOrDefault(),
                         SourceUnit = (from t in _context.Entities
                                       where t.Id == r.CallingEntityId
                                       select new { t.NormalisedUnit }).FirstOrDefault()
                     });

            foreach (var a in f)
            {
                //add check to see: does reverse (target, source) relationship exist?
                var loopbackExist = (from m in _entityRels
                                     where m.CalledEntityId == a.SourceEntityId
                                     && m.CallingEntityId == a.TargetEntityId
                                     select m);

                //build internal bucket links and nodes
                if (a.SourceUnit.NormalisedUnit == a.TargetUnit.NormalisedUnit)
                {
                    string unit = a.SourceUnit.NormalisedUnit.ToString();

                    if (a.SourceEntityId != a.TargetEntityId)
                    {

                        var ent1 = (from m in _entities
                                    where m.Id == a.SourceEntityId
                                    select m).FirstOrDefault();
                        Entity x = (Entity)ent1;
                        Node source = AddNode(x);

                        var ent2 = (from m in _entities
                                    where m.Id == a.TargetEntityId
                                    select m).FirstOrDefault();
                        Entity xx = (Entity)ent2;
                        Node target = AddNode(xx);

                        //deal with links that exist also in reverse (a calls b, b calls a)
                        if (loopbackExist.Any())
                        {
                            //check if either link exists as tree
                            var link = (from m in _entityTreeLinks
                                        where m.Source == a.SourceEntityId
                                        && m.Target == a.TargetEntityId
                                        select m);
                            var loopLink = (from m in _entityTreeLinks
                                            where m.Target == a.SourceEntityId
                                            && m.Source == a.TargetEntityId
                                            select m);

                            var targetExists = (from n in _entityTreeLinks
                                                where n.Target.Equals(a.TargetEntityId)
                                                select n);
                            //if either exist as tree, add non-tree link
                            if (link.Any() || loopLink.Any())
                            {
                                //add this to a list of links to check later on - may need to add orphans to buckets
                                AddNonTreeLink(source, target);
                            }
                            else
                            {
                                _linksToCheck.Add(AddTreeLink(source, target));
                            }

                        }
                        else if (!loopbackExist.Any())
                        {
                            //does a relative call my target?
                            if (CheckForParent(source, target))
                            {
                                AddNonTreeLink(source, target);
                            }
                            else
                            {
                                AddLinkCheck(source, target);
                                bool exists = CheckParent(a.TargetEntityId, a.TargetUnit, a.SourceEntityId);
                                if (!exists)
                                {
                                    AddLink(GetBucketNode(source), source);
                                }
                            }
                        }

                    }
                }
            }
        }
示例#10
0
        public void StartGraph(ConsoleLog log)
        {
            //instatiate and populate global variables
            entityNodeCount = 0;
            entityLinkCount = 0;
            FAASModel _context = new FAASModel();
            _entities = _context.Entities.ToList();
            _entityRels = _context.EntityRelationships.ToList();
            _entityBuckets = _context.Buckets.ToList();

            //call main methods
            log.Log("Building entity level graph - start");
            AddArtificialNodesLinks();
            AddInternalEntityLinks();
            //call clean to add all current homeless nodes to their respective buckets - fix bug where they were being allocated to external buckets
            CleanLinks(log);
            AddExternalEntityLinks(log);
            CleanLinks(log);
            log.Log("Building entity level graph - complete");
            PrintGraph(log);
        }
 private void PopulateRules()
 {
     FAASModel _context = new FAASModel();
     log.Log("Persist Rule Definitions to DB - start");
     try
     {
         foreach (RuleDefinition item in _rules)
         {
             _context.RuleDefinitions.Add(item);
         }
         _context.SaveChanges();
         log.Log("Persist Rule Definitions to DB - complete");
     }
     catch (Exception e)
     {
         log.Log(string.Format("Error persisting Rule Definitions to DB: {0}", e.Message));
     }
 }
        private void PopulateTables()
        {
            FAASModel _context = new FAASModel();


            log.Log("Persist Table Definitions to DB - start");
            try
            {
                foreach (TableDefinition item in _tables)
                //Parallel.ForEach(_tables, item =>
                {
                    _context.TableDefinitions.Add(item);

                }
                //   );
                _context.SaveChanges();
                log.Log("Persist Table Definitions to DB - complete");
            }
            catch (Exception e)
            {
                log.Log(string.Format("Error persisting Table Definitions to DB: {0}: ", e.Message));
            }
        }
        private void PopulateTriggers()
        {
            FAASModel _context = new FAASModel();

            log.Log("Persist Triggers to DB - start");
            try
            {
                foreach (TriggerDefinition item in _triggers)
                {
                    _context.TriggerDefinitions.Add(item);
                    _context.SaveChanges();
                }
                log.Log("Persist Triggers to DB - complete");
            }
            catch (Exception e)
            {
                log.Log(string.Format("Error persisting Triggers Definitions to DB: {0}: ", e.Message));
            }
        }
示例#14
0
        private void PopulateInterfaceReporting(ConsoleLog log)
        {
            FAASModel _context = new FAASModel();

            log.Log("Persist Interface Reports to DB - start");
            try
            {
                foreach (InterfaceReporting item in _interfaceReports)
                {
                    _context.InterfaceReportings.Add(item);
                }
                _context.SaveChanges();
                log.Log("Persist Interface Reports to DB - complete");
                log.Log(string.Format("{0} Interfaces assessed", _interfaceReports.Count));
            }
            catch (Exception e)
            {
                log.Log(string.Format("Error persisting Interface Reports to DB: {0}: ", e.Message));
            }
        }
示例#15
0
        private void PopulateEntityResidence(ConsoleLog log)
        {
            FAASModel _context = new FAASModel();

            log.Log("Persist entity ownership strength to DB - start");
            try
            {
                foreach (EntityResidence item in _entStr)
                {
                    _context.EntityResidences.Add(item);
                }
                _context.SaveChanges();
                log.Log("Persist entity ownership strength to DB - complete");
                log.Log(string.Format("{0} entities assessed", _entities.Count));
            }
            catch (Exception e)
            {
                log.Log(string.Format("Error persisting entity ownership strength to DB: {0}: ", e.Message));
            }
        }
示例#16
0
        private void PopulateBucketConnections(ConsoleLog log)
        {
            FAASModel _context = new FAASModel();

            log.Log("Persist Bucket Connections to DB - start");
            try
            {
                foreach (BucketConnection item in _bucketConnections)
                {
                    _context.BucketConnections.Add(item);
                }
                _context.SaveChanges();
                log.Log("Persist Bucket Connections to DB - complete");
                log.Log(string.Format("{0} bucket to bucket connections assessed", _bucketConnections.Count));
            }
            catch (Exception e)
            {
                log.Log(string.Format("Error persisting Bucket Connections to DB: {0}: ", e.Message));
            }
        }
 private void ConvertEntityCallsToInt()
 {
     try
     {
         FAASModel _context = new FAASModel();
         log.Log("Converting entity link names into ID's & populating table - start");
         //Parallel.ForEach(_links, link =>
         foreach (Link link in _links)
         {
             int a = (from qq in _entities
                      where qq.Name.Equals(link.CallingEnt)
                      select qq.Id).FirstOrDefault();
             int b = (from qq in _entities
                      where qq.Name.Equals(link.CalledEnt)
                      select qq.Id).FirstOrDefault();
             EntityRelationship rel = new EntityRelationship();
             rel.CallingEntityId = a;
             rel.CalledEntityId = b;
             _entityRelations.Add(rel);
         }
         log.Log("Converting entity link names into ID's & populating table - complete");
     }
     catch (Exception e)
     {
         log.Log(string.Format("Error converting link names to link ID's: {0}", e.Message));
         log.Log(string.Format("ERROR: {0}", e.Message));
     }
 }
        public void ClearTable(string table)
        {
            FAASModel _context = new FAASModel();

            try
            {
                _context.Database.ExecuteSqlCommand(string.Format("truncate table {0}", table));
                _context.SaveChanges();

                log.Log(string.Format("{0} table cleared", table));
            }

            catch (Exception e)
            {
                log.Log(string.Format("Error clearing {0} table in DB: {1}", table, e.Message));

            }
        }
 private void PopulateEntityRelationships()
 {
     FAASModel _context = new FAASModel();
     log.Log("Persist Entity Relationship to DB - start");
     try
     {
     foreach (EntityRelationship item in _entityRelations)
     {
         _context.EntityRelationships.Add(item);
     }
     _context.SaveChanges();
     log.Log("Persist Entity Relationship to DB - complete");
     log.Log(string.Format("{0} entity relationships created", _entityRelations.Count()));
     }
     catch (Exception e)
     {
     log.Log(string.Format("Error persisting Entity Relationship to DB: {0}", e.Message));
     }
 }
示例#20
0
        /// <summary>
        /// Check for existing interface - if exists add current relationship and return true
        /// </summary>
        /// <param name="targetId"></param>
        /// <param name="targetUnit"></param>
        /// <param name="sourceId"></param>
        /// <returns></returns>
        private bool CheckInterface(int targetId, object targetUnit, int sourceId)
        {
            FAASModel _context = new FAASModel();
            bool exists = false;

            foreach (Interface item in _interfaces)
            {
                if (item.TargetEntityId.Equals(targetId) && item.TargetUnit.Equals(targetUnit))
                {
                    //Add relationship to interface - hoping this doesnt malform the list of interface objects...
                    item.EntityRelationshipIds = item.EntityRelationshipIds + "," + sourceId.ToString();
                    exists = true;
                }
            }
            return exists;
        }
示例#21
0
        private void AddExternalEntityLinks(ConsoleLog log)
        {
            log.Log("Building entity level graph external links - start");

            FAASModel _context = new FAASModel();

            var f = (from r in _context.EntityRelationships
                     select new
                     {
                         RelationshipId = r.Id,
                         TargetEntityId = r.CalledEntityId,
                         SourceEntityId = r.CallingEntityId,
                         TargetUnit = (from t in _context.Entities
                                       where t.Id == r.CalledEntityId
                                       select new { t.NormalisedUnit }).FirstOrDefault(),
                         SourceUnit = (from t in _context.Entities
                                       where t.Id == r.CallingEntityId
                                       select new { t.NormalisedUnit }).FirstOrDefault()
                     });
            //46364 error

            foreach (var a in f)
            {
                //add check to see: does reverse (target, source) relationship exist?
                var loopbackExist = (from m in _entityRels
                                     where m.CalledEntityId == a.SourceEntityId
                                     && m.CallingEntityId == a.TargetEntityId
                                     select m);

                //build external (bucket to bucket) links
                if (a.SourceUnit.NormalisedUnit != a.TargetUnit.NormalisedUnit)
                {
                    var ent1 = (from m in _entities
                                where m.Id == a.SourceEntityId
                                select m).FirstOrDefault();
                    Entity x = (Entity)ent1;
                    //get node or add if doesnt exist
                    Node source = GetNode(ent1);

                    var ent2 = (from m in _entities
                                where m.Id == a.TargetEntityId
                                select m).FirstOrDefault();
                    Entity xx = (Entity)ent2;
                    //get node or add if doesnt exist
                    Node target = GetNode(ent2);

                        AddLink(source, target);
                }
            }
            log.Log("Building entity level graph external links - complete");
        }
示例#22
0
        private void PopulateInterfaces()
        {
            FAASModel _context = new FAASModel();

            log.Log("Persits Interfaces to DB - start");
            try
            {
                foreach (Interface item in _interfaces)
                {
                    _context.Interfaces.Add(item);
                }
                _context.SaveChanges();
                log.Log("Persist Interfaces to DB - complete");
                log.Log(string.Format("{0} interfaces created", _interfaces.Count()));
            }
            catch (Exception e)
            {
                log.Log(string.Format("Error persisting Intefaces to DB: {0}: ", e.Message));
            }
        }
示例#23
0
        private bool CheckParent(int targetId, object targetUnit, int sourceId)
        {
            FAASModel _context = new FAASModel();
            bool exists = false;

            //check if current source is called anywhere (is it an orphan?)
            foreach (EntityRelationship item in _entityRels)
            {
                if (item.CalledEntityId.Equals(sourceId))
                {
                    exists = true;
                }
            }
            return exists;
        }
示例#24
0
        /// <summary>
        /// Returns number of source entities that call the supplied entity (based on internal or external interfaces)
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private int GetStrength(Entity entity, string type)
        {
            FAASModel _context = new FAASModel();
            List<int> nums = new List<int>();
            int value = 0;

            if (type.Equals("external"))
            {
                foreach (Interface extInterface in _externalInterfaces)
                {
                    if (extInterface.TargetEntityId.Equals(entity.Id))
                    {
                        nums = RetreiveIds(extInterface.EntityRelationshipIds.ToString());
                    }

                }
            }

            if (type.Equals("internal"))
            {
                foreach (InternalInterface intInterface in _internalInterfaces)
                {
                    if (intInterface.TargetEntityId.Equals(entity.Id))
                    {
                        nums = RetreiveIds(intInterface.EntityRelationshipIds.ToString());
                    }

                }
            }

            value = nums.Count;
            return value;
        }
示例#25
0
        private void PopulateBuckets()
        {
            FAASModel _context = new FAASModel();

            log.Log("Persits Buckets to DB - start");
            try
            {
                foreach (Bucket item in _buckets)
                {
                    _context.Buckets.Add(item);

                }
                _context.SaveChanges();
                log.Log("Persist Buckets to DB - complete");
                log.Log(string.Format("{0} buckets created", _buckets.Count()));
            }
            catch (Exception e)
            {
                log.Log(string.Format("Error persisting Buckets to DB: {0}: ", e.Message));
            }
        }
示例#26
0
 private bool RePopulatePackageList()
 {
     log.Log(String.Format("Repopulating Package Definitions from Database."));
     FAASModel _repopulateContext = new FAASModel();
     _packages.Clear();
     _packages = _repopulateContext.PackageDefinitions.ToList();
     log.Log(string.Format("Repopulation of Package Definitions from Database complete."));
     return true;
 }
示例#27
0
        private void UpdateMappedEntities()
        {
            FAASModel _context = new FAASModel();
            log.Log("Persist mapped entity units to DB - start");
            _entities = _context.Entities.ToList();

            foreach (EntityMap mappedEntity in _mappedEntities)
            {

                foreach (Entity entity in _entities)
                {
                    foreach (string type in _types)
                    {
                        if (mappedEntity.Name.Equals(entity.Name) && mappedEntity.Type.Equals(type))
                        {
                            entity.NormalisedUnit = mappedEntity.NormalisedUnit;
                        }
                    }
                }
            }
            _context.SaveChanges();
            log.Log("Persist mapped entity units to DB - complete");

            var count = (from x in _context.Entities
                         where x.NormalisedUnit != "N/A"
                         && x.NormalisedUnit != "LONELY"
                         select x).Count();

            log.Log(string.Format("{0} entities Normalised", count));
        }
示例#28
0
 private void PopulatePackages()
 {
     FAASModel _context = new FAASModel();
     log.Log("Persist Package Definitions to DB - start");
     try
     {
         foreach (PackageDefinition item in _packages)
         {
             _context.PackageDefinitions.Add(item);
         }
         _context.SaveChanges();
         log.Log("Persist Package Definitions to DB - complete");
     }
     catch (DbEntityValidationException e)
     {
         log.Log(string.Format("Error persisting Package Definitions to DB: {0}", e.Message));
         foreach (var validationErrors in e.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             }
         }
     }
 }
示例#29
0
        private void PopulateFunctions()
        {
            FAASModel _context = new FAASModel();
            log.Log("Persist Function Definitions to DB - start");
            try
            {
                foreach (FunctionDefinition item in _functions)
                {
                    _context.FunctionDefinitions.Add(item);
                }
                _context.SaveChanges();
                log.Log("Persist Function Definitions to DB - complete");
            }
            catch (DbEntityValidationException e)
            {
                log.Log(string.Format("Error persisting Function Definitions to DB: {0}", e.Message));
                foreach (var eve in e.EntityValidationErrors)
                {
                    log.Log(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validations errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var xxx in eve.ValidationErrors)
                    {
                        log.Log(string.Format(" - Property: \"{0}\", Error: \"{1}\"", xxx.PropertyName, xxx.ErrorMessage));
                    }
                }

            }
        }
示例#30
0
        private void BuildBucketReporting(ConsoleLog log)
        {
            FAASModel _context = new FAASModel();
            _buckets = _context.Buckets.ToList();

            foreach (Bucket bucket in _buckets)
            {
                _bucketReports.Add(CreateBucketReport(bucket));
            }
        }