本文整理汇总了C#中ISettingsManager.GetItem方法的典型用法代码示例。如果您正苦于以下问题:C# ISettingsManager.GetItem方法的具体用法?C# ISettingsManager.GetItem怎么用?C# ISettingsManager.GetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISettingsManager
的用法示例。
在下文中一共展示了ISettingsManager.GetItem方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NicoAccessTimer
private NicoAccessTimer(ISettingsManager smng, Dictionary<string, NicoWaitInfo> baseWaitInfoMap)
{
waitInfoMap = new Dictionary<string, NicoWaitInfo>();
patternMap = new Dictionary<string, List<Regex>>();
foreach (string timerName in smng.GetItems<string>(SettingsConstants.TIMER_NAME)) {
string intervalKey = string.Format("{0}_{1}", SettingsConstants.TIMER_INTERVAL_PREFIX, timerName);
TimeSpan interval = smng.GetItem<TimeSpan>(intervalKey);
NicoWaitInfo waitInfo;
NicoWaitInfo baseWaitInfo;
if (baseWaitInfoMap != null && baseWaitInfoMap.TryGetValue(timerName, out baseWaitInfo)) {
waitInfo = new NicoWaitInfo(interval, baseWaitInfo.LastAccess);
}
else {
waitInfo = new NicoWaitInfo(interval);
}
waitInfoMap.Add(timerName, waitInfo);
List<Regex> patternList = new List<Regex>();
patternMap.Add(timerName, patternList);
string patternKey = string.Format("{0}_{1}", SettingsConstants.TIMER_PATTERN_PREFIX, timerName);
foreach (Regex pattern in smng.GetItems<Regex>(patternKey)) {
patternList.Add(pattern);
}
}
}
示例2: Unzip
private static void Unzip(ISettingsManager smng)
{
OutputDebug("Unzip start");
var cancellationToken = smng.GetItem<CancellationToken>(SMNGKEY_CANCELLATION_TOKEN).Value;
var baseDir = smng.GetItem<string>(SMNGKEY_BASE_DIR);
var unzipWorkDir = new DirectoryInfo(Path.Combine(baseDir, "unzipWork"));
if (unzipWorkDir.Exists) {
Directory.Delete(unzipWorkDir.FullName, true);
}
unzipWorkDir.Create();
unzipWorkDir.Refresh();
if (!unzipWorkDir.Exists) {
throw new Exception(string.Format("Can't create directory: {0}", unzipWorkDir.FullName));
}
if (unzipWorkDir.EnumerateFileSystemInfos().Any()) {
throw new Exception(string.Format("Can't delete directory contents: {0}", unzipWorkDir.FullName));
}
var unzip = smng.GetItem<string>(SMNGKEY_UNZIP);
var downloadPath = smng.GetItem<string>(SMNGKEY_DOWNLOAD_PATH);
var startInfo = new ProcessStartInfo(unzip) {
Arguments = string.Format("\"{0}\"", downloadPath),
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = unzipWorkDir.FullName
};
using (var process = new Process()) {
process.StartInfo = startInfo;
DataReceivedEventHandler onDataReceived = delegate(object sender, DataReceivedEventArgs e) {
var data = e.Data;
OutputMessage(data);
};
process.OutputDataReceived += onDataReceived;
process.ErrorDataReceived += onDataReceived;
cancellationToken.ThrowIfCancellationRequested();
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
var exitCode = process.ExitCode;
if (exitCode != 0) {
throw new Exception(string.Format("Unzip returned error: {0}", exitCode));
}
}
var unzippedDir = Path.Combine(unzipWorkDir.FullName, "chrome-win32");
if (!Directory.Exists(unzippedDir)) {
throw new Exception(string.Format("Unzip failed, zip: {0}, destination: {1}", downloadPath, unzippedDir));
}
smng.SetOrAddNewItem(SMNGKEY_UNZIPPED_DIR, unzippedDir);
OutputDebug("Unzip end");
}
示例3: WaitChromiumExited
private static void WaitChromiumExited(ISettingsManager smng)
{
OutputDebug("WaitChromiumExited start");
var cancellationToken = smng.GetItem<CancellationToken>(SMNGKEY_CANCELLATION_TOKEN).Value;
var exeName = smng.GetItem<string>(SMNGKEY_EXE_NAME);
var sleepSec = smng.GetItem<int>(SMNGKEY_SLEEP_SEC);
while (true) {
var processes = Process.GetProcessesByName(exeName);
try {
if (processes.Length >= 1) {
cancellationToken.WaitHandle.WaitOne(TimeSpan.FromSeconds(sleepSec));
cancellationToken.ThrowIfCancellationRequested();
}
else {
break;
}
}
finally {
foreach (var p in processes) {
p.Dispose();
}
}
}
OutputDebug("WaitChromiumExited end");
}
示例4: RenameUnziped
private static void RenameUnziped(ISettingsManager smng)
{
OutputDebug("RenameUnziped start");
var unzippedDir = smng.GetItem<string>(SMNGKEY_UNZIPPED_DIR);
var baseDir = smng.GetItem<string>(SMNGKEY_BASE_DIR);
var appDir = Path.Combine(baseDir, "chrome-win32");
Directory.Move(unzippedDir, appDir);
if (Directory.Exists(unzippedDir)) {
throw new Exception(string.Format("Rename unzipped dir failed, src: {0}", unzippedDir));
}
if (!Directory.Exists(appDir)) {
throw new Exception(string.Format("Rename unzipped dir failed, dst: {0}", appDir));
}
OutputDebug("RenameUnziped end");
}
示例5: GetRevision
private static void GetRevision(ISettingsManager smng)
{
OutputDebug("GetRevision start");
var cancellationToken = smng.GetItem<CancellationToken>(SMNGKEY_CANCELLATION_TOKEN).Value;
var client = GetHttpClient(smng);
var hashUrl = smng.GetItem<Uri>(SMNGKEY_HASH_URL);
var revision = client.GetAsync(hashUrl, cancellationToken).Result.Content.ReadAsStringAsync().Result;
var baseDir = smng.GetItem<string>(SMNGKEY_BASE_DIR);
var pattern = string.Format("chrome-win32_*_{0}.zip", revision);
bool isLatest;
if (Directory.EnumerateFiles(baseDir, pattern).Any()) {
isLatest = true;
}
else {
isLatest = false;
}
smng.SetOrAddNewItem(SMNGKEY_IS_LATEST, isLatest);
smng.SetOrAddNewItem(SMNGKEY_REVISION, revision);
OutputDebug("GetRevision end");
}
示例6: DownloadZip
private static void DownloadZip(ISettingsManager smng)
{
OutputDebug("DownloadZip start");
var cancellationToken = smng.GetItem<CancellationToken>(SMNGKEY_CANCELLATION_TOKEN).Value;
var revision = smng.GetItem<string>(SMNGKEY_REVISION);
string zipUrlTemplate = smng.GetItem<string>(SMNGKEY_ZIP_URL_TEMPLATE);
var zipUrlStr = zipUrlTemplate.Replace("{hash}", revision);
var zipUrl = new Uri(zipUrlStr);
var client = GetHttpClient(smng);
cancellationToken.ThrowIfCancellationRequested();
var dlTask = client.GetAsync(zipUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
long contentLength;
var baseDir = smng.GetItem<string>(SMNGKEY_BASE_DIR);
var timestamp = DateTime.Now.ToString("yyyyMMddHHmmssfff");
var downloadFile = string.Format("chrome-win32_{0}_{1}.zip", timestamp, revision);
var downloadPath = Path.Combine(baseDir, downloadFile);
using (var response = dlTask.Result)
using (var content = response.Content) {
contentLength = content.Headers.ContentLength ?? -1;
OutputMessage(string.Format("Total {0} bytes", contentLength));
var percentage = 0L;
var prevPercentage = -1L;
var current = 0L;
smng.SetOrAddNewItem(SMNGKEY_DOWNLOAD_PATH, downloadPath);
cancellationToken.ThrowIfCancellationRequested();
using (var input = content.ReadAsStreamAsync().Result)
using (var output = File.Open(downloadPath, FileMode.Create, FileAccess.Write, FileShare.None)) {
var buffer = new byte[8192];
int count;
while ((count = input.Read(buffer, 0, buffer.Length)) > 0) {
cancellationToken.ThrowIfCancellationRequested();
output.Write(buffer, 0, count);
current += count;
percentage = current * 100L / contentLength;
if (prevPercentage < percentage) {
prevPercentage = percentage;
lock (consoleWriteLock) {
Console.Write(string.Format("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bdownloading {0,3}%", percentage));
}
}
}
OutputMessage(string.Empty);
}
}
var downloadFileInfo = new FileInfo(downloadPath);
long fileLength = downloadFileInfo.Length;
if (fileLength != contentLength) {
throw new Exception(string.Format("Incomplete download, expected: {0}, actual: {1}", contentLength, fileLength));
}
if (!downloadFileInfo.Exists) {
throw new Exception(string.Format("Download zip failed: {0}", downloadPath));
}
// ^chrome-win32_(?<timestamp>\d+)_[0-9a-f]+\.zip$
var zipPattern = "^chrome-win32_(?<timestamp>\\d+)_[0-9a-f]+\\.zip$";
int backupCycle;
if (!smng.TryGetItem(SMNGKEY_BACKUP_CYCLE, out backupCycle)) {
backupCycle = int.MaxValue;
}
var oldVersionZipQuery = Directory.GetFiles(baseDir)
.Select(x => Path.GetFileName(x))
.Select(x => Regex.Match(x, zipPattern))
.Where(m => m.Success)
.OrderByDescending(m => m.Groups["timestamp"].Value)
.Skip(backupCycle)
.Select(m => Path.Combine(baseDir, m.Value));
foreach (string backupToDelete in oldVersionZipQuery) {
if (File.Exists(backupToDelete)) {
File.Delete(backupToDelete);
}
if (File.Exists(backupToDelete)) {
cancellationToken.ThrowIfCancellationRequested();
throw new Exception(string.Format("Error: delete old zip: {0}", backupToDelete));
}
}
OutputDebug("DownloadZip end");
}
示例7: BackupProfileDir
private static void BackupProfileDir(ISettingsManager smng)
{
OutputDebug("BackupProfileDir start");
string ffc;
string profileDir;
string profileBackup;
int profileBackupCycle;
if (!smng.TryGetItem<string>("ffc", out ffc)) {
return;
}
if (!smng.TryGetItem<string>("profileDir", out profileDir)) {
return;
}
if (!smng.TryGetItem<string>("profileBackup", out profileBackup)) {
return;
}
if (!smng.TryGetItem<int>("profileBackupCycle", out profileBackupCycle)) {
return;
}
else if (profileBackupCycle < 1) {
return;
}
if (File.Exists(ffc) && Directory.Exists(profileDir) && Directory.Exists(profileBackup)) {
OutputMessage("Backup profile directory");
var src = profileDir.TrimEnd('\\', '/');
var dstNewDir = string.Format("ChromiumUserData_{0}", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
var dst = Path.Combine(profileBackup, dstNewDir);
OutputMessage(string.Format(" {0} -> {1}", src, dst));
var startInfo = new ProcessStartInfo(ffc) {
Arguments = string.Format("\"{0}\" /to:\"{1}\" /ed /md /ft:15", src, dst),
CreateNoWindow = false,
UseShellExecute = false,
};
var cancellationToken = smng.GetItem<CancellationToken>(SMNGKEY_CANCELLATION_TOKEN).Value;
cancellationToken.ThrowIfCancellationRequested();
using (Process process = new Process()) {
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
int exitCode = process.ExitCode;
if (exitCode != 0) {
throw new Exception(string.Format("ffc has exited with code {0}", exitCode));
}
}
if (!Directory.Exists(dst)) {
throw new Exception(string.Format("Backup profile dir filed, dst: {0}", dst));
}
var oldProfileBackupQuery = Directory.GetDirectories(profileBackup)
.Select(x => Path.GetFileName(x))
.Where(x => Regex.IsMatch(x, "^ChromiumUserData_(\\d{17})$")) // ^ChromiumUserData_(\d{17})$
.OrderByDescending(x => x)
.Skip(profileBackupCycle)
.Select(x => Path.Combine(profileBackup, x));
bool isFirst = true;
foreach (string oldProfileBackup in oldProfileBackupQuery) {
if (isFirst) {
isFirst = false;
OutputMessage("Remove old profile backups");
}
OutputMessage(string.Format(" {0}", oldProfileBackup));
Directory.Delete(oldProfileBackup, true);
}
}
OutputDebug("BackupProfileDir end");
}
示例8: BackupExeDir
private static void BackupExeDir(ISettingsManager smng)
{
OutputDebug("BackupExeDir start");
var cancellationToken = smng.GetItem<CancellationToken>(SMNGKEY_CANCELLATION_TOKEN).Value;
cancellationToken.ThrowIfCancellationRequested();
var baseDir = smng.GetItem<string>(SMNGKEY_BASE_DIR);
var currentBackupNum = Directory.GetDirectories(baseDir, "chrome-win32~*")
.Select(x => int.Parse(Regex.Match(x, "chrome-win32~(\\d+)").Groups[1].Value))
.OrderByDescending(x => x)
.First();
var backupNum = currentBackupNum + 1;
var backupDir = Path.Combine(baseDir, string.Format("chrome-win32~{0}", backupNum));
var appDir = Path.Combine(baseDir, "chrome-win32");
Directory.Move(appDir, backupDir);
if (Directory.Exists(appDir)) {
throw new Exception(string.Format("Move directory failed, src: {0}", appDir));
}
if (!Directory.Exists(backupDir)) {
throw new Exception(string.Format("Move directory failed, dst: {1}", backupDir));
}
int backupCycle;
if (!smng.TryGetItem(SMNGKEY_BACKUP_CYCLE, out backupCycle)) {
backupCycle = int.MaxValue;
}
var oldExeDirQuery = Directory.GetDirectories(baseDir)
.Select(x => Path.GetFileName(x))
.Where(x => Regex.IsMatch(x, "^chrome-win32~(?<num>\\d+)$")) // ^chrome-win32~(?<num>\d+)$
.OrderByDescending(x => int.Parse(Regex.Match(x, "^chrome-win32~(?<num>\\d+)$").Groups["num"].Value))
.Skip(backupCycle)
.Select(x => Path.Combine(baseDir, x));
foreach (string backupToDelete in oldExeDirQuery) {
OutputDebug(string.Format("Deleting {0}", Path.GetFileName(backupToDelete)));
Directory.Delete(backupToDelete, true);
}
OutputDebug("BackupExeDir end");
}