/// <summary>
        /// The test validation.
        /// </summary>
        /// <param name="applicationService">
        /// The application service.
        /// </param>
        protected void TestValidation(IProjectDefinitionApplicationService applicationService)
        {
            DomainDefinition domain = new DomainDefinition();

            domain.Id = Guid.Empty;



            applicationService.ProjectDefinition.Domains.Add(domain);
            applicationService.Validate();
            Assert.AreEqual(10, applicationService.ValidationResult.Count, "There should be 10 validation errors");

            applicationService.ProjectDefinition.BaseNameSpace = "a";
            applicationService.ProjectDefinition.OutputFolder  = "b";
            applicationService.ProjectDefinition.Version       = 0.1;
            applicationService.ProjectDefinition.ModelPath     = "c";
            applicationService.ProjectDefinition.Domains[0].NamingConventionId = Guid.NewGuid();
            applicationService.ProjectDefinition.Domains[0].SourceTypeId       = Guid.NewGuid();

            domain.Name = "Test Domain";
            domain.Id   = Guid.NewGuid();
            domain.DriverIdList.Add(Guid.NewGuid());
            domain.CollectionOptionId = Guid.NewGuid();
            applicationService.Validate();

            Assert.AreEqual(0, applicationService.ValidationResult.Count, "There should be 0 validation errors");
        }
Esempio n. 2
0
        private void InitializeToolStripFind()
        {
            if (DesignMode)
            {
                return;
            }

            if (Settings.Default.SearchMRUNameList == null)
            {
                Settings.Default.SearchMRUNameList = new StringCollection();
            }

            if (Settings.Default.SearchMRUFormIDList == null)
            {
                Settings.Default.SearchMRUFormIDList = new StringCollection();
            }

            if (Settings.Default.SearchMRUFullList == null)
            {
                Settings.Default.SearchMRUFullList = new StringCollection();
            }

            var items = new object[]
                {
                    new MRUComboHelper<SearchType, string>(SearchType.EditorID, "Editor ID", Settings.Default.SearchMRUNameList), 
                    new MRUComboHelper<SearchType, string>(SearchType.FormID, "Form ID", Settings.Default.SearchMRUFormIDList), 
                    new MRUComboHelper<SearchType, string>(SearchType.FullSearch, "Full Search", Settings.Default.SearchMRUFullList), 
                    new MRUComboHelper<SearchType, string>(SearchType.TypeEditorIdSearch, "Name w/Type", Settings.Default.SearchMRUNameList), 
                    new MRUComboHelper<SearchType, string>(SearchType.TypeFullSearch, "Full w/Type", Settings.Default.SearchMRUFullList), 
                    new MRUComboHelper<SearchType, string>(SearchType.FormIDRef, "Form ID Ref.", Settings.Default.SearchMRUFormIDList), 
                    new MRUComboHelper<SearchType, string>(SearchType.BasicCriteriaRef, "Basic Search", new StringCollection()), 
                };
            this.toolStripIncrFindType.Items.Clear();
            this.toolStripIncrFindType.Items.AddRange(items);

            int idx = 0;
            if (!string.IsNullOrEmpty(Settings.Default.LastSearchType))
            {
                idx = this.toolStripIncrFindType.FindStringExact(Settings.Default.LastSearchType);
            }

            idx = idx >= 0 ? idx : 0;
            this.toolStripIncrFindType.SelectedIndex = idx;

            this.ResetSearch();
            this.toolStripIncrFindStatus.Text = string.Empty;
            this.toolStripIncrFindTypeFilter.Sorted = true;
            this.toolStripIncrFindTypeFilter.Items.Clear();
            this.toolStripIncrFindTypeFilter.Items.AddRange(DomainDefinition.GetRecordNames());
            this.toolStripIncrFindTypeFilter.SelectedIndex = 0;

            this.backgroundWorker1.DoWork += this.backgroundWorker1_DoWork;
            this.backgroundWorker1.RunWorkerCompleted += this.backgroundWorker1_RunWorkerCompleted;
            this.backgroundWorker1.ProgressChanged += this.backgroundWorker1_ProgressChanged;
        }
Esempio n. 3
0
        private void ReinitializeToolStripFind()
        {
            var recitems = DomainDefinition.GetRecordNames();

            this.toolStripIncrFindTypeFilter.Sorted = true;
            this.toolStripIncrFindTypeFilter.Items.Clear();
            this.toolStripIncrFindTypeFilter.Items.AddRange(recitems);
            if (this.toolStripIncrFindTypeFilter.SelectedIndex < 0 && recitems.Length > 0)
            {
                this.toolStripIncrFindTypeFilter.SelectedIndex = 0;
            }
        }
Esempio n. 4
0
        public FormIDElement()
        {
            this.InitializeComponent();

            var recitems = DomainDefinition.GetRecordNames();

            this.cboRecType.Sorted = true;
            this.cboRecType.Items.Clear();
            this.cboRecType.Items.Add("<All>");
            this.cboRecType.Items.AddRange(recitems);
            this.cboRecType.SelectedIndex = 0;
        }
        /// <summary>
        /// The button delete_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ButtonDelete_Click(object sender, EventArgs e)
        {
            Logger.Trace("Started ButtonDelete_Click()");

            DomainDefinition definition = this.DomainsListBox.SelectedItem as DomainDefinition;

            if (definition != null)
            {
                this.DeleteDomain(definition.Id);
            }

            Logger.Trace($"Completed ButtonDelete_Click()");
        }
Esempio n. 6
0
        public void UpdateselectedDomainName(string name)
        {
            DomainDefinition definition = this.DomainsListBox.SelectedItem as DomainDefinition;

            DomainsListBox.DataSource = null;

            DomainsListBox.DataSource    = ApplicationService.ProjectDefinition.Domains;
            DomainsListBox.DisplayMember = "Name";
            DomainsListBox.ValueMember   = "Id";

            this.DomainsListBox.SelectedItem = definition;
            //definition.Name = name;
        }
        /// <summary>
        ///     The add domain.
        /// </summary>
        /// <returns>
        ///     The <see cref="DomainDefinition" />.
        /// </returns>
        public DomainDefinition AddDomain()
        {
            Logger.Trace("Started AddDomain()");

            DomainDefinition result = this.ApplicationService.AddDomain();

            this.UpdateDataSource();
            this.Changed = true;

            this.DomainsListBox.SelectedItem = result;
            Logger.Trace("Completed AddDomain()");

            return(result);
        }
Esempio n. 8
0
        public Plugin(byte[] data, string name)
        {
            Name = name;
            var br = new BinaryReader(new MemoryStream(data));

            try
            {
                this.LoadPluginData(br, false, null);
                this.FileName = Path.GetFileNameWithoutExtension(name);
                define        = this.DetectVersion();
            }
            finally
            {
                br.Close();
            }
        }
        /// <summary>
        /// Test TestDeleteDomain.
        /// </summary>
        /// <param name="applicationService">
        /// The application service.
        /// </param>
        protected void TestDeleteDomain(IProjectDefinitionApplicationService applicationService)
        {
            DomainDefinition domain = applicationService.AddDomain();

            Assert.AreEqual(1, applicationService.ProjectDefinition.Domains.Count, "There should be 1 domain");
            domain = applicationService.AddDomain();
            Assert.AreEqual(2, applicationService.ProjectDefinition.Domains.Count, "There should be 2 domains");

            Guid id = applicationService.ProjectDefinition.Domains[0].Id;

            applicationService.Delete(id);
            Assert.AreEqual(1, applicationService.ProjectDefinition.Domains.Count, "There should be 1 domain");

            id = applicationService.ProjectDefinition.Domains[0].Id;
            applicationService.Delete(id);
            Assert.AreEqual(0, applicationService.ProjectDefinition.Domains.Count, "There should be 0 domains");
        }
        /// <summary>
        /// Test AddDomain.
        /// </summary>
        /// <param name="applicationService">
        /// The application service.
        /// </param>
        protected void TestAddDomain(IProjectDefinitionApplicationService applicationService)
        {
            DomainDefinition domain = applicationService.AddDomain();

            Assert.AreEqual(1, applicationService.ProjectDefinition.Domains.Count, "There should be 1 domain");
            Assert.AreEqual("Domain1", domain.Name, "The domain name should be Domain1");
            domain = applicationService.AddDomain();
            Assert.AreEqual(2, applicationService.ProjectDefinition.Domains.Count, "There should be 2 domains");
            Assert.AreEqual("Domain2", domain.Name, "The domain name should be Domain2");
            domain = applicationService.AddDomain();
            Assert.AreEqual(3, applicationService.ProjectDefinition.Domains.Count, "There should be 3 domains");
            Assert.AreEqual("Domain3", domain.Name, "The domain name should be Domain3");
            applicationService.ProjectDefinition.Domains[0].Name = "A";
            domain = applicationService.AddDomain();
            Assert.AreEqual(4, applicationService.ProjectDefinition.Domains.Count, "There should be 4 domains");
            Assert.AreEqual("Domain1", domain.Name, "The domain name should be Domain1");
        }
Esempio n. 11
0
        private DomainDefinition DetectVersion()
        {
            Record brcTES = this.Records.OfType <Record>().FirstOrDefault(x => x.Name.StartsWith("TES"));

            if (brcTES == null)
            {
                throw new ApplicationException("Plugin lacks a valid TES4 record. Cannot continue.");
            }
            var hdr = brcTES.SubRecords.FirstOrDefault(x => x.Name == "HEDR");

            if (hdr == null)
            {
                throw new ApplicationException("Plugin lacks a valid HEDR subrecord. Cannot continue.");
            }
            var version = hdr.GetValue <float>(0);

            return(DomainDefinition.DetectDefinitionFromVersion(brcTES.Name, version));
        }
Esempio n. 12
0
        private DomainDefinition DetectVersion(BinaryReader br, string fileName)
        {
            // Quick check for master esm.  Skyrim.esm uses same as fallout. so harder to detect
            if (!string.IsNullOrEmpty(fileName))
            {
                foreach (var domain in DomainDefinition.AllDomains().Where(domain =>
                                                                           string.Compare(domain.Master, Path.GetFileName(fileName), StringComparison.InvariantCultureIgnoreCase) == 0))
                {
                    if (!domain.Loaded)
                    {
                        DomainDefinition.Load(domain.Name);
                    }
                    return(domain);
                }
            }

            var tes = ReadRecName(br);

            if (tes == "TES3")
            {
                return(DomainDefinition.Load("Morrowind")); // hardcoded?
            }
            if (tes != "TES4")
            {
                throw new Exception("File is not a valid TES4 plugin (Missing TES4 record)");
            }
            // Check for file version by checking the position of the HEDR field in the file. (ie. how big are the record header.)
            br.BaseStream.Position = 20;
            var s = ReadRecName(br);

            if (s == "HEDR")
            {
                return(DomainDefinition.Load("Oblivion")); // hardcoded?
            }
            s = ReadRecName(br);
            if (s != "HEDR")
            {
                throw new Exception("File is not a valid TES4 plugin (Missing HEDR subrecord in the TES4 record)");
            }
            var recsize = br.ReadUInt16();
            var version = br.ReadSingle();

            return(DomainDefinition.DetectDefinitionFromVersion(tes, version));
        }
Esempio n. 13
0
        /// <summary>
        ///     The add domain.
        /// </summary>
        /// <returns>
        ///     The <see cref="DomainDefinition" />.
        /// </returns>
        public DomainDefinition AddDomain()
        {
            Logger.Trace($"Started AddDomain()");
            DomainDefinition result = new DomainDefinition();

            int index = 1;

            while (ProjectDefinition.Domains.Exists(d => d.Name == $"Domain{index}"))
            {
                index++;
            }

            result.Name = $"Domain{index}";
            Logger.Trace($"Domain name: {result.Name}");
            ProjectDefinition.Domains.Add(result);
            Logger.Trace($"Completed AddDomain()");

            return(result);
        }
Esempio n. 14
0
        public Plugin(string filePath, bool headerOnly, Func <string, bool> includeFilter)
        {
            Name       = Path.GetFileName(filePath);
            PluginPath = Path.GetDirectoryName(filePath);
            var fi = new FileInfo(filePath);

            using (var br = new BinaryReader(fi.OpenRead()))
            {
                define = this.DetectVersion(br, filePath);
                br.BaseStream.Position = 0;
                this.LoadPluginData(br, headerOnly, includeFilter);
            }

            this.FileName = Path.GetFileNameWithoutExtension(filePath);
            if (!headerOnly)
            {
                this.StringsFolder = Path.Combine(Path.GetDirectoryName(filePath), "Strings");
            }

            this.ReloadStrings();
        }
 public UniversalDomain(double start, double end)
 {
     definition = new DomainDefinition(start, end);
 }
Esempio n. 16
0
        /// <summary>
        /// For the given type, gets the associated type mapping given the domain and known types.
        /// </summary>
        /// <param name="typeDefinition"></param>
        /// <param name="domainDefinition"></param>
        /// <param name="knownTypes"></param>
        /// <param name="isArray"></param>
        /// <returns></returns>
        public static string GetTypeMappingForType(TypeDefinition typeDefinition, DomainDefinition domainDefinition, IDictionary <string, TypeInfo> knownTypes, bool isArray = false)
        {
            var type = typeDefinition.Type;

            if (String.IsNullOrWhiteSpace(type))
            {
                type = typeDefinition.TypeReference;
            }

            string mappedType = null;

            if (type.Contains(".") && knownTypes.ContainsKey(type))
            {
                var typeInfo = knownTypes[type];
                if (typeInfo.IsPrimitive)
                {
                    var primitiveType = typeInfo.TypeName;

                    if (typeDefinition.Optional && typeInfo.ByRef)
                    {
                        primitiveType += "?";
                    }

                    if (isArray)
                    {
                        primitiveType += "[]";
                    }

                    return(primitiveType);
                }
                mappedType = $"{typeInfo.Namespace}.{typeInfo.TypeName}";
                if (typeDefinition.Optional && typeInfo.ByRef)
                {
                    mappedType += "?";
                }
            }

            if (mappedType == null)
            {
                var fullyQualifiedTypeName = $"{domainDefinition.Name}.{type}";

                if (knownTypes.ContainsKey(fullyQualifiedTypeName))
                {
                    var typeInfo = knownTypes[fullyQualifiedTypeName];

                    mappedType = typeInfo.TypeName;
                    if (typeInfo.ByRef && typeDefinition.Optional)
                    {
                        mappedType += "?";
                    }
                }
            }


            if (mappedType == null)
            {
                switch (type)
                {
                case "number":
                    mappedType = typeDefinition.Optional ? "double?" : "double";
                    break;

                case "integer":
                    mappedType = typeDefinition.Optional ? "long?" : "long";
                    break;

                case "boolean":
                    mappedType = typeDefinition.Optional ? "bool?" : "bool";
                    break;

                case "string":
                    mappedType = "string";
                    break;

                case "object":
                case "any":
                    mappedType = "object";
                    break;

                case "binary":
                    mappedType = "byte[]";
                    break;

                case "array":
                    mappedType = GetTypeMappingForType(typeDefinition.Items, domainDefinition, knownTypes, true);
                    break;

                default:
                    throw new InvalidOperationException($"Unmapped data type: {type}");
                }
            }

            if (isArray)
            {
                mappedType += "[]";
            }

            return(mappedType);
        }
Esempio n. 17
0
 private Plugin(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     // detect version
     define = this.DetectVersion();
 }
Esempio n. 18
0
 public Plugin()
     : this(DomainDefinition.LoadedDomains().FirstOrDefault())
 {
 }
Esempio n. 19
0
 public Plugin(DomainDefinition define)
 {
     this.Name   = "New plugin.esp";
     this.define = define;
 }