105 lines
2.7 KiB
C#
105 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using KGdev.BI3D.Revit.Common;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace KGdev.BI3D.Revit.Implementations
|
|
{
|
|
internal class DefaultGlobalStore : IGlobalStore
|
|
{
|
|
public string GetKey()
|
|
{
|
|
return this.Read("key");
|
|
}
|
|
|
|
public string GetToken()
|
|
{
|
|
return this.Read("token");
|
|
}
|
|
|
|
public void SetKey(string key)
|
|
{
|
|
this.Write("key", key);
|
|
}
|
|
|
|
public void SetToken(string token)
|
|
{
|
|
this.Write("token", token);
|
|
}
|
|
|
|
public string GetAppTempDirectoryPath()
|
|
{
|
|
return this.BuildFolderPath();
|
|
}
|
|
|
|
public Dictionary<string, object> GetDefaultExporterChosenOptionValues()
|
|
{
|
|
Dictionary<string, object> dictionary = new Dictionary<string, object>();
|
|
string text = this.Read("defaultOptionValues");
|
|
try
|
|
{
|
|
dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(text);
|
|
}
|
|
catch { }
|
|
return dictionary;
|
|
}
|
|
|
|
public void SetDefaultExporterChosenOptionValues(
|
|
Dictionary<string, object> valuesDictionary
|
|
)
|
|
{
|
|
string text = JsonConvert.SerializeObject(valuesDictionary);
|
|
this.Write("defaultOptionValues", text);
|
|
}
|
|
|
|
private string Read(string key)
|
|
{
|
|
string text = this.BuildPath(key);
|
|
bool flag = !File.Exists(text);
|
|
string text2;
|
|
if (flag)
|
|
{
|
|
text2 = null;
|
|
}
|
|
else
|
|
{
|
|
text2 = File.ReadAllText(text);
|
|
}
|
|
return text2;
|
|
}
|
|
|
|
private void Write(string key, string value)
|
|
{
|
|
string text = this.BuildPath(key);
|
|
File.WriteAllText(text, value);
|
|
}
|
|
|
|
private string BuildFolderPath()
|
|
{
|
|
string folderPath = Environment.GetFolderPath(
|
|
Environment.SpecialFolder.LocalApplicationData
|
|
);
|
|
string text = Path.Combine(folderPath, ".3dbi-for-revit");
|
|
Directory.CreateDirectory(text);
|
|
return text;
|
|
}
|
|
|
|
private string BuildPath(string key)
|
|
{
|
|
string text = this.BuildFolderPath();
|
|
return Path.Combine(text, key + ".setting");
|
|
}
|
|
|
|
private const string DIRECTORY_NAME = ".3dbi-for-revit";
|
|
|
|
private const string SETTINGS_FILE_EXTENSION = ".setting";
|
|
|
|
private const string KEY_KEY = "key";
|
|
|
|
private const string KEY_TOKEN = "token";
|
|
|
|
private const string KEY_DEFAULT_OPTION_VALUES = "defaultOptionValues";
|
|
}
|
|
}
|