我必须逐行读取日志文件.它的大小约为6MB,总线数为40000.但在测试我的程序后,我发现该日志文件仅由LF字符分隔.所以我不能使用类的Readline方法StreamReader
我该如何解决这个问题?
编辑:我尝试使用文本阅读器,但我的程序仍然无法正常工作:
using (TextReader sr = new StreamReader(strPath, Encoding.Unicode))
{
sr.ReadLine(); //ignore three first lines of log file
sr.ReadLine();
sr.ReadLine();
int count = 0; //number of read line
string strLine;
while (sr.Peek()!=0)
{
strLine = sr.ReadLine();
if (strLine.Trim() != "")
{
InsertData(strLine);
count++;
}
}
return count;
}
Run Code Online (Sandbox Code Playgroud) 我的程序现在仍在运行,以将数据从日志文件导入远程SQL Server数据库.日志文件大小约为80MB,包含大约470000行,大约25000行数据.我的程序只能导入300行/秒,这真的很糟糕.:(
public static int ImportData(string strPath)
{
//NameValueCollection collection = ConfigurationManager.AppSettings;
using (TextReader sr = new StreamReader(strPath))
{
sr.ReadLine(); //ignore three first lines of log file
sr.ReadLine();
sr.ReadLine();
string strLine;
var cn = new SqlConnection(ConnectionString);
cn.Open();
while ((strLine = sr.ReadLine()) != null)
{
{
if (strLine.Trim() != "") //if not a blank line, then import into database
{
InsertData(strLine, cn);
_count++;
}
}
}
cn.Close();
sr.Close();
return _count;
}
}
Run Code Online (Sandbox Code Playgroud)
InsertData只是使用ADO.NET的普通插入方法.它使用解析方法:
public Data(string strLine)
{
string[] list = strLine.Split(new[] …Run Code Online (Sandbox Code Playgroud) 我有一个包含7个字段的Access文件:
DocID - text - primary
SourceID - text
ReceivedDay - Date/Time
Summary - text
DueDay - Date/Time
Person - text
Status - Yes/No
Run Code Online (Sandbox Code Playgroud)
现在我想用以下代码更新此文件:
const string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\DocMan.mdb;Persist Security Info=True";
const string InsertQuery = "INSERT Into Docs(DocID,ReceivedDay,Summary,Person,DueDay,Status,SourceID) Values(@DocID,@ReceivedDay,@Summary,@Person,@DueDay,@Status,@SourceID)";
string DocID = textBox1.Text;
string SourceID = comboBox1.SelectedIndex.ToString();
DateTime ReceivedDay = dateTimePicker1.Value;
string Summary = richTextBox1.Text;
string Person = textBox2.Text;
DateTime DueDay = dateTimePicker2.Value;
bool Status = false;
OleDbConnection cnn = new OleDbConnection(ConnectionString);
cnn.Open();
OleDbCommand cmd = new OleDbCommand(InsertQuery, …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的方法:
public virtual Tuple<int,int> GetQuantities(Entry entry, CartHelper cartHelper)
{
//something to do
return new Tuple<int, int>(minQuantity, maxQuantity);
}
Run Code Online (Sandbox Code Playgroud)
并对它进行单元测试,我写这个模拟:
ProductMock
.Setup(
u => u.GetQuantities(It.IsAny<Entry>(),
It.IsAny<CartHelper>()))
.Returns(new Tuple<int,int>(minQuantity, maxQuantity));
Run Code Online (Sandbox Code Playgroud)
但是此代码无法编译,出现此错误:
参数1:无法从'
System.Tuple<int,int>' 转换为'System.Tuple`2<int,int>'
System.Tuple`2 向我展示了Tuple课程背后的"匿名类型",但我无法找到幕后发生的事情,以及如何解决这个问题.
编辑:对不起,我的坏,我刚刚发现我们的主项目设置为.NET 3.5,它使用自定义引用(System.ComponentModel.Composition)中的Tuple,测试项目使用.NET 4.0,它使用. NET的Tuple类.我不知道这个版本不一致如何解决我们的解决方案,但我不得不切换到另一种解决方法.而不是使用元组.
谢谢您的帮助.
谢谢.
我有一些像这样的代码:
var A = function(a,b,c) {
var self = this;
self.a = ko.observable(a);
...
self.function1 = ko.computed(function () {
dothing(a);
...
}
self.function2 = ko.computed(function () {
dothing(b);
...
}
}
var B = function(a,b,c,d) {
var self = this;
self.a = ko.observable(a);
...
self.function1 = ko.computed(function () {
dothing(a);
...
}
self.function2 = ko.computed(function () {
dothing(b);
...
}
}
Run Code Online (Sandbox Code Playgroud)
如何将function1和function2"提取"到A和B可以共享的功能?
我想设计一个关于公交车站的数据库.这个城市大约有60辆公共汽车,每个都有这些信息:
该数据库必须能够有效地进行搜索,例如,当用户想要列出通过A和B站的总线时,它必须快速运行.
在我的第一个想法中,我想将站点放在一个单独的表中,包括StationId和Station,然后站点列表将包含那些StationIds.我拜访它可能有用,但不确定它是否有效.
我该如何设计这个数据库?
非常感谢你.
我正在使用我的队友(.NET/Oracle)的遗留项目.该项目尚未完成,正在建设中,远未生产.他遵循"传统方式"来访问数据,即创建存储过程然后使用数据库驱动程序来调用它们.我想按照"现代方式"来访问数据:使用ORM来抽象和访问数据.在时间和金钱方面,这个开关不会花费太多.问题是,他比我更有经验,他有点讨厌ORM(他没有解释原因,但他说这令人困惑).我现在独自一人,但我没有足够的鼓励转向ORM.
那么,我应该切换到ORM吗?如果是的话,请鼓励我.
编辑:我不知道为什么有人需要关闭这个问题.我不够鼓励,因为我不确定哪条路更好.您可以说服我,ORM让我发展得更快,错误更少,或者存储过程更快,......无论如何.我想问你,恕我直言,有经验的程序员(比我,还有我的队友).我的队友有理由使用存储过程,许多程序员都有自己的存储过程.我需要知道为什么他们认为(存储过程非常好或他们只是想使用与它们类似的东西等等)
非常感谢.
我想创建一个这样的存储过程:
PROCEDURE P_CUSTOMER_UPDATE
(
pADSLTable IN Table,
pAccountname IN NVARCHAR2,
pStatus IN NUMBER,
pNote IN NVARCHAR2,
pEmail IN NVARCHAR2,
pMobi IN NVARCHAR2,
pServiceTypeID IN NUMBER,
pDate IN DATE
)
IS
BEGIN
UPDATE pADSLTable
SET STATUS = pStatus, NOTE = pNote, EMAIL = pEmail, MOBI = pMobi, SERVICETYPE_ID = pServiceTypeID, ACTIVATION_DATE = pDate
WHERE ACCOUNT_NAME = pAccountname;
END;
Run Code Online (Sandbox Code Playgroud)
当然,Oracle不允许我这样做.有办法解决这个问题吗?非常感谢你.
我有这样一张桌子:
UserID Customer ID status
1 1 1
1 2 1
1 3 1
1 4 2
1 5 1
1 6 3
1 7 2
2 8 1
2 9 2
........
Run Code Online (Sandbox Code Playgroud)
我想总结一下这个表,对此:
UserID count(status 1) count(status 2) count(status 3)
1 4 2 1
2 1 2 3
.........
Run Code Online (Sandbox Code Playgroud)
我怎么能在PL/SQL中做到这一点?
预先感谢
在我们的代码库中
public ActionResult Copy(string id, string targetId)
{
//lot of similar code
Copy(sourcePageRef, destinationPageRef);
//lot of similar code
}
Run Code Online (Sandbox Code Playgroud)
和
public ActionResult Move(string id, string targetId)
{
//lot of similar code
Move(sourcePageRef, destinationPageRef);
//lot of similar code
}
Run Code Online (Sandbox Code Playgroud)
问题是,复制和移动有不同的签名:
PageRef Copy(PageRef, PageRef)
Run Code Online (Sandbox Code Playgroud)
和
void Move(PageRef, PageRef)
Run Code Online (Sandbox Code Playgroud)
如何重构这些方法以避免重复?谢谢
c# ×5
.net ×3
database ×3
oracle ×3
plsql ×2
sql ×2
ado.net ×1
file ×1
inheritance ×1
javascript ×1
knockout.js ×1
moq ×1
ms-access ×1
mysql ×1
oledb ×1
orm ×1
refactoring ×1
sql-server ×1
streamreader ×1
tuples ×1
unit-testing ×1