Ejemplo n.º 1
0
 private void definingForm_Load(object sender, EventArgs e)
 {
     displayLabel.Text = DisplayLabelText;
     DefaultForm.Files.AddRange(Conf.EmptyFormDefaultCode);
     if (DefinitionType == Conf.Definition.Trigger)
     {
         DefaultSource.Files.Add(new File(Conf.DefaultFileName, Conf.TriggerDefaultCode, true));
     }
     else if (DefinitionType == Conf.Definition.Condition)
     {
         DefaultSource.Files.Add(new File(Conf.DefaultFileName, Conf.ConditionDefaultCode, true));
     }
     else if (DefinitionType == Conf.Definition.Action)
     {
         DefaultSource.Files.Add(new File(Conf.DefaultFileName, Conf.ActionDefaultCode, true));
     }
     if (IsEditing)
     {
         IsCodeValid = true;
         IsFormValid = true;
         nameTextBox.Text = this.OriginalDefinition.Name;
         groupNameTextBox.Text = this.OriginalDefinition.GroupName;
         descriptionTextBox.Text = this.OriginalDefinition.Description;
         needParamsCheckBox.Checked = this.OriginalDefinition.NeedsParams;
         Form = this.OriginalDefinition.FormSource;
         Source = this.OriginalDefinition.Source;
     }
 }
Ejemplo n.º 2
0
 public compilerForm(Source DefaultSource, Criticals Criticals = null)
 {
     InitializeComponent();
     this.DefaultSource = DefaultSource;
     this.ReferencedAssemblies = DefaultSource.ReferencedAssemblies;
     this.Criticals = Criticals;
 }
Ejemplo n.º 3
0
 //Construct Definition from a XML element containing the nessecary data
 public Definition(XmlElement Element)
 {
     this.Name = Element.GetElementsByTagName("Name")[0].InnerText;
     this.GroupName = Element.GetElementsByTagName("GroupName")[0].InnerText;
     this.Description = Element.GetElementsByTagName("Description")[0].InnerText;
     this.Active = (Element.GetElementsByTagName("Active")[0].InnerText == "1");
     if (this.Active)
     {
         XmlElement ArgsElement = (XmlElement)Element.GetElementsByTagName("Args")[0];
         if (ArgsElement.ChildNodes.Count > 0)
         {
             this.Args = new object[ArgsElement.GetElementsByTagName("Arg").Count];
             int Count = 0;
             foreach (XmlElement ArgElement in ArgsElement.GetElementsByTagName("Arg"))
             {
                 this.Args[Count] = Serializer.DeserializeXML((XmlElement)ArgsElement.FirstChild);
             }
         }
     }
     this.NeedsParams = (Element.GetElementsByTagName("NeedsParams")[0].InnerText == "1");
     if (this.NeedsParams)
     {
         this.FormSource = new Source((XmlElement)Element.GetElementsByTagName("FormSource")[0]);
     }
     this.Source = new Source((XmlElement)Element.GetElementsByTagName("Source")[0]);
 }
Ejemplo n.º 4
0
 //Construct Definition from strongly typed variables
 public Definition(string Name, string GroupName, string Description, Source Source, bool NeedsParams, Source FormSource, object[] Args = null)
 {
     this.Name = Name;
     this.GroupName = GroupName;
     this.Description = Description;
     this.Source = Source;
     this.Args = Args;
     this.NeedsParams = NeedsParams;
     this.FormSource = FormSource;
 }
Ejemplo n.º 5
0
 private void editFormButton_Click(object sender, EventArgs e)
 {
     compilerForm Form = new compilerForm(DefaultForm, Conf.FormCriticals);
     if (this.Form != null)
         Form = new compilerForm(this.Form, Conf.FormCriticals);
     Form.ShowDialog();
     if (Form.IsFinished)
         this.Form = Form.Source;
     IsFormValid = (this.Form != null);
 }
Ejemplo n.º 6
0
 private void editCodeButton_Click(object sender, EventArgs e)
 {
     compilerForm Form = new compilerForm(DefaultSource, Criticals);
     if(this.Source != null)
         Form = new compilerForm(this.Source, Criticals);
     Form.ShowDialog();
     if (Form.IsFinished)
         this.Source = Form.Source;
     IsCodeValid = (this.Source != null);
 }
Ejemplo n.º 7
0
 public Trigger(string Name, string GroupName, string Description, Source Source, bool NeedsParams, Source FormSource, object[] Args = null)
     : base(Name, GroupName, Description, Source, NeedsParams, FormSource, Args)
 {
 }
Ejemplo n.º 8
0
        public bool Validate(Source Source)
        {
            bool IsValid = false;
            bool NamespaceExists = false;
            bool ClassExists = false;
            List<string> MissingMethods = new List<string>();
            List<string> MissingFields = new List<string>();
            Assembly Asm = Compiler.BuildAssembly(Source.CodeList().ToArray(), Source.ReferencedAssemblies.ToArray());
            foreach (Type Type in Asm.GetTypes())
                if (Type.Namespace == this.Namespace)
                {
                    NamespaceExists = true;
                    IsValid = true;
                    if (this.Class != null)
                    {
                        IsValid = false;
                        if (Type.Name == this.Class)
                        {
                            ClassExists = true;
                            IsValid = true;
                            if (this.Methods.Count > 0)
                            {
                                IsValid = false;

                                List<string> MethodNames = new List<string>();
                                Type.GetMethods().ToList().ForEach(i => MethodNames.Add(i.Name));

                                if (this.Methods.All(i => MethodNames.Contains(i)))
                                    IsValid = true;
                                else
                                    MissingMethods.AddRange(this.Methods.Except(MethodNames));
                            }

                            if (this.Fields.Count > 0)
                            {
                                IsValid = false;

                                List<string> FieldNames = new List<string>();
                                Type.GetFields().ToList().ForEach(i => FieldNames.Add(i.Name));

                                if (this.Fields.All(i => FieldNames.Contains(i)))
                                    IsValid = true;
                                else
                                    MissingFields.AddRange(this.Fields.Except(FieldNames));
                            }

                            if (MissingMethods.Count > 0 || MissingFields.Count > 0)
                                IsValid = false;

                            break;
                        }
                    }
                    else
                        break;
                }
            if (!IsValid)
            {
                string Error = string.Empty;
                if (!NamespaceExists)
                    Error += "Critical Namespace \"" + this.Namespace + "\" does not exist." + Environment.NewLine;
                else if (!ClassExists)
                    Error += "Critical Class \"" + this.Class + "\" does not exist." + Environment.NewLine;
                else
                {
                    MissingMethods.ForEach(i => Error += "Critical Method \"" + i + "\" does not exist." + Environment.NewLine);
                    MissingFields.ForEach(i => Error += "Critical Field \"" + i + "\" does not exist." + Environment.NewLine);
                }
                throw new Exception(Error);
            }
            return IsValid;
        }