Пример #1
0
        public void TestEquals()
        {
            IResourceFormat a = (IResourceFormat)resourceFormat.GetType().GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>());
            IResourceFormat b = (IResourceFormat)resourceFormat.GetType().GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>());

            Assert.AreEqual(b, a);
        }
        public void TestGetFormat()
        {
            var filename = "NCDK.Data.Smiles.test2.smi";

            Trace.TraceInformation("Testing: " + filename);
            var ins = ResourceLoader.GetAsStream(filename);
            EnumerableSMILESReader reader = new EnumerableSMILESReader(ins, ChemObjectBuilder.Instance);
            IResourceFormat        format = reader.Format;

            Assert.IsTrue(format is SMILESFormat);
        }
Пример #3
0
 private void loadFormats()
 {
     if (formats == null)
     {
         formats = new System.Collections.ArrayList();
         try
         {
             //logger.debug("Starting loading Formats...");
             //UPGRADE_TODO: The differences in the expected value  of parameters for constructor 'java.io.BufferedReader.BufferedReader'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
             //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'"
             //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'"
             //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetClassLoader'"
             System.IO.StreamReader reader = new System.IO.StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + IO_FORMATS_LIST));//new System.IO.StreamReader(this.GetType().getClassLoader().getResourceAsStream(IO_FORMATS_LIST), System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(this.GetType().getClassLoader().getResourceAsStream(IO_FORMATS_LIST), System.Text.Encoding.Default).CurrentEncoding);
             int formatCount = 0;
             while (reader.Peek() != -1)
             {
                 // load them one by one
                 System.String formatName = reader.ReadLine();
                 formatCount++;
                 try
                 {
                     //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.loadClass' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'"
                     //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetClassLoader'"
                     ObjectHandle    handle = System.Activator.CreateInstance("NuGenCDKSharp", formatName);
                     IResourceFormat format = (IResourceFormat)handle.Unwrap();//System.Activator.CreateInstance(//this.GetType().getClassLoader().loadClass(formatName));
                     if (format is IChemFormat)
                     {
                         formats.Add(format);
                         //logger.info("Loaded IChemFormat: " + format.GetType().FullName);
                     }
                 }
                 //UPGRADE_NOTE: Exception 'java.lang.ClassNotFoundException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"
                 catch (System.Exception exception)
                 {
                     //logger.error("Could not find this IResourceFormat: ", formatName);
                     //logger.debug(exception);
                 }
                 //catch (System.Exception exception)
                 //{
                 //    //logger.error("Could not load this IResourceFormat: ", formatName);
                 //    //logger.debug(exception);
                 //}
             }
             //logger.info("Number of loaded formats used in detection: ", formatCount);
         }
         catch (System.Exception exception)
         {
             //logger.error("Could not load this io format list: ", IO_FORMATS_LIST);
             //logger.debug(exception);
         }
     }
 }
Пример #4
0
        private void LoadFormats()
        {
            if (formats == null)
            {
                formats = new List <IChemFormat>();
                try
                {
                    Debug.WriteLine("Starting loading Formats...");
                    var    reader      = new StreamReader(ResourceLoader.GetAsStream(typeof(IResourceFormat).Assembly, IO_FORMATS_LIST));
                    int    formatCount = 0;
                    string formatName;

                    while ((formatName = reader.ReadLine()) != null)
                    {
                        // load them one by one
                        formatCount++;
                        try
                        {
                            var cls = typeof(IResourceFormat).Assembly.GetType(formatName);
                            if (cls != null)
                            {
                                IResourceFormat format = (IResourceFormat)cls.GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>());
                                if (format is IChemFormat)
                                {
                                    formats.Add((IChemFormat)format);
                                    Trace.TraceInformation("Loaded IChemFormat: " + format.GetType().Name);
                                }
                            }
                        }
                        catch (ArgumentException exception)
                        {
                            Trace.TraceError($"Could not find this IResourceFormat: {formatName}");
                            Debug.WriteLine(exception);
                        }
                        catch (IOException exception)
                        {
                            Trace.TraceError($"Could not load this IResourceFormat: {formatName}");
                            Debug.WriteLine(exception);
                        }
                    }
                    Trace.TraceInformation("Number of loaded formats used in detection: ", formatCount);
                }
                catch (Exception exception)
                {
                    Trace.TraceError($"Could not load this io format list: {IO_FORMATS_LIST}");
                    Debug.WriteLine(exception);
                }
            }
        }
Пример #5
0
        private static void ExpectFormat(string filename, IResourceFormat expectedFormat)
        {
            var ins = ResourceLoader.GetAsStream(filename);

            Assert.IsNotNull(ins, $"Cannot find file: {filename}");
            if (expectedFormat is IChemFormatMatcher)
            {
                factory.RegisterFormat((IChemFormatMatcher)expectedFormat);
            }
            ins = new BufferedStream(ins);
            IChemFormat format = factory.GuessFormat(ins);

            Assert.IsNotNull(format);
            Assert.AreEqual(expectedFormat.FormatName, format.FormatName);
        }
Пример #6
0
 private void LoadFormats()
 {
     if (formats == null)
     {
         formats = new List <IChemFormat>();
         try
         {
             Debug.WriteLine("Starting loading Formats...");
             var    reader      = new StreamReader(ResourceLoader.GetAsStream(IO_FORMATS_LIST));
             int    formatCount = 0;
             string formatName;
             while ((formatName = reader.ReadLine()) != null)
             {
                 // load them one by one
                 formatCount++;
                 try
                 {
                     System.Type formatClass       = this.GetType().Assembly.GetType(formatName);
                     var         getinstanceMethod = formatClass.GetProperty("Instance").GetGetMethod();
                     if (getinstanceMethod == null)
                     {
                         Trace.TraceError($"Could not find this IResourceFormat: {formatName}");
                     }
                     else
                     {
                         IResourceFormat format = (IResourceFormat)getinstanceMethod.Invoke(null, null);
                         if (format is IChemFormat)
                         {
                             formats.Add((IChemFormat)format);
                             Trace.TraceInformation("Loaded IChemFormat: " + format.GetType().Name);
                         }
                     }
                 }
                 catch (Exception exception)
                 {
                     Trace.TraceError($"Could not load this IResourceFormat: {formatName}");
                     Debug.WriteLine(exception);
                 }
             }
             Trace.TraceInformation("Number of loaded formats used in detection: ", formatCount);
         }
         catch (Exception exception)
         {
             Trace.TraceError($"Could not load this io format list: {IO_FORMATS_LIST}");
             Debug.WriteLine(exception);
         }
     }
 }
Пример #7
0
        internal void ExpectReader(string filename, IResourceFormat expectedFormat, int expectedAtomCount, int expectedBondCount)
        {
            var ins = ResourceLoader.GetAsStream(filename);

            Assert.IsNotNull(ins, "Cannot find file: " + filename);
            if (expectedFormat is IChemFormatMatcher)
            {
                factory.RegisterFormat((IChemFormatMatcher)expectedFormat);
            }
            ISimpleChemObjectReader reader = factory.CreateReader(ins);

            Assert.IsNotNull(reader);
            Assert.AreEqual(((IChemFormat)expectedFormat).ReaderClassName, reader.GetType().FullName);
            // now try reading something from it
            IChemObject[] objects = { new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction() };
            bool          read    = false;

            for (int i = 0; (i < objects.Length && !read); i++)
            {
                if (reader.Accepts(objects[i].GetType()))
                {
                    IChemObject chemObject = reader.Read(objects[i]);
                    Assert.IsNotNull(chemObject, "Reader accepted a " + objects[i].GetType().Name + " but failed to read it");
                    AssertAtomCount(expectedAtomCount, chemObject);
                    AssertBondCount(expectedBondCount, chemObject);
                    read = true;
                }
            }
            if (read)
            {
                // ok, reseting worked
            }
            else
            {
                Assert.Fail("Reading an IChemObject from the Reader did not work properly.");
            }
        }
Пример #8
0
        public virtual void TestGetFormat()
        {
            IResourceFormat format = ChemObjectIOToTest.Format;

            Assert.IsNotNull(format, "The IChemObjectIO.Format method returned null.");
        }
Пример #9
0
 public void SetResourceFormat(IResourceFormat format)
 {
     this.resourceFormat = format;
 }
Пример #10
0
        public void TestEquals_null()
        {
            IResourceFormat a = (IResourceFormat)resourceFormat.GetType().GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>());

            Assert.IsNotNull(a);
        }