我正在研究实现以下目标的最佳方法:
我有一堆CCTV录像文件(MP4文件,大小从4MB到50MB不等),我想通过门户网站提供这些文件.我的第一个想法是通过Web API流式传输文件,所以我找到了以下链接:
http://www.strathweb.com/2013/01/asynchronously-streaming-video-with-asp-net-web-api/
在实现示例项目之后,我意识到该示例基于Web API 1,而不是Web API 2.1,这就是我正在使用的.在做了一些研究之后,我得到了用WebAPI 2.1编译的代码.然后我意识到,如果我想做流媒体我不能使用MP4文件,这背后有相当多的技术细节,所以这是线程:
似乎这个工作我需要将我的MP4文件编码为像WebM这样的东西,但这需要花费太多时间.Icecast(http://icecast.org/),这是一个流媒体服务器,但我还没有尝试过,再次不确定这是否是我需要做的.
现在我想到了,我实际上不需要直播,我只需要允许客户端通过他们的浏览器播放视频文件,也许使用HTML5视频元素?问题是,我的应用程序也需要在IOS上工作,所以我认为这意味着我甚至无法将我的MP4编码为FLV并只使用闪存.
我真正需要的是将所有视频剪辑作为缩略图放在网页上,如果客户点击其中一个,它就会开始尽快播放,而不必下载整个文件.想想imdb.com上的"Watch Trailer"功能.只需播放视频文件,这就是我想要的.我不需要LIVE流媒体,这是我认为WebM的用途?再一次,不确定.
设计背景:
我正在尝试为以下数据库结构创建代码优先的EF6映射:
数据库设计如下:我们有一个CustomerRelationship表,其中包含CustomerID,然后是"RelatedID",而不是将"CustomerID"作为所有相关实体(就业,费用,收入等)的外键. "列将包含相关实体的密钥.例如,假设我为CustomerID = 1添加了一份就业记录,那么将发生以下情况:
在CustomerRelationship中创建记录,设置CustomerID = 1 RelatedID = {new autogenerated EmploymentID,假设5} CustomerRelationshipTypeID = 55(查找表中的Id表明此记录属于就业类型)
在就业表中创建记录(EmploymentID = 5)
上述结构适用于与客户关联的所有实体.
我有为就业工作的关系映射,这是我的课程:
public abstract class EntityBase : IEntity
{
#region IEntity Members
public int Id { get; set; }
public DateTime CreatedDate { get; set; }
public int CreatedUserId { get; set; }
public int CreatedSource { get; set; }
public DateTime ModifiedDate { get; set; }
public int ModifiedUserId { get; set; }
public int? DataMigrationId { get; …Run Code Online (Sandbox Code Playgroud) 我不能让它工作......我只是想改变一个全局定义的变量的值:
<xsl:variable name="isBusiness"></xsl:variable>
<xsl:choose>
<xsl:when test="yes this is a business">
<xsl:variable name="isBusiness">true</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="isBusiness">false</xsl:variable>
</xsl:otherwise>
</xsl:choose>
Run Code Online (Sandbox Code Playgroud)
显然代码是无效的,因为已经定义了,但是如何更改值呢?
我有以下统一构造方法:
public static IUnityContainer CreateContainer()
{
UnityContainer container = new UnityContainer();
container.LoadConfiguration();
.......
}
Run Code Online (Sandbox Code Playgroud)
然后是一个接口和一个实现类:
namespace MyCompany.Web.Areas.MyApp.Common
{
public interface ISession
{
}
}
namespace MyCompany.Web.Areas.MyApp.Common
{
public class SessionHandler : ISession
{
}
}
Run Code Online (Sandbox Code Playgroud)
而不是这样做:
Container.RegisterType<ISession, SessionHandler>(new ContainerControlledLifetimeManager()) ;
Run Code Online (Sandbox Code Playgroud)
我想使用container.LoadConfiguration()从web.config加载上面的RegisterType配置.但它似乎不起作用
web.config中:
<unity>
<containers>
<container>
<types>
<type type="MyCompany.Web.Areas.MyApp.Common.ISession" mapTo="MyCompany.Web.Areas.MyApp.Common.SessionHandler">
<lifetime type="singleton"/>
</type>
</types>
</container>
</containers>
</unity>
Run Code Online (Sandbox Code Playgroud)
例外:
无法解析类型名称或别名MyProject.Web.Areas.MyApp.Common.ISession.请检查配置文件并验证此类型名称.
描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息: System.InvalidOperationException:无法解析类型名称或别名MyProject.Web.Areas.MyApp.Common.ISession.请检查配置文件并验证此类型名称.
来源错误:
第33行:{第34行:UnityContainer容器=新的UnityContainer(); 第35行:container.LoadConfiguration(); 第36行:第37行://container.RegisterType(new ContainerControlledLifetimeManager());
堆栈跟踪:
[InvalidOperationException:无法解析类型名称或别名MyProject.Web.Areas.MyApp.Common.ISession.请检查您的配置文件并验证此类型名称.] e:\ Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration \中的Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolverImpl.ResolveType(String typeNameOrAlias,Boolean throwIfResolveFails) Src\ConfigurationHelpers\TypeResolverImpl.cs:110 Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolver.ResolveType(String typeNameOrAlias)在e:\ Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\ConfigurationHelpers\TypeResolver中. cs:47 …
我有一张有 4000 万条记录的表。我需要向该表添加一个新的 INT NOT NULL 列,默认值 = 0
使用以下内容添加此列时:
ALTER TABLE myTable ADD NewColumnID int NOT NULL CONSTRAINT DF_Constraint DEFAULT 0
Run Code Online (Sandbox Code Playgroud)
它将所有记录的 NewColumnID 设置为 0。在我们有 4000 万条记录的 prod 表上运行这个查询时,这需要很长时间吗?因为我知道执行以下操作需要很长时间:
UPDATE myTable SET NewColumnID = 0
Run Code Online (Sandbox Code Playgroud)
更新:2020 年 1 月 5 日:
自从我上次登录我的堆栈溢出帐户以来已经有一段时间了。我注意到我在 2013 年发布的这个特定问题。我收到了一些针对这个问题的糟糕代表,现在我明白了原因。我不得不通读好几遍才能理解我到底在问什么以及答案是如何适用的。看到它已被查看超过 6000 次,也许值得(7 年后,抱歉)提供更多背景信息。
请允许我澄清这个问题:
我在一家银行软件提供商工作。我们在世界各地有各种各样的客户,并且正在对我们的软件进行大规模更新,这需要将一个新列添加到我们软件使用的现有表中。根据银行的规模,这张特殊的桌子通常很大。要求是在第一次添加列时,将特定 ID 分配给所有现有记录,之后表中的所有新条目都将恢复为值“0”。
所以......在测试阶段,我们注意到在我们的升级脚本中包含以下内容需要将近一个小时来处理 40m 记录:
ALTER TABLE myTable ADD NewColumnID int NOT NULL CONSTRAINT DF_Constraint DEFAULT 0
UPDATE myTable SET NewColumnID = 50
Run Code Online (Sandbox Code Playgroud)
上面的示例将添加新列,然后使用 NewColumnID = 50 更新所有现有记录。这在运行它的硬件上花费了将近一个小时。我明白这会因客户的基础设施而有很大差异。
提出这个问题的原因是想看看是否有更快的方法来完成上述工作。
请允许我澄清答案: …
这可能是一个愚蠢的问题,但这里有:
是否有标准或最佳实践,它指定表中的外键列应按什么顺序排列?
我想知道PK是表中的第一列,后面是所有外键,然后是与该表相关的列.
其他方法是将PK作为第一列,然后是所有支持列,然后是所有外键......
我想这真的没关系,但我想为我的组织制定一个标准......
我在OS X Mavericks上没有运气安装libav.我尝试了一切.
我正在遵循本指南:http://earthwithsun.com/questions/568464/install-latest-libav-avconv-on-osx
在完成macport依赖性检查后,我会运行
./configure \
--enable-gpl --enable-libx264 --enable-libxvid \
--enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb \
--enable-nonfree --enable-libfaac \
--enable-libmp3lame --enable-libspeex --enable-libvorbis --enable-libtheora --enable-libvpx \
--enable-libopenjpeg --enable-libfreetype --enable-doc --enable-gnutls --enable-shared
Run Code Online (Sandbox Code Playgroud)
此操作失败,并显示以下错误:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
ERROR: gnutls not found
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report …Run Code Online (Sandbox Code Playgroud) 我有一个面向公众的网站(银行相关),将在未来几周内更新PROD.我需要在停机窗口期间显示"向下维护"页面.因为银行已经为我提供了页面的特定要求,需要与网站本身完全相同,我不认为app_offline.htm解决方案因为我无法访问我的样式表和图像,因此我会为我工作,因为IIS会将所有请求重定向到此页面.
我想知道,什么是最好的解决方案设计,以便我可以在我的维护页面上使用我的网站中的样式和图像?有人告诉我,这样做的一个好方法是创建一个新的网站,包括样式和图像,并将其作为IIS中的单独网站进行部署<然后在停机窗口中我切换IIS中的IP地址绑定指向我的维修网站.维护完成后,我将其切换回指向主网站.这是一个很好的方法吗?
更新:
我实现了以下,它似乎工作得很好.当我将Outage.htm或Maintenance.htm文件放入我的Web根文件夹时,它将相应地重定向.停电和定期维护具有不同的样式和内容,因此我必须创建2个页面.此外,当处于中断或维护模式,并且请求来自localhost时,则不要重定向,以允许在执行维护之后测试网站,同时阻止外部请求.
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new CheckForDownPage());
}
}
public sealed class CheckForDownPage : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string ipAddress = HttpContext.Current.Request.UserHostAddress;
var outagePage = System.Web.Hosting.HostingEnvironment.MapPath("~/Outage.htm");
var maintenancePage = System.Web.Hosting.HostingEnvironment.MapPath("~/Maintenance.htm");
var isOutage = System.IO.File.Exists(outagePage);
var isMaintenance = System.IO.File.Exists(maintenancePage);
if ( (isOutage || isMaintenance) && ipAddress != "::1")
{
filterContext.HttpContext.Response.Clear();
filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
filterContext.HttpContext.Response.StatusDescription = "Service Unavailable.";
filterContext.HttpContext.Response.WriteFile(isOutage ? outagePage : maintenancePage);
filterContext.HttpContext.Response.End();
return;
}
base.OnActionExecuting(filterContext);
}
}
Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用UI路由器.我的应用程序的主页包含4个选项卡,每个选项卡都路由到不同的模板.这是我当前的路由代码,即使用forEach创建6条路由.
['Draft','Assigned','InProgress','Completed','Rejected','All'].forEach(function (val) {
$stateProvider.state({
name: 'root.jobs.list.' + val.toLowerCase(),
url: '/' + val.toLowerCase(),
views: {
'currentTab': {
templateUrl: 'adminworkspace/jobs',
controller: 'JobsController'
}
},
data: {
userJobsStatus: val
}
});
});
Run Code Online (Sandbox Code Playgroud)
默认情况下,当用户登录时,它将转到"root.jobs.list.draft".如何根据登录用户的角色(管理员,用户,文员等)重定向到给定状态.如果要将属于"工程师"或"首席工程师"角色的所有用户重定向到"root.jobs.list.inprogress"
我最初在控制器中有这个,但正如你所看到的,它没有用,因为每次我点击一个标签时,它总是路由回"root.jobs.list.inprogress"
if (user !== undefined) {
if (user.BusinessRole == "Engineer" || user.BusinessRole == "Lead Engineer")
$state.go('root.jobs.list.inprogress');
}
Run Code Online (Sandbox Code Playgroud) 我一直在使用ASP.NET应用程序时出现非常糟糕的内存问题.似乎每次页面加载时,旧的前一页面实例都不会从内存中删除.如果按F5十次,内存会为实例添加10-20MB.在压力和性能测试期间,这将最大化内存,Web服务器将崩溃...
我运行了ANTS内存分析,它确认每次加载页面时,旧的instane都会保留在内存中.我的所有ASP.NET网页也使用Master页面.同样,如果我加载页面10次,则存在10个网页实例,以及10个主页面实例...
http://oi51.tinypic.com/21msy2g.jpg
查看蚂蚁分析器结果,您可以看到每个页面重新加载大约320Kb到内存,这就是网页,甚至没有考虑到母版页.我的应用程序是一个捕获应用程序的人寿保险应用程序,所以它通过大约30-40页.所以你可以看出为什么这是一个大规模的问题.
我怎样才能找到将页面保留在内存中的最新信息?我不知道从哪里开始...:\
我的所有页面都使用Unity和Dependency注入来注册服务......不确定在page_onUnload期间是否需要取消注册这些服务.
编辑
好的,我已成功追踪问题了.页面未被处理(GCollected)的原因是因为在卸载页面期间已注册但未注册的Unity服务实例.这就是我在我的页面上使用Unity的方式:
我通过公共财产注入服务
#region Services
[Dependency]
public ReviewReportService SummaryService { get; set; }
[Dependency]
public Portfolios.PortfolioService PortfolioService { get; set; }
#endregion
Run Code Online (Sandbox Code Playgroud)
然后页面init,我做Unity Buildup:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ApplicationContainer.BuildUp(this.Context, this);
}
Run Code Online (Sandbox Code Playgroud)
现在显然当页面经历其正常的生命周期并调用Unload时,由于依赖注入引用而无法卸载...我只是不确定如何取消注册服务(SummaryService,PortfolioService)
我尝试在OnUnload中调用以下内容,但它什么也没做:
ApplicationContainer.GetContainer(上下文).Teardown(本);
我有一个代码块,用于检查我的上下文是否正在跟踪实体.如果是的话,我需要分开它.这适用于给定的T类型.
public virtual async Task<bool> InsertOrUpdate(TE entity)
{
if (entity.Id == 0 || entity.Id == ModelState.New)
{
// attach new entity
_context.Entry(entity).State = EntityState.Added;
}
else
{
// Sometimes when you want to update a detached entity, before attempting to attach it (by setting the .State property),
// you first need to make sure the entity isn't already attached and being tracked. If this is the case, the existing entity
// needs to be detached, and the updated entity, attached. …Run Code Online (Sandbox Code Playgroud) 我知道已经有几个关于此的问题,但没有一个真正解决我的问题:
应用背景
我有一个首先使用 Entity Framework 6.1 Code 的 Web 应用程序。我在 DAL 中使用存储库模式,这意味着我有存储库来查询我的上下文并将结果返回到服务,然后服务使用自动映射器将我的实体映射到视图模型,然后返回虚拟机。服务通过 Web API 方法调用。
基于上述架构,很明显我正在使用独立的实体。
我遇到的问题是更新(PUT)现有实体。流程如下所示:
Angular 向 WebAPI 方法发出 HTTP PUT,将 VM 作为参数传递。然后,WebAPI 调用 Service 方法,并将 VM 作为参数传递。服务方法使用自动映射器将 VM 转换为 EF 实体 服务方法然后调用相应的存储库,将分离的 EF 实体的新实例作为参数传递。
服务方法示例:
public async Task<List<DependantViewModel>> SaveDependants(int customerId, List<DependantViewModel> dependantViewModels)
{
var dependantEntities = Mapper.Map<List<DependantViewModel>, List<Dependant>>(dependantViewModels);
bool result = false;
foreach (var dependantEntity in dependantEntities)
{
result = await _dependantRepository.InsertOrUpdate(dependantEntity);
if (result != true)
{
// log errror
}
}
return Mapper.Map<List<Dependant>, List<DependantViewModel>>(dependantEntities);
} …Run Code Online (Sandbox Code Playgroud) 无论我做什么,我根本无法让它在Firefox或IE或Chrome中播放声音.
<html>
<head>
<script type="text/javascript">
function play()
{
var embed = document.createElement('object');
embed.setAttribute('src', 'c:\\test.wav');
embed.setAttribute('hidden', true);
embed.setAttribute('autostart', true);
embed.setAttribute('enablejavascript', true);
document.childNodes[0].appendChild(embed);
}
// -->
</script>
</head>
<body onload="play();">
</body>
</html>
Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net ×2
javascript ×2
performance ×2
sql ×2
angularjs ×1
asp.net-mvc ×1
audio ×1
avconv ×1
configure ×1
database ×1
ffmpeg ×1
generics ×1
html ×1
html5-video ×1
iis ×1
libav ×1
libavcodec ×1
macos ×1
maintenance ×1
memory-leaks ×1
sql-server ×1
xml ×1
xslt ×1