我正在使用android xml rpc来安装服务器.为此我正在使用和intentService.唯一的问题是,当启动服务器类时,永远不会调用包含服务器的onHandleIntent.
我做了一些研究,我找到了一个有同样问题的人,他通过使用超级类来管理它,但我是编程的新手,并没有设法做他做的事情==> 链接
这是我的代码:
package tfe.rma.ciss.be;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlrpc.android.MethodCall;
import org.xmlrpc.android.XMLRPCServer;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
public class Server extends IntentService {
public String myData="";
public String streamTitle = "",path="";
public void onCreate() {
Log.d("Server", ">>>onCreate()");
}
public Server() {
super("Server");
}
public void …
Run Code Online (Sandbox Code Playgroud) 在我的程序中,我使用运行对象表(ROT)来确保只运行一个程序实例.由于我从一位不幸离开公司的开发人员那里"继承"了这段代码,我是解决问题的穷人.代码工作正常,但我们有3个客户(39,000个)将获得AccessDeniedException
.每个客户都以用户模式运行软件.
有什么建议可能是错的吗?
bool retVal = false;
IMoniker[] arrMoniker = new IMoniker[1];
IBindCtx bindCtx = null;
string displayName;
int hResult;
int mkSys;
Guid clsidRot;
bool guidCompare = false;
IntPtr number = IntPtr.Zero;
moreObjectsListed = false;
objectFromRot = null;
try
{
// check the objects in the running object table for fitting the specified class id
while ((retVal == false) && (0 == enumMoniker.Next(1, arrMoniker, number)))
{
hResult = CreateBindCtx(0, out bindCtx);
if (hResult == 0)
{
arrMoniker[0].IsSystemMoniker(out mkSys);
if …
Run Code Online (Sandbox Code Playgroud) 我正在使用C#导入一个包含6-8百万行的CSV.
我的表看起来像这样:
CREATE TABLE [Data] ([ID] VARCHAR(100) NULL,[Raw] VARCHAR(200) NULL)
CREATE INDEX IDLookup ON Data(ID ASC)
Run Code Online (Sandbox Code Playgroud)
我正在使用System.Data.SQLite来进行导入.
目前在Windows 7 32位,Core2Duo 2.8Ghz和4GB RAM上耗时6分55秒.这不是太糟糕,但我只是想知道是否有人能够更快地看到导入它的方法.
这是我的代码:
public class Data
{
public string IDData { get; set; }
public string RawData { get; set; }
}
string connectionString = @"Data Source=" + Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + "\\dbimport");
System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection(connectionString);
conn.Open();
//Dropping and recreating the table seems to be the quickest way to get old data removed
System.Data.SQLite.SQLiteCommand command = new System.Data.SQLite.SQLiteCommand(conn); …
Run Code Online (Sandbox Code Playgroud) 我想根据当前Locale的值包含一个js文件.我试图从JSP访问它如下:
<%@ page import="java.util.Locale" %>
<% if( ((Locale) pageContext.getAttribute("org.apache.struts.action.LOCALE",PageContext.REQUEST_SCOPE)).getLanguage().equals("de")) { %>
<script src="../themes/administration/js/languages/i18nDE.js" type="text/javascript"> </script>
<% } else { %>
<script src="../themes/administration/js/languages/i18nEN.js" type="text/javascript"> </script>
<% } %>
Run Code Online (Sandbox Code Playgroud)
但是,我得到一个java.lang.NullPointerException
,因为 pageContext.getAttribute("org.apache.struts.action.LOCALE",PageContext.REQUEST_SCOPE)
是NULL
.
有谁知道我怎么能解决这个问题?
我正在为我们的应用程序实现观察者模式 - 目前正在使用RX Framework.
我目前有一个看起来像这样的例子:
Observable.FromEventPattern<PropertyChangedEventArgs>(Instance.Address, "PropertyChanged")
.Where(e => e.EventArgs.PropertyName == "City")
.ObserveOn(Scheduler.ThreadPool)
.Subscribe(search => OnNewSearch(search.EventArgs));
Run Code Online (Sandbox Code Playgroud)
(我有一个类似的"PropertyChanging")
EventArgs不会给我太多.我想要的是EventArgs的扩展,它使我能够查看先前和新值,以及在"更改"侦听器中标记事件的能力,以便更改实际上不会持续存在.如何才能做到这一点?谢谢.
我对SortedSet的行为有点疑惑,请看下面的例子:
public class Blah
{
public double Value { get; private set; }
public Blah(double value)
{
Value = value;
}
}
public class BlahComparer : Comparer<Blah>
{
public override int Compare(Blah x, Blah y)
{
return Comparer<double>.Default.Compare(x.Value, y.Value);
}
}
public static void main()
{
var blahs = new List<Blah> {new Blah(1), new Blah(2),
new Blah(3), new Blah(2)}
//contains all 4 entries
var set = new HashSet<Blah>(blahs);
//contains only Blah(1), Blah(2), Blah(3)
var sortedset = new SortedSet<Blah>(blahs, new BlahComparer()); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个程序,它将获取一行数据并将其传递到另一个窗口/进程.
这是我到目前为止的代码,但我还没有弄清楚如何将键盘命令发送到OUTLOOK进程.
我希望能够使用Tab命令/键和Enter命令/键.
这是我到目前为止所尝试的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;
namespace Config
{
class Program
{
[STAThread]
static void Main(string[] args)
{
System.Threading.Thread.Sleep(30);//300000
TextReader tr = new StreamReader("config.txt");
Clipboard.SetText(tr.ReadLine());
tr.Close();
var proc = Process.GetProcessesByName("OUTLOOK").FirstOrDefault();
if (proc != null && proc.MainWindowHandle != IntPtr.Zero)
{
SetForegroundWindow(proc.MainWindowHandle);
//SendKeys.Send("{ENTER}");
// Clipboard.GetText();
}
}
[DllImport("user32")]
private static extern bool SetForegroundWindow(IntPtr hwnd);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用文件流的类.它需要在应用程序关闭时关闭流,因此我使类实现IDisposable.
该类是另一个类的成员,它是另一个类的成员等.一直到我的主应用程序.
因此,我是否必须在所有这些类上实现IDisposable ?
如果我将来更改文件实现以便在每次写入后关闭文件怎么办?我现在有一整套无条件实现IDisposable的类.
我想我对将IDisposable语义扼杀到除了链上的一些轻微的实现细节之外的不需要它们的类中感到不舒服.这有什么办法吗?
//Assert
Lazy<INotificationService> notificationService = Substitute.For<Lazy<INotificationService>>();
Service target = new Service(repository, notificationService);
//Act
target.SendNotify("Message");
//Arrange
notificationService.Received().Value.sendNotification(null, null, null, null);
Run Code Online (Sandbox Code Playgroud)
上面的代码抛出异常.
lazily-initialized类型没有公共的无参数构造函数
我正在使用C#4.0和NSubstitute 1.2.1
我们的项目中有一些安装类,它们使用来自某些.config-Files的XmlSerializer进行序列化/反序列化.在其中一些安装类中,我们有子设置的集合,如下所示:
using System;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
namespace Datev.Framework.Shared.Actions.Setup
{
[Serializable]
[XmlSerializerAssembly]
[XmlRoot("setup")]
public class SetupXml
{
public SetupXml()
{
SubSetups = new Collection<SubSetupXml>();
}
[XmlArray("subSetups")]
[XmlArrayItem("subSetup")]
public Collection<SubSetupXml> SubSetups { get; private set; }
}
[Serializable]
public class SubSetupXml
{
[XmlElement("someValue")]
public string SomeValue { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我们使用属性[XmlSerializerAssembly]来获得读写设置的最佳性能.这是我的问题:我们使用Collection来避免CA警告"不要使用数组".当我们公开SubSetup的setter时,我们得到CA-Warning CA2227"不要公开集合的setter".如果我们将属性SubSetups的setter设为私有(如代码示例中所示),我们将在生成的序列化程序中出错.方法"GenerateSerializer"(在我们的工具中调用)代码有这样一行:
if (o.SubSetups == null) o.SubSetups = new Collection<SubSetupXml>();
Run Code Online (Sandbox Code Playgroud)
如果我们将setter设为私有,我们将在构建序列化程序时获得CS0200"Property SubSetups".有没有人知道如何使用生成的序列化程序进行正确设置而不抑制CA警告?