Example #1
0
        // Form processing invokes handles form creation
        // Once the form exits these functions also handle refreshing/updating UI elements
        // and setting form global variables (such as if we need to save)
        // @edit_action : can either be an existing action (for editing) or null (create new)
        // @index       : index of existing action, unused if new action.

        private void ProcessForm_AddEditPressAction(Action edit_action, int index)
        {
            frm_AddEdit_PressAction newPressAction;

            // Create a new action
            if (edit_action == null)
            {
                newPressAction = new frm_AddEdit_PressAction();
            }
            // Edit an existing action
            else
            {
                newPressAction = new frm_AddEdit_PressAction(edit_action);
            }
            // Invoke Form
            if (newPressAction.ShowDialog() == DialogResult.OK)
            {
                // if OK pull out edited or new action
                if (newPressAction.get_action() != null)
                {
                    // Called by Add
                    if (edit_action == null)
                    {
                        // Insert number of times specified by the form
                        for (int i = 0; i < newPressAction.get_times_to_add(); i++)
                        {
                            sequence_to_edit.Add(newPressAction.get_action());
                        }
                    }
                    // Called by Edit
                    else
                    {
                        sequence_to_edit.action_sequence[index] = newPressAction.get_action();
                    }
                }
                else
                {
                    MessageBox.Show("WARNING: Press form returned an invalid action.");
                    return;
                }
                ActionSequenceEdited = true;
                refresh_dgActionSequence();
                // Bring Selection back to edited element
                dgActionSequence.CurrentCell = dgActionSequence.Rows[index].Cells[0];
            }
        }
Example #2
0
        public void load_profile(string filename)
        {
            //Clean Current
            Profile_Triggers = new List<VI_Trigger>();
            Profile_ActionSequences = new List<VI_Action_Sequence>();
            //Constructor will catch.
            XmlDocument profile_xml = new XmlDocument();
            profile_xml.Load(filename);
            //Check first element tag
            if (profile_xml.DocumentElement.Name != "gavpi") {
                throw new Exception("Malformed profile expected first tag gavpi got,"
                + profile_xml.DocumentElement.Name);
            }
            XmlNodeList profile_xml_elements = profile_xml.DocumentElement.ChildNodes;
            foreach (XmlNode element in profile_xml_elements)
            {
                if (element.Name == "VI_Action_Sequence")
                {
                    VI_Action_Sequence ack_frm_file;
                    ack_frm_file = new VI_Action_Sequence(element.Attributes.GetNamedItem("name").Value);
                    ack_frm_file.type = element.Attributes.GetNamedItem("type").Value;
                    ack_frm_file.comment = element.Attributes.GetNamedItem("comment").Value;

                    foreach (XmlNode action in element.ChildNodes)
                    {
                        string action_type = action.Attributes.GetNamedItem("type").Value;
                        string action_value = action.Attributes.GetNamedItem("value").Value;
                        Type new_action_type = Type.GetType("GAVPI." + action_type );
                        object action_instance;
                        if (action_type == "Speak")
                        {
                            action_instance = Activator.CreateInstance(new_action_type,this.synth, action_value);
                        }
                        else
                        {
                            action_instance = Activator.CreateInstance(new_action_type, action_value);
                        }
                        ack_frm_file.Add((Action)action_instance);
                    }
                    if (!Profile_ActionSequences.Any(ack => ack.name == ack_frm_file.name))
                    {
                        Profile_ActionSequences.Add(ack_frm_file);
                    }
                }
                else if (element.Name == "VI_Trigger")
                {
                    VI_Trigger trig_frm_file;
                    string trigger_name = element.Attributes.GetNamedItem("name").Value;
                    string trigger_type = element.Attributes.GetNamedItem("type").Value;
                    string trigger_value = element.Attributes.GetNamedItem("value").Value;
                    string trigger_comment= element.Attributes.GetNamedItem("comment").Value;

                    Type new_trigger_type = Type.GetType("GAVPI." + trigger_type);
                    object trigger_isntance = trigger_isntance = Activator.CreateInstance(new_trigger_type, trigger_name, trigger_value);
                    trig_frm_file = (VI_Trigger)trigger_isntance;
                    trig_frm_file.comment = trigger_comment;

                    // Trigger Events
                    foreach (XmlElement trigger_event in element.ChildNodes)
                    {
                        string event_type = trigger_event.Attributes.GetNamedItem("type").Value;
                        string event_name = trigger_event.Attributes.GetNamedItem("name").Value;
                        string event_value = trigger_event.Attributes.GetNamedItem("value").Value;
                        if (event_type == "VI_Action_Sequence")
                        {
                            trig_frm_file.Add(Profile_ActionSequences.Find( ackseq => ackseq.name == event_name));
                        }
                        else if (event_type == "VI_Phrase")
                        {
                            VI_Trigger newMetaTrigger;
                            Type meta_trigger_type = Type.GetType("GAVPI." + event_type);
                            object meta_trigger_isntance = Activator.CreateInstance(meta_trigger_type,event_name, event_value);
                            newMetaTrigger = (VI_Trigger)meta_trigger_isntance;

                            trig_frm_file.Add(newMetaTrigger);
                        }
                    }
                    // Malformed xml or double load, need to switch to dictionaries tbh
                    if (!Profile_Triggers.Any(trig=>trig.name == trig_frm_file.name))
                    {
                        Profile_Triggers.Add(trig_frm_file);
                    }
                }
            }
        }
Example #3
0
        }  //  public bool NewProfile()

        public bool load_profile(string filename)
        {
            if (filename == null)
            {
                return(false);
            }

            //  Reset any states...

            NewProfile();

            XmlDocument profile_xml = new XmlDocument();

            //  Let's ensure that the user has actually selected a well-formed XML document for us to navigate as
            //  opposed to - oh, I don't know: a picture of their cat?

            try {
                profile_xml.Load(filename);
            } catch (Exception) {
                return(false);
            }

            //Check first element tag
            if (profile_xml.DocumentElement.Name != "gavpi")
            {
                throw new Exception("Malformed profile expected first tag gavpi got,"
                                    + profile_xml.DocumentElement.Name);
            }
            XmlNodeList profile_xml_elements = profile_xml.DocumentElement.ChildNodes;

            foreach (XmlNode element in profile_xml_elements)
            {
                if (element.Name == "AssociatedProcess")
                {
                    AssociatedProcess = element.InnerText;
                }
                else if (element.Name == "VI_Action_Sequence")
                {
                    VI_Action_Sequence ack_frm_file;
                    ack_frm_file         = new VI_Action_Sequence(element.Attributes.GetNamedItem("name").Value);
                    ack_frm_file.type    = element.Attributes.GetNamedItem("type").Value;
                    ack_frm_file.comment = element.Attributes.GetNamedItem("comment").Value;

                    foreach (XmlNode action in element.ChildNodes)
                    {
                        string action_type     = action.Attributes.GetNamedItem("type").Value;
                        string action_value    = action.Attributes.GetNamedItem("value").Value;
                        Type   new_action_type = Type.GetType("GAVPI." + action_type);
                        object action_instance;
                        if (action_type == "Speak")
                        {
                            action_instance = Activator.CreateInstance(new_action_type, this.synth, action_value);
                        }
                        else
                        {
                            action_instance = Activator.CreateInstance(new_action_type, action_value);
                        }
                        ack_frm_file.Add((Action)action_instance);
                    }
                    if (!Profile_ActionSequences.Any(ack => ack.name == ack_frm_file.name))
                    {
                        Profile_ActionSequences.Add(ack_frm_file);
                    }
                }
                else if (element.Name == "VI_Trigger")
                {
                    VI_Trigger trig_frm_file;
                    string     trigger_name    = element.Attributes.GetNamedItem("name").Value;
                    string     trigger_type    = element.Attributes.GetNamedItem("type").Value;
                    string     trigger_value   = element.Attributes.GetNamedItem("value").Value;
                    string     trigger_comment = element.Attributes.GetNamedItem("comment").Value;

                    Type   new_trigger_type = Type.GetType("GAVPI." + trigger_type);
                    object trigger_isntance = trigger_isntance = Activator.CreateInstance(new_trigger_type, trigger_name, trigger_value);
                    trig_frm_file         = (VI_Trigger)trigger_isntance;
                    trig_frm_file.comment = trigger_comment;

                    // Trigger Events
                    foreach (XmlElement trigger_event in element.ChildNodes)
                    {
                        string event_type  = trigger_event.Attributes.GetNamedItem("type").Value;
                        string event_name  = trigger_event.Attributes.GetNamedItem("name").Value;
                        string event_value = trigger_event.Attributes.GetNamedItem("value").Value;
                        if (event_type == "VI_Action_Sequence")
                        {
                            trig_frm_file.Add(Profile_ActionSequences.Find(ackseq => ackseq.name == event_name));
                        }
                        else if (event_type == "VI_Phrase")
                        {
                            VI_Trigger newMetaTrigger;
                            Type       meta_trigger_type     = Type.GetType("GAVPI." + event_type);
                            object     meta_trigger_isntance = Activator.CreateInstance(meta_trigger_type, event_name, event_value);
                            newMetaTrigger = (VI_Trigger)meta_trigger_isntance;

                            trig_frm_file.Add(newMetaTrigger);
                        }
                    }
                    // Malformed xml or double load, need to switch to dictionaries tbh
                    if (!Profile_Triggers.Any(trig => trig.name == trig_frm_file.name))
                    {
                        Profile_Triggers.Add(trig_frm_file);
                    }
                }
            }

            // Load Database Components
            // DB will parse out the VI_DB tag, allong with its children.
            ProfileDB = new VI_DB(filename);

            //
            //  We have successfully loaded the Profile, so retain the Profile's filename for future reference...
            //

            ProfileFilename = filename;

            return(true);
        }  //  public void load_profile()
Example #4
0
        }  //  public bool NewProfile()

        public bool load_profile()
        {
            string filename;

            //  If there are any unsaved changes to an existing Profile, offer the opportunity to save them before opening
            //  another Profile...

            if (UnsavedProfileChanges && !IsEmpty())
            {
                DialogResult save_changes = MessageBox.Show("It appears you have made changes to your Profile.\n\n" +
                                                            "Would you like to save those changes now?",
                                                            "Unsaved Profile",
                                                            MessageBoxButtons.YesNo);


                if (save_changes == DialogResult.Yes && !save_profile())
                {
                    return(false);
                }
            }  //  if()

            //
            //  Present the user with a File Open Dialog through which they may choose a Profile to load.
            //

            using (OpenFileDialog profile_dialog = new OpenFileDialog()) {
                //  Give the Dialog a title and then establish a filter to hide anything that isn't an XML file by default.

                profile_dialog.Title            = "Select a Profile to open";
                profile_dialog.Filter           = "Profiles (*.XML)|*.XML|All Files (*.*)|*.*";
                profile_dialog.RestoreDirectory = true;

                if (profile_dialog.ShowDialog() == DialogResult.Cancel)
                {
                    return(false);
                }

                //  Save the loaded Profile's filename for convenience sake.

                filename = profile_dialog.FileName;
            }

            //  Reset any states...

            UnsavedProfileChanges = false;

            //Clean Current
            Profile_Triggers        = new List <VI_Trigger>();
            Profile_ActionSequences = new List <VI_Action_Sequence>();
            //Constructor will catch.
            XmlDocument profile_xml = new XmlDocument();

            //  Let's ensure that the user has actually selected a well-formed XML document for us to navigate as
            //  opposed to - oh, I don't know: a picture of their cat?

            try {
                profile_xml.Load(filename);
            } catch (XmlException exception) {
                MessageBox.Show("There appears to be a problem with the Profile you have chosen.\n\n" +
                                "It may not been an actual Profile, or it may have become corrupted.",
                                "I cannot load the Profile",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);

                return(false);
            }

            //Check first element tag
            if (profile_xml.DocumentElement.Name != "gavpi")
            {
                throw new Exception("Malformed profile expected first tag gavpi got,"
                                    + profile_xml.DocumentElement.Name);
            }
            XmlNodeList profile_xml_elements = profile_xml.DocumentElement.ChildNodes;

            foreach (XmlNode element in profile_xml_elements)
            {
                if (element.Name == "VI_Action_Sequence")
                {
                    VI_Action_Sequence ack_frm_file;
                    ack_frm_file         = new VI_Action_Sequence(element.Attributes.GetNamedItem("name").Value);
                    ack_frm_file.type    = element.Attributes.GetNamedItem("type").Value;
                    ack_frm_file.comment = element.Attributes.GetNamedItem("comment").Value;

                    foreach (XmlNode action in element.ChildNodes)
                    {
                        string action_type     = action.Attributes.GetNamedItem("type").Value;
                        string action_value    = action.Attributes.GetNamedItem("value").Value;
                        Type   new_action_type = Type.GetType("GAVPI." + action_type);
                        object action_instance;
                        if (action_type == "Speak")
                        {
                            action_instance = Activator.CreateInstance(new_action_type, this.synth, action_value);
                        }
                        else
                        {
                            action_instance = Activator.CreateInstance(new_action_type, action_value);
                        }
                        ack_frm_file.Add((Action)action_instance);
                    }
                    if (!Profile_ActionSequences.Any(ack => ack.name == ack_frm_file.name))
                    {
                        Profile_ActionSequences.Add(ack_frm_file);
                    }
                }
                else if (element.Name == "VI_Trigger")
                {
                    VI_Trigger trig_frm_file;
                    string     trigger_name    = element.Attributes.GetNamedItem("name").Value;
                    string     trigger_type    = element.Attributes.GetNamedItem("type").Value;
                    string     trigger_value   = element.Attributes.GetNamedItem("value").Value;
                    string     trigger_comment = element.Attributes.GetNamedItem("comment").Value;

                    Type   new_trigger_type = Type.GetType("GAVPI." + trigger_type);
                    object trigger_isntance = trigger_isntance = Activator.CreateInstance(new_trigger_type, trigger_name, trigger_value);
                    trig_frm_file         = (VI_Trigger)trigger_isntance;
                    trig_frm_file.comment = trigger_comment;

                    // Trigger Events
                    foreach (XmlElement trigger_event in element.ChildNodes)
                    {
                        string event_type  = trigger_event.Attributes.GetNamedItem("type").Value;
                        string event_name  = trigger_event.Attributes.GetNamedItem("name").Value;
                        string event_value = trigger_event.Attributes.GetNamedItem("value").Value;
                        if (event_type == "VI_Action_Sequence")
                        {
                            trig_frm_file.Add(Profile_ActionSequences.Find(ackseq => ackseq.name == event_name));
                        }
                        else if (event_type == "VI_Phrase")
                        {
                            VI_Trigger newMetaTrigger;
                            Type       meta_trigger_type     = Type.GetType("GAVPI." + event_type);
                            object     meta_trigger_isntance = Activator.CreateInstance(meta_trigger_type, event_name, event_value);
                            newMetaTrigger = (VI_Trigger)meta_trigger_isntance;

                            trig_frm_file.Add(newMetaTrigger);
                        }
                    }
                    // Malformed xml or double load, need to switch to dictionaries tbh
                    if (!Profile_Triggers.Any(trig => trig.name == trig_frm_file.name))
                    {
                        Profile_Triggers.Add(trig_frm_file);
                    }
                }
            }

            //
            //  We have successfully loaded the Profile, so retain the Profile's filename for future reference...
            //

            ProfileFilename = filename;

            return(true);
        }  //  public void load_profile()
Example #5
0
        private void btnActSeqAdd_Click(object sender, EventArgs e)
        {
            Type new_action_type = Type.GetType("GAVPI." + cbActSeqActionType.SelectedItem.ToString());

            // Number of Times to Add particular action
            int times_to_add = 1; //by default it is one unless the check fails

            if (Int32.TryParse(txtActionXTimes.Text, out times_to_add))
            {
                if (times_to_add <= 0)
                {
                    MessageBox.Show("Times to add value cannot be less than or equal to 0.");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Times to add value must be a valid integer greater than one. (Max size 32bits)");
                return;
            }


            object action_instance;

            if (new_action_type.ToString() == "GAVPI.Speak")
            {
                action_instance = Activator.CreateInstance(new_action_type, GAVPI.vi_profile.synth, cbActSeqActionValue.Text);

                for (uint i = 0; i < times_to_add; i++)
                {
                    action_sequence.Add((Action)action_instance);
                }

                refresh_editactionsequence();
            }
            else if (new_action_type.ToString() == "GAVPI.Wait")
            {
                int test;
                if (Int32.TryParse(cbActSeqActionValue.Text, out test) && test > 0)
                {
                    action_instance = Activator.CreateInstance(new_action_type, cbActSeqActionValue.Text);
                    for (uint i = 0; i < times_to_add; i++)
                    {
                        action_sequence.Add((Action)action_instance);
                    }
                    refresh_editactionsequence();
                }
                else
                {
                    MessageBox.Show("Wait must be positive integer in milliseconds.");
                    return;
                }
            }
            else
            {
                action_instance = Activator.CreateInstance(new_action_type, cbActSeqActionValue.SelectedItem.ToString());
                for (uint i = 0; i < times_to_add; i++)
                {
                    action_sequence.Add((Action)action_instance);
                }
                refresh_editactionsequence();
            }

            //  We've updated the Action Sequence, so allow the user to save their changes...

            this.btnActSeqSave.Enabled = true;
        }