Beispiel #1
0
            internal void getMessageToTable(ref dynamic obj)
            {
                String columns    = " *";
                String parameters = "";

                try
                {
                    //if ((obj.DataBase as IDictionary<string, object>).ContainsKey("DBQueryColumns"))
                    //{
                    //    columns = " (";
                    //    foreach (String parame in obj.DataBase.DBQueryColumns)
                    //    {
                    //        columns += (String)parame + ", ";
                    //    }
                    //    columns = columns.Substring(0, columns.Length - 2) + ") ";
                    //}
                    //if ((obj.DataBase as IDictionary<string, object>).ContainsKey("DBQueryValues"))
                    //{
                    //    parameters = " WHERE ";
                    //    foreach (String parame in obj.DataBase.DBQueryValues)
                    //    {
                    //        parameters += parame;
                    //    }
                    //}

                    obj.DBQuery = _DBQueryType + columns + " FROM " + _DBDefaultTableName; //+ parameters;
                    _exeBaseDeDatos.GetData(ref obj, "Get");
                }
                catch (Exception ex)
                {
                    throw SpinException.GetException("SPINIODB:: " + ex.Message, ex);
                }
            }
Beispiel #2
0
        /// <summary>
        /// Envía datos por el socket \n
        /// </summary>
        /// <param name="obj">
        /// Variable dinamica de donde obtener los datos a establecer \n
        /// COMMessage: Este objeto puede ser o bien de tipo Byte[] o de tipo String. Por el socket viaja en tipo byte \n
        /// </param>
        /// <param name="parameters">
        /// "EnviarMensaje" - Envía datos por el socket \n
        /// </param>
        public override void SetData(ref dynamic obj, params string[] parameters)
        {
            try
            {
                foreach (string parameter in parameters)
                {
                    switch (parameter)
                    {
                    case "EnviarMensaje":
                        EnviarDatos(obj);
                        break;

                    default:
                        obj.COMErrors = "Wrong Query";
                        break;
                    }
                }
                obj.COMErrors = "";
            }
            catch (Exception ex)
            {
                obj.COMErrors = ex.Message;
                SpinException.GetException("SpinCom:: " + ex.Message, ex);
            }
        }
Beispiel #3
0
 public void Stop()
 {
     try
     {
         Status = SpinDispatcherStatus.Stopping;
         //paro hilos
         if (_socketType == "SERVER")
         {
             if (((HiloComunicacionesAccept)_DispatcherThreads["ComunicacionesAccept"])._socketDatos != null)
             {
                 ((HiloComunicacionesAccept)_DispatcherThreads["ComunicacionesAccept"])._socketDatos.Shutdown(SocketShutdown.Both);
                 ((HiloComunicacionesAccept)_DispatcherThreads["ComunicacionesAccept"])._socketDatos.Disconnect(false);
                 ((HiloComunicacionesAccept)_DispatcherThreads["ComunicacionesAccept"])._socketDatos.Close();
             }
             ((HiloComunicacionesAccept)_DispatcherThreads["ComunicacionesAccept"]).Stop();
             ((HiloComunicacionesAccept)_DispatcherThreads["ComunicacionesAccept"]).Join();
         }
         if (_socketDatos != null)
         {
             _socketDatos.Shutdown(SocketShutdown.Both);
             _socketDatos.Disconnect(false);
             _socketDatos.Close();
         }
         if (_socketEscucha != null)
         {
             _socketEscucha.Close();
         }
         Status = SpinDispatcherStatus.Stopped;
     }
     catch (Exception ex)
     {
         SpinException.GetException(ex.Message, ex);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Cierra conexión FTP
 /// </summary>
 public void Stop()
 {
     try
     {
         clienteFTP.Close();
     }
     catch (Exception ex)
     {
         throw SpinException.GetException("SpinFTP:: " + ex.Message, ex);
     }
 }
Beispiel #5
0
 /// <summary>
 /// Abre la conexión FTP
 /// </summary>
 public void Start()
 {
     try
     {
         clienteFTP.Open();
         clienteFTP.Login();
     }
     catch (Exception ex)
     {
         throw SpinException.GetException("SpinFTP:: " + ex.Message, ex);
     }
 }
Beispiel #6
0
 /// <summary>
 /// Se encarga de abrir la conexión con la base de datos objetivo
 /// No necesita parámetros de entrada o salida
 /// </summary>
 public void Start()
 {
     try
     {
         this._cnn             = new System.Data.OleDb.OleDbConnection();
         _cnn.ConnectionString = _DBProvider + _DBConnectionString;
         _cnn.Open();
     }
     catch (OleDbException ex)
     {
         throw SpinException.GetException("SpinDatabase:: " + ex.Message, ex);
     }
 }
Beispiel #7
0
        internal dynamic ExecuteGetQuery(dynamic obj)
        {
            if (_DBType != "MYSQL")
            {
                if ((obj as IDictionary <string, object>).ContainsKey("DBQuery"))
                {
                    try
                    {
                        _cmd = new System.Data.OleDb.OleDbCommand(obj.DBQuery, _cnn);

                        DataSet myDataSet = new DataSet();
                        // Execute the query
                        OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(_cmd);
                        int valor = myDataAdapter.Fill(myDataSet, _DBDefaultTableName);

                        obj.Response = myDataSet.Tables;
                    }
                    catch (Exception ex)
                    {
                        throw SpinException.GetException("SpinDatabase:: " + ex.Message, ex);
                    }
                    return(obj);
                }
                else
                {
                    return(obj);
                }
            }
            else
            {
                if ((obj.DataBase as IDictionary <string, object>).ContainsKey("DBQuery"))
                {
                    String conexion = _DBConnectionString;
                    conexion = conexion.Replace("Password", "Pwd");
                    conexion = conexion.Replace("User ID", "Uid");
                    conexion = conexion.Replace("DATA SOURCE", "Database");
                    conexion = conexion.Replace("HOST", "Server");

                    //  MySqlConnection conn = new MySqlConnection(conexion);
                    //conn.Open();
                    //MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(obj.DBQuery, conn);
                    DataSet myDataSet = new DataSet();
                    //int valor = myDataAdapter.Fill(myDataSet, _DBDefaultTableName);
                    obj.Response = myDataSet.Tables;
                    //conn.Close();

                    return(obj);
                }
                return(null);
            }
        }
Beispiel #8
0
 internal void ExecuteSetQuery(dynamic obj)
 {
     try
     {
         if ((obj as IDictionary <string, object>).ContainsKey("DBQuery"))
         {
             _cmd = new System.Data.OleDb.OleDbCommand(obj.DBQuery, _cnn);
             _cmd.ExecuteNonQuery();
         }
     }
     catch (Exception ex)
     {
         throw SpinException.GetException("SpinDatabase:: " + ex.Message, ex);
     }
 }
Beispiel #9
0
 internal void GetValues(ref dynamic obj)
 {
     getMessageToTable(ref obj);
     try
     {
         DataTable table = obj.Response[_DBDefaultTableName];
         obj.Response = new List <string>();
         foreach (DataRow dr in table.Rows)
         {
             obj.Response.Add((string)dr[0]);
         }
     }
     catch (Exception ex)
     {
         throw SpinException.GetException("SpinIODB:: " + ex.Message, ex);
     }
 }
Beispiel #10
0
 public void Start(Socket socket, Socket socketEscucha, String socketType)
 {
     try
     {
         _socketClosed  = false;
         _socketType    = socketType;
         _socketEscucha = socketEscucha;
         _socketDatos   = socket;
         _StopEvent.Reset();                                                  //reset stop event
         _MainThread      = new Thread(new ThreadStart(EntryFunctionThread)); // Create thread
         _MainThread.Name = _Name;
         _MainThread.Start();                                                 //The thread is started and will call EntryFunctionThread
     }
     catch (Exception ex)
     {
         throw SpinException.GetException(SpinExceptionConstants.SPIN_ERROR_THREAD_STARTING, ex);
     }
 }
Beispiel #11
0
 public override bool Stop()
 {
     try
     {
         _StopEvent.Set();
         _socketClosed = true;
         if (_socketDatos != null)
         {
             _socketDatos.Shutdown(SocketShutdown.Both);
             _socketDatos.Close();
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw SpinException.GetException(SpinExceptionConstants.SPIN_ERROR_THREAD_ABORTING, ex);
     }
 }
Beispiel #12
0
 /// <summary>
 /// Se encarga de cerrar la conexión con la base de datos objetivo
 /// No necesita parámetros de entrada o salida
 /// </summary>
 public void Stop()
 {
     try
     {
         _cnn.Close();
         _cnn.Dispose();
         try
         {
             _cmd.Connection.Close();
         }
         catch
         {
             Console.WriteLine("SpinDataBase::If you are working with MYSQL, this object isn´t necessary or it is null");
         }
     }
     catch (Exception ex)
     {
         throw SpinException.GetException("SpinDatabase:: " + ex.Message, ex);
     }
 }
Beispiel #13
0
        public void Start(IPEndPoint extremoFinal, Socket socket, Socket socketEscucha, String socketType, HiloComunicaciones Comunicaciones)
        {
            try
            {
                _comunicaciones = Comunicaciones;
                _extremoFinal   = extremoFinal;
                _socketEscucha  = socketEscucha;
                _socketDatos    = socket;
                // Registrar el socket y ponerlo escuchar peticiones
                _socketEscucha.Bind(_extremoFinal);                                  // Se registra el socket
                _socketEscucha.Listen(5);                                            // 5 indica la longitud máxima de la cola de conexiones pendientes

                _StopEvent.Reset();                                                  //reset stop event
                _MainThread      = new Thread(new ThreadStart(EntryFunctionThread)); // Create thread
                _MainThread.Name = _Name;
                _MainThread.Start();                                                 //The thread is started and will call EntryFunctionThread
            }
            catch (Exception ex)
            {
                throw SpinException.GetException(SpinExceptionConstants.SPIN_ERROR_THREAD_STARTING, ex);
            }
        }
Beispiel #14
0
        override public void FunctionToExecuteByThread()
        {
            try
            {
                // Crear un socket para escuchar peticiones
                if (!_socketClosed)
                {
                    Console.WriteLine("\nAceptando una peticion ... ");
                    _socketDatos = _socketEscucha.Accept(); // Se bloquea en este punto hasta que llegue una petición

                    if (_started)
                    {
                        try
                        {
                            //Aqui me cargo el hilo con una nueva conexión
                            _comunicaciones.Stop();
                            _comunicaciones.Join();
                        }
                        catch (Exception ex)
                        {
                            SpinException.GetException("SpinCOM:: " + ex.Message, ex);
                        }
                    }
                    _comunicaciones.Start(_socketDatos, _socketEscucha, "SERVER");
                    _started = true;
                }
                else
                {
                    _StopEvent.Set();
                }
            }
            catch (SocketException socketEx)
            {
                //Error por cerrar el socket desde la clase padre
                _socketClosed = true;
                Console.WriteLine("Socket closed");
            }
        }
Beispiel #15
0
            internal object unserialize(string filename, Type t)
            {
                StreamReader stream = null;

                try
                {
                    SpinIOTxt modulo = new SpinIOTxt();
                    stream = modulo.openFileReader(filename, false);
                    XmlSerializer serializer = new XmlSerializer(t);
                    return(serializer.Deserialize(stream));
                }
                catch (Exception ex)
                {
                    throw SpinException.GetException(SpinExceptionConstants.SPIN_ERROR_XML_UNSERIALIZING + filename, ex);
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }
            }
Beispiel #16
0
        public override void SetData(dynamic obj)
        {
            /// <summary>
            /// Se encarga de enviar mensajes desde el hilo principal a través del socket abierto a quien esté escuchando si hay alguien
            /// En concreto el objeto de entrada debe disponer de los siguientes campos:
            /// (OBLIGATORIO)COMMessage: Este objeto puede ser o bien de tipo Byte[] o de tipo String. Por el socket viaja en tipo byte
            /// </summary>

            try
            {
                if ((obj.COMMessage).GetType() == typeof(String))
                {
                    _buferEnvia = Encoding.ASCII.GetBytes(obj.COMMessage);
                }
                else
                {
                    _buferEnvia = obj.COMMessage;
                }

                if (((HiloComunicaciones)_DispatcherThreads["Comunicaciones"])._socketDatos != null)
                {
                    BytesEnviados = ((HiloComunicaciones)_DispatcherThreads["Comunicaciones"])._socketDatos.Send(_buferEnvia);

                    Console.Write(BytesEnviados);
                    Console.Write(" Bytes enviados --> ");
                    Console.WriteLine(Encoding.ASCII.GetString(_buferEnvia));
                }
                else
                {
                    Console.Write(" Socket de datos cerrado,no se ha mandado el mensaje");
                }
            }
            catch (Exception ex)
            {
                SpinException.GetException("SpinCom:: " + ex.Message, ex);
            }
        }
Beispiel #17
0
 public override bool Stop()
 {
     try
     {
         if (_socketEscucha != null)
         {
             //_socketEscucha.Shutdown(SocketShutdown.Both);
             //_socketEscucha.Disconnect(true);
             _socketEscucha.Close();
         }
         if (_socketDatos != null)
         {
             _socketDatos.Shutdown(SocketShutdown.Both);
             //_socketDatos.Disconnect(true);
             _socketDatos.Close();
         }
         _StopEvent.Set();
         return(true);
     }
     catch (Exception ex)
     {
         throw SpinException.GetException(SpinExceptionConstants.SPIN_ERROR_THREAD_ABORTING, ex);
     }
 }
Beispiel #18
0
 internal void addMessageToTable(dynamic obj)
 {
     if ((obj as IDictionary <string, object>).ContainsKey("Message"))
     {
         for (int i = 0; i < obj.Message.Count; i++)
         {
             try
             {
                 //String columnas = "";
                 //if ((obj.DataBase as IDictionary<string, object>).ContainsKey("DBQueryColumns"))
                 //    columnas = "(" + obj.DataBase.DBQueryColumns[i] + ")";
                 //if (_data.DBQueryType == "INSERT")
                 //    obj.DataBase.DBQuery = _data.DBQueryType + " INTO " + _data.DBDefaultTableName + " " + columnas + " VALUES ('" + obj.Message[i] + "')";
                 //else if (_data.DBQueryType == "UPDATE")
                 //{
                 //    string valores = "";
                 //    string[] separators = new string[1];
                 //    separators[0] = ",";
                 //    string[] valo = ((String)obj.Message[i]).Split(separators, 1000, StringSplitOptions.RemoveEmptyEntries);
                 //    string[] name = ((String)obj.DataBase.DBQueryColumns[i]).Split(separators, 1000, StringSplitOptions.RemoveEmptyEntries);
                 //    for (int tam = 0; tam < valo.Length; tam++)
                 //    {
                 //        valores = name[tam] + "='" + valo[tam] + "', ";
                 //    }
                 //    obj.DataBase.DBQuery = _data.DBQueryType + " " + _data.DBDefaultTableName + " SET " + valores.Substring(0, valores.Length - 2) + " WHERE " + obj.DataBase.DBQueryUpdateRow[i];
                 //}
                 obj.DBQuery = _DBQueryType + " INTO " + _DBDefaultTableName + " VALUES ('" + obj.Message[i] + "')";
                 _exeBaseDeDatos.SetData(ref obj, "Set");
             }
             catch (Exception ex)
             {
                 throw SpinException.GetException("SPINIODB:: " + ex.Message, ex);
             }
         }
     }
 }