Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何通过Powershell在应用程序结构上创建区域_.net_Caching_Powershell_Appfabric - Fatal编程技术网

.net 如何通过Powershell在应用程序结构上创建区域

.net 如何通过Powershell在应用程序结构上创建区域,.net,caching,powershell,appfabric,.net,Caching,Powershell,Appfabric,我想标题很清楚,我在网上冲浪大约一个小时,但每个页面都在谈论使用.net动态创建区域。我确信我们有一个命令要在powershell上执行。你知道吗 提前感谢,对于创建/管理区域,没有现成的Powershell commandlet 解决方案-写一个 正如Daniel Richnak在评论中所说,Powershell是一个隐藏的.NET,这意味着您可以编写额外的Powershell commandlets来填补空白 commandlet是从System.Management.Automation.

我想标题很清楚,我在网上冲浪大约一个小时,但每个页面都在谈论使用.net动态创建区域。我确信我们有一个命令要在powershell上执行。你知道吗


提前感谢,

对于创建/管理区域,没有现成的Powershell commandlet

解决方案-写一个

正如Daniel Richnak在评论中所说,Powershell是一个隐藏的.NET,这意味着您可以编写额外的Powershell commandlets来填补空白

commandlet是从
System.Management.Automation.Cmdlet
继承的一个常规类,它还用
System.Management.Automation.Cmdlet
属性修饰。然后,让它工作就是重写
ProcessRecord
方法。命令行参数作为类的属性实现,并用
System.Management.Automation.Parameter
属性修饰。因此,用于创建区域的commandlet类似于:

using System.Management.Automation;
using Microsoft.ApplicationServer.Caching;

[Cmdlet(VerbsCommon.New, "CacheRegion")]
public class NewCacheRegion : Cmdlet
{
    [Parameter(Mandatory = true, Position = 1)]
    public string Cache { get; set; }
    [Parameter(Mandatory = true, Position = 2)]
    public string Region { get; set; }

    protected override void ProcessRecord()
    {
        base.ProcessRecord();

        DataCacheFactory factory = new DataCacheFactory();
        DataCache cache = factory.GetCache(Cache);

        try
        {
            cache.CreateRegion(Region);
        }
        catch (DataCacheException ex)
        {
            if (ex.ErrorCode == DataCacheErrorCode.RegionAlreadyExists)
            {
                Console.WriteLine(string.Format("There is already a region named {0} in the cache {1}.", Region, Cache));
            }
        }
    }
}

没有现成的Powershell commandlet用于创建/管理区域

解决方案-写一个

正如Daniel Richnak在评论中所说,Powershell是一个隐藏的.NET,这意味着您可以编写额外的Powershell commandlets来填补空白

commandlet是从
System.Management.Automation.Cmdlet
继承的一个常规类,它还用
System.Management.Automation.Cmdlet
属性修饰。然后,让它工作就是重写
ProcessRecord
方法。命令行参数作为类的属性实现,并用
System.Management.Automation.Parameter
属性修饰。因此,用于创建区域的commandlet类似于:

using System.Management.Automation;
using Microsoft.ApplicationServer.Caching;

[Cmdlet(VerbsCommon.New, "CacheRegion")]
public class NewCacheRegion : Cmdlet
{
    [Parameter(Mandatory = true, Position = 1)]
    public string Cache { get; set; }
    [Parameter(Mandatory = true, Position = 2)]
    public string Region { get; set; }

    protected override void ProcessRecord()
    {
        base.ProcessRecord();

        DataCacheFactory factory = new DataCacheFactory();
        DataCache cache = factory.GetCache(Cache);

        try
        {
            cache.CreateRegion(Region);
        }
        catch (DataCacheException ex)
        {
            if (ex.ErrorCode == DataCacheErrorCode.RegionAlreadyExists)
            {
                Console.WriteLine(string.Format("There is already a region named {0} in the cache {1}.", Region, Cache));
            }
        }
    }
}

链接到.NET中的示例?PowerShell基于.NET,可以导入.NET名称空间,因此从C#示例进行此类转换通常很简单。相对于appfabric,区域是什么?从没听说过。appfabric缓存还是wcf托管?@x0n在.NET中的一个示例链接中有一个区域描述?PowerShell基于.NET,可以导入.NET名称空间,因此从C#示例进行此类转换通常很简单。相对于appfabric,区域是什么?从没听说过。appfabric缓存还是wcf托管?@x0n上有一个关于区域的描述,感谢您提供了非常详细的答案!谢谢你的详细回答!