Exemple #1
0
        private void WriteXMLReceived(string username, string message, bool online)
        {
            string sPath = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/DataConversation/" + username);

            if (!Directory.Exists(sPath))
            {
                Directory.CreateDirectory(sPath);
            }
            if (Directory.Exists(sPath))
            {
                string idfile = "";
                foreach (var j in Users)
                {
                    if (Context.User.Identity.Name != j.Value.Name)
                    {
                        idfile = j.Value.ID;
                        break;
                    }
                }
                if (idfile != "")
                {
                    try
                    {
                        Conversations userdataConver = new Conversations();
                        userdataConver.data = new List <Conversation>();
                        string filename = Path.Combine(sPath, idfile + ".dat");
                        if (File.Exists(filename))
                        {
                            System.Xml.Serialization.XmlSerializer reader =
                                new System.Xml.Serialization.XmlSerializer(typeof(Conversations));
                            System.IO.StreamReader file = new System.IO.StreamReader(
                                filename);
                            userdataConver = (Conversations)reader.Deserialize(file);
                            file.Close();
                        }
                        userdataConver.Name = username;
                        userdataConver.data.Add(new Conversation()
                        {
                            content = message, Name = Context.User.Identity.Name, status = online
                        });
                        var writer = new System.Xml.Serialization.XmlSerializer(typeof(Conversations));
                        var wfile  = new System.IO.StreamWriter(filename);
                        writer.Serialize(wfile, userdataConver);
                        wfile.Close();
                    }
                    catch { }
                }
            }
        }
Exemple #2
0
        public static Conversations ReadXMLData(string username, string useSend)
        {
            string sPath = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/DataConversation/" + useSend);

            if (Directory.Exists(sPath))
            {
                string idfile = "";
                foreach (var j in Users)
                {
                    if (username != j.Value.Name)
                    {
                        idfile = j.Value.ID;
                        break;
                    }
                }
                if (idfile != "")
                {
                    try
                    {
                        Conversations userdataConver = new Conversations();
                        string        filename       = Path.Combine(sPath, idfile + ".dat");
                        if (File.Exists(filename))
                        {
                            System.Xml.Serialization.XmlSerializer reader =
                                new System.Xml.Serialization.XmlSerializer(typeof(Conversations));
                            System.IO.StreamReader file = new System.IO.StreamReader(
                                filename);
                            userdataConver = (Conversations)reader.Deserialize(file);
                            file.Close();
                            return(userdataConver);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return(new Conversations());
        }