zoukankan      html  css  js  c++  java
  • Cloudservie将LocalStroage中的内容通过WAD自动上传到BLOB中

    开发云服务程序,如果使用Local stroage存储我们临时生成的日志或者文件并将它们自动上传到BLOB中,可以通过WAD来实现,具体如下:

    1.配置webrole,开启Local stroage功能:

    2.修改wadcfgx文件,添加DataSources属性:

    3.添加上传到local storage的代码:

    Index.cshtml

    @{
        ViewBag.Title = "Home Page";
    }
    <div class="jumbotron">
        <h1>ASP.NET</h1>
        <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
        <p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
    </div>
    <div class="row">
        <div class="col-md-12">
            @using (Html.BeginForm("UploadZipFile", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                <div class="form-group">
                    <label for="zipFile">Zip File</label>
                    <input type="file" id="zipFile" name="zipFile">
                </div>
                <button type="submit" class="btn btn-default">Submit</button>
            }
        </div>
    </div>

    对应的HomeController.cs实现如下:

            public ActionResult UploadZipFile(HttpPostedFileBase zipFile)
            {
                var localResource = RoleEnvironment.GetLocalResource("ZipFiles");
    
                // Save zip file.
                var localZipFilePath = Path.Combine(localResource.RootPath, zipFile.FileName);
                zipFile.SaveAs(localZipFilePath);
    
                // Extract zip file to a random folder.
                var localExtractedPath = Path.Combine(localResource.RootPath, Guid.NewGuid().ToString());
                Directory.CreateDirectory(localExtractedPath);
                System.IO.Compression.ZipFile.ExtractToDirectory(localZipFilePath, localExtractedPath);
    
                // Upload everything to blob storage.
                foreach (var file in Directory.GetFiles(localExtractedPath, "*", SearchOption.AllDirectories))
                {
                    // Upload to blob storage.
                }
    
                return RedirectToAction("Index");
            }

    获取Local Storege的路径是:var localResource = RoleEnvironment.GetLocalResource("ZipFiles");

    3.我在本地做了测试,通过代码上传到设置的Local Storage后,通过RDP登陆实例,会看到文件已经存在了,路径是C:ResourcesDirectory{部署ID}.WebRole1.ZipFiles

    4.一旦指定的Local Storage有了内容,对应的存储账号会生成容器wad-testcustom(这也是自己设置的名称),当日志自动上传成功后,会看到对应的存储账号容器中,上传了之前测试的文件:

    具体可以参考:http://blogs.msdn.com/b/davidhardin/archive/2011/03/31/configuring-diagnostics-wadcfg-to-capture-custom-log-files.aspx

    关于Local Storage,就算不勾选"Clean on role recycle",在节点故障转移的时候,如果有的日志还没有及时存到BLOB中,我们还是会丢掉它们,具体可以参考:

    http://justazure.com/microsoft-azure-cloud-services-part-3-service-package/

  • 相关阅读:
    Codeforces Round #313 (Div. 2) D. Equivalent Strings 解题心得
    UVA
    2015 HUAS Summer Contest#1~A
    2015 HUAS Summer Training#2~D
    2015 HUAS Summer Training#2~C
    2015 HUAS Summer Training#2~E
    2015 HUAS Summer Training#2~A
    2015 HUAS Provincial Select Contest #1
    2015 HUAS Provincial Select Contest #1~F
    2015 HUAS Provincial Select Contest #2~A
  • 原文地址:https://www.cnblogs.com/xiuj/p/4700171.html
Copyright © 2011-2022 走看看