Beispiel #1
0
        public void Load_Settings_With_Password()
        {
            try
            {
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = File.Open("default.cnf", FileMode.Open);

                password = (string)formatter.Deserialize(stream);

                int users_count = (int)formatter.Deserialize(stream);
                int msgs_count  = (int)formatter.Deserialize(stream);

                Clear_Users();

                for (int i = 0; i < users_count; i++)
                {
                    User user = (User)formatter.Deserialize(stream);
                    Add_User(user);
                }

                Singleton.Instance.messages_dict = new Dictionary <string, Message_Add>();

                for (int i = 0; i < msgs_count; i++)
                {
                    string      id  = (string)formatter.Deserialize(stream);
                    Message_Add msg = (Message_Add)formatter.Deserialize(stream);
                    Add_Message(id, msg);
                }



                Singleton.Instance.configuration = new Dictionary <string, Dictionary <string, Configuration> >();

                foreach (User user in Singleton.Instance.users)
                {
                    Singleton.Instance.configuration[user.Get_ID()] = new Dictionary <string, Configuration>();
                }


                foreach (User user in Singleton.Instance.users)
                {
                    int n = (int)formatter.Deserialize(stream);
                    for (int i = 0; i < n; i++)
                    {
                        string        msg_id = (string)formatter.Deserialize(stream);
                        Configuration load   = (Configuration)formatter.Deserialize(stream);
                        Add_To_Config(user.Get_ID(), msg_id, load);
                    }
                }

                Add_Lines_To_Windows();

                //Singleton.Show_MessageBox("wczytano pomyślnie");
            }
            catch (Exception ex)
            {
                Singleton.Show_MessageBox(ex.Message);
            }
        }
        void ImportMessages_Click(Object sender, EventArgs e)
        {
            try
            {
                IFormatter formatter = new BinaryFormatter();

                OpenFileDialog openFileDialog = new OpenFileDialog
                {
                    InitialDirectory = "c:\\Users\\Szymon\\Desktop",
                    Filter = "mes files (*.mes)|*.mes",
                    FilterIndex = 2,
                    RestoreDirectory = true
                };
                bool? result = openFileDialog.ShowDialog();

                Stream stream;

                if (result == true)
                {
                    if ((stream = openFileDialog.OpenFile()) != null)
                    {
                        int msgs_count = (int)formatter.Deserialize(stream);

                        Singleton.Instance.Clear_Messages();

                        Dictionary<string, Message_Add> new_msgs = new Dictionary<string, Message_Add>();

                        for (int i = 0; i < msgs_count; i++)
                        {
                            string key = (string)formatter.Deserialize(stream);
                            Message_Add new_msg = (Message_Add)formatter.Deserialize(stream);
                            new_msgs[key] = new_msg;
                        }


                        foreach (KeyValuePair<string, Message_Add> msg in new_msgs)
                        {
                            Singleton.Instance.Add_Message(msg.Key, msg.Value);
                        }

                        Singleton.Instance.configuration = new Dictionary<string, Dictionary<string, Configuration>>();

                        Singleton.Instance.messages_page.Window_Clear();

                        foreach (KeyValuePair<string, Message_Add> msg in new_msgs)
                            Singleton.Instance.messages_page.Add_Line(msg.Key, msg.Value.Comment, msg.Value.IsActive());


                        Singleton.Instance.configuration_page.Refresh();
                        Singleton.Show_MessageBox("wczytano pomyślnie");
                    }
                }
            }
            catch (Exception ex)
            {
                Singleton.Show_MessageBox(ex.Message);
            }
        }
Beispiel #3
0
        public bool Add_Message(string id, Message_Add msg)
        {
            if (messages_dict.ContainsKey(id))
            {
                Singleton.Show_MessageBox("id nie mogą się powtarzać");
                return(false);
            }

            messages_dict[id] = msg;
            return(true);
        }
        void ImportConfig_Click(Object sender, EventArgs e)
        {
            if (Singleton.Instance.Admin)
            {
                try
                {
                    IFormatter formatter = new BinaryFormatter();

                    OpenFileDialog openFileDialog = new OpenFileDialog
                    {
                        InitialDirectory = "c:\\Users\\Szymon\\Desktop",
                        Filter = "config files (*.cnf)|*.cnf",
                        FilterIndex = 2,
                        RestoreDirectory = true
                    };
                    bool? result = openFileDialog.ShowDialog();

                    Stream stream;

                    if (result == true)
                    {
                        if ((stream = openFileDialog.OpenFile()) != null)
                        {

                            int users_count = (int)formatter.Deserialize(stream);
                            int messages_count = (int)formatter.Deserialize(stream);

                            Singleton.Instance.Clear_Users();
                            for (int i = 0; i < users_count; i++)
                            {
                                User user = (User)formatter.Deserialize(stream);
                                Singleton.Instance.Add_User(user);
                            }

                            Singleton.Instance.Clear_Messages_Dict();
                            for (int i = 0; i < messages_count; i++)
                            {
                                string id = (string)formatter.Deserialize(stream);
                                Message_Add msg = (Message_Add)formatter.Deserialize(stream);
                                Singleton.Instance.messages_dict[id] = msg;
                            }


                            Singleton.Instance.configuration = new Dictionary<string, Dictionary<string, Configuration>>();
                            foreach (User user in Singleton.Instance.users)
                            {
                                Singleton.Instance.configuration[user.Get_ID()] = new Dictionary<string, Configuration>();
                            }


                            foreach (User user in Singleton.Instance.users)
                            {
                                int n = (int)formatter.Deserialize(stream);
                                for (int i = 0; i < n; i++)
                                {
                                    string msg_id = (string)formatter.Deserialize(stream);
                                    Configuration load = (Configuration)formatter.Deserialize(stream);
                                    Singleton.Instance.Add_To_Config(user.Get_ID(), msg_id, load);
                                }
                            }

                            Singleton.Instance.Add_Lines_To_Windows();

                            Singleton.Show_MessageBox("wczytano pomyślnie");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Singleton.Show_MessageBox(ex.Message);
                }
            }
            else
                Singleton.Show_MessageBox("Niewystarczające uprawnienia!");
        }