Exemplo n.º 1
0
        private Dictionary <Type, List <Type> > TypeDependencies(StreamDirection direction)
        {
            var typeDependencies = new Dictionary <Type, List <Type> >();

            //Build up dictionary of new GSA schema types and keywords - to be used to construct dependencies based on these new types
            var layerSchemaDict     = layerKeywordTypes[Initialiser.AppResources.Settings.TargetLayer];
            var layerSchemaTypes    = layerSchemaDict.Keys;
            var layerSchemaKeywords = layerSchemaDict.Values;
            var layerKwDependencies = layerSchemaTypes.ToDictionary(t => layerSchemaDict[t],
                                                                    t => GsaRecord.GetReferencedKeywords(t).Where(kw => layerSchemaKeywords.Contains(kw)).ToList());

            foreach (var oldT in oldSchemaTypes)
            {
                var oldTKeyword = ((string)oldT.GetAttribute <GSAObject>("GSAKeyword")).Split('.').First();
                if (!string.IsNullOrEmpty(oldTKeyword) && !layerKwDependencies.Keys.Any(k => k.GetStringValue().Equals(oldTKeyword, StringComparison.InvariantCultureIgnoreCase)))
                {
                    continue;
                }

                if (!typeDependencies.ContainsKey(oldT))
                {
                    typeDependencies.Add(oldT, new List <Type>());
                }

                var attVal           = oldT.GetAttribute <GSAObject>(((direction == StreamDirection.Receive) ? "Write" : "Read") + "Prerequisite");
                var prereqs          = (attVal != null) ? ((Type[])attVal).ToList() : new List <Type>();
                var isAnalylsisLayer = (Initialiser.AppResources.Settings.TargetLayer == GSATargetLayer.Analysis);

                foreach (var tPrereq in prereqs)
                {
                    //Remove version for comparison with keyword enum
                    var kwPrereq = ((string)tPrereq.GetAttribute <GSAObject>("GSAKeyword")).Split('.').First();

                    if (layerKwDependencies.Keys.Any(k => k.GetStringValue().Equals(kwPrereq, StringComparison.InvariantCultureIgnoreCase)) ||
                        (tPrereq.Name.Contains("Result") && isAnalylsisLayer))
                    {
                        typeDependencies[oldT].Add(tPrereq);
                    }
                }
            }

            return(typeDependencies);
        }
Exemplo n.º 2
0
        private void GenerateLayerKeywords(IEnumerable <Type> relevantSchemaTypes)
        {
            //This dictionary should be independent of layer
            var keywordDependencies = relevantSchemaTypes.ToDictionary(t => GsaRecord.GetGwaKeyword(t), t => GsaRecord.GetReferencedKeywords(t));

            var implementedKwsByLayer = relevantSchemaTypes.ToDictionary(t => GsaRecord.GetGwaKeyword(t), t => TypeLayers(t));

            foreach (var kw in keywordDependencies.Keys)
            {
                foreach (var layer in new[] { GSATargetLayer.Design, GSATargetLayer.Analysis })
                {
                    if (implementedKwsByLayer[kw][layer])
                    {
                        if (!layerKeywords[layer].Contains(kw))
                        {
                            layerKeywords[layer].Add(kw);
                        }
                    }
                    if (keywordDependencies[kw] != null && keywordDependencies[kw].Length > 0)
                    {
                        foreach (var kwPrereq in keywordDependencies[kw])
                        {
                            //The attributes on the types are the container for knowing which layer a keyword is for.  For each referenced
                            //(i.e. prerequiste) keyword of a keyword, a corresponding type will need to be found in order to determine which
                            //layer that referenced keyword is on.
                            //However, at any point in time, there might not be a type created yet for that referenced keyword.  For these cases,
                            //assume that the referenced keyword is for both layers.

                            if (((implementedKwsByLayer.ContainsKey(kwPrereq) && implementedKwsByLayer[kwPrereq][layer]) || !implementedKwsByLayer.ContainsKey(kwPrereq)) &&
                                (!layerKeywords[layer].Contains(kwPrereq)))
                            {
                                layerKeywords[layer].Add(kwPrereq);
                            }
                        }
                    }
                }
            }
        }