虽然我知道这是一个简单的问题,并且我的知识存在差距 - 请记住我正在编写此代码来学习(详细的解释或最佳实践建议将对此有很大帮助)。
首先,这是我的课:
namespace CCQ.Crawler._2010
{
public class MSSQL
{
public MSSQL(string connectionString)
{
ConnectionString = connectionString;
}
public static string ConnectionString { get; private set; }
/// <summary>
/// Class to house statements that insert or update data into the database
/// </summary>
public class Upserts
{
/// <summary>
/// Add or update a new entry on the site collection table
/// </summary>
/// <param name="siteCollectionName"></param>
public void SiteCollection(string siteCollectionName)
{
const string queryString =
@"INSERT INTO [dbo].[SiteCollections]
([SnapShotDate]
,[SiteCollectionName]
,[SiteWebCount]
,[ContentDatabase]
,[SiteWebApplication])
VALUES
(@snapShotDate, @siteCollectionName, @siteWebCount, @contentDatabase, @siteWebApplication)";
using (var connection = new SqlConnection(ConnectionString))
{
using (var cmd = new SqlCommand(queryString, connection))
{
connection.Open();
cmd.Parameters.AddWithValue("snapShotDate", DateTime.Today.Date);
cmd.Parameters.AddWithValue("siteCollectionName", siteCollectionName);
cmd.ExecuteNonQuery();
}
}
}
}
}
}
这是我的主程序文件:
namespace CCQ.Crawler._2010
{
internal class Program
{
private static string _connectionString;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public static string ConnectionString
{
get
{
if (string.IsNullOrEmpty(_connectionString))
{
_connectionString = AES.DecryptFromBase64String(ConfigurationManager.AppSettings["DatastoreConnection"]);
}
return _connectionString;
}
}
static void Main(string[] args)
{
string version = Assembly.GetAssembly(typeof(Program)).GetName().Version.ToString();
Console.WriteLine("[{0}] SharePoint Crawler started with version '{1}'.", DateTime.Now.ToShortTimeString(), version);
Logger.Info(string.Format("[{0}] SharePoint Crawler started with version '{1}'.", DateTime.Now.ToShortTimeString(), version));
try
{
var query = new MSSQL(ConnectionString);
}
catch (Exception ex)
{
Logger.Error(String.Format("[{0}] {1}", DateTime.Now.ToShortTimeString(), ex.GetBaseException()));
Console.WriteLine("[{0}] {1}", DateTime.Now.ToShortTimeString(), ex.GetBaseException());
}
}
}
}
现在我认为我可以用这门课做的是:
var query = new MSSQL(ConnectionString).Upserts;
query.SiteCollection("testing");
但是,好吧,那是行不通的。当我尝试声明类时遇到的错误是:
类名此时无效
我知道在我的知识/班级建设的某个地方存在巨大的差距,这就是为什么,但我不知道从哪里开始——我的思维错误在哪里?