小编Bul*_*nes的帖子

安装Sqlite3 Gem错误

尝试在安装了XCode 4.2的OS X Lion上安装Sqlite3 gem时出现以下错误:

$ gem install sqlite3
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
    ERROR: Failed to build gem native extension.

        /Users/me/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... yes
checking for sqlite3_backup_init()... yes
checking for sqlite3_column_database_name()... no
checking for sqlite3_enable_load_extension()... yes
checking for sqlite3_load_extension()... yes
creating Makefile

make
compiling backup.c
make: /usr/bin/gcc-4.2: No such file or directory
make: *** [backup.o] Error …
Run Code Online (Sandbox Code Playgroud)

sqlite macos gem

5
推荐指数
1
解决办法
1329
查看次数

LINQ to XML新手问题:返回多个结果

问候!

我正在努力绕着LINQ缠头.如果我有一些这样的XML加载到XDocument对象中:

<Root>
    <GroupA>
        <Item attrib1="aaa" attrib2="000" attrib3="true" />
    </GroupA>
    <GroupB>
        <Item attrib1="bbb" attrib2="111" attrib3="true" />
        <Item attrib1="ccc" attrib2="222" attrib3="false" />
        <Item attrib1="ddd" attrib2="333" attrib3="true" />
    </GroupB>
    <GroupC>
        <Item attrib1="eee" attrib2="444" attrib3="true" />
        <Item attrib1="fff" attrib2="555" attrib3="true" />
    </GroupC>
</Root>
Run Code Online (Sandbox Code Playgroud)

我想获取Group元素的所有Item子元素的属性值.这是我的查询的样子:

var results = from thegroup in l_theDoc.Elements("Root").Elements(groupName)
              select new
              { 
                 attrib1_val = thegroup.Element("Item").Attribute("attrib1").Value,      
                 attrib2_val = thegroup.Element("Item").Attribute("attrib2").Value,
              };
Run Code Online (Sandbox Code Playgroud)

该查询有效,但是如果例如groupName变量包含"GroupB",则只返回一个结果(第一个Item元素)而不是三个.我错过了什么吗?

c# linq-to-xml

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

使用WebClient获取远程图像会产生粒状GIF,无法处理PNG + BMP

问候!

我正在创建一个Web表单原型(ImageLaoder.aspx),它将返回一个图像,以便它可以像其他Web表单/网页的简单示例一样使用:

<img src="http://www.mydomain.com/ImageLoader.aspx?i=http://images.mydomain.com/img/a.jpg" />
Run Code Online (Sandbox Code Playgroud)

到目前为止,它加载JPG没有问题,但是与原始数据相比,GIF看起来"颗粒状",而BMP和PNG导致以下异常:

System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误

到目前为止我的代码看起来像这样:

protected void Page_Load(object sender, EventArgs e)
{
    string l_filePath = Request.QueryString["i"];

    System.Drawing.Image l_image = GetImage(l_filePath);
    if (l_image != null)
    {
        System.Drawing.Imaging.ImageFormat l_imageFormat = DetermineImageFormat(l_filePath);
        WriteImageAsReponse(l_image, l_imageFormat);
    }
}

private System.Drawing.Image GetImage(string filePath)
{
    WebClient l_WebClient = new WebClient();
    byte[] l_imageBytes = l_WebClient.DownloadData(filePath);

    System.Drawing.Image l_image = null;
    using (MemoryStream l_MemStream = new MemoryStream(l_imageBytes, 0, l_imageBytes.Length))
    {
        l_MemStream.Write(l_imageBytes, 0, l_imageBytes.Length);
        l_image = System.Drawing.Image.FromStream(l_MemStream, true);
        l_MemStream.Close();
    }

    return l_image;
}

private System.Drawing.Imaging.ImageFormat DetermineImageFormat(string filePath) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net webclient

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

Linq问题:结合Where子句

素不相识的!

我有一些看起来像这样的XML:

<Root>
    <SectionA>
        <Item id="111">
            <Options>
                <Option val="a" cat="zzz">
                    <Package value="apple" />
                    <Feature value="avacado" />
                </Option>
                <Option val="b" cat="yyy">
                    <Package value="banana" />
                    <Feature value="blueberry" />
                </Option>
            </Options>
        </Item>
        <Item id="222">
            <Options>
                <Option val="c" cat="xxx">
                    <Package value="carrot" />
                    <Feature value="cucumber" />
                </Option>
                <Option val="d" cat="www">
                    <Package value="dairy" />
                    <Feature value="durom" />
                </Option>
            </Options>
        </Item>
    </SectionA>
    <SectionB>
    .
    .
    .
    </SectionB>
</Root>
Run Code Online (Sandbox Code Playgroud)

我想根据ITEM的ID属性为"111"得到PACKAGE和FEATURE值,OPTION的VAL属性为"a".

我不知道从哪里开始.我可以使用where选择ITEM节点,但我不确定如何将它与OPTION节点上的where子句相结合.有任何想法吗?

.net c# linq linq-to-xml

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

TraceSource和ASP.NET:适用于Web应用程序,而不适用于WebSites

我正在向ASP.NET网站添加跟踪功能,所以我决定通过创建几个原型来研究TraceSource ; Web应用程序项目和网站项目.

我正在为每个项目使用类似的Web.config来记录到Windows事件日志的跟踪:

<configuration>
    <system.web>
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
    </system.web>    
    <system.diagnostics>
        <trace autoflush="true" />
        <sources>
            <source name="HelloWorld">
                <listeners>
                    <add name="eventlogListener" />
                </listeners>
            </source>
        </sources>    
        <sharedListeners>
            <add name="eventlogListener" type="System.Diagnostics.EventLogTraceListener" initializeData="My Source" />
        </sharedListeners>
    </system.diagnostics>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我只是从以下基本跟踪开始:

private static TraceSource _ts = new TraceSource("HelloWorld", SourceLevels.All);

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    _ts.TraceEvent(TraceEventType.Information, 10, "Greetings from OnLoad.");
}
Run Code Online (Sandbox Code Playgroud)

使用Web应用程序项目,我可以看到在事件日志中创建的跟踪.但是,有了网站项目,我不能.

网站项目需要使用TraceSource的其他步骤(例如:web.config设置,权限等)吗?

c# asp.net trace .net-4.0 tracesource

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

特定标记的正则表达式

我正在.NET项目中使用正则表达式来获取特定标记.我想匹配整个DIV标签及其内容:

<html>
   <head><title>Test</title></head>
   <body>
     <p>The first paragraph.</p>
     <div id='super_special'>
        <p>The Store paragraph</p>
     </div>
     </body>
  </head>
Run Code Online (Sandbox Code Playgroud)

码:

    Regex re = new Regex("(<div id='super_special'>.*?</div>)", RegexOptions.Multiline);


    if (re.IsMatch(test))
        Console.WriteLine("it matches");
    else
        Console.WriteLine("no match");
Run Code Online (Sandbox Code Playgroud)

我想要匹配这个:

<div id="super_special">
   <p>Anything could go in here...doesn't matter.  Let's get it all</p>
</div>
Run Code Online (Sandbox Code Playgroud)

我以为.应该得到所有的角色,但似乎有回车问题.我的正则表达式遗失了什么?

谢谢.

.net regex

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

查询以检索组节点的名称

如果我有一些这样的XML加载到XDocument对象中:

<Root>
    <GroupA>
        <Item attrib1="aaa" attrib2="000" />
    </GroupA>
    <GroupB>
        <Item attrib1="bbb" attrib2="111" />
        <Item attrib1="ccc" attrib2="222" />
        <Item attrib1="ddd" attrib2="333" />
    </GroupB>
    <GroupC>
        <Item attrib1="eee" attrib2="444" />
        <Item attrib1="fff" attrib2="555" />
    </GroupC>
</Root>
Run Code Online (Sandbox Code Playgroud)

检索组节点的名称会是什么样的?

例如,我想要一个返回的查询:

GroupA
GroupB
GroupC
Run Code Online (Sandbox Code Playgroud)

.net c# linq linq-to-xml

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

ASP.NET:以编程方式设置HTML元素的样式

我正在生成一个菜单,其中一个Repeater控件绑定到一个XmlDataSource.

<asp:Repeater ID="myRepeater" runat="server" 
    DataSourceID="myDataSource" 
    onitemdatabound="myRepeater_ItemDataBound" 
    onitemcreated="myRepeater_ItemCreated">
    <HeaderTemplate>
        <ul class="menu_list">
    </HeaderTemplate>
    <ItemTemplate>
        <li id="liMenu" runat="server"><asp:HyperLink ID="hrefMenuItem" runat="server" Text='<%# XPath("@text")%>' NavigateUrl='<%# XPath("@href")%>'></asp:HyperLink></li>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>
<asp:XmlDataSource runat="server" ID ="myDataSource" XPath="Menu/Items/*" EnableCaching="False" /> 
Run Code Online (Sandbox Code Playgroud)

我希望能够根据鼠标悬停事件和当前选择的菜单项设置包含LI的样式.我尝试通过HtmlGenericControl,但我收到一个错误,它是readonly.

protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HyperLink hrefCurrentMenuLink = e.Item.FindControl("hrefMenuItem") as HyperLink;
                HtmlGenericControl l_genericControl = e.Item.FindControl("liMenu") as HtmlGenericControl;

                if ((hrefCurrentMenuLink != null) && (l_genericControl != null))
                {
                    string l_currentPage = GetCurrentWebPage();

                    if (String.Compare(Path.GetFileNameWithoutExtension(hrefCurrentMenuLink.NavigateUrl), l_currentPage, StringComparison.OrdinalIgnoreCase) == …
Run Code Online (Sandbox Code Playgroud)

asp.net repeater htmlgenericcontrol

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

ENTER按键上的DropDownList回发未触发服务器端事件

问候!

我有一个简单的导航菜单,其中包含一个asp:DropDownList和一个asp:Button。用户从下拉菜单中选择一个项目,然后单击按钮以转到新的URL。我希望能够在用户选择下拉列表项时按ENTER键时提供支持,以便复制用户的行为,就像单击按钮一样。

到目前为止,这是我所拥有的:

<asp:DropDownList ID="ddlMenu"
                  runat="server"
                  onkeypress="if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {__doPostBack('GoButton',''); return false;}" />

<asp:Button ID="btnGoButton" runat="server" onclick="GoButton_Click"/>
Run Code Online (Sandbox Code Playgroud)

该按钮的点击代码为:

protected void GoButton_Click(object sender, EventArgs e)
{
    string l_url = ddlMenu.SelectedItem.Value;
    Response.Redirect(l_url);
}
Run Code Online (Sandbox Code Playgroud)

但是,每次我按ENTER键时,页面都会回发,但是按钮的客户端事件处理程序不会触发。我想念什么吗?

c# asp.net postback

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

UpdatePanel中元素上的jQuery事件

我在UpdatePanel中有一些元素可能会或可能会显示,具体取决于各种条件.

<asp:UpdatePanel ID="MyUpdatePanel" runat="server">
    <ContentTemplate>
        <asp:Panel ID="MyPanel" runat="server">
            <img id="clickableImage" src="/path/to/image.png" alt="Clickable Image" />
            <span id="specialMessage">You clicked on the image!</span>
        <asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)

我正在尝试连接它,以便在使用以下单击clickableImage IMG时显示specialMessage SPAN:

$(document).ready(function() {
    $("#clickableImage").click(function() {
        $("#specialMessage").show();
    });

    $("#specialMessage").draggable();
});
Run Code Online (Sandbox Code Playgroud)

但是,由于MyPanel在页面加载时通常不可见(但稍后可能会根据用户交互显示),因此事件不会被连接起来.有没有办法可以挂钩这些事件,即使MyPanel在初始页面加载时不可见?

jquery updatepanel asp.net-ajax

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

LINQ to XML新手问题:按节点名称返回节点

问候!

如果我有这样的XML:

<Root>
    <AlphaSection>
    .
    .
    .
    </AlphaSection>

    <BetaSection>
        <Choices>
            <SetA>
                <Choice id="choice1">Choice One</Choice> 
                <Choice id="choice2">Choice Two</Choice>
            </SetA>
            <SetB>
                <Choice id="choice3">Choice Three</Choice> 
                <Choice id="choice4">Choice Four</Choice>
            </SetB>
        </Choices>
    </BetaSection>

    <GammaSection>
    .
    .
    .
    </GammaSection>
</Root>
Run Code Online (Sandbox Code Playgroud)

我想获得"BetaSection"中的所有Choice项目,无论它们属于哪个"Set".我尝试过以下方法:

var choiceList = from choices in myXDoc.Root.Element("BetaSection").Elements("Choices")
                 where (choices.Name == "Choice")
                 select new
                 {
                     Name = choices.Attribute("id").Value,
                     Data = choice.Value
                 };
Run Code Online (Sandbox Code Playgroud)

但无济于事.我该怎么做?

谢谢.

c# xml linq-to-xml c#-3.0

0
推荐指数
1
解决办法
4620
查看次数