创建程序包资源名称问题 [英] Creating Packages Recource Name Question
问题描述
我正在尝试创建一个结合了LightSwitch控件的数据包.我的应用程序文件夹中有以下代码.但我不知道在字符串ResourceName中输入什么.我试图以这种方式将这些数据添加到excel Zip文件中 它创造"了该表将覆盖当前工作表1,并将其替换为具有来自实体/Silverlight"屏幕的网格的数据的表,该表由另一表选择一个人的订单进行过滤.我得到一个Null的未处理异常,我相信 因为我没有解决资源问题.我是否也应该将引用添加到我尝试访问的已过滤网格中,所以我以这种方式构建软件包非常新.还请注意,有代码可以打开(处理开始)另一个excel文件,但是我不能 似乎放置了它,因此在构建程序包的代码运行后便会触发,这是必要的,因为启动过程"程序包具有指向我要构建的book1的链接.
I am trying to create a package combining the data grim a LightSwitch control. I have the following code in my application folder. but I don't know what to put in for the string ResourceName. I am trying to add this data to the excel Zip file in a way that it "creates" the table overwriting the current sheet1 and replacing it with one that has the Data From the Entity/Silverlight screen's grid which is filter by another table selecting the orders for a person. I get a Null not handled exception I believe because I am not address the resource right. Also were am I supposed to put the reference to the filtered Grid I am trying to access I am very new at building packages this way. also note there is code to Open(process Start) the other excel file but I can't seem to place it so it fires after the code for building the package runs this is necessary because the Process started package has links to the book1 I am trying to build.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.IsolatedStorage;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Security.Server;
using Microsoft.LightSwitch.Framework.Server;
using System.IO;
using System.IO.Packaging;
using System.Reflection;
//added this to allow the process statement that opens excel
using System.Diagnostics;
using System.Linq.Expressions;
namespace LightSwitchApplication
{
public partial class ApplicationDataService
{
private string _PackageName = "Book1.xlsx";
partial void Commands_Inserting(Command entity)
{
switch (entity.Argument)
{
case "CreateDocument":
//This opens the excel file from the current directory
Process.Start("MAR mod1.1.xlsx");
entity.Result = _PackageName;
//Package, file name and Uri location
Package package = Package.Open(_PackageName, FileMode.Open);
Uri uri = new Uri("/xl/worksheets.sheet1", UriKind.Relative);
//Content Type for Each Part
PackagePart DocPart = package.CreatePart(uri, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
string ResourceName = "Book1.xlsx.zip/xl/worksheets/sheet1.xml";
Assembly ResourceAssembly = Assembly.GetExecutingAssembly();
using (Stream DocPartStream = DocPart.GetStream(FileMode.Create))
{
using (Stream DocSourceStream = ResourceAssembly.GetManifestResourceStream(ResourceName))
{
DocSourceStream.CopyTo(DocPartStream);
}
}
package.CreateRelationship(uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "rID1");
package.Close();
break;
}
}
}
}
异常详细信息
System.NullReferenceException由用户代码未处理
HResult = -2147467261
Message =对象引用未设置为对象的实例.
来源= Application.Server
StackTrace:
在LightSwitchApplication.ApplicationDataService.Commands_Inserting(命令实体)
在LightSwitchApplication.ApplicationDataService.DetailsClass .__ Commands_Inserting(ApplicationDataService d,Command e)
在Microsoft.LightSwitch.Details.Framework.Server.EntitySetEntry`2.Microsoft.LightSwitch.Details.Framework.Server.IEntitySetEntry.InvokeInserting(IDataService dataService,IEntityObject实体)
在Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1处.<> c__DisplayClass40.< PerformPreEvent> b__3a(IEntitySetEntry entitySetEntry)
在Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.<> c__DisplayClass43.< CallPrePostUserCode> b__42()
在Microsoft.LightSwitch.Utilities.Internal.UserCodeHelper.CallUserCode(Type sourceType,String methodName,String instance,String operation,ILoggingContext context,Action action,String AdditionalText,Func`1 getCompletedMessage,
布尔tryHandleException,布尔swallowException,Exception&例外)
InnerException:
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Application.Server
StackTrace:
at LightSwitchApplication.ApplicationDataService.Commands_Inserting(Command entity)
at LightSwitchApplication.ApplicationDataService.DetailsClass.__Commands_Inserting(ApplicationDataService d, Command e)
at Microsoft.LightSwitch.Details.Framework.Server.EntitySetEntry`2.Microsoft.LightSwitch.Details.Framework.Server.IEntitySetEntry.InvokeInserting(IDataService dataService, IEntityObject entity)
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.<>c__DisplayClass40.<PerformPreEvent>b__3a(IEntitySetEntry entitySetEntry)
at Microsoft.LightSwitch.ServerGenerated.Implementation.DataServiceImplementation`1.<>c__DisplayClass43.<CallPrePostUserCode>b__42()
at Microsoft.LightSwitch.Utilities.Internal.UserCodeHelper.CallUserCode(Type sourceType, String methodName, String instance, String operation, ILoggingContext context, Action action, String additionalText, Func`1 getCompletedMessage,
Boolean tryHandleException, Boolean swallowException, Exception& exception)
InnerException:
推荐答案
我也收到超时未处理的错误,但是我认为是由于前面的错误.仅当我继续执行代码以解决第一个错误时,它才会触发.但我会在此回复中包含例外情况,以防万一还有其他问题.
I also get a Timeout Unhandled Error but I think that is because of the preceding error. It only fires when I continue the code stepping past the first error. but I will include the exception in this reply just in case it is something else.
partial void MAR_Execute()
{
// Write your code here.
var _with1 = this.DataWorkspace.ApplicationData;
dynamic command = _with1.Commands.AddNew();
command.Name = "Commands_Inserting";
command.Argument = "CreateDocument";
_with1.SaveChanges();
}
例外
System.TimeoutException未由用户代码处理
Message =操作已超时.
StackTrace:
在Microsoft.LightSwitch.Framework.Base.ExecutableObject.Execute(Boolean allowJoin)
在Microsoft.LightSwitch.Framework.Base.ExecutableObject.Execute()
在Microsoft.LightSwitch.Details.Framework.Base.MethodInvocation`2.Execute()
在Microsoft.LightSwitch.Framework.Base.DataService`2.SaveChanges()
在LightSwitchApplication.TimesAndMARs.MAR_Execute()
在LightSwitchApplication.TimesAndMARs.DetailsClass.MethodSetProperties._MAR_InvokeMethod(DetailsClass d,ReadOnlyCollection`1 args)
在Microsoft.LightSwitch.Details.Framework.Internal.BusinessMethodImplementation`2.< TryInvokeMethod> b__5()
在Microsoft.LightSwitch.Utilities.Internal.UserCodeHelper.CallUserCode(Type sourceType,String methodName,String instance,String operation,ILoggingContext context,Action action,String AdditionalText,Func`1 getCompletedMessage,
布尔tryHandleException,布尔swallowException,Exception&例外)
InnerException:
System.TimeoutException was unhandled by user code
Message=The operation has timed out.
StackTrace:
at Microsoft.LightSwitch.Framework.Base.ExecutableObject.Execute(Boolean allowJoin)
at Microsoft.LightSwitch.Framework.Base.ExecutableObject.Execute()
at Microsoft.LightSwitch.Details.Framework.Base.MethodInvocation`2.Execute()
at Microsoft.LightSwitch.Framework.Base.DataService`2.SaveChanges()
at LightSwitchApplication.TimesAndMARs.MAR_Execute()
at LightSwitchApplication.TimesAndMARs.DetailsClass.MethodSetProperties._MAR_InvokeMethod(DetailsClass d, ReadOnlyCollection`1 args)
at Microsoft.LightSwitch.Details.Framework.Internal.BusinessMethodImplementation`2.<TryInvokeMethod>b__5()
at Microsoft.LightSwitch.Utilities.Internal.UserCodeHelper.CallUserCode(Type sourceType, String methodName, String instance, String operation, ILoggingContext context, Action action, String additionalText, Func`1 getCompletedMessage,
Boolean tryHandleException, Boolean swallowException, Exception& exception)
InnerException:
这篇关于创建程序包资源名称问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!