Catalog/CatalogLib/PicSettings.cs

429 lines
11 KiB
C#
Raw Normal View History

2016-07-04 16:45:45 +02:00
using System;
using System.Collections.Generic;
2016-11-07 16:20:31 +01:00
using System.Diagnostics;
2016-07-04 16:45:45 +02:00
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2016-11-07 16:20:31 +01:00
using Newtonsoft.Json;
2016-07-04 16:45:45 +02:00
namespace CatalogLib
{
public class PicSettings
{
2016-11-07 16:20:31 +01:00
private static PicSettings _instance = new PicSettings();
2016-11-07 20:58:16 +01:00
public static PicSettings Instance
{
get { return _instance; }
}
2016-07-04 16:45:45 +02:00
private Dictionary<string, object> _settingsDict = new Dictionary<string, object>();
public PicSettings()
{
SetDefaults();
}
2016-11-07 16:20:31 +01:00
public string SerializeSettings()
{
return JsonConvert.SerializeObject(_settingsDict);
2016-11-07 20:58:16 +01:00
}
2016-11-07 16:20:31 +01:00
2016-11-07 20:58:16 +01:00
public void DeserializeSettings(string serializedData)
{
_settingsDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(serializedData);
2017-03-17 16:23:29 +01:00
2016-11-07 16:20:31 +01:00
}
2017-03-17 16:23:29 +01:00
public void SetBase(string key, object value)
2016-07-04 16:45:45 +02:00
{
if (_settingsDict.ContainsKey(key))
{
_settingsDict[key] = value;
}
else
{
2016-11-07 16:20:31 +01:00
_settingsDict.Add(key, value);
2016-07-04 16:45:45 +02:00
}
}
2016-11-07 20:58:16 +01:00
public void SetString(string key, string value)
2016-11-07 16:20:31 +01:00
{
2017-03-17 16:23:29 +01:00
SetBase(key, value);
2016-11-07 16:20:31 +01:00
}
public void SetInt(string key, int value)
{
2017-03-17 16:23:29 +01:00
SetBase(key, value);
2016-11-07 16:20:31 +01:00
}
public void SetBool(string key, bool value)
{
2017-03-17 16:23:29 +01:00
SetBase(key, value);
2016-11-07 16:20:31 +01:00
}
2017-03-17 16:23:29 +01:00
public void SetDouble(string key, double value)
{
SetBase(key, value);
}
2016-11-07 16:20:31 +01:00
2017-03-17 16:23:29 +01:00
public void Set<T>(string key, T value)
{
SetBase(key, value);
}
2016-11-07 16:20:31 +01:00
2016-07-04 16:45:45 +02:00
public bool Exists(string key)
{
return _settingsDict.ContainsKey(key);
}
2016-11-07 20:58:16 +01:00
public int GetInt(string key, int defaultValue = 0)
2016-07-04 16:45:45 +02:00
{
2016-11-07 20:58:16 +01:00
if (!_settingsDict.ContainsKey(key))
{
SetInt(key, defaultValue);
}
if (_settingsDict[key] is int) return (int)_settingsDict[key];
Debug.WriteLine($"Error while parsing {key}");
//return defaultValue;
2017-03-17 16:23:29 +01:00
2016-11-07 20:58:16 +01:00
int r;
if (int.TryParse(_settingsDict[key].ToString(), out r))
{
SetInt(key, r);
}
else
{
SetInt(key, defaultValue);
}
2017-03-17 16:23:29 +01:00
return (int)_settingsDict[key];
2016-11-07 20:58:16 +01:00
//return (int) _settingsDict[key];
//return _settingsDict.ContainsKey(key) ? (int)_settingsDict[key] : defaultValue;
2016-07-04 16:45:45 +02:00
}
2017-03-17 16:23:29 +01:00
public double GetDouble(string key, double defaultValue = 0)
{
if (!_settingsDict.ContainsKey(key))
{
SetDouble(key, defaultValue);
// setdouble default
}
if (_settingsDict[key] is double) return (double)_settingsDict[key];
Debug.WriteLine($"Error while parsing {key}");
double d;
if (double.TryParse(_settingsDict[key].ToString(), out d))
{
SetDouble(key, d);
// setdouble key r
}
else
{
SetDouble(key, defaultValue);
//setdouble defaultvalue
}
return (double)_settingsDict[key];
}
public T Get<T>(string key, T defaultValue)
{
if (!_settingsDict.ContainsKey(key))
{
Set<T>(key, defaultValue);
// setdouble default
}
2017-03-23 14:36:06 +01:00
return (T)_settingsDict[key];
2017-03-17 16:23:29 +01:00
}
2016-11-07 20:58:16 +01:00
public string GetString(string key, string defaultValue = "")
2016-07-04 16:45:45 +02:00
{
2016-11-07 20:58:16 +01:00
if (!_settingsDict.ContainsKey(key))
{
SetString(key, defaultValue);
}
2017-03-17 16:23:29 +01:00
return (string)_settingsDict[key];
2016-11-07 20:58:16 +01:00
//return _settingsDict.ContainsKey(key) ? (string)_settingsDict[key] : defaultValue;
2016-07-04 16:45:45 +02:00
}
2016-11-07 20:58:16 +01:00
public bool GetBool(string key, bool defaultValue = false)
2016-07-04 16:45:45 +02:00
{
2016-11-07 20:58:16 +01:00
if (!_settingsDict.ContainsKey(key))
{
SetBool(key, defaultValue);
return defaultValue;
}
2017-03-17 16:23:29 +01:00
return (bool)_settingsDict[key];
2016-11-07 20:58:16 +01:00
//return _settingsDict.ContainsKey(key) && (bool)_settingsDict[key];
2016-07-04 16:45:45 +02:00
}
2016-11-07 20:58:16 +01:00
public object GetObject(string key, object defaultValue = null)
2016-07-04 16:45:45 +02:00
{
2016-11-07 20:58:16 +01:00
if (!_settingsDict.ContainsKey(key))
{
Set(key, defaultValue);
return defaultValue;
}
return _settingsDict[key];
//return _settingsDict.ContainsKey(key) ? _settingsDict[key] : defaultValue;
2016-07-04 16:45:45 +02:00
}
2016-11-07 16:20:31 +01:00
2016-07-04 16:45:45 +02:00
public void SetDefaults()
{
2016-11-07 20:58:16 +01:00
2016-07-04 16:45:45 +02:00
}
2016-11-07 16:20:31 +01:00
public bool DirAggiornaSottoDirectory
{
2016-11-07 20:58:16 +01:00
get { return this.GetBool("DirAggiornaSottoDirectory", true); }
set { this.SetBool("DirAggiornaSottoDirectory", value); }
2016-11-07 16:20:31 +01:00
}
public bool Grassetto
2016-07-04 16:45:45 +02:00
{
get { return GetBool("Grassetto"); }
2016-11-07 16:20:31 +01:00
set { SetBool("Grassetto", value); }
2016-07-04 16:45:45 +02:00
}
public string IlFont //todo
{
get { return GetString(""); }
set { }
}
public bool TestoMin //todo
{
get { return false; }
set { }
}
public bool AggTempoGaraMin //todo
{
get { return false; }
set { }
}
public bool UsaTempoGaraTestoApplicare //todo
{
get { return false; }
set { }
}
public bool AggNumTempMin //todo
{
get { return false; }
set { }
}
public bool CreaMiniature //todo
{
get { return false; }
set { }
}
2016-11-07 16:20:31 +01:00
public bool AggiungiScritteMiniature
{
get { return false; }
set { }
}
2016-07-04 16:45:45 +02:00
2016-11-07 16:20:31 +01:00
public string Suffisso
{
get { return string.Empty; }
set { }
}
2016-07-04 16:45:45 +02:00
2016-11-07 16:20:31 +01:00
public string Codice
{
get { return null; }
set { }
}
2016-07-04 16:45:45 +02:00
2016-11-07 16:20:31 +01:00
public int Trasparenza
{
get { return 0; }
}
2016-07-04 16:45:45 +02:00
2016-11-07 16:20:31 +01:00
public string Posizione
{
get { return string.Empty; }
}
2016-07-04 16:45:45 +02:00
2016-08-02 13:22:13 +02:00
public bool UsaRotazioneAutomatica { get; set; }
public DateTime DataPartenza { get; set; }
public string TestoOrario { get; internal set; }
public int DimStandard { get; internal set; }
public int DimStandardMiniatura { get; internal set; }
public bool UsaOrarioTestoApplicare { get; set; }
public bool UsaOrarioMiniatura { get; set; }
public string TestoFirmaStart { get; set; }
public string TestoFirmaStartV { get; set; }
public bool UsaForzaJpg { get; set; }
2016-11-07 20:58:16 +01:00
public string DirectorySorgente
{
get { return GetString("DirSorgente"); }
set { SetString("DirSorgente", value); }
}
public string DirectoryDestinazione
{
get { return GetString("DirDestinazione"); }
set { SetString("DirDestinazione", value); }
}
2016-08-02 13:22:13 +02:00
public float Margine { get; set; }
public float MargVert { get; set; }
public string Allineamento { get; set; }
2016-11-07 20:58:16 +01:00
public bool GeneraleForzaJPG
{
get { return GetBool("GeneraleForzaJPG", true); }
set { SetBool("GeneraleForzaJPG", value); }
}
public bool GeneraleRotazioneAutomatica
{
2017-03-23 14:36:06 +01:00
get { return GetBool("GeneraleRotazioneAutomatica", true); }
2016-11-07 20:58:16 +01:00
set { SetBool("GeneraleRotazioneAutomatica", value); }
}
public bool GeneraleSovrascriviFile
{
get { return GetBool("GeneraleSovrascriviFile"); }
set { SetBool("GeneraleSovrascriviFile", value); }
}
public bool SubdirCreaSottoCartelle
{
get { return GetBool("SubdirCreaSottoCartelle"); }
set { SetBool("SubdirCreaSottoCartelle", value); }
}
public int SubdirIntervalloFile
{
get { return GetInt("SubdirIntervalloFile", 99); }
set { SetInt("SubdirIntervalloFile", value); }
}
public string SubdirSuffisso
{
get { return GetString("SubdirSuffisso"); }
set { SetString("SubdirSuffisso", value); }
}
public int SubdirCifreContatore
{
get { return GetInt("SubdirCifreContatore", 2); }
set { SetInt("SubdirCifreContatore", value); }
}
public bool SubdirNumerazioneProgressiva
{
get { return GetBool("SubdirNumerazioneProgressiva", true); }
set { SetBool("SubdirNumerazioneProgressiva", value); }
}
public bool SubdirNumerazioneFiles
{
get { return GetBool("SubdirNumerazioneFiles", false); }
set { SetBool("SubdirNumerazioneFiles", value); }
}
public int FotoAltezza
{
get { return GetInt("FotoAltezza", 2240); }
set { SetInt("FotoAltezza", value); }
}
public int FotoLarghezza
{
get { return GetInt("FotoLarghezza", 2240); }
set { SetInt("FotoLarghezza", value); }
}
public int CompressioneJpeg
{
get { return GetInt("CompressioneJpeg", 85); }
set { SetInt("CompressioneJpeg", value); }
}
public bool FotoMantieniDimensioni
{
get { return GetBool("FotoMantieniDimensioni", true); }
set { SetBool("FotoMantieniDimensioni", value); }
}
public string FotoSuffisso
{
get { return GetString("FotoSuffisso"); }
set { SetString("FotoSuffisso", value); }
}
2017-03-23 14:36:06 +01:00
2016-11-07 20:58:16 +01:00
public bool EnableThumbnails
{
get { return GetBool("EnableThumbnails", false); }
set { SetBool("EnableThumbnails", value); }
}
public bool EnableLogo
{
get { return GetBool("EnableLogo", false); }
set { SetBool("EnableLogo", value); }
}
2017-03-17 16:23:29 +01:00
#region Text
public bool EnableText
{
get { return GetBool("EnableText", false); }
set { SetBool("EnableText", value); }
}
public string NomeFont
{
get { return GetString("nomeFont", "Verdana"); }
set { SetString("nomeFont", value); }
}
public double DimensioneFont
{
get { return Get<double>("dimensioneFont", 1); }
set { SetDouble("dimensioneFont", value); }
}
2017-03-23 14:36:06 +01:00
public string TestoApplicareOrizzontale
{
get
{
return Get<string>("TestoApplicareOrizzontale", "");
}
set
{
Set<string>("TestoApplicareOrizzontale", value);
}
}
2017-03-17 16:23:29 +01:00
#endregion
2016-07-04 16:45:45 +02:00
}
2016-11-07 20:58:16 +01:00
}