private static ElementoBinario IGetSerialitzerAuto(Type tipo) { ElementoBinario elemento; Type generic; Type[] parametros; Type[] parametrosSerializador; Type serialitzerType; if (tipo.IsGenericType) { generic = tipo.GetGenericTypeDefinition(); parametros = tipo.GetGenericArguments(); parametrosSerializador = parametros; if (generic.ImplementInterficie(typeof(IDictionary))) { generic = typeof(IDictionary <,>); parametros = new Type[] { tipo }.AfegirValors(parametros).ToArray(); } else if (generic.ImplementInterficie(typeof(IList))) { generic = typeof(IList <>); parametros = new Type[] { tipo }.AfegirValors(parametros).ToArray(); } serialitzerType = Type.GetType(DicTiposGenericos[generic.AssemblyQualifiedName]).SetTypes(parametros); elemento = (ElementoBinario)serialitzerType.GetObj(parametrosSerializador.Select((p) => GetSerializador(p)).ToArray()); } else if (tipo.IsArray && tipo.GetElementType().AssemblyQualifiedName != typeof(byte).AssemblyQualifiedName) { serialitzerType = typeof(ElementoArrayBinario <>).SetTypes(tipo.GetElementType()); elemento = (ElementoBinario)serialitzerType.GetObj(GetSerializador(tipo.GetElementType())); } else { if (DicTipos.ContainsKey(tipo.AssemblyQualifiedName)) { elemento = DicTipos[tipo.AssemblyQualifiedName]; } else if (GuardarSerializadoresAutosHechos && SerializadoresElementosAutosHechos.ContainsKey(tipo.AssemblyQualifiedName)) { elemento = SerializadoresElementosAutosHechos[tipo.AssemblyQualifiedName].Clon(); } else { try { elemento = GetElementoComplejoAuto(tipo);//mirar si funciona if (GuardarSerializadoresAutosHechos) { SerializadoresElementosAutosHechos.Add(tipo.AssemblyQualifiedName, elemento.Clon()); } } catch { elemento = null; } } } return(elemento); }
public Tarea(Lista lista, string contenido, long idUnico) { this.contenidoConFormato = contenido; this.idUnico = idUnico; this.Lista = lista; listasTareaHecha = new LlistaOrdenada <Lista, DateTime>(); listasTareaOculta = new ListaUnica <Lista>(); todasLasTareas.Add(this); if (!tareasPorLista.ContainsKey(lista)) { tareasPorLista.Add(lista, new ListaUnica <Tarea>()); } if (!tareasPorLista[lista].Contains(this)) { tareasPorLista[lista].Add(this); } }
public Tarea(long lista, string contenido, long idUnico) { this.ContenidoConFormato = contenido; this.IdUnico = idUnico; this.IdListaParent = lista; ListasTareaHecha = new LlistaOrdenada <long, DateTime>(); ListasTareaOculta = new LlistaOrdenada <long, long>(); Todas.Add(this); if (!TodasAgrupadas.ContainsKey(lista)) { TodasAgrupadas.Add(lista, new LlistaOrdenada <Tarea>()); } if (!TodasAgrupadas[lista].ContainsKey(this)) { TodasAgrupadas[lista].Add(this); } }
public bool EstaHecha(Lista lista) { return(listasTareaHecha.ContainsKey(lista)); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { Int32 port; IPAddress localAddr; TcpClient client; Byte[] bytes; NetworkStream stream; byte[] msg; Data data; TcpListener server = default; try { // Set the TcpListener on port 13000. port = 13000; localAddr = IPAddress.Parse("127.0.0.1"); // TcpListener server = new TcpListener(port); server = new TcpListener(localAddr, port); // Start listening for client requests. server.Start(); // Buffer for reading data bytes = new byte[1024]; data = default; // Enter the listening loop. while (!stoppingToken.IsCancellationRequested) { Console.Write("Waiting for a connection... "); // Perform a blocking call to accept requests. // You could also user server.AcceptSocket() here. client = await server.AcceptTcpClientAsync(); Console.WriteLine("Connected!"); data = default; // Get a stream object for reading and writing stream = client.GetStream(); data = Data.GetData(stream.GetBytes()); if (data.IsAKey) { DicKeys.AddOrReplace(data.Id, data.Key); msg = MsgKeyInstalledSuccessfully; } else if (DicKeys.ContainsKey(data.Id)) { //quiere cifrar o descifrar if (data.Cifrar) { msg = DicKeys[data.Id].Encrypt(data.Datos); } else { msg = DicKeys[data.Id].Decrypt(data.Datos); } } else { msg = MsgKeyNotInstalled; } msg = Data.GetResponse(data.Id, msg); // Send back a response. stream.Write(msg, 0, msg.Length); // Shutdown and end connection client.Close(); } } catch (SocketException e) { Console.WriteLine("SocketException: {0}", e); } finally { if (server != default) { // Stop listening for new clients. server.Stop(); } SaveKeys(); } }