小编Ωme*_*Man的帖子

Powershell - 运行外部 powershell 脚本并捕获输出 - 无法传递参数

我在从另一个 powershell 脚本中运行 powershell 脚本、传递参数和捕获输出时遇到问题。我曾尝试使用与号运算符,通过调用它powershell.exe -Command但似乎没有任何效果。

似乎有效的是使用固定参数和存储在这样的变量中的值C:\path\to\script.ps1 -arg1 $value
如果没有其他方法,这可能会提供一个解决方案,但我想运行与此类似的命令& $pathToScript $params 2>&12>&1用于捕获错误输出以及标准)。


有时构造只打印脚本的路径,
有时它会说Cannot run file in the middle of pipeline
有时它会抱怨它找不到提到的脚本文件(我有时在我的路径中有空格,但我认为引用它就足够了:引用是这样完成的$path = "`"C:\path\with space\to\script.ps1`"")。

这是我想在以下情况下使用的简化函数:

Function captureScriptOutput
{
    #the function receives the script path and parameters
    param($path, $params)
    
    #this works if no params are passed, but I need params!
    $output = & $path $params 2>&1 | Out-String
}
Run Code Online (Sandbox Code Playgroud)

powershell ampersand

5
推荐指数
1
解决办法
1万
查看次数

How to position and center text in PDFsharp?

I need the "Job Setup Sheet" centered under the Heading. How should that be done?

Here is what I tried:

// Create an empty page
PdfPage page = document.AddPage();
page.Size = PageSize.Letter;
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);

//XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode,
                                                PdfFontEmbedding.Always);

// Create a font
XFont HeadingFont = new XFont("Times New Roman", 20, XFontStyle.Bold);
XFont BodyFont = new XFont("Times New Roman", 12);
// Draw the text
gfx.DrawString("Texas Exterior Systems", HeadingFont, XBrushes.Black,
  new …
Run Code Online (Sandbox Code Playgroud)

c# pdfsharp

5
推荐指数
1
解决办法
8046
查看次数

C#Runspace Powershell(交互式)

我正在尝试使用C#在运行空间中执行带有参数的Powershell文件.不幸的是我得到以下输出:

public string ExecuteCommandDirect(int psId, string psMaster, string psFile)
{
    String FullPsFilePath = @"C:\CloudPS\" + psFile + ".ps1";

    String PsParameters = FullPsFilePath + " -psId " + psId + " -psMaster " + psMaster + " -NonInteractive";

    // Create Powershell Runspace
    Runspace runspace = RunspaceFactory.CreateRunspace();

    runspace.Open();

    // Create pipeline and add commands
    Pipeline pipeline = runspace.CreatePipeline();
    pipeline.Commands.AddScript(PsParameters);

    // Execute Script
    Collection<PSObject> results = new Collection<PSObject>();
    try
    {
        results = pipeline.Invoke();
    }
    catch (Exception ex)
    {
        results.Add(new PSObject((object)ex.Message));
    }

    // Close …
Run Code Online (Sandbox Code Playgroud)

c# powershell runspace

5
推荐指数
2
解决办法
1万
查看次数

正则表达式减慢了程序

我正在尝试创建一个程序来解析游戏聊天记录中的数据.到目前为止,我已经设法让程序工作并解析我想要的数据,但问题是程序变慢了.

目前解析一个10MB的文本文件需要5秒钟,如果我将RegexOptions.Compiled添加到我的正则表达式,我注意到它下降到3秒.

我相信我已经在我的正则表达式匹配中找到了问题.由于5个正则表达式,当前读取了一行5次,因此当我稍后添加更多时,程序会变得更慢.

我应该怎么做才能使我的程序不会因多个正则表达式而减速?所有建议,使代码更好的表示赞赏!

if (sender.Equals(ButtonParse))
        {
            var totalShots = 0f;
            var totalHits = 0f;
            var misses = 0;
            var crits = 0;

            var regDmg = new Regex(@"(?<=\bSystem\b.* You inflicted )\d+.\d", RegexOptions.Compiled);
            var regMiss = new Regex(@"(?<=\bSystem\b.* Target evaded attack)", RegexOptions.Compiled);
            var regCrit = new Regex(@"(?<=\bSystem\b.* Critical hit - additional damage)", RegexOptions.Compiled);
            var regHeal = new Regex(@"(?<=\bSystem\b.* You healed yourself )\d+.\d", RegexOptions.Compiled);
            var regDmgrec = new Regex(@"(?<=\bSystem\b.* You take )\d+.\d", RegexOptions.Compiled);

            var dmgList = new List<float>(); //New list for damage …
Run Code Online (Sandbox Code Playgroud)

c# regex parsing

5
推荐指数
1
解决办法
163
查看次数

为什么在Visual Studio中具有正向后视的正则表达式会导致每隔第二个匹配被替换?

给定以下正则表达式正则表达式(从我实际上想使用的正则表达式简化):

(?<=\s|\n)(".*?")
Run Code Online (Sandbox Code Playgroud)

和以下替换表达式:

_T($1)
Run Code Online (Sandbox Code Playgroud)

Visual Studio 2013将找到每个匹配的字符串,但是在替换时,将替换与后续匹配相对应的字符串,因此将替换第二个字符串。

此外,Replace All它不起作用,并说它找不到任何匹配的文本(即使a Find All会找到相关的字符串)。

这是Visual Studio中的错误,还是我做错了什么?


演示

在此处输入图片说明

regex replace visual-studio

5
推荐指数
1
解决办法
424
查看次数

编译器警告CS0067:从不使用该事件

我有一个我正在使用的事件,所以我真的不明白这个警告的真正含义.有人可以澄清吗?

public abstract class Actor<T> : Visual<T> where T : ActorDescription
{
    #region Events
    /// <summary>
    /// Event occurs when the actor is dead
    /// </summary>
    public event Action Dead;
    #endregion

/// <summary>
    /// Take damage if the actor hasn't taken damage within a time limit
    /// </summary>
    /// <param name="damage">amount of damage</param>
    public void TakeDamage(int damage)
    {
        if (damage > 0 && Time.time > m_LastHitTimer + m_DamageHitDelay)
        {
            m_CurrentHealth -= damage;

            if (m_CurrentHealth <= 0)
            {
                m_CurrentHealth = 0; …
Run Code Online (Sandbox Code Playgroud)

c# events

5
推荐指数
1
解决办法
4794
查看次数

使用ViewModel中的多个变量绑定WPF控件可见性

我正在编写一个WPF用户控件,它显示一个包含多个页面的动态生成的TabControl,每个页面依次包含一个动态生成的控件列表(TextBox,Checkbox等).

我想根据用户是否有权查看它们来设置TextBox,CheckBox控件的可见性.此权限是每个控件ViewModel('VisiblyBy')上的值的组合,也是整个UserControl ViewModel('UserRole')的属性的组合.我刚刚开始使用WPF,但标准方法似乎是使用ValueConvertor - 但我不明白我如何编写一个可以组合/访问不同属性(VisiblyBy和UserRole)的方法,因为它们存在于不同的级别在我的ViewModel文件中.

这是我绑定到ViewModel的XAML的一部分:

<TabControl ItemsSource="{Binding VariableData.Pages}" SelectedIndex="0">
<!-- this is the header template-->
   <TabControl.ItemTemplate>
  <DataTemplate>
     <TextBlock Text="{Binding Title}" FontWeight="Bold"/>
  </DataTemplate>
</TabControl.ItemTemplate>
            
<!-- this is the tab content template-->
   <TabControl.ContentTemplate>
  <DataTemplate>
     <StackPanel>
        <ListBox  Grid.IsSharedSizeScope="True" 
                  ItemsSource="{Binding Variables}"
                  ItemTemplateSelector="{StaticResource templateSelector}">
        </ListBox>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
           <Button Content="Cancel" />
               <Button Content="Submit" 
                       Command="{Binding DataContext.CommitChangesCommand, 
                                   RelativeSource={RelativeSource FindAncestor, 
                                   AncestorType={x:Type TabControl}}}" />
        </StackPanel>
    </StackPanel>
</DataTemplate>
  </TabControl.ContentTemplate>
</TabControl>
Run Code Online (Sandbox Code Playgroud)

我还需要扩展控制未来可见性的变量数量,因为它还取决于使用它的应用程序的位置.

c# wpf xaml

5
推荐指数
1
解决办法
7868
查看次数

如何隐藏项目?

我有一个大型 VS 解决方案,但我只处理两个不同的项目,但需要加载所有项目才能进行构建。

是否可以只查看我感兴趣的项目而不更改解决方案的结构以进行构建?

如果不可能,但有解决方法吗?

visual-studio visual-studio-2013

5
推荐指数
2
解决办法
3727
查看次数

替换最后一个特定字符串

我有一个这样的字符串:

string myText = "abc def ghi 123 abc def ghi 123 abc def";
Run Code Online (Sandbox Code Playgroud)

我只想abc用空替换最后一个。

这是我的代码:

string pattern2 = "([abc])$";
string replacement2 = "";
Regex regEx = new Regex(pattern2);
var b = Regex.Replace(regEx.Replace(myText, replacement2), @"\s", " ");
Run Code Online (Sandbox Code Playgroud)

它不能正常工作,那么如何才能做到呢?

c# regex

5
推荐指数
0
解决办法
1859
查看次数

Azure APIM无法从Function App创建API

当我尝试通过使用API​​M在APIM中创建API时Create from Function App,我填写了字段并单击Create。该操作会提供等待点,并在五秒钟后返回并说

无法创建API。请稍后再试。

我可以创建一个空白的API,但是不能从现有的功能应用程序中创建一个。我尝试了多种组合,没有产品,所有产品,没有版本,版本..etc。没运气。

有什么想法吗?


在此处输入图片说明


笔记

  • 有问题的功能是HTTP触发器。
  • 该功能在我的开发盒和Azure中本地工作。
  • APIM Tier是开发人员
  • 在该Function应用程序上,我报告了在Visual Studio中发布期间,尝试在发布失败之前管理应用程序设置并尝试添加新设置会导致Visual Studio意外关闭。 不知道是否在“发布相关”上管理应用程序设置

azure-api-management

5
推荐指数
2
解决办法
625
查看次数