Пример #1
0
        private void connectionWork(object sender, DoWorkEventArgs e)
        {
            while (!worker.CancellationPending)
            {
                if (selectedFilter.Item1 == -1)
                {
                    byte[] objectBytes = sendMsg(new Int16[1] {
                        0
                    });
                    if (objectBytes == null)
                    {
                        continue;
                    }
                    var mStream      = new MemoryStream();
                    var binFormatter = new BinaryFormatter();

                    // Where 'objectBytes' is your byte array.
                    mStream.Write(objectBytes, 0, objectBytes.Length);
                    mStream.Position = 0;
                    selectedFilter   = binFormatter.Deserialize(mStream) as Tuple <int, int, int, int>;
                    idComputadora    = Convert.ToInt16(selectedFilter.Item4);
                    Console.WriteLine("Conectado...");
                }//Crear una conexion con el servidor
                else if (selectedFilter.Item1 == -3)
                {
                    byte[] objectBytes = sendMsg(new Int16[1] {
                        -1
                    });
                    if (objectBytes == null)
                    {
                        continue;
                    }
                    var mStream      = new MemoryStream();
                    var binFormatter = new BinaryFormatter();

                    // Where 'objectBytes' is your byte array.
                    mStream.Write(objectBytes, 0, objectBytes.Length);
                    mStream.Position = 0;
                    selectedFilter   = binFormatter.Deserialize(mStream) as Tuple <int, int, int, int>;
                    Console.WriteLine("Desconectado...");
                    worker.CancelAsync();
                }//Desconectar el servidor
                else
                {
                    byte[] objectBytes = sendMsg(new Int16[2] {
                        1, idComputadora
                    });
                    if (objectBytes == null)
                    {
                        continue;
                    }
                    var mStream      = new MemoryStream();
                    var binFormatter = new BinaryFormatter();

                    // Where 'objectBytes' is your byte array.
                    mStream.Write(objectBytes, 0, objectBytes.Length);
                    mStream.Position = 0;
                    selectedFilter   = binFormatter.Deserialize(mStream) as Tuple <int, int, int, int>;
                    if (selectedFilter.Item1 == 1)
                    {
                        funcs.ObtenerURLs(selectedFilter.Item2, selectedFilter.Item3);
                        Console.WriteLine("Indices inicio: {0} final: {1}", selectedFilter.Item2, selectedFilter.Item3);
                        funcs.ClasificarURLsSecuencial(ref progressBar1, ref label3);
                        funcs.BayesSecuencial(ref progressBar1, ref label3);
                        Console.WriteLine("subiendo datos...");
                        funcs.subirDatos();
                        Console.WriteLine("Proceso Terminado");

                        objectBytes = sendMsg(new Int16[1] {
                            2
                        });
                        if (objectBytes == null)
                        {
                            continue;
                        }
                        mStream      = new MemoryStream();
                        binFormatter = new BinaryFormatter();

                        // Where 'objectBytes' is your byte array.
                        mStream.Write(objectBytes, 0, objectBytes.Length);
                        mStream.Position = 0;
                        selectedFilter   = binFormatter.Deserialize(mStream) as Tuple <int, int, int, int>;
                    }
                    else if (selectedFilter.Item1 == 2)
                    {
                        funcs.ObtenerURLs(selectedFilter.Item2, selectedFilter.Item3);
                        Console.WriteLine("Indices inicio: {0} final: {1}", selectedFilter.Item2, selectedFilter.Item3);
                        funcs.URLsConcurrente(ref progressBar1, ref label3);
                        funcs.BayesConcurrente(ref progressBar1, ref label3);
                        Console.WriteLine("subiendo datos...");
                        funcs.subirDatos();
                        Console.WriteLine("Proceso Terminado");

                        objectBytes = sendMsg(new Int16[1] {
                            2
                        });
                        if (objectBytes == null)
                        {
                            continue;
                        }
                        mStream      = new MemoryStream();
                        binFormatter = new BinaryFormatter();

                        // Where 'objectBytes' is your byte array.
                        mStream.Write(objectBytes, 0, objectBytes.Length);
                        mStream.Position = 0;
                        selectedFilter   = binFormatter.Deserialize(mStream) as Tuple <int, int, int, int>;
                    }
                }//Esperando a realizar un proceso
            }
        }