示例#1
0
        public IActionResult Query(ConfigQuery request)
        {
            var result = _configRepository.GetEntity(request);

            if (!request.UpdateTime.HasValue || result.UpdateTime > request.UpdateTime)
            {
                return(Json(result));
            }
            return(Json());
        }
示例#2
0
        public void SendConfiguration(ConfigurationParams parameters, string queryId, IConfigurationCallback callbacks, double timeoutMs)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (callbacks == null)
            {
                throw new ArgumentNullException("callbacks");
            }

            if (timeoutMs <= 0)
            {
                throw new ArgumentException("timeout");
            }

            if (string.IsNullOrEmpty(queryId))
            {
                throw new ArgumentException("queryId");
            }

            ConfigurationRequest request = new ConfigurationRequest(parameters, queryId);
            ConfigurationTimer   timer   = new ConfigurationTimer(timeoutMs, request);
            ConfigQuery          query   = new ConfigQuery(request, callbacks, timer);

            lock (this.awaitingResponses)
            {
                this.awaitingResponses.Add(queryId, query);
                timer.AutoReset = false;
                timer.Elapsed  += new ElapsedEventHandler(this.OnTimedEvent);
                timer.Start();
            }

            this.sender.SendMessage(this.serializer.Serialize(request));
        }
示例#3
0
        public static int Main(String[] args)
        {
            System.Configuration.Web.Assembly a = null;  // BUGBUG: need this so that System.Configuration.Objects.dll is found
            a = new System.Configuration.Web.Assembly(); // get rid of the warning...

            Boolean bFullPropertyMeta  = false;
            Boolean bShowPropertyNames = true;

            IConfigCollection props      = null;
            IConfigCollection collection = null;
            IConfigCollection propmeta   = null;

            String configtype = "AppDomain";
            String url        = "file://" + new LocalMachineSelector().Argument;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].StartsWith("/") || args[i].StartsWith("-"))
                {
                    String arg = args[i].Substring(1).ToLower();

                    if ("?" == arg)
                    {
                        Console.WriteLine("Usage: mtest [<configtype>] [<prefix>:<selector>] [/nometa] [/meta] [/?]");
                        Console.WriteLine("  <configtype>        - the config type for which data is to be shown. Default: AppDomain");
                        Console.WriteLine("  <prefix>:<selector> - a selector string, i.e. file://c:\\foo.cfg. Default: <machinecfgdir>\\config.cfg");
                        Console.WriteLine("  :                   - use no selector at all.");
                        Console.WriteLine("  /nometa             - don't show property names, only values");
                        Console.WriteLine("  /meta               - show all schema information for each property");
                        return(0);
                    }
                    if ("meta" == arg)
                    {
                        bFullPropertyMeta = true;
                    }
                    if ("nometa" == arg)
                    {
                        bShowPropertyNames = false;
                        bFullPropertyMeta  = false;
                    }
                }
                else if (args[i].IndexOf(':') < 0)
                {
                    configtype = args[i];
                }
                else
                {
                    if (args[i].Equals(":"))
                    {
                        url = "";
                    }
                    else
                    {
                        url = args[i];
                    }
                }
            }

/*
 *  // strongly typed version...
 *              IISProcessModel pm = (IISProcessModel) ConfigManager.GetItem("iisprocessmodel", "file://c:\\urt\\config\\src\\test\\xsp\\config.web", 0);
 *
 *              Console.WriteLine(pm.enable);
 *              Console.WriteLine(pm.timeout);
 *              Console.WriteLine(pm.idletimeout);
 *              Console.WriteLine(pm.shutdowntimeout);
 *              Console.WriteLine(pm.requestlimit);
 *              Console.WriteLine(pm.memorylimit);
 *              Console.WriteLine(pm.cpumask);
 *              Console.WriteLine(pm.usecpuaffinity);
 */

            // Read the data
            collection = ConfigManager.Get(configtype, url, 0);

            if (bShowPropertyNames)
            {
                // Read the schema: to be able to show the property names
                ConfigQuery q = new ConfigQuery("select * from Property where Table=" + ConfigSchema.ConfigTypeSchema(configtype).InternalName);

                props = ConfigManager.Get("Property", q, 0);

                // Read the meta schema for properties: to be able to show the names of the schema information
                if (bFullPropertyMeta)
                {
                    ConfigQuery qmetameta = new ConfigQuery("select * from Property where Table=COLUMNMETA");
                    //qmetameta.Add(0, QueryCellOp.Equal, "COLUMNMETA");
                    propmeta = ConfigManager.Get("Property", qmetameta, 0);
                }
            }

            for (int k = 0; k < collection.Count; k++)
            {
                IConfigItem item = collection[k];
                if (bFullPropertyMeta)
                {
                    // Write the type of each item
                    Console.WriteLine("Type: " + item.ToString());
                }
                for (int i = 0; i < item.Count; i++)
                {
                    if (bShowPropertyNames)
                    {
                        // Write the property name
                        Console.Write(props[i]["PublicName"] + ": ");
                    }

                    // Write the property value
                    Console.WriteLine(item[i]);

                    if (bFullPropertyMeta)
                    {
                        // Write the schema information for the property
                        Console.WriteLine("[");
                        for (int j = 0; j < props[i].Count; j++)
                        {
                            // Write the name of the meta property
                            Console.Write("    " + propmeta[j]["PublicName"]);

                            // Write the value of the meta property
                            Console.Write("=" + props[i][j]);
                            Console.WriteLine();
                        }
                        Console.WriteLine("]");
                    }
                }
            }

            return(0);
        }
示例#4
0
 public void SaveConfig(ConfigDto config)
 {
     var query = new ConfigQuery();
     _configQueryHandler.CreateOrUpdateValueById<ConfigDto>(query, config);
 }
示例#5
0
 public ConfigDto GetConfig()
 {
     var query = new ConfigQuery();
     return _configQueryHandler.GetValueById(query);
 }
示例#6
0
        public Object Read(String configType, Selector selector, int los, Object currentObject)
        {
            Selector    url   = null;
            ConfigQuery query = null;
            Object      val   = null;

            IConfigCollection result = null;
            IConfigItem       node   = null;


            if (selector is ConfigQuery && ((ConfigQuery)selector).Count > 0)
            {
                query = (ConfigQuery)selector;
                url   = query.Selector;
            }
            else
            {
                if (selector is NullSelector)
                {
                    url = null;
                }
                else
                {
                    url = selector;
                }
                query = null;
            }
            if (url != null && !(url is HttpSelector) && !(url is WebServiceSelector))
            {
                throw new ConfigException("Invalid Selector");
            }
            switch (configType)
            {
            case ctNodes:
                // LogicalName, PhysicalName, Parent, NodeType
                // Q by ParentName==NULL: "IISWebService" entry (LogicalName = ?)
                // Q by "IISWebService" LogicalName: all IIS web sites
                // Q by LogicalName: UNC from URL - site binding
                // NodeType: IIS6!
                // PhysicalName: UNC from URL (MB)

                if (query != null)
                {
                    if (query.Count > 1)
                    {
                        throw new ConfigException("Can't query by more than one property");
                    }
                    val = query[0].Value;
                }

                if ((query != null && query[0].PropertyIndex == 2) || url == null) // Query by Parent?
                {
                    if (val == null || (val is String && ((String)val) == String.Empty))
                    {
                        // return IISWebService node
                        result = ConfigManager.GetEmptyConfigCollection(configType);
                        node   = ConfigManager.GetEmptyConfigItem(configType);
                        WebServiceSelector ws = new WebServiceSelector();
                        node["LogicalName"]  = ws.ToString();
                        node["PhysicalName"] = new WebServiceSelector().Argument;
                        node["Parent"]       = "";
                        node["RelativeName"] = ".NET Web Service";
                        node["NodeType"]     = nodetypeWebService;
                        result.Add(node);
                        return(result);
                    }
                    if (val is String)
                    {
                        if ((String)val == new WebServiceSelector().ToString())
                        {
                            // return all sites
                            result = ConfigManager.GetEmptyConfigCollection(configType);
                            node   = ConfigManager.GetEmptyConfigItem(configType);
                            // BUGBUG really enumerate the metabase
                            node["LogicalName"]  = "http://localhost";
                            node["PhysicalName"] = IISAdminHelper.GetPathForUrl((String)node["LogicalName"]);
                            node["Parent"]       = new WebServiceSelector().ToString();
                            node["RelativeName"] = node["LogicalName"];
                            node["NodeType"]     = nodetypeWebServer;
                            result.Add(node);
                            return(result);
                        }
                        // read children from metabase
                        String[] children = IISAdminHelper.GetChildrenForUrl((String)val);

                        result = ConfigManager.GetEmptyConfigCollection(configType);
                        foreach (String child in children)
                        {
                            node = ConfigManager.GetEmptyConfigItem(configType);
                            // BUGBUG really enumerate the metabase
                            node["Parent"]       = (String)val;
                            node["LogicalName"]  = ((String)val) + "/" + child;
                            node["PhysicalName"] = IISAdminHelper.GetPathForUrl((String)node["LogicalName"]);
                            node["RelativeName"] = child;
                            node["NodeType"]     = nodetypeWebDirectory;
                            result.Add(node);
                        }
                        return(result);
                    }
                    throw new ConfigException("Invalid query for UINavigationNodes.Parent!");
                }

                if ((query == null && url != null) || (query != null && query[0].PropertyIndex == 0)) // Query by LogicalName?
                {
                    if (query == null)
                    {
                        val = url.ToString();
                    }
                    if (!(val is String) || ((String)val) == String.Empty)
                    {
                        throw new ConfigException("Invalid Query for UINavigationNode.LogicalName!");
                    }

                    WebServiceSelector ws = new WebServiceSelector();
                    if ((String)val == ws.ToString())
                    {
                        // return IISWebService node
                        result = ConfigManager.GetEmptyConfigCollection(configType);
                        node   = ConfigManager.GetEmptyConfigItem(configType);
                        node["LogicalName"]  = ws.ToString();
                        node["PhysicalName"] = ws.Argument.Substring(0, ws.Argument.LastIndexOf('\\'));
                        node["Parent"]       = "";
                        node["RelativeName"] = "";
                        node["NodeType"]     = nodetypeWebService;
                        result.Add(node);
                        return(result);
                    }


                    result = ConfigManager.GetEmptyConfigCollection(configType);
                    node   = ConfigManager.GetEmptyConfigItem(configType);
                    node["LogicalName"]  = (String)val;
                    node["PhysicalName"] = IISAdminHelper.GetPathForUrl((String)val);
                    // BUGBUG compute only the immediate parent!
                    String[] parents = IISAdminHelper.GetParentUrlsForUrl((String)val);
                    if (parents.Length >= 2)
                    {
                        node["Parent"]       = parents[parents.Length - 2];
                        node["RelativeName"] = ((String)val).Substring(((String)val).LastIndexOf('/'));
                    }
                    else
                    {
                        node["Parent"]       = new WebServiceSelector().ToString();
                        node["RelativeName"] = node["LogicalName"];
                    }
                    node["NodeType"] = nodetypeWebDirectory;
                    result.Add(node);
                    return(result);
                }
                throw new ConfigException("Invalid Query for UINavigationNode.LogicalName!");
            //break;

// *******************************************************************************************************
            case ctConfigFileHierarchy:
                // LogicalName, ConfigFilePath, Location
                // Q by LogicalName=all config file for this node and it's parents

                if (query == null || query.Count == 0)
                {
                    if (url == null)
                    {
                        throw new ConfigException("Can't enumerate all nodes!");
                    }
                }
                if (query != null)
                {
                    if (query.Count > 1)
                    {
                        throw new ConfigException("Can't query by more than one property");
                    }
                    val = query[0].Value;
                }

                if ((query != null && query[0].PropertyIndex == 0) || (query == null && url != null)) // Query by LogicalName?
                {
                    if (query == null)
                    {
                        val = url.ToString();
                    }

                    if (val == null || (val is String && ((String)val) == String.Empty))
                    {
                        throw new ConfigException("Can't query for all root nodes.");
                    }
                    if (val is String)
                    {
                        result = ConfigManager.GetEmptyConfigCollection(configType);

                        node = ConfigManager.GetItem(ctNodes, url);
                        do
                        {
                            IConfigCollection files = ConfigManager.Get(ctFileLocation, (String)node["LogicalName"]);
                            foreach (IConfigItem file in files)
                            {
                                IConfigItem hierarchyfile = ConfigManager.GetEmptyConfigItem(configType);

                                hierarchyfile["LogicalName"]    = file["LogicalName"];
                                hierarchyfile["ConfigFilePath"] = file["ConfigFilePath"];
                                hierarchyfile["Location"]       = "";
                                result.Add(hierarchyfile);
                            }
                            if (node["Parent"] != "")
                            {
                                node = ConfigManager.GetItem(ctNodes, (String)node["Parent"]);
                            }
                            else
                            {
                                break;
                            }
                        } while (true);

                        return(result);
                    }
                    throw new ConfigException("Invalid query for " + ctConfigFileHierarchy + ".LogicalName!");
                }
                throw new ConfigException("Invalid Query for " + ctHierarchy + ".");

            //break;
            case ctFileLocation:
                // LogicalName, ConfigFilePath, Description
                IConfigCollection nodes = (IConfigCollection)Read(ctNodes, selector, los, currentObject);
                if (nodes.Count > 1)
                {
                    throw new ConfigException("More than one node for this URL!");
                }

                result = ConfigManager.GetEmptyConfigCollection(configType);
                if (nodes.Count == 1)
                {
                    node = ConfigManager.GetEmptyConfigItem(configType);
                    node["LogicalName"]    = nodes[0]["LogicalName"];
                    node["ConfigFilePath"] = ((String)nodes[0]["PhysicalName"]) + "\\config.web";
                    node["Description"]    = "";
                    result.Add(node);
                }
                return(result);

            default:
                throw new ConfigException("Invalid ConfigType");
            }
        }
示例#7
0
        public async Task <QueryResult <IDictionary <string, object> > > QueryConfigDynamic(
            ConfigQueryProjection projection,
            ConfigQueryOptions options,
            ConfigQueryFilter filter = null,
            ConfigQuerySort sort     = null,
            ConfigQueryPaging paging = null)
        {
            var conn     = context.Database.GetDbConnection();
            var openConn = conn.OpenAsync();
            var query    = ConfigQuery.CreateDynamicSql();

            #region General
            if (filter != null)
            {
                query = query.SqlFilter(filter);
            }
            query = query.SqlJoin(projection);
            DynamicSql countQuery = null; int?totalCount = null; Task <int> countTask = null;
            if (options.count_total)
            {
                countQuery = query.SqlCount("*");
            }
            query = query.SqlProjectFields(projection);
            #endregion
            await openConn;
            if (!options.single_only)
            {
                #region List query
                if (sort != null)
                {
                    query = query.SqlSort(sort);
                }
                if (paging != null && (!options.load_all || !ConfigQueryOptions.IsLoadAllAllowed))
                {
                    query = query.SqlSelectPage(paging.page, paging.limit);
                }
                #endregion
                #region Count query
                if (options.count_total)
                {
                    countTask = conn.ExecuteScalarAsync <int>(
                        sql: countQuery.PreparedForm,
                        param: countQuery.DynamicParameters);
                }
                #endregion
            }
            var queryResult = await conn.QueryAsync(
                sql : query.PreparedForm,
                types : query.GetTypesArr(),
                map : (objs) => ProcessMultiResults(query, objs),
                splitOn : string.Join(',', query.GetSplitOns()),
                param : query.DynamicParameters);

            if (options.single_only)
            {
                var single = queryResult.FirstOrDefault();
                if (single == null)
                {
                    return(null);
                }
                var singleResult = GetConfigDynamic(single, projection, options);
                return(new QueryResult <IDictionary <string, object> >()
                {
                    SingleResult = singleResult
                });
            }
            if (options.count_total)
            {
                totalCount = await countTask;
            }
            var result = GetConfigDynamic(queryResult, projection, options, totalCount);
            return(result);
        }