输入文件:
column1;column2;column3
data1a;data2a;data3a
data1b;data2b;data3b
Run Code Online (Sandbox Code Playgroud)
目标:输出带有重新排序列的文件,比方说
column1;column3;column2
...
Run Code Online (Sandbox Code Playgroud)
更新问题:使用PowerShell解决此问题的好方法是什么.我知道存在与CSV相关的cmdlet,但这些都有局限性.请注意,不需要更改记录的顺序,因此不需要将整个输入/输出文件加载到内存中.
我试图完成这项工作并进行了许多google/stackoverflow搜索而根本没有运气.
我有一个简单的模型:
public class MovieModel
{
public string Id { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器中的方法:
// POST: api/Movies
public IHttpActionResult Post([FromBody]MovieModel movieModel)
{
if (ModelState.IsValid)
{
//Code
}
}
Run Code Online (Sandbox Code Playgroud)
一个测试方法(是一个集成测试,但在单元测试中会发生同样的情况):
[TestMethod]
public void MoviesController_Post_Without_Name()
{
// Arrange
var model = new MovieModel();
model.Name = "";
// Act
var result = controller.Post(model);
// Assert
Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult));
Assert.AreEqual(6, controller.Get().Count());
}
Run Code Online (Sandbox Code Playgroud)
尽管模型显然无效,但它总是将IsValid属性评估为true.
到目前为止,我尝试了许多方法但没有成
我已经将WebApi项目升级到.net core 2.2,从那时起,我的所有控制器都从每个GET调用中提取415不支持的媒体类型。这非常奇怪,因为根据我的经验,415通常是为POST保留的。
如果我降级到2.1,问题就消失了。我已经在控制器设置和基本的启动配置下面发布了代码。
[Route("v1/[controller]")]
[Produces("application/json")]
[Consumes("application/json")]
[Authorize]
public class JobsController : ControllerBase
{
[HttpGet]
public IActionResult GetJobSummaryByUserId([FromQuery] PagedJobRequest pagedJobRequest)
{
if (pagedJobRequest.UserId == Guid.Empty)
{
pagedJobRequest.UserId = _jwtUtility.GetIdentityId();
}
if (!_jwtUtility.DoesJwtIdentityIdMatch(pagedJobRequest.UserId) && !_jwtUtility.IsUserInRole("Administrator"))
{
return Unauthorized();
}
var returnObj = _jobsService.GetJobSummariesByUserId(pagedJobRequest);
return Ok(returnObj);
}
}
Run Code Online (Sandbox Code Playgroud)
在Startup.cs中:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddCors(x => x.AddPolicy("MVRCors", y => y.AllowCredentials().AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));
services.AddEntityFrameworkSqlServer();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(s =>
{
s.SwaggerEndpoint("/swagger/v1/swagger.json", "MVR.Api.Jobs"); …
Run Code Online (Sandbox Code Playgroud) 我对 GTM 完全感到困惑,我将它实现到我的网站上以触发一些事件来处理流量等...大约 2 天我看到了以下错误:
Error from the trackerPageView => TypeError: window.gtag is not a function
at _app.js:1
at _app.js:1
at commons.c57c1be722ad069a7405.js:1
at Array.map (<anonymous>)
at Object.emit (commons.c57c1be722ad069a7405.js:1)
at commons.c57c1be722ad069a7405.js:1
Run Code Online (Sandbox Code Playgroud)
我没有看到任何关于这个问题的文档,所以我发了一篇文章来集中有关这个问题的信息。
我的配置是一个 webApp(nextjs、Reactjs、typeScript、redux),希望这会有所帮助。
_document.tsx:
import Document, { Head, Main, NextScript } from "next/document";
import { GA_TRACKING_ID } from "../lib/gtag";
import { Fragment } from "react";
export default class MyDocument extends Document {
setGoogleTags() {
return {
__html: `
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${GA_TRACKING_ID}');
`,
};
}
render() { …
Run Code Online (Sandbox Code Playgroud) 我正在制定验证文件的流程,以确保它们符合公司标准.其中一个步骤是确保Word文档不使用未经批准的字体.
我有以下代码存根,它有效:
Dim wordApplication As Word.ApplicationClass = New Word.ApplicationClass()
Dim wordDocument As Word.Document = Nothing
Dim fontList As New List(Of String)()
Try
wordDocument = wordApplication.Documents.Open(FileName:="document Path")
'I've also tried using a for loop with an integer counter, no change in speed'
For Each c As Word.Range In wordDocument.Characters
If Not fontList.Contains(c.Font.Name) Then
fontList.Add(c.Font.Name)
End If
Next
Run Code Online (Sandbox Code Playgroud)
但这非常慢!令人难以置信的慢= 2500字符/分钟(我用StopWatch计时).我的大多数文件大约是6000字/ 30,000个字符(约25页).但有一些文件在100页的页面中......
有更快的方法吗?我必须支持Office 2003格式文件,因此Open XML SDK不是一个选项.
--UPDATE--
我尝试将其作为Word宏运行(使用@ http://word.tips.net/Pages/T001522_Creating_a_Document_Font_List.html中找到的代码),它运行得更快(一分钟内).不幸的是,出于我的目的,我不相信宏会起作用.
--UPDATE#2--
我接受了Chris的建议并将文档转换为Open XML格式.然后我使用以下代码查找所有RunFonts对象并读取字体名称:
Using docP As WordprocessingDocument = WordprocessingDocument.Open(tmpPath, False)
Dim …
Run Code Online (Sandbox Code Playgroud) 我在RSS提要中添加了标题,标题链接和说明.但无法将图像添加为RSS源的一部分.
请指导我如何在标记中包含图像并将其显示在RSS源中.
此致,古拉夫
Tooltip
当鼠标进入特定控件时,是否可以使用光标移动或类似的东西?
我试过TextBlock
,但Margin
财产不起作用.
private TextBlock tooltip = new TextBlock();
private void imgRoom_MouseEnter(object sender, MouseEventArgs e)
{
Point position = e.GetPosition((IInputElement)sender);
tooltip.Visibility = System.Windows.Visibility.Visible;
tooltip.Margin = new Thickness(position.X, position.Y, 0, 0);
tooltip.Width = 100;
tooltip.Height = 100;
tooltip.Background = new SolidColorBrush(Colors.Red);
}
private void imgRoom_MouseMove(object sender, MouseEventArgs e)
{
Point position = e.GetPosition((IInputElement)sender);
tooltip.Margin = new Thickness(position.X, position.Y, 0, 0);
}
Run Code Online (Sandbox Code Playgroud) 你能否在T-SQL的case语句中引发错误?我总是遇到SQL case语句的问题:/
begin try
declare @i int
--set @i = (select COUNT(1) from table_name)
select Item_Num =
CASE (select COUNT(1) from table_name)
when 1 then (select Item_Num from table_name)
when 0 then (raiserror('No records in database', 0, 0))
ELSE (raiserror('Multiple records in database', 0, 0))
END
from table_name
end try
begin catch
declare @errormsg nvarchar(1024),
@severity int,
@errorstate int;
select @errormsg = error_message(),
@severity = error_severity(),
@errorstate = error_state();
raiserror(@errormsg, @severity, @errorstate);
end catch
Run Code Online (Sandbox Code Playgroud) 用pip安装wxpython报错ModuleNotFoundError: No module named \'attrdict\'
py -3.10-64 -m pip install -U wxpython
\nCollecting wxpython\n Using cached wxPython-4.2.0.tar.gz (71.0 MB)\n Preparing metadata (setup.py) ... error\n error: subprocess-exited-with-error\n\n \xc3\x97 python setup.py egg_info did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [8 lines of output]\n Traceback (most recent call last):\n File "<string>", line 2, in <module>\n File "<pip-setuptools-caller>", line 34, in <module>\n File "C:\\Users\\Bernard\\AppData\\Local\\Temp\\pip-install-dokcizpt\\wxpython_662eefb4314c47eba7b194b4d07a8e18\\setup.py", line 27, in <module>\n from buildtools.config import Config, msg, opj, runcmd, canGetSOName, getSOName\n …
Run Code Online (Sandbox Code Playgroud) 给出以下 API
public class PagedRequest
{
[Required, Range(1, 100, ErrorMessage = "Limit must be from 1 to 100.")]
public int Top { get; set; }
[Required, Range(0, int.MaxValue, ErrorMessage = "Skip must be 0 or greater.")]
public int Skip { get; set; }
}
[Route("test")]
[HttpGet]
public ActionResult<BarResponse> GetFoos([FromQuery] PagedRequest request)
{
if (!ModelState.IsValid) return BadRequest(ModelState);
// Return 200 OK with data here
}
Run Code Online (Sandbox Code Playgroud)
按预期工作:
没有按预期工作
笔记:
c# ×4
.net-core ×1
asp.net-core ×1
case ×1
csv ×1
cursor ×1
modelstate ×1
ms-word ×1
next.js ×1
onmousemove ×1
pip ×1
powershell ×1
python ×1
raiserror ×1
reactjs ×1
rss ×1
t-sql ×1
testing ×1
tooltip ×1
typescript ×1
vb.net ×1
wpf ×1
wxpython ×1