这可能是一个愚蠢的问题,但我正在编写一个快速测试页面,并意识到我不知道如何将字符串的数组或ArrayList绑定到例如ASP.NET Repeater.
我试验了一下.
<asp:Repeater ID="rptImages" runat="server">
<HeaderTemplate>
<h3>Items</h3>
</HeaderTemplate>
<ItemTemplate>
<p style="background-color:Black;color:White"><%#Eval(Container.DataItem.ToString())%></p>
</ItemTemplate>
<FooterTemplate>
<h4>End of Items</h4>
</FooterTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
我完全是傻瓜吗?我只是将它用于具有属性的对象集合.
我有一个从服务中读取JSON的方法,我正在使用Gson进行序列化,并使用类型参数编写了以下方法.
public T getDeserializedJSON(Class<T> aClass,String url)
{
Reader r = getJSONDataAsReader(url);
Gson gson = new Gson();
return gson.fromJson(r, aClass);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用json,它只返回一个类型的数组,例如
[
{ "prop":"value" }
{ "prop":"value" }
]
Run Code Online (Sandbox Code Playgroud)
我有一个映射到这个对象的java类,我们称之为MyClass.但是要使用我的方法,我需要这样做:
RestClient<ArrayList<MyClass>> restClient = new RestClient<ArrayList<MyClass>>();
ArrayList<MyClass> results = restClient.getDeserializedJSON(ArrayList<MyClass>.class, url);
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚它的语法.仅传递ArrayList.class不起作用.
那么有没有办法可以摆脱Class参数或者如何获取MyClass的ArrayList类?
场景:
我正在编写一个层来将3个类似的Web服务抽象为一个可用的类.每个Web服务都公开一组共享共性的对象.我创建了一组利用共性的中间对象.但是在我的图层中,我需要在Web服务对象和我的对象之间进行转换.
在调用Web服务之前,我已经使用反射在运行时创建了相应的类型,如下所示:
public static object[] CreateProperties(Type type, IProperty[] properties)
{
//Empty so return null
if (properties==null || properties.Length == 0)
return null;
//Check the type is allowed
CheckPropertyTypes("CreateProperties(Type,IProperty[])",type);
//Convert the array of intermediary IProperty objects into
// the passed service type e.g. Service1.Property
object[] result = new object[properties.Length];
for (int i = 0; i < properties.Length; i++)
{
IProperty fromProp = properties[i];
object toProp = ReflectionUtility.CreateInstance(type, null);
ServiceUtils.CopyProperties(fromProp, toProp);
result[i] = toProp;
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
这是我的调用代码,来自我的一个服务实现:
Property[] props …Run Code Online (Sandbox Code Playgroud) 好吧,我的手上有一个有趣的问题.这里有一些背景知识:
我正在编写一个媒体库服务实现,它将为前端Flash播放器提供URL.客户希望能够通过将带有一些元数据的文件上传到FTP文件夹来将内容推送到服务中 - 我可以控制元数据模式.观看此文件夹的服务将获取任何新文件,将其复制到"内容"文件夹中,然后将元数据和URL推送到内容服务中的内容并进入数据库.
完成内容服务不是问题.观看FTP文件夹是.
我当前的实现使用FileSystemWatcher对象和xml文件的过滤器.
每个内容项可能有多个文件,例如高,中,低质量的视频.
我计划通过流程或工具强制执行内容被组织到自己的文件夹中只是为了简洁,但这不是一个真正的问题.
xml文件看起来有点像这样:
<media>
<meta type="video">
<name>The Name Displayed</name>
<heading>The title of the video</heading>
<description>
A lengthy description about the video..
</description>
<length>00:00:19</length>
</meta>
<files>
<video file="somevideo.flv" quality="low"/>
<video file="somevideo.flv" quality="medium"/>
<video file="somevideo.flv" quality="high"/>
</files>
</media>
Run Code Online (Sandbox Code Playgroud)
因此,当创建新文件时,会触发FileSystemWatcher.Created事件.我有一个单独的线程运行来处理与主服务进程共享队列的内容(不要担心它使用生产者消费者模式,详见此处:http://msdn.microsoft.com/en-us/ library/yy12yx1f.aspx).
这一切都很好,但现在我遇到边缘情况左右中心!
我已经考虑到视频上传需要更长的时间,因此处理器会尝试获取独占锁定,如果失败,它会将项目移动到队列的后面并移动到下一个项目.
任何人都可以为这种情况推荐最佳做法吗?filesystemwatcher是个好主意还是服务只是定期扫描文件夹?
编辑:只是为了让您了解规模.我们总共谈论了1000件商品中的10件.可能上传大块.
我有一个类似于这里的问题:Javascript循环中的事件处理程序 - 需要一个闭包吗?但是我正在使用jQuery,并且给出的解决方案似乎在绑定而不是点击时触发事件.
这是我的代码:
for(var i in DisplayGlobals.Indicators)
{
var div = d.createElement("div");
div.style.width = "100%";
td.appendChild(div);
for(var j = 0;j<3;j++)
{
var test = j;
if(DisplayGlobals.Indicators[i][j].length > 0)
{
var img = d.createElement("img");
jQuery(img).attr({
src : DisplayGlobals.Indicators[i][j],
alt : i,
className: "IndicatorImage"
}).click(
function(indGroup,indValue){
jQuery(".IndicatorImage").removeClass("active");
_this.Indicator.TrueImage = DisplayGlobals.Indicators[indGroup][indValue];
_this.Indicator.FalseImage = DisplayGlobals.IndicatorsSpecial["BlankSmall"];
jQuery(this).addClass("active");
}(i,j)
);
div.appendChild(img);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的方法但没有成功......
最初的问题是_this.Indicator.TrueImage始终是最后一个值,因为我使用循环计数器而不是参数来选择正确的图像.
我正在尝试使用以下方法从Android应用程序调用RESTful Web服务:
HttpHost target = new HttpHost("http://" + ServiceWrapper.SERVER_HOST,ServiceWrapper.SERVER_PORT);
HttpGet get = new HttpGet("/list");
String result = null;
HttpEntity entity = null;
HttpClient client = new DefaultHttpClient();
try {
HttpResponse response = client.execute(target, get);
entity = response.getEntity();
result = EntityUtils.toString(entity);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (entity!=null)
try {
entity.consumeContent();
} catch (IOException e) {}
}
return result;
Run Code Online (Sandbox Code Playgroud)
我可以浏览地址并使用Android Emulator浏览器和我的机器查看xml结果.我已经给了我的应用程序INTERNET权限.
我正在用eclipse开发.
我已经看到它提到我可能需要配置一个代理,但由于我正在调用的Web服务是在80端口,这应该不重要吗?我可以用浏览器调用该方法.
有任何想法吗?
我刚刚开始一个新项目,我发现了一些非常奇怪的事情.
ASP.NET 3.5,VS2008.
我已经尝试重建,关闭VS,删除所有内容并再次从svn获取,但我无法理解为什么以下的转发器在page_load上为null.
我知道这将是一个令人头疼的时刻.帮帮我?
标记:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GalleryControl.ascx.cs" Inherits="Site.UserControls.GalleryControl" %>
<asp:Repeater ID="rptGalleries" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<ItemTemplate>
<li>wqe</li>
</ItemTemplate>
<FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
代码背后
public partial class GalleryControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
rptGalleries.DataSource = new[] {1, 2, 3, 4, 5};
rptGalleries.DataBind();
}
}
Run Code Online (Sandbox Code Playgroud)
设计师:
public partial class GalleryControl {
/// <summary>
/// rptGalleries control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks> …Run Code Online (Sandbox Code Playgroud) 我已经将MVC2项目升级到MVC3,现在想要开始使用Razor视图引擎但是当我执行Add-> View时它不会给我选择视图引擎的选项.
我已经更新了我的views文件夹中的Web.config,并与一个新的MVC 3项目进行了比较,但没有任何工作.
有任何想法吗?
给定以下源类型:
public class BaseViewModel
{
public string Prop1 { get; set; }
}
public class FirstViewModelImpl : BaseViewModel
{
public string Prop2 { get; set; }
}
public class SecondViewModelImpl : BaseViewModel
{
public string AnotherProp { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以及目的地类型
public class BaseDto
{
public string Prop1 { get; set; }
}
public class FirstDtoImpl : BaseDto
{
public string Prop2 { get; set; }
}
public class SecondDtoImpl : BaseViewModel
{
public string AnotherProp { get; set; …Run Code Online (Sandbox Code Playgroud) 我的开发虚拟机上安装了SDL Tridion 2011 SP1,我遇到了问题.
当我添加新发布时,我无法将现有发布添加为父级,因此我无法创建BluePrint层次结构.
添加发布按钮会闪烁对话框但随后会消失.
每个出版物似乎都是在自己的BluePrint层次结构中创建的.
我错过了一些非常明显的东西吗
c# ×4
arrays ×2
asp.net ×2
java ×2
.net ×1
android ×1
automapper ×1
casting ×1
closures ×1
generics ×1
javascript ×1
jquery ×1
loops ×1
polymorphism ×1
razor ×1
reflection ×1
repeater ×1
rest ×1
testing ×1
tridion ×1
tridion-2011 ×1
webforms ×1