Exemplo n.º 1
0
        internal static KernelMethodInfo Deserialize(XElement xe, CudafyModule parentModule, string directory = null)
        {
            string methodName = xe.GetAttributeValue(csNAME);
            string methodTypeName = xe.GetAttributeValue(csTYPE);
            eKernelMethodType methodType = (eKernelMethodType)Enum.Parse(typeof(eKernelMethodType), methodTypeName);
            bool? isDummy = xe.TryGetAttributeBoolValue(csISDUMMY);
            string behaviourStr = xe.TryGetAttributeValue(csDUMMYBEHAVIOUR);  
            string typeName = xe.Element(csTYPE).Value;
            string assemblyFullName = xe.Element(csASSEMBLY).Value;
            string assemblyName = xe.Element(csASSEMBLYNAME).Value;
            string assemblyPath = xe.TryGetElementValue(csASSEMBLYPATH);
            long checksum = XmlConvert.ToInt64(xe.Element(csCHECKSUM).Value);
            eCudafyDummyBehaviour behaviour = string.IsNullOrEmpty(behaviourStr) ? eCudafyDummyBehaviour.Default : (eCudafyDummyBehaviour)Enum.Parse(typeof(eCudafyDummyBehaviour), behaviourStr);
            MethodInfo mi = null;
            KernelMethodInfo kmi = null;

            if(!string.IsNullOrEmpty(typeName) && !string.IsNullOrEmpty(assemblyFullName))
            {
                Assembly assembly = null;
                try
                {
                    assembly = Assembly.Load(assemblyFullName);
                }
                catch (FileNotFoundException)
                {
                    directory = directory != null ? directory : string.Empty;
                    assemblyName = directory + Path.DirectorySeparatorChar + assemblyName;
                    if (File.Exists(assemblyName + ".dll"))
                    {
                        assembly = Assembly.LoadFrom(assemblyName + ".dll");
                    }
                    else if (File.Exists(assemblyName + ".exe"))
                    {
                        assembly = Assembly.LoadFrom(assemblyName + ".exe");
                    }
                    else if (!string.IsNullOrEmpty(assemblyPath))
                    {
                        assembly = Assembly.LoadFrom(assemblyPath);
                    }
                    else
                        throw;
                }
                if (assembly == null)
                    throw new CudafyException(CudafyException.csCOULD_NOT_LOAD_ASSEMBLY_X, assemblyFullName);
                Type type = assembly.GetType(typeName);
                if (type == null)
                    throw new CudafyException(CudafyException.csCOULD_NOT_FIND_TYPE_X_IN_ASSEMBLY_X, typeName, assemblyFullName);
                mi = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                if (mi == null)
                    throw new CudafyException(CudafyException.csCOULD_NOT_FIND_METHOD_X_IN_TYPE_X_IN_ASSEMBLY_X, methodName, typeName, assemblyFullName);
                kmi = new KernelMethodInfo(type, mi, methodType, isDummy == true ? true : false, behaviour, parentModule);                
            }
            kmi.DeserializedChecksum = checksum;
            return kmi;
        }
Exemplo n.º 2
0
        internal static KernelMethodInfo Deserialize(XElement xe, CudafyModule parentModule, string directory = null)
        {
            string            methodName     = xe.GetAttributeValue(csNAME);
            string            methodTypeName = xe.GetAttributeValue(csTYPE);
            eKernelMethodType methodType     = (eKernelMethodType)Enum.Parse(typeof(eKernelMethodType), methodTypeName);
            bool?  isDummy                  = xe.TryGetAttributeBoolValue(csISDUMMY);
            string behaviourStr             = xe.TryGetAttributeValue(csDUMMYBEHAVIOUR);
            string typeName                 = xe.Element(csTYPE).Value;
            string assemblyFullName         = xe.Element(csASSEMBLY).Value;
            string assemblyName             = xe.Element(csASSEMBLYNAME).Value;
            string assemblyPath             = xe.TryGetElementValue(csASSEMBLYPATH);
            long   checksum                 = XmlConvert.ToInt64(xe.Element(csCHECKSUM).Value);
            eCudafyDummyBehaviour behaviour = string.IsNullOrEmpty(behaviourStr) ? eCudafyDummyBehaviour.Default : (eCudafyDummyBehaviour)Enum.Parse(typeof(eCudafyDummyBehaviour), behaviourStr);
            MethodInfo            mi        = null;
            KernelMethodInfo      kmi       = null;

            if (!string.IsNullOrEmpty(typeName) && !string.IsNullOrEmpty(assemblyFullName))
            {
                Assembly assembly = null;
                try
                {
                    assembly = Assembly.Load(assemblyFullName);
                }
                catch (FileNotFoundException)
                {
                    directory    = directory != null ? directory : string.Empty;
                    assemblyName = directory + Path.DirectorySeparatorChar + assemblyName;
                    if (File.Exists(assemblyName + ".dll"))
                    {
                        assembly = Assembly.LoadFrom(assemblyName + ".dll");
                    }
                    else if (File.Exists(assemblyName + ".exe"))
                    {
                        assembly = Assembly.LoadFrom(assemblyName + ".exe");
                    }
                    else if (!string.IsNullOrEmpty(assemblyPath))
                    {
                        assembly = Assembly.LoadFrom(assemblyPath);
                    }
                    else
                    {
                        throw;
                    }
                }
                if (assembly == null)
                {
                    throw new CudafyException(CudafyException.csCOULD_NOT_LOAD_ASSEMBLY_X, assemblyFullName);
                }
                Type type = assembly.GetType(typeName);
                if (type == null)
                {
                    throw new CudafyException(CudafyException.csCOULD_NOT_FIND_TYPE_X_IN_ASSEMBLY_X, typeName, assemblyFullName);
                }
                mi = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                if (mi == null)
                {
                    throw new CudafyException(CudafyException.csCOULD_NOT_FIND_METHOD_X_IN_TYPE_X_IN_ASSEMBLY_X, methodName, typeName, assemblyFullName);
                }
                kmi = new KernelMethodInfo(type, mi, methodType, isDummy == true ? true : false, behaviour, parentModule);
            }
            kmi.DeserializedChecksum = checksum;
            return(kmi);
        }
Exemplo n.º 3
0
 private string GetSpecific(KernelMethodInfo kmi)
 {
     StringBuilder sb = new StringBuilder();
     if (kmi != null)
     {
         sb.AppendLine("Parameters            : " + kmi.GetParametersString());
     }
     return sb.ToString();
 }