private void ParseElement(D900CdrElement element)
        {
            ID900CdrElementDefinition elementDef = DefinitionProvider.FindDefinition(element.Path);

            if (elementDef != null)
            {
                if (elementDef.Name.Length != 0)
                {
                    element.Name = elementDef.Name;
                }

                if (elementDef.Parselet.Length > 0)
                {
                    ID900Parselet parselet = ParseletProvider.FindParselet(elementDef.Parselet);
                    if (parselet != null)
                    {
                        element.Parselet         = parselet;
                        element.DefaultValueType = elementDef.ValueType;
                    }
                }
            }

            if (element.Parselet == null && !element.IsConstructed)
            {
                element.Parselet = D900ParseletProvider.Instance.FindParselet("GenericParselet");
            }

            if ((element.IsConstructed) && (!element.IsEmpty))
            {
                foreach (D900CdrElement e in (element.Value as List <D900CdrElement>))
                {
                    this.ParseElement(e);
                }
            }
        }
示例#2
0
    public bool TryGetHistoricalStatDefinition(string key, BungieLocales locale,
                                               out DestinyHistoricalStatsDefinition definition)
    {
        if (Repository.TryGetDestinyHistoricalDefinition(locale, key, out definition))
        {
            return(true);
        }

        var getterTask = DefinitionProvider.LoadHistoricalStatsDefinition(key, locale);

        definition = getterTask.GetAwaiter().GetResult();

        if (!getterTask.IsCompleted)
        {
            throw new Exception("ValueTask faulted to get result.");
        }

        if (definition is null)
        {
            return(false);
        }
        if (_configuration.CacheDefinitions)
        {
            Repository.AddDestinyHistoricalDefinition(locale, definition);
        }
        return(true);
    }
        public void Verify_SimpleElementDefinitionObjectProperties()
        {
            Guid typeId = ElementAttributeGrabber.GetTypeId(typeof(ImportNetworkElement));

            DefinitionProvider prov = new DefinitionProvider();
            IElementDefinition def = prov.GetDefinition(typeId);

            Assert.NotNull(def.AssemblyName);
            Assert.NotNull(def.AssemblyVersion);
            Assert.NotNull(def.PackageName);
            Assert.NotNull(def.PackageVersion);
            Assert.NotNull(def.ElementName);
            Assert.NotNull(def.Caption);
            Assert.NotNull(def.ElementDescription);
            Assert.NotNull(def.NameSpace);
            Assert.NotNull(def.ElementVersion);
            Assert.Equal(def.Scope, ElementScope.Simple);
            Assert.NotEqual(def.ElementTypeId, Guid.Empty);

            Assert.NotNull(def.SmallIconName);
            Assert.NotNull(def.MediumIconName);

            Assert.NotNull(def.SmallImageName);
            Assert.NotNull(def.MediumImageName);
            Assert.NotNull(def.MediumImageCompleteName);
            Assert.NotNull(def.MediumImageErrorName);
            Assert.NotNull(def.LargeImageName);

            Assert.NotNull(def.OutputPortTypes);
            Assert.NotNull(def.InputPortTypes);
        }
示例#4
0
        public void Definitions_ReturnsAListOfAllElementDefinitions()
        {
            DefinitionProvider dp = new DefinitionProvider();

            IList<IElementDefinition> defs = dp.Definitions;

            Assert.NotNull(defs);
        }
 /// <summary>
 ///     Specifies definition provider
 /// </summary>
 /// <param name="provider"></param>
 /// <returns></returns>
 /// <exception cref="Exception"></exception>
 public BungieClientSettings UseDefinitionProvider(DefinitionProvider provider)
 {
     if (provider is null)
     {
         throw new Exception("Provider is null.");
     }
     DefinitionLoadingSettings.UsedProvider = provider;
     return(this);
 }
    public LinkHandlerProvider(ISettings settings, Git git, ILogger logger)
    {
        _logger = logger;

        _handlers = DefinitionProvider
                    .GetDefinitions()
                    .OrderBy((x) => x.Name)
                    .Select((x) => new LinkHandler(x, settings, git))
                    .ToList();
    }
        public static void Write(string portName, string deviceName, string deviceAddress, string inFile)
        {
            var definition = new DefinitionProvider().Get(deviceName);

            byte address     = string.IsNullOrWhiteSpace(deviceAddress) ? 0x50 : deviceAddress.ToByte();
            var  eeprom      = new I2CEEPROM(portName, address, definition);
            var  fileContent = File.ReadAllBytes(inFile);

            eeprom.WriteToAddress(0, fileContent);
            Console.WriteLine($"Succesfully wrote {fileContent.Length} bytes to EEPROM.");
        }
示例#8
0
        public static void Read(string portName, string deviceName, string deviceAddress, string outFile)
        {
            var definition = new DefinitionProvider().Get(deviceName);

            byte address       = string.IsNullOrWhiteSpace(deviceAddress) ? 0x50 : deviceAddress.ToByte();
            var  eeprom        = new I2CEEPROM(portName, address, definition);
            var  eepromContent = eeprom.ReadFromAddress(0, definition.MemorySize / definition.WordSize);

            File.WriteAllBytes(outFile, eepromContent);
            Console.WriteLine($"Succesfully read {eepromContent.Length} bytes from EEPROM.");
        }
示例#9
0
        public void GetDefinition_ByTypeId(string requestedTypeId, string expectedName)
        {
            Guid typeId = new Guid(requestedTypeId);

            DefinitionProvider dp = new DefinitionProvider();

            IElementDefinition def = dp.GetDefinition(typeId);

            Assert.NotNull(def);
            Assert.Equal(def.ElementTypeId, typeId);
            Assert.Equal(def.ElementName, expectedName);
        }
示例#10
0
        private static string Launch(string PathAndQuery)
        {
            var w = new StringBuilder();



            var p = new DefinitionProvider(PathAndQuery, k => k.ToWebString());


            w.Append(p.GetString());


            return(w.ToString());
        }
示例#11
0
        public void Create_ReturnsTheSpecifiedElementFactoryClass(string requestedTypeId, Type expectedType)
        {
            Guid typeId = new Guid(requestedTypeId);

            DefinitionProvider dp = new DefinitionProvider();
            IElementDefinition def = dp.GetDefinition(typeId);

            FactoryProvider fp = new FactoryProvider();

            IElementFactory fac = fp.Create(def);

            Assert.NotNull(fac);
            Assert.IsType(expectedType,fac);
        }
示例#12
0
        public void VerifyDefinitionContentIsNotNull(string requestedTypeId, string expectedName)
        {
            Guid typeId = new Guid(requestedTypeId);

            DefinitionProvider dp = new DefinitionProvider();

            IElementDefinition def = dp.GetDefinition(typeId);

            Assert.NotNull(def.AssemblyName);
            Assert.NotNull(def.AssemblyVersion);
            Assert.NotNull(def.Caption);
            Assert.NotNull(def.ElementDescription);
            Assert.NotNull(def.ElementName);
            Assert.NotEqual(Guid.Empty, def.ElementTypeId);
            Assert.NotNull(def.ElementVersion);
            Assert.NotNull(def.FactoryName);
            Assert.NotNull(def.InputPortTypes);
            Assert.NotNull(def.LargeImageName);
            Assert.NotNull(def.MediumIconName);
            Assert.NotNull(def.MediumImageCompleteName);
            Assert.NotNull(def.MediumImageErrorName);
            Assert.NotNull(def.MediumImageName);
            Assert.NotNull(def.NameSpace);
            Assert.NotNull(def.OutputPortTypes);
            Assert.NotNull(def.PackageName);
            Assert.NotNull(def.PackageVersion);
            //ElementScope Scope, "  should not be null.");
            Assert.NotNull(def.SmallIconName);
            Assert.NotNull(def.SmallImageName);

            Assert.NotEqual("", def.AssemblyName);
            Assert.NotEqual("", def.AssemblyVersion);
            Assert.NotEqual("", def.Caption);
            Assert.NotEqual("", def.ElementDescription);
            Assert.NotEqual("", def.ElementName);
            Assert.NotEqual("", def.ElementVersion);
            Assert.NotEqual("", def.FactoryName);
            Assert.NotEqual("", def.LargeImageName);
            Assert.NotEqual("", def.MediumIconName);
            Assert.NotEqual("", def.MediumImageCompleteName);
            Assert.NotEqual("", def.MediumImageErrorName);
            Assert.NotEqual("", def.MediumImageName);
            Assert.NotEqual("", def.NameSpace);
            Assert.NotEqual("", def.PackageName);
            Assert.NotEqual("", def.PackageVersion);
            Assert.NotEqual("", def.SmallIconName);
            Assert.NotEqual("", def.SmallImageName);
        }
示例#13
0
        private void ReadJsonDefinitions(StreamReader jsonFile)
        {
            if (jsonFile == null)
                throw new BadConfigurationException("eventDefinitions", "null");

            try
            {
                this.definitionProvider = JsonConvert.DeserializeObject<DefinitionProvider>(jsonFile.ReadToEnd());
            }
            catch (JsonReaderException jre)
            {
                string message = "Can't read JSON definition file. Exception was thrown while parsing file:\n" +
                                 jre.Message;
                throw new BadConfigurationException(message);
            }
        }
示例#14
0
        private void ReadJsonDefinitions(StreamReader jsonFile)
        {
            if (jsonFile == null)
            {
                throw new BadConfigurationException("eventDefinitions", "null");
            }

            try
            {
                this.definitionProvider = JsonConvert.DeserializeObject <DefinitionProvider>(jsonFile.ReadToEnd());
            }
            catch (JsonReaderException jre)
            {
                string message = "Can't read JSON definition file. Exception was thrown while parsing file:\n" +
                                 jre.Message;
                throw new BadConfigurationException(message);
            }
        }
示例#15
0
        private static void Main(string[] args)
        {
            var options = new Options();

            if (!Parser.Default.ParseArguments(args, options))
            {
                throw new ArgumentException("Invalid parameters.");
            }

            /* In order to leave the main assembly unlocked,
             * we create a copy of the file and use it for readonly operations */
            var readonlyAssemblyPath = CreateReadonlyAssembly(options.AssemblyPath);

            var dependencyDirectories = new List <string>
            {
                Path.GetDirectoryName(options.AssemblyPath)
            };

            if (options.DependencyDirectories != null)
            {
                dependencyDirectories.AddRange(options.DependencyDirectories);
            }

            var assemblyWeaver     = new AssemblyWeaver(options.AssemblyPath, dependencyDirectories);
            var assemblyResolver   = new AssemblyResolver(readonlyAssemblyPath, dependencyDirectories);
            var definitionProvider = new DefinitionProvider(assemblyWeaver.AssemblyDefinition);

            if (options.ShouldEnableLogging)
            {
                SetupExceptionLogger(assemblyWeaver, assemblyResolver, definitionProvider.MethodDefinitions);
            }

            if (options.ShouldEnableProfiler)
            {
                SetupPerformanceProfiler(assemblyWeaver, assemblyResolver, definitionProvider.MethodDefinitions);
            }

            assemblyWeaver.Reweave();
        }
示例#16
0
    public async ValueTask <bool> TryGetHistoricalStatDefinitionAsync(string key, BungieLocales locale,
                                                                      Action <DestinyHistoricalStatsDefinition> success)
    {
        if (Repository.TryGetDestinyHistoricalDefinition(locale, key, out var definition))
        {
            success(definition);
            return(true);
        }

        definition = await DefinitionProvider.LoadHistoricalStatsDefinition(key, locale);

        if (definition is null)
        {
            return(false);
        }
        if (_configuration.CacheDefinitions)
        {
            Repository.AddDestinyHistoricalDefinition(locale, definition);
        }
        success(definition);
        return(true);
    }
示例#17
0
    /// <summary>
    ///     <inheritdoc cref="IBungieClient.TryGetDefinitionAsync{T}" />
    /// </summary>
    /// <param name="hash"></param>
    /// <param name="locale"></param>
    /// <param name="success"></param>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    public async ValueTask <bool> TryGetDefinitionAsync <T>(uint hash, BungieLocales locale, Action <T> success)
        where T : IDestinyDefinition
    {
        if (Repository.TryGetDestinyDefinition <T>(hash, locale, out var definition))
        {
            success(definition);
            return(true);
        }

        definition = await DefinitionProvider.LoadDefinition <T>(hash, locale);

        if (definition is null)
        {
            return(false);
        }
        if (_configuration.CacheDefinitions)
        {
            Repository.AddDefinition(locale, definition);
        }
        success(definition);
        return(true);
    }
示例#18
0
    public bool TryGetDefinition <T>(uint hash, BungieLocales locale, out T definition) where T : IDestinyDefinition
    {
        if (Repository.TryGetDestinyDefinition(hash, locale, out definition))
        {
            return(true);
        }

        var defTask = DefinitionProvider.LoadDefinition <T>(hash, locale);

        definition = defTask.GetAwaiter().GetResult();
        if (!defTask.IsCompleted)
        {
            throw new Exception("ValueTask faulted to get result.");
        }
        if (definition is null)
        {
            return(false);
        }
        if (_configuration.CacheDefinitions)
        {
            Repository.AddDefinition(locale, definition);
        }
        return(true);
    }
 public void CanLoadDefinitions()
 {
     // This test is really just a way to debug the definition loading.
     Assert.NotEmpty(DefinitionProvider.GetDefinitions().ToList());
 }
示例#20
0
 public void Dispose()
 {
     DefinitionProvider.Dispose();
 }
示例#21
0
 public async ValueTask DisposeAsync()
 {
     await DefinitionProvider.DisposeAsync();
 }