Esempio n. 1
0
 /// <summary>
 /// Constructs a new <see cref="GlobalState"/> with the specified default cluster.
 /// </summary>
 public GlobalState WithCluster(ClusterSymbol cluster)
 {
     if (!this.Clusters.Contains(cluster))
     {
         var newClusters = new List <ClusterSymbol>(this.Clusters);
         newClusters.Add(cluster);
         return(With(cluster: cluster, clusters: newClusters));
     }
     else
     {
         return(With(cluster: cluster));
     }
 }
Esempio n. 2
0
        private ClusterGraphicObject(MapPoint mapPoint, IList <Graphic> cluster)
        {
            Geometry = mapPoint;
            Symbol   = new ClusterSymbol();

            SolidColorBrush fillColor = _GetFillColor(cluster);

            Attributes.Add(SymbologyContext.FILL_ATTRIBUTE_NAME, fillColor);

            _cluster = cluster;
            foreach (Graphic graphic in _cluster)
            {
                graphic.PropertyChanged += new PropertyChangedEventHandler(graphic_PropertyChanged);
            }

            _SelectIfNeeded();
        }
        /// <summary>
        /// Constructs a new <see cref="GlobalState"/> instance.
        /// </summary>
        private GlobalState(
            IReadOnlyList <ClusterSymbol> clusters,
            ClusterSymbol cluster,
            DatabaseSymbol database,
            IReadOnlyList <FunctionSymbol> functions,
            IReadOnlyList <FunctionSymbol> aggregates,
            IReadOnlyList <FunctionSymbol> plugins,
            IReadOnlyList <OperatorSymbol> operators,
            IReadOnlyList <CommandSymbol> commands,
            IReadOnlyList <ParameterSymbol> parameters,
            IReadOnlyList <OptionSymbol> options,
            KustoCache cache,
            Dictionary <Symbol, ClusterSymbol> reverseClusterMap,
            Dictionary <Symbol, DatabaseSymbol> reverseDatabaseMap,
            Dictionary <Symbol, TableSymbol> reverseTableMap,
            Dictionary <string, FunctionSymbol> functionsMap,
            Dictionary <string, FunctionSymbol> aggregatesMap,
            Dictionary <string, FunctionSymbol> pluginMap,
            Dictionary <OperatorKind, OperatorSymbol> operatorMap,
            Dictionary <string, CommandSymbol> commandMap,
            Dictionary <string, OptionSymbol> optionMap)
        {
            this.Clusters   = clusters ?? EmptyReadOnlyList <ClusterSymbol> .Instance;
            this.Cluster    = cluster ?? ClusterSymbol.Unknown;
            this.Database   = database ?? DatabaseSymbol.Unknown;
            this.Functions  = functions ?? EmptyReadOnlyList <FunctionSymbol> .Instance;
            this.Aggregates = aggregates ?? EmptyReadOnlyList <FunctionSymbol> .Instance;
            this.PlugIns    = plugins ?? EmptyReadOnlyList <FunctionSymbol> .Instance;
            this.Operators  = operators ?? EmptyReadOnlyList <OperatorSymbol> .Instance;
            this.Commands   = commands ?? EmptyReadOnlyList <CommandSymbol> .Instance;
            this.Parameters = parameters ?? EmptyReadOnlyList <ParameterSymbol> .Instance;
            this.Options    = options ?? EmptyReadOnlyList <OptionSymbol> .Instance;
            this.Cache      = cache != null?cache.WithGlobals(this) : null;

            this.reverseClusterMap  = reverseClusterMap;
            this.reverseDatabaseMap = reverseDatabaseMap;
            this.reverseTableMap    = reverseTableMap;
            this.functionsMap       = functionsMap;
            this.aggregatesMap      = aggregatesMap;
            this.pluginMap          = pluginMap;
            this.operatorMap        = operatorMap;
            this.commandMap         = commandMap;
            this.optionMap          = optionMap;
        }
        /// <summary>
        /// Creates a new <see cref="GlobalState"/> with the new cluster added or replacing an existing cluster with the same name.
        /// </summary>
        public GlobalState AddOrUpdateCluster(ClusterSymbol newCluster)
        {
            var clusterInList = this.Clusters.FirstOrDefault(c => c.Name == newCluster.Name);

            if (clusterInList == null)
            {
                // if it was not in the list add it
                return(this.WithClusterList(this.Clusters.Concat(new[] { newCluster }).ToList()));
            }
            else if (clusterInList == newCluster)
            {
                // this is the same cluster instance that is already in the list, so do nothing
                return(this);
            }
            else
            {
                // make a new list with the old cluster instance removed and the new instance added
                var newList    = this.Clusters.Select(c => c == clusterInList ? newCluster : c).ToArray();
                var newGlobals = this.WithClusterList(newList);

                // check to see if the current cluster was this cluster and update it too.
                if (this.Cluster == clusterInList)
                {
                    newGlobals = newGlobals.WithCluster(newCluster);
                }

                // check to see if the current database was a member of this cluster and if so, update it as well.
                var oldCurrentDatabase = clusterInList.Databases.FirstOrDefault(d => d == this.Database);
                if (oldCurrentDatabase != null)
                {
                    var newDatabase = newCluster.Databases.FirstOrDefault(d => d.Name == oldCurrentDatabase.Name);
                    if (newDatabase != null)
                    {
                        newGlobals = newGlobals.WithDatabase(newDatabase);
                    }
                }

                return(newGlobals);
            }
        }
 /// <summary>
 /// Constructs a new <see cref="GlobalState"/> with the specified default database.
 /// </summary>
 public GlobalState WithDatabase(DatabaseSymbol database)
 {
     if (this.Cluster != null && this.Cluster.Databases.Contains(database))
     {
         // same cluster, just change database
         return(With(database: database));
     }
     else
     {
         var existingCluster = GetCluster(database);
         if (existingCluster != null)
         {
             // changing the current database changes the current cluster too
             return(With(cluster: existingCluster, database: database));
         }
         else
         {
             // no existing cluster for this database, so make a new one
             var cluster = new ClusterSymbol(database.Name + ":cluster", database);
             return(WithCluster(cluster).With(database: database));
         }
     }
 }
        private DatabaseReference GetDatabaseReference(FunctionCallExpression fc, SyntaxNode location, ClusterSymbol defaultCluster)
        {
            if (fc.ReferencedSymbol == Functions.Database &&
                TryGetConstantStringArgumentValue(fc, 0, out var databaseName))
            {
                location = location ?? fc.ArgumentList.Expressions[0].Element;

                string cluster;

                // get cluster name from explicit cluster reference (if possible)
                if (!(fc.Parent is PathExpression p &&
                      p.Selector == fc &&
                      p.Expression is FunctionCallExpression fcCluster &&
                      fcCluster.ReferencedSymbol == Functions.Cluster &&
                      TryGetConstantStringArgumentValue(fcCluster, 0, out cluster)))
                {
                    // otherwise use the default cluster
                    cluster = defaultCluster.Name;
                }

                return(new DatabaseReference(databaseName, cluster, location.TextStart, location.Width));
            }

            return(null);
        }