小编Sha*_*eKm的帖子

LINQ过去12个月

我怎么拉

最近12个(月)记录按ServiceId过滤,按最近排序

使用linq给出这个db表数据:

 - Date         ServiceId     Views     Clicks
 - 2009-03-01       3         88107     244223
 - 2009-03-01       5         41563     94770
 - 2009-03-01       7         24165     45378
 - 2009-03-01       8         16415     24311
 - 2009-03-01       4         50341     127114
 - 2009-04-01       3         70646     211999
 - 2009-04-01       5         40380     102241
 - 2009-04-01       7         23905     40768
 - 2009-04-01       8         18996     29220
 - 2009-04-01       4         45685     112635
 - 2009-05-01       3         81044     215753
 - 2009-05-01       5         46273     121343
 - 2009-05-01       7         25744     41578
 - 2009-05-01       8         21122     32607
 - 2009-05-01 …
Run Code Online (Sandbox Code Playgroud)

linq asp.net asp.net-mvc

4
推荐指数
1
解决办法
5062
查看次数

如何使用MVC 3将文本数据导出到csv?

我需要将文本数据导出到MVC3中的csv.我做以下事情:

视图:

$(".export").click(function() {
    $.get("@Url.Action("Export","Log")");
});
Run Code Online (Sandbox Code Playgroud)

控制器:

    public ActionResult Export()
    {
        var sb = new StringBuilder();

        var list = this.systemLogRepository.GetFilterList(
            null, this.ControllerContext.RequestContext.HttpContext.Request.QueryString, null);

        foreach (var item in list)
        {
            sb.AppendFormat(
                "{0},{1},{2},{3},{4}", item.Machine.Name, item.PackageID, item.ErrorDescription, item.OccurenceTime, Environment.NewLine);
        }

        return this.File(new UTF8Encoding().GetBytes(sb.ToString()), "text/csv", string.Format("Log-{0}.csv", DateTime.Now.ToString("g").Replace("/","-").Replace(":","_").Replace(" ", "-")));
    }
Run Code Online (Sandbox Code Playgroud)

这将返回内容,但不会弹出一个带有"另存为"和"打开"选项的窗口?谢谢

asp.net-mvc export-to-csv asp.net-mvc-3

4
推荐指数
1
解决办法
4848
查看次数

C#检查任务是否正在运行

我需要能够检查特定任务是否正在运行:

            Task.Run(() =>
                {
                    int counter = 720;
                    int sleepTime = 7000;
                    int operationId = 0;
                    Thread.CurrentThread.Name = "GetTasksStatusAsync";
......
Run Code Online (Sandbox Code Playgroud)

因此在我的代码中另一个类的某个地方,我需要检查“ GetTasksStatusAsync”是否正在运行。谢谢

.net asp.net c#-4.0 asp.net-mvc-4

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

MVC网站图片路径在发布版本中无效

在本地运行我的mvc网站(VS IIS)时,图像显示正确:

css片段:

.sprites {
    background: transparent url(../images/sprites.png) no-repeat 0 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,当站点发布到服务器或本地IIS(而不是VS IIS)时,图像无法加载(给出无效路径)

要在服务器上正确显示图像的唯一方法是修改CSS文件和代替"../images/sprites.png""/content/images/sprites.png"

这是为什么?

asp.net-mvc asp.net-mvc-4

4
推荐指数
1
解决办法
3909
查看次数

C#BinaryReader无法访问已关闭的文件

控制器:

private readonly Dictionary<string, Stream> streams;

        public ActionResult Upload(string qqfile, string id)
        {
            string filename;
            try
            {
                Stream stream = this.Request.InputStream;
                if (this.Request.Files.Count > 0)
                {
                    // IE
                    HttpPostedFileBase postedFile = this.Request.Files[0];
                    stream = postedFile.InputStream;
                }
                else
                {
                    stream = this.Request.InputStream;
                }

                filename = this.packageRepository.AddStream(stream, qqfile);
            }
            catch (Exception ex)
            {
                return this.Json(new { success = false, message = ex.Message }, "text/html");
            }

            return this.Json(new { success = true, qqfile, filename }, "text/html");
        }
Run Code Online (Sandbox Code Playgroud)

添加流的方法:

        public string AddStream(Stream stream, string …
Run Code Online (Sandbox Code Playgroud)

c# asp.net stream binarystream

4
推荐指数
1
解决办法
6061
查看次数

dotCover过滤器使用命令行

调用dotCover命令运行器传递几个过滤器的正确方法是什么?

我尝试过以下但是它只排除了第一个组件:

dotcover c /TargetExecutable="c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MsTest.exe" /TargetArguments="/testcontainer:c:\dev\SampleProject\UnitTests\bin\Debug\UnitTests.dll" /Output="c:\temp\Snapshot1.dcvr" /Filters="-:Assembly1, -:Assembly2"
Run Code Online (Sandbox Code Playgroud)

它会忽略任何东西,在过滤器标签.

c# dotcover resharper-8.0

4
推荐指数
1
解决办法
1262
查看次数

适用于.net Core的Amazon DynamoDb ORM

DynamoDB和.NET Core有快速,简单的ORM吗?我找到了PocoDynamo,但它与.net Core不兼容.

.net orm asp.net-core

4
推荐指数
1
解决办法
3026
查看次数

在 Minikube 中运行本地 docker 镜像

我已经为 Windows 和 minikube 设置了 Docker。此处列出的 (k8s.gcr.io/echoserver:1.10) 示例工作正常:https ://kubernetes.io/docs/setup/learning-environment/minikube/ 。

但是,当我在 c:\dev\helloworld 下创建简单的 .NET MVC 应用程序并尝试在 Minikube 中运行时,我得到状态:CrashLoopBackOff

环境:Windows 10 企业版

请帮忙。我需要设置什么才能完成这项工作? 你

docker minikube

4
推荐指数
1
解决办法
3283
查看次数

VS2019 Docker 支持和 Dockerfile 失败

VS2019,创建了一个全新的 mvc 应用程序,支持 Windows Docker。

Dockerfile 内容(从模板创建):

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build
WORKDIR /src
COPY ["mvc1.csproj", "mvc1/"]
RUN dotnet restore "mvc1/mvc1.csproj"
COPY . .
WORKDIR "/src/mvc1"
RUN dotnet build "mvc1.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "mvc1.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "mvc1.dll"]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

当我执行时:

docker build -t mvc1 .
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5): 错误:无法加载源https://api.nuget.org/v3/index.json的服务索引 。[C:\src\mvc1\mvc1.csproj] C:\Program Files\dotnet\sdk\2.2.401\NuGet.targets(123,5): …

.net c# docker dockerfile visual-studio-2019

4
推荐指数
1
解决办法
1758
查看次数

处置FileSystemWatcher

所以我的理解是,每当使用实现IDisposable的类时,它的父级也需要实现IDisposable接口。(使用FileSystemWatcher的FileWatcher)

因此,在使用FileSystemWatcher时,处置FileSystemWatcher的正确方法是什么?我希望在关闭应用程序之前不处理/(监视)FileWatcher。

我会使用“负责任的所有者模式”吗(尝试/最终)还是其他?我的FileWatcher是否也应该实现IDisposable?我将无法使用using {},因为此fileWatcher应该在应用程序整个运行过程中监视文件的更改。处理这种情况的正确方法是什么?

public class FileWatcher : IFileWatcher
{
    private FileSystemWatcher watcher;

    public event EventHandler<EventArgs> SettingsChanged;

    public FileWatcher(bool start)
    {
        this.RegisterForChanges();
    }

    public void OnChanged(object source, EventArgs e)
    {
        if (this.SettingsChanged != null)
        {
            this.SettingsChanged(source, new EventArgs());
        }
    }

    private void RegisterForChanges()
    {
        /// more code here etc
        ...
        this.watcher = new FileSystemWatcher
                           {
                               Path = directory, 
                               NotifyFilter =
                                   NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                   | NotifyFilters.FileName | NotifyFilters.DirectoryName, 
                               Filter = fileName
                           };

        // Add event handlers.
        this.watcher.Changed += this.OnChanged;

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

.net c# filesystemwatcher .net-4.5

3
推荐指数
1
解决办法
5546
查看次数