小编gre*_*gor的帖子

实体框架线程安全

实体框架生成的上下文对象不是线程安全的.

如果我使用两个独立的实体上下文,每个线程一个(并SaveChanges()在每个上调用),这会是线程安全的吗?

// this method is called from several threads concurrently
public void IncrementProperty()
{
   var context = new MyEntities();

   context.SomeObject.SomeIntProperty++;
   context.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)

我相信实体框架上下文实现了某种"计数器"变量,它跟踪上下文中的当前值是否是新鲜的.

  1. 使用上面的代码 - 从单独的线程调用 - 我是否还需要锁定增量/保存更改?
  2. 如果是这样,在这个简单的场景中实现这一目标的首选方法是什么?

c# datacontext concurrency thread-safety entity-framework-4

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

检测用户是否在圈内点击

如何检测用户何时点击红色气泡?

它不应该像一个方形场.鼠标必须在圆圈内:

IMG

这是代码:

<canvas id="canvas" width="1000" height="500"></canvas>
<script>
var canvas = document.getElementById("canvas")
var ctx = canvas.getContext("2d")

var w = canvas.width
var h = canvas.height

var bubble = {
  x: w / 2,
  y: h / 2,
  r: 30,
}

window.onmousedown = function(e) {
    x = e.pageX - canvas.getBoundingClientRect().left
    y = e.pageY - canvas.getBoundingClientRect().top

    if (MOUSE IS INSIDE BUBBLE) {
        alert("HELLO!")
    }
}

ctx.beginPath()
ctx.fillStyle = "red"
ctx.arc(bubble.x, bubble.y, bubble.r, 0, Math.PI*2, false)
ctx.fill()
ctx.closePath()
</script>
Run Code Online (Sandbox Code Playgroud)

html javascript events canvas click

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

无法加载地图.联系Google服务器时出错 这可能是一个身份验证问题

我搜索了所有的日子,我找不到答案......

一切准备就绪,但谷歌地图仍然无法显示片段与标签

我检查我已经打开谷歌地图android v2和正确的API_KEY

我不知道发生了什么!

IMG

MainActivity.java:

public class MainActivity extends FragmentActivity implements
        ActionBar.TabListener {

    SectionsPagerAdapter mSectionsPagerAdapter;

    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String titles[] = { this.getString(R.string.title_around),
                this.getString(R.string.title_map),
                this.getString(R.string.title_favorite),
                this.getString(R.string.title_achievement), };

        final ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mSectionsPagerAdapter = new SectionsPagerAdapter(
                getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager
                .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
                    @Override
                    public void onPageSelected(int position) {
                        actionBar.setSelectedNavigationItem(position);
                    }
                });

        for (int i = 0; i < titles.length; i++) {
            actionBar.addTab(actionBar.newTab().setText(titles[i])
                    .setTabListener(this));
        }
    }

    @Override
    public …
Run Code Online (Sandbox Code Playgroud)

android google-maps android-fragments android-tabs

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

我可以禁用y对话框的打印页面x吗?

我正在使用c#开发全屏信息亭应用程序.我需要打印门票和收据.我使用PrintDocument类进行打印.打印机完美打印,但我需要禁用打印过程中显示的弹出对话框.

截图

我听说可以通过控制面板中的"打印机和传真"禁用它,但我在控制面板中没有"打印机和传真".

我可以禁用显示的对话框吗?如果可以,我该怎么办?

c# printdocument windows-7

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

没有样式ViewPagerIndicator与SherlockActionBar结合使用

我正在尝试使用SherlockActionBar实现ViewPagerIndicator.它的工作原理:我可以滑动碎片,但风格不起作用!

它看起来像这样:

IMG

相关主题:https://github.com/JakeWharton/Android-ViewPagerIndicator/issues/66

我知道出了什么问题:在VPI的示例中,页面的样式在AndroidManifest.xml中设置(例如)

<activity
     android:name=".SampleTabsDefault"
     android:theme="@style/Theme.PageIndicatorDefaults"> 
</activity>
Run Code Online (Sandbox Code Playgroud)

但是当我将android:theme元素添加到我自己的Manifest.xml中时,我得到以下异常:

03-16 11:06:24.400: E/AndroidRuntime(483): Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
Run Code Online (Sandbox Code Playgroud)

我还尝试将所有样式信息复制到styles.xml,但这也不起作用.

你能告诉我如何设置VPI的风格吗?谢谢!

编辑:现在我已经添加了

<activity
         android:name=".SampleTabsDefault"
         android:theme="@style/StyledIndicators"> 
</activity>
Run Code Online (Sandbox Code Playgroud)

到我的Manifest.xml

以及styles.xml中的以下样式

<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
        <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
    </style>   

    <style name="StyledIndicators" parent="Theme.BataApp">
        <item name="vpiTitlePageIndicatorStyle">@style/Widget.TitlePageIndicator</item>
        <item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
        <item name="vpiTabTextStyle">@style/Widget.TabPageIndicator.Text</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

结果:我没有得到任何异常,看到样式,但我现在看不到任何碎片:(

活动代码可以在这里找到:http://pastebin.com/hsNgxFDZ 当前页面的风格截图:

IMG

android android-theme android-viewpager actionbarsherlock

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

启动程序时 Arduino IDE (Win10) 崩溃

我的 Arduino IDE(Win10 上的 1.8.12 版)在启动时崩溃。运行arduino_debug.exe我收到此错误消息。

C:\Program Files (x86)\Arduino>arduino_debug.exe
Set log4j store directory C:\Users\volke\AppData\Local\Arduino15
Loading configuration...
Initializing packages...
java.lang.NullPointerException
        at cc.arduino.contributions.packages.ContributionsIndexer.parseIndex(ContributionsIndexer.java:134)
        at processing.app.BaseNoGui.initPackages(BaseNoGui.java:483)
        at processing.app.Base.<init>(Base.java:273)
        at processing.app.Base.main(Base.java:150)

C:\Program Files (x86)\Arduino>
Run Code Online (Sandbox Code Playgroud)

任何解决方案?我试图删除配置文件package_index.jsonpackage_esp32_index.json但没有任何运气。

windows crash arduino arduino-ide windows-10

24
推荐指数
2
解决办法
6050
查看次数

Lucene的算法

我读过Doug Cutting的论文; " 总排名的空间优化 ".

由于它是很久以前写的,我想知道lucene使用什么算法(关于帖子列表遍历和分数计算,排名).

特别是,那里描述的总排名算法涉及遍历每个查询词的整个帖子列表,因此在非常常见的查询词如"黄狗"的情况下,2个词中的任何一个可能具有非常长的帖子列表,如果是网络搜索.它们是否真的遍及当前的Lucene/Solr?或者是否有任何启发式方法来截断所使用的列表?

在只返回前k个结果的情况下,我可以理解,在多个机器上分发发布列表,然后组合每个机器的top-k可以工作,但是如果我们需要返回"第100个结果页面",即结果排名从990-1000,然后每个分区仍然必须找出前1000,所以分区将没有多大帮助.

总的来说,有没有关于Lucene使用的内部算法的最新详细文档?

lucene algorithm indexing information-retrieval inverted-index

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

Android Facebook锁屏通知

在Android应用程序的最新版本Facebook上显示锁定屏幕通知功能,就像在这个截图上:

截图

有没有人试图实现这个?

我知道在锁定屏幕上显示Activity很简单,但遗憾的是它不适用于半透明背景.基本上它工作,但在我们的活动下面,我们看到启动器屏幕,而不是锁定屏幕(在这种情况下像锁屏也将是透明的).

我现在尝试的是:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
Run Code Online (Sandbox Code Playgroud)

在我的活动中.

我也试过这个例子:https://gist.github.com/daichan4649/5352944

正如我所描述的 - 一切正常但没有透明度.

根据我的观察,Facebook使用主题:

@android:style/Theme.Translucent.NoTitleBar
Run Code Online (Sandbox Code Playgroud)

并且没有许可:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
Run Code Online (Sandbox Code Playgroud)

此外,我注意到锁定屏幕通知会获取触摸,因此我们无法通过手势显示状态栏中的通知.

任何想法如何在Android L发布之前创建这种通知.

notifications android facebook lockscreen

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

添加注释到Openseadragon

var viewer = OpenSeadragon({
    id: "openseadragon1",
    prefixUrl: "images/openseadragon/",
    showNavigator:  true,
    navigatorPosition:   "BOTTOM_RIGHT",
    tileSources: '/fcgi-bin/iipsrv.fcgi?Deepzoom=<?=$plink?>.jp2.dzi',
    crossOriginPolicy: 'Anonymous',
    zoomInButton:   "zoom-in",
    zoomOutButton:  "zoom-out",
    homeButton:     "home",
    fullPageButton: "full-page"
});

anno.makeAnnotatable(viewer);

$.ajax({
    url: "handlers/H_AnnotationHandler.php",
    data: "case_id=<?=$case_id?>&plink=<?=$plink?>&mode=get",
    type: "post",
    dataType: "json",
    success: function(response) {
        if (!response.error) {
            for (var i=0; i<response.annots.length; i++) {
                console.log(response.annots[i].comment);
                anno.addAnnotation({
                    text: response.annots[i].comment,
                    shapes: [{
                        type: 'rect',
                        geometry: {
                            x: response.annots[i].rect_x,
                            y: response.annots[i].rect_y,
                            width: response.annots[i].rect_w,
                            height: response.annots[i].rect_h
                        }
                    }]
                });
            }
        } else {
            console.log(response.error);
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

我可以直接添加注释:http://annotorious.github.io/demos/openseadragon-preview.html …

javascript php jquery openseadragon

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

将大于cellHeight的子视图添加到UITableViewCell?

我正在尝试向UITableViewCell添加子视图,而我正在使用的设计要求这个特定的子视图(图像)需要比实际的UITableViewCell更大,因此部分重叠其兄弟.

所以我设置了我的表格单元格,生成了我的图像并将其添加到单元格的contentView中:

// rowHeight for the UITableView is 45.0f

UIImage *image = [self createCellThumbnail: someImage];
UIImageView *thumbView = [[UIImageView alloc] initWithFrame: CGRectMake(150, -5, 55,55)];
thumbView.transform = CGAffineTransformMakeRotation(0.1f);
thumbView.image = image;

cell.clipsToBounds = NO;
cell.contentView.clipsToBounds = NO;

[cell.contentView addSubview: thumbView];
Run Code Online (Sandbox Code Playgroud)

当图像"溢出"到其下方的单元格中时,图像的顶部始终被剪裁,如下所示:

IMG

有谁知道我现在的做法是否有可能做到?

或者我应该想办法在绘制完所有单元格后将这些图像绘制到UITableView上(它是一个不可滚动的tableview,这样就可以了,并且相当容易).

更新:

还尝试添加以下内容,但无济于事:

cell.opaque = NO;
cell.contentView.opaque = NO;

cell.clearsContextBeforeDrawing = NO;
cell.contentView.clearsContextBeforeDrawing = NO;

cell.clipsToBounds = NO;    
cell.contentView.clipsToBounds = NO;
Run Code Online (Sandbox Code Playgroud)

iphone clipping uitableview

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