/// <summary> /// index [0, count-1] /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tablename"></param> /// <param name="t"></param> /// <param name="index"></param> public static void Load <T>(string tablename, T t, int index) where T : class, new() { //Debug.Log(SelectTableText<T>(tablename, index)); try { OpenDb(); sqlCommand.CommandText = SelectTableText <T>(tablename, index); using (var sqlReader = sqlCommand.ExecuteReader()) { if (sqlReader.Read()) { int count = sqlReader.FieldCount; for (int i = 0; i < count; i++) { RefUtility <T> .SetPropertyValue(i, t, sqlReader.GetValue(i)); //Debug.LogFormat("{0} Value: {1}", i, sqlReader.GetValue(i)); } } } } catch (Exception e) { t = new T(); Debug.LogError(e.Message + "\n" + e.Source + "\n" + e.StackTrace + "\n" + e.Data); } }
public static void PrintT <T>(T t) { var builder = new StringBuilder(); var length = RefUtility <T> .GetPropertiesLength(); for (int i = 0; i < length; i++) { builder.AppendFormat("{0} {1}{2}", RefUtility <T> .GetPropertyName(i), RefUtility <T> .GetPropertyValue(i, t), i < length - 1 ? ", " : ";"); } Debug.Log(builder.ToString()); }
public static string InsertTableText <T>(string tablename, T t) { var length = RefUtility <T> .GetPropertiesLength(); var builder = new StringBuilder(string.Format(@"INSERT INTO {0} VALUES (", tablename)); for (var i = 0; i < length; i++) { builder.AppendFormat("\'{0}\'{1}", RefUtility <T> .GetPropertyValue(i, t), i < length - 1 ? ", " : ")"); } return(builder.ToString()); }
public static string CreateTableText <T>(string tablename) { var length = RefUtility <T> .GetPropertiesLength(); StringBuilder builder = new StringBuilder(string.Format(@"CREATE TABLE IF NOT EXISTS {0} (", tablename)); for (int i = 0; i < length; i++) { builder.AppendFormat("{0} {1}{2}", RefUtility <T> .GetPropertyName(i), GetSqliteType(RefUtility <T> .GetPropertyType(i)), i < length - 1 ? ", " : ")"); } return(builder.ToString()); }
public static string UpdateTableText <T>(string tablename, T t, int index) { var length = RefUtility <T> .GetPropertiesLength(); var builder = new StringBuilder(string.Format(@"UPDATE {0} SET ", tablename)); for (var i = 0; i < length; i++) { builder.AppendFormat("{0}=\'{1}\'{2}", RefUtility <T> .GetPropertyName(i), RefUtility <T> .GetPropertyValue(i, t), i < length - 1 ? ", " : " WHERE ROWID=" + (index + 1)); } return(builder.ToString()); }
public static string SelectTableText <T>(string tablename, int index) { var length = RefUtility <T> .GetPropertiesLength(); StringBuilder builder = new StringBuilder(@"SELECT "); for (int i = 0; i < length; i++) { builder.AppendFormat("{0}{1}", RefUtility <T> .GetPropertyName(i), i < length - 1 ? ", " : " "); } builder.AppendFormat("FROM {0} LIMIT 1 OFFSET {1}", tablename, index); return(builder.ToString()); }
public override CommandResult Execute(IEnumerable <string> inputParams) { if (!ExecuteCommon(inputParams)) { return(new CommandResult(false, _outputMessages)); } // deserialise client file OpcuaClientApp opcuaClient = null; OpcuaClientServerApp opcuaClientServer = null; RefUtility.DeserializeClient(ref opcuaClient, ref opcuaClientServer, _clientFullName, _fileSystem); if (opcuaClient == null && opcuaClientServer == null) { AppioLogger.Warn(LoggingText.ReferenceCouldntDeserliazeClient); _outputMessages.Add(string.Format(OutputText.ReferenceCouldntDeserliazeClient, _clientFullName), string.Empty); return(new CommandResult(false, _outputMessages)); } // check if server is part of client's reference and remove it string clientNewContent = string.Empty; IOpcuaServerApp serverReference = null; if (opcuaClientServer != null && (serverReference = opcuaClientServer.ServerReferences.SingleOrDefault(x => x.Name == _serverName)) != null) { opcuaClientServer.ServerReferences.Remove(serverReference); clientNewContent = JsonConvert.SerializeObject(opcuaClientServer, Formatting.Indented); } else if (opcuaClient != null && (serverReference = opcuaClient.ServerReferences.SingleOrDefault(x => x.Name == _serverName)) != null) { opcuaClient.ServerReferences.Remove(serverReference); clientNewContent = JsonConvert.SerializeObject(opcuaClient, Formatting.Indented); } else { AppioLogger.Warn(LoggingText.ReferenceRemoveServerIsNotInClient); _outputMessages.Add(string.Format(OutputText.ReferenceRemoveServerIsNotInClient, _serverName, _clientName), string.Empty); return(new CommandResult(false, _outputMessages)); } _fileSystem.WriteFile(_clientFullName, new List <string> { clientNewContent }); // exit method with success AppioLogger.Info(LoggingText.ReferenceRemoveSuccess); _outputMessages.Add(string.Format(OutputText.ReferenceRemoveSuccess, _clientName, _serverName), string.Empty); return(new CommandResult(true, _outputMessages)); }
public override CommandResult Execute(IEnumerable <string> inputParams) { if (!ExecuteCommon(inputParams)) { return(new CommandResult(false, _outputMessages)); } // validate server var serverFullName = _fileSystem.CombinePaths(_serverName, _serverName + Constants.FileExtension.Appioproject); if (!ValidateServer(_serverName, serverFullName)) { return(new CommandResult(false, _outputMessages)); } // deserialize server file OpcuaServerApp opcuaServer = SlnUtility.DeserializeFile <OpcuaServerApp>(serverFullName, _fileSystem); if (opcuaServer == null) { AppioLogger.Warn(LoggingText.ReferenceAddCouldntDeserliazeServer); _outputMessages.Add(string.Format(OutputText.ReferenceAddCouldntDeserliazeServer, serverFullName), string.Empty); return(new CommandResult(false, _outputMessages)); } // check if deserialized server is not a client if (opcuaServer.Type == Constants.ApplicationType.Client) { AppioLogger.Warn(LoggingText.ReferenceAddClientCannotBeReferred); _outputMessages.Add(string.Format(OutputText.ReferenceAddClientCannotBeReferred, _serverName), string.Empty); return(new CommandResult(false, _outputMessages)); } // deserialize client file OpcuaClientApp opcuaClient = null; OpcuaClientServerApp opcuaClientServer = null; RefUtility.DeserializeClient(ref opcuaClient, ref opcuaClientServer, _clientFullName, _fileSystem); if (opcuaClient == null && opcuaClientServer == null) { AppioLogger.Warn(LoggingText.ReferenceCouldntDeserliazeClient); _outputMessages.Add(string.Format(OutputText.ReferenceCouldntDeserliazeClient, _clientFullName), string.Empty); return(new CommandResult(false, _outputMessages)); } // check if deserialized client is not a server if (!ClientIsNotAServer(ref opcuaClient, ref opcuaClientServer, _clientName)) { return(new CommandResult(false, _outputMessages)); } // check if server is not already a part of client's references if (!ServerIsNotYetClientsReference(ref opcuaClient, ref opcuaClientServer, _clientName, opcuaServer.Name)) { return(new CommandResult(false, _outputMessages)); } // overwrite client appioproj file with new server reference string clientNewContent = string.Empty; if (opcuaClientServer != null) { opcuaClientServer.ServerReferences.Add(opcuaServer); clientNewContent = JsonConvert.SerializeObject(opcuaClientServer, Formatting.Indented); } else { opcuaClient.ServerReferences.Add(opcuaServer); clientNewContent = JsonConvert.SerializeObject(opcuaClient, Formatting.Indented); } _fileSystem.WriteFile(_clientFullName, new List <string> { clientNewContent }); // exit with success AppioLogger.Info(LoggingText.ReferenceAddSuccess); _outputMessages.Add(string.Format(OutputText.RefereneceAddSuccess, _serverName, _clientName), string.Empty); return(new CommandResult(true, _outputMessages)); }