Esempio n. 1
0
        public void ConcurrentContainerRegisterInstanceTest()
        {
            // registration by type

            Assert.IsFalse(_container.IsRegisteredInstance <IMetadataFactory>());

            MetadataFactory unnamedFactory = new MetadataFactory();

            _container.RegisterInstance <IMetadataFactory>(unnamedFactory);

            Assert.IsTrue(_container.IsRegisteredInstance <IMetadataFactory>());
            Assert.IsTrue(_container.IsRegisteredInstance(typeof(IMetadataFactory)));
            Assert.IsTrue(_container.IsRegisteredInstance(typeof(IMetadataFactory).FullName));
            Assert.IsTrue(_container.IsRegisteredInstance(unnamedFactory));

            Assert.Throws <ArgumentNullException>(() => _container.RegisterInstance(null, typeof(GeometryFactory)));
            Assert.Throws <ArgumentNullException>(() => _container.RegisterInstance(typeof(IGeometryFactory), null));
            Assert.Throws <ArgumentException>(() => _container.RegisterInstance(typeof(IGeometryFactory), unnamedFactory));
            Assert.Throws <InvalidOperationException>(() => _container.RegisterInstance(typeof(IMetadataFactory), unnamedFactory));

            _container.RegisterInstance <IMetadataFactory>(unnamedFactory, true);
            Assert.IsTrue(_container.IsRegisteredInstance <IMetadataFactory>());
            Assert.IsTrue(_container.IsRegisteredInstance(unnamedFactory));

            _container.RegisterInstance(typeof(IMetadataFactory), unnamedFactory, true);
            Assert.IsTrue(_container.IsRegisteredInstance <IMetadataFactory>());

            Assert.IsTrue(_container.UnregisterInstance <IMetadataFactory>()); // unregister
            Assert.IsFalse(_container.IsRegisteredInstance <IMetadataFactory>());
            Assert.IsFalse(_container.UnregisterInstance <IMetadataFactory>());

            _container.RegisterInstance <IMetadataFactory>(unnamedFactory);
            Assert.IsTrue(_container.UnregisterInstance(unnamedFactory));
            Assert.IsFalse(_container.IsRegisteredInstance <IMetadataFactory>());

            Assert.IsFalse(_container.UnregisterInstance(new Object()));


            // registration by name

            MetadataFactory namedFactory = new MetadataFactory();

            _container.RegisterInstance <IMetadataFactory>("MetadataFactoryRegistration", namedFactory);
            Assert.IsTrue(_container.IsRegisteredInstance("MetadataFactoryRegistration"));
            Assert.IsTrue(_container.IsRegisteredInstance(namedFactory));

            _container.RegisterInstance <IMetadataFactory>("MetadataFactoryRegistration", namedFactory, true);
            Assert.IsTrue(_container.IsRegisteredInstance("MetadataFactoryRegistration"));

            _container.RegisterInstance("MetadataFactoryRegistration", typeof(IMetadataFactory), namedFactory, true);
            Assert.IsTrue(_container.IsRegisteredInstance("MetadataFactoryRegistration"));

            Assert.IsTrue(_container.UnregisterInstance("MetadataFactoryRegistration")); // unregister
            Assert.IsFalse(_container.IsRegisteredInstance("MetadataFactoryRegistration"));
            Assert.IsFalse(_container.UnregisterInstance("MetadataFactoryRegistration"));

            _container.RegisterInstance("MetadataFactoryRegistration", typeof(IMetadataFactory), namedFactory);
            Assert.IsTrue(_container.IsRegisteredInstance("MetadataFactoryRegistration"));


            // exceptions

            Assert.Throws <ArgumentNullException>(() => _container.UnregisterInstance((String)null));
            Assert.Throws <ArgumentNullException>(() => _container.UnregisterInstance((Type)null));
            Assert.Throws <ArgumentNullException>(() => _container.UnregisterInstance((Object)null));
            Assert.Throws <InvalidOperationException>(() => _container.RegisterInstance <IMetadataFactory>("MetadataFactoryRegistration", unnamedFactory));

            Assert.Throws <ArgumentNullException>(() => _container.RegisterInstance((Type)null, (Type)null));
            Assert.Throws <ArgumentNullException>(() => _container.RegisterInstance((Type)null, (Type)null, true));
            Assert.Throws <ArgumentNullException>(() => _container.RegisterInstance(typeof(IMetadataFactory), (Type)null));
            Assert.Throws <ArgumentNullException>(() => _container.RegisterInstance((String)null, (Type)null, (Type)null, true));
            Assert.Throws <ArgumentNullException>(() => _container.RegisterInstance(typeof(IMetadataFactory).FullName, (Type)null, (Type)null, true));
            Assert.Throws <ArgumentNullException>(() => _container.RegisterInstance(typeof(IMetadataFactory).FullName, typeof(IMetadataFactory), (Type)null, true));

            Assert.Throws <ArgumentNullException>(() => _container.IsRegisteredInstance((String)null));
            Assert.Throws <ArgumentNullException>(() => _container.IsRegisteredInstance((Type)null));
            Assert.Throws <ArgumentNullException>(() => _container.IsRegisteredInstance((Object)null));
        }
Esempio n. 2
0
        public void ConcurrentContainerResolveInstanceTest()
        {
            // unnamed registration

            IMetadataFactory unnamedFactory = new MetadataFactory();

            _container.RegisterInstance <IMetadataFactory>(unnamedFactory);

            IMetadataFactory resolvedFactory = _container.ResolveInstance <IMetadataFactory>();

            Assert.IsNotNull(resolvedFactory);
            Assert.AreEqual(unnamedFactory, resolvedFactory);

            resolvedFactory = _container.ResolveInstance <IMetadataFactory>(typeof(IMetadataFactory).FullName);
            Assert.IsNotNull(resolvedFactory);
            Assert.AreEqual(unnamedFactory, resolvedFactory);

            Object resolvedObject = _container.ResolveInstance(typeof(IMetadataFactory));

            Assert.IsNotNull(resolvedObject);
            Assert.AreEqual(unnamedFactory, resolvedObject);

            resolvedObject = _container.ResolveInstance(typeof(IMetadataFactory).FullName);
            Assert.IsNotNull(resolvedObject);
            Assert.AreEqual(unnamedFactory, resolvedObject);

            resolvedObject = _container.ResolveInstance(typeof(IMetadataFactory), typeof(IMetadataFactory).FullName);
            Assert.IsNotNull(resolvedObject);
            Assert.AreEqual(unnamedFactory, resolvedObject);


            // named registration

            IMetadataFactory namedFactory = new MetadataFactory();

            _container.RegisterInstance <IMetadataFactory>("MetadataFactoryRegistration", namedFactory);

            resolvedFactory = _container.ResolveInstance <IMetadataFactory>("MetadataFactoryRegistration");
            Assert.IsNotNull(resolvedFactory);
            Assert.AreEqual(namedFactory, resolvedFactory);

            resolvedObject = _container.ResolveInstance("MetadataFactoryRegistration");
            Assert.IsNotNull(resolvedObject);
            Assert.AreEqual(namedFactory, resolvedObject);

            resolvedObject = _container.ResolveInstance(typeof(IMetadataFactory), "MetadataFactoryRegistration");
            Assert.IsNotNull(resolvedObject);
            Assert.AreEqual(namedFactory, resolvedObject);


            // exceptions

            Assert.Throws <ArgumentNullException>(() => _container.ResolveInstance <IMetadataFactory>(null));
            Assert.Throws <InvalidOperationException>(() => _container.ResolveInstance <IMetadataFactory>("InvalidName"));
            Assert.Throws <InvalidOperationException>(() => _container.ResolveInstance <IGeometryFactory>("MetadataFactoryRegistration"));
            Assert.Throws <InvalidOperationException>(() => _container.ResolveInstance <IGeometryFactory>());

            Assert.Throws <ArgumentNullException>(() => _container.ResolveInstance((Type)null));
            Assert.Throws <ArgumentNullException>(() => _container.ResolveInstance((String)null));
            Assert.Throws <ArgumentNullException>(() => _container.ResolveInstance((Type)null, (String)null));
        }
Esempio n. 3
0
 public PortablePdbReader(DataReaderFactory pdbStream, PdbFileKind pdbFileKind)
 {
     this.pdbFileKind = pdbFileKind;
     pdbMetadata      = MetadataFactory.CreateStandalonePortablePDB(pdbStream, true);
 }
 public void CanGetEnabledSiteClassifications()
 {
     IMetadataFactory _factory = MetadataFactory.GetInstance();
     IMetadataManager _manager = _factory.GetManager();
     var _actual = _manager.GetAvailableSiteClassifications();
 }
Esempio n. 5
0
#pragma warning restore CS8618 // Non-nullable field is uninitialized.

        public override bool Execute()
        {
            if (string.IsNullOrWhiteSpace(IVTString))
            {
                Log.LogMessageFromText(nameof(IVTString) + " is an empty string", MessageImportance.High);
                return(false);
            }

            if (string.IsNullOrWhiteSpace(DestinationDirectory))
            {
                Log.LogMessageFromText(nameof(DestinationDirectory) + " is an empty string", MessageImportance.High);
                return(false);
            }

            var assembliesToFix = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var tmp in AssembliesToMakePublic.Split(';'))
            {
                var asmName       = tmp.Trim();
                var asmSimpleName = asmName;
                int index         = asmSimpleName.IndexOf(',');
                if (index >= 0)
                {
                    asmSimpleName = asmSimpleName.Substring(0, index).Trim();
                }
                if (asmSimpleName.Length == 0)
                {
                    continue;
                }
                assembliesToFix.Add(asmSimpleName);
            }

            OutputReferencePath = new ITaskItem[ReferencePath.Length];
            byte[]? ivtBlob     = null;
            for (int i = 0; i < ReferencePath.Length; i++)
            {
                var file = ReferencePath[i];
                OutputReferencePath[i] = file;
                var filename      = file.ItemSpec;
                var fileExt       = Path.GetExtension(filename);
                var asmSimpleName = Path.GetFileNameWithoutExtension(filename);
                if (!assembliesToFix.Contains(asmSimpleName))
                {
                    continue;
                }
                if (!File.Exists(filename))
                {
                    Log.LogMessageFromText($"File does not exist: {filename}", MessageImportance.High);
                    return(false);
                }

                var patchDir = DestinationDirectory;
                Directory.CreateDirectory(patchDir);

                var  fileInfo  = new FileInfo(filename);
                long filesize  = fileInfo.Length;
                long writeTime = fileInfo.LastWriteTimeUtc.ToBinary();

                var extraInfo       = $"_{VERSION} {filesize} {writeTime}_";
                var patchedFilename = Path.Combine(patchDir, asmSimpleName + extraInfo + fileExt);
                if (StringComparer.OrdinalIgnoreCase.Equals(patchedFilename, filename))
                {
                    continue;
                }

                if (!File.Exists(patchedFilename))
                {
                    if (ivtBlob is null)
                    {
                        ivtBlob = CreateIVTBlob(IVTString);
                    }
                    var data = File.ReadAllBytes(filename);
                    try {
                        using (var peImage = new PEImage(data, filename, ImageLayout.File, verify: true)) {
                            using (var md = MetadataFactory.CreateMetadata(peImage, verify: true)) {
                                var result = new IVTPatcher(data, md, ivtBlob).Patch();
                                if (result != IVTPatcherResult.OK)
                                {
                                    string errMsg;
                                    switch (result)
                                    {
                                    case IVTPatcherResult.NoCustomAttributes:
                                        errMsg = $"Assembly '{asmSimpleName}' has no custom attributes";
                                        break;

                                    case IVTPatcherResult.NoIVTs:
                                        errMsg = $"Assembly '{asmSimpleName}' has no InternalsVisibleToAttributes";
                                        break;

                                    case IVTPatcherResult.IVTBlobTooSmall:
                                        errMsg = $"Assembly '{asmSimpleName}' has no InternalsVisibleToAttribute blob that is big enough to store '{IVTString}'. Use a shorter assembly name and/or a shorter public key, or skip PublicKey=xxxx... altogether (if it's a C# assembly)";
                                        break;

                                    default:
                                        Debug.Fail($"Unknown error result: {result}");
                                        errMsg = "Unknown error";
                                        break;
                                    }
                                    Log.LogMessageFromText(errMsg, MessageImportance.High);
                                    return(false);
                                }
                                try {
                                    File.WriteAllBytes(patchedFilename, data);
                                }
                                catch {
                                    try { File.Delete(patchedFilename); } catch { }
                                    throw;
                                }
                            }
                        }
                    }
                    catch (Exception ex) when(ex is IOException || ex is BadImageFormatException)
                    {
                        Log.LogMessageFromText($"File '{filename}' is not a .NET file", MessageImportance.High);
                        return(false);
                    }

                    var xmlDocFile = Path.ChangeExtension(filename, "xml");
                    if (File.Exists(xmlDocFile))
                    {
                        var newXmlDocFile = Path.ChangeExtension(patchedFilename, "xml");
                        if (File.Exists(newXmlDocFile))
                        {
                            File.Delete(newXmlDocFile);
                        }
                        File.Copy(xmlDocFile, newXmlDocFile);
                    }
                }

                OutputReferencePath[i] = new TaskItem(patchedFilename);
            }

            return(true);
        }
        /// <summary>
        /// retrieves the DSD from database
        /// </summary>
        /// <returns>list of DataStructure for SDMXObject</returns>
        public List <DataStructureObjectImpl> GetDSDs()
        {
            try
            {
                if (ReferencesObject == null)
                {
                    ReferencesObject = new IReferencesObject();
                }

                if (ReferencesObject.DSDs != null)
                {
                    return(ReferencesObject.DSDs);
                }

                if (ReferencesObject.FoundedDataflows == null || ReferencesObject.FoundedDataflows.Count == 0)
                {
                    IDataflowsManager gdf = new MetadataFactory().InstanceDataflowsManager((ISdmxParsingObject)this.parsingObject.Clone(), this.versionTypeResp);
                    gdf.parsingObject.MaintainableId  = null;
                    ReferencesObject.FoundedDataflows = gdf.GetDataFlows();
                }

                if (ReferencesObject.FoundedDataflows == null || ReferencesObject.FoundedDataflows.Count == 0)
                {
                    throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.DataflowNotFound, new Exception(this.parsingObject.ConstrainDataFlow));
                }



                if (!string.IsNullOrEmpty(this.parsingObject.MaintainableId))
                {
                    FlyNameArtefactSettings fnas = new FlyNameArtefactSettings(this.parsingObject);
                    string DataFlowCode          = fnas.GetDataFlowCodeFromKeyFamily();
                    //Controllo se esiste il Dataflow
                    ReferencesObject.FoundedDataflows = new List <IDataflowObject>()
                    {
                        ReferencesObject.FoundedDataflows.Find(df => df.Id.Trim().ToUpper() == DataFlowCode.Trim().ToUpper())
                    };
                }

                if (ReferencesObject.FoundedDataflows == null)
                {
                    throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.DataflowNotFound);
                }

                ReferencesObject.DSDs = new List <DataStructureObjectImpl>();
                if (ReferencesObject.Codelists == null)
                {
                    ReferencesObject.Codelists = new List <ICodelistMutableObject>();
                }
                if (ReferencesObject.Concepts == null)
                {
                    ReferencesObject.Concepts = new Dictionary <string, List <IConceptObjectImpl> >();
                }
                foreach (var df in ReferencesObject.FoundedDataflows)
                {
                    ReferencesObject.DSDs.Add(BuildDSD(df));
                }
                return(ReferencesObject.DSDs);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.BuildDSD, ex);
            }
        }
        static DmdEcma335MetadataReader Create(DmdModuleImpl module, IPEImage peImage)
        {
            var metadata = MetadataFactory.CreateMetadata(peImage);

            return(new DmdEcma335MetadataReader(module, metadata));
        }
Esempio n. 8
0
 private static IAttributeProperty Convert(Mono.Cecil.CustomAttributeNamedArgument property, int sequence)
 {
     return(MetadataFactory.InitializeAttributeProperty(
                property.Name, property.Argument.Type.FullName, sequence, property.Argument.Value));
 }
Esempio n. 9
0
 public async Task PostMetadataFactoryAsync([FromBody] MetadataFactory metadataFactory)
 {
     await _writeService.CreateFactoryAsync(metadataFactory);
 }