using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using static DataStoreServiceNameSpace.DataStoreServiceMain;
namespace DataStoreService
{
public struct DataStore
{
public string Name = "ERROR";
public string filepath = "ERROR";
public string path = "ERROR";
public DataStore(string ACCESSCODE = "IMINTROUBLE")
{
if (ACCESSCODE == "CODE-PASS-ID:6t2uy3i2u3i2132131io31oi31u31ou3i1o3")
{
}
else
{
throw new Exception("DataStores Must Be Declared Using DataStoreService.GetDataStore");
}
}
public string GetAsync(string key)
{
string[] lines = File.ReadAllLines(filepath);
string data = "";
bool FoundData = false;
foreach (string line in lines)
{
string[] split = line.Split('"');
if (split == null)
{
throw new Exception("Can not find key:" + key + ". Did you forget to use DataStore.SetAsync");
}
if (split[0] == key)
{
FoundData = true;
data = split[1];
}
}
if (FoundData == false)
{
throw new Exception("Can not find key:" + key + ". Did you forget to use DataStore.SetAsync");
}
return data;
}
public bool SetAysnc(string key, string data)
{
if (key == null)
{
throw new ArgumentNullException();
}
string[] lines = File.ReadAllLines(filepath);
bool FoundData = false;
int position = -1;
int i = 0;
foreach (string line in lines)
{
string[] split = line.Split('"');
if (split[0] == key)
{
position = i;
FoundData = true;
}
i = i + 1;
}
if (FoundData)
{
lines[position] = key + '"' + data;
File.WriteAllLines(filepath, lines);
}
else
{
string[] e = { key + '"' + data };
File.AppendAllLines(filepath, e);
}
return true;
}
}
public class DataStoreServiceMain
{
public DataStoreServiceNameSpace.DataStore
GetDataStore(string name)
{
DataStoreServiceNameSpace.DataStore d = new DataStoreServiceNameSpace.DataStore("CODE-PASS-ID:6t2uy3i2u3i2132131io31oi31u31ou3i1o3");
d.path = GetType().Assembly.Location;
d.filepath = Directory.GetParent(d.path).Parent.Parent.Parent.FullName + "/DataStores/" + name + ".bendata";
d.Name = name;
if (File.Exists(d.filepath))
{
}
else
{
FileStream file = File.Create(d.filepath);
file.Close();
}
return d;
}
}
}
2条答案
按热度按时间70gysomp1#
您必须使用xml。有关详细信息:http://msdn.microsoft.com/en-us/library/system.data.dataset(v=vs.110).aspx和http://msdn.microsoft.com/en-us/library/ws09ehyc(v=vs.110).aspx
whlutmcx2#
您可以做的一件事是使用此名称空间
在文件的目录中设置一个文件夹并将其命名为(DataStores)