Torna al Thread

class Program { static void Main(string[] args) //Immagino che comunque debba essere un WInForm visto che usi le message boxes { } ClassSerializeLog deserLog; //non so dove andasse questo membro public static bool DeSerializeLog(Utente utente, UnknownClassType m_FPrincipale) { DateTime dataCorrente = DateTime.Now; ClassSerializeLog deserLog = new ClassSerializeLog(); String numeratore = dataCorrente.ToShortDateString(); numeratore = numeratore.Trim().Replace(" ", "_"); numeratore = numeratore.Trim().Replace("/", "_");//il trim e il replace //sono obbligatori, in quanto i nome file di windows non riconoscono i //caratteri / e 'spaziovuoto' string nomeCartella = @"C:\Documents and Settings\Proprietario\RML\Log\" + numeratore; string nomeFile; /*2*/ if (utente != null) nomeFile = nomeCartella + @"\UtensLog" + numeratore + "_" + utente.NomeUtente + " " + utente.CognomeUtente + "_" + ".rmll"; else nomeFile = nomeCartella + @"\UtensLog" + numeratore + "_" + ".rmll"; ///Questo interrompe il processo corrente fino a che viene premuto OK! if (utente.AccessLevel >= AccessLevel.Professor) MessageBox.Show("percorso del file Log : " + nomeFile); System.IO.Directory.CreateDirectory(nomeCartella); // Verify that the input file exists if (File.Exists(nomeFile)) { Stream file = File.Open(nomeFile, FileMode.Open); // Create a formatter object based on command line arguments IFormatter formatter = (IFormatter)new BinaryFormatter(); /*1*/ // Deserialize the object graph from stream try { deserLog = formatter.Deserialize(file) as ClassSerializeLog; if (deserLog != null) { MessageBox.Show(String.Format("{0}", "Lista Log di oggi trovata con il nome " + deserLog.ToString())); m_FPrincipale.serLog = deserLog; foreach (Logg ut in deserLog.listaLoggSer) // { //m_FPrincipale.listaLog.Add(ut); (m_FPrincipale.serLog).listaLoggSer.Add(ut); } else { ClassSerializeLog serLogNuovo = new ClassSerializeLog(); serLogNuovo.TimingSer = DateTime.Now; serLogNuovo.UtenteLogSer = utente; serLogNuovo.AzioneLogSer = " ha creato un nuovo file di log"; m_FPrincipale.serLog = serLogNuovo; } } // Handler for BinaryFormatter exception catch (SerializationException e) { if (utente.AccessLevel >= AccessLevel.Tutor) MessageBox.Show(String.Format("{0}", "Lista Log di oggi non trovata")); ClassSerializeLog serLogNuovo = new ClassSerializeLog(); serLogNuovo.TimingSer = DateTime.Now; serLogNuovo.UtenteLogSer = utente; serLogNuovo.AzioneLogSer = " ha creato un nuovo file di log"; MessageBox.Show(String.Format("{0}", "ha creato un nuovo file di log")); m_FPrincipale.serLog = serLogNuovo; } // All done file.Close(); return true; } return false; } public static bool SerializeLog(ClassSerializeLog serData, string NomeFile) { bool RetValue = false; Stream file = File.Open(NomeFile, FileMode.Create); IFormatter formatter = new BinaryFormatter(); //Questo andrebbe in un try x gestire le ecccezioni. // Serialize the object graph to stream formatter.Serialize(file, serData); // All done file.Close(); RetValue = true; return RetValue; } }
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5