Beispiel #1
1
        public PythonSingleLayer(PythonScriptHost host, string code, string name)
        {
            Name = name;
            Code = code;
            Host = host;

            string[] codeWithoutWhitespace = code.Split(new char[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            string alltokens = "";

            foreach (string token in codeWithoutWhitespace)
            {
                alltokens += token;
            }

            _id = alltokens.GetHashCode().ToString();

            _scope = host.CreateScriptSource(code, name);

            if (_scope.ContainsVariable(_processannotations))
            {
                _processAnnotationsFunc = _scope.GetVariable(_processannotations);
            }

            if (_scope.ContainsVariable(_interpret))
            {
                _interpretFunc = _scope.GetVariable(_interpret);
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method needs updating.
        /// The assembly needs to be loaded without locking the file,
        /// there's an appropriate solution to this, but I'm just hacking it for now.
        /// See this thread.
        /// http://stackoverflow.com/questions/1031431/system-reflection-assembly-loadfile-locks-file
        /// </summary>
        /// <param name="dirs"></param>
        /// <param name="seeds"></param>
        /// <param name="seedDirs"></param>
        private static void GetSeedLayersHelper(IEnumerable <string> dirs, IEnumerable <LayerInfo> infos,
                                                PythonScriptHost pythonhost,
                                                List <LayerSeed> seeds, Dictionary <Layer, string> seedDirs = null)
        {
            foreach (string dir in dirs)
            {
                string[] files = Directory.GetFiles(dir, "*.dll");
                GetDllLayers(files, seeds, dir);



                var pyinfos     = infos.Where(i => i.Directory.Equals(dir) && i.Name.Contains(".py"));
                var pythonfiles = new List <string>();
                foreach (var info in pyinfos)
                {
                    pythonfiles.Add(info.Directory + "/" + info.Name);
                }
                GetPythonLayers(pythonfiles, seeds, pythonhost);

                if (seedDirs != null)
                {
                    foreach (LayerSeed seed in seeds)
                    {
                        seedDirs[seed.Seed] = dir;
                    }
                }
            }
        }
Beispiel #3
0
        public PythonLayer(PythonScriptHost host, string code, string name)
        {
            Name = name;
            Code = code;
            Host = host;

            string[] codeWithoutWhitespace = code.Split(new char[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            string   alltokens             = "";

            foreach (string token in codeWithoutWhitespace)
            {
                alltokens += token;
            }

            _id = alltokens.GetHashCode().ToString();

            _scope = host.CreateScriptSource(code, name);

            _annotionArgs = new PythonAnnotatedNodeArgs();

            if (_scope.ContainsVariable(_processannotations))
            {
                _processAnnotationsFunc = _scope.GetVariable(_processannotations);
            }

            if (_scope.ContainsVariable(_interpret))
            {
                _interpretFunc = _scope.GetVariable(_interpret);
            }

            //if (_scope.ContainsVariable(_annotationlibs))
            //{
            //    _getAnnotationLibsFunc = _scope.GetVariable(_annotationlibs);
            //}

            if (_scope.ContainsVariable(_afterinterpret))
            {
                _afterInterpretFunc = _scope.GetVariable(_afterinterpret);
            }

            //if (_scope.ContainsVariable(_init))
            //{
            //    _initFunc = _scope.GetVariable(_init);
            //}
        }
Beispiel #4
0
        private static void GetPythonLayers(IEnumerable <string> files, List <LayerSeed> seeds, PythonScriptHost host)
        {
            foreach (string file in files)
            {
                string name = System.IO.Path.GetFileName(file);
                string path = System.IO.Path.GetFullPath(file);
                path = System.IO.Path.GetDirectoryName(path);
                host.AddPath(path);

                PythonLayer layer = new PythonLayer(host, File.ReadAllText(file), name);
                seeds.Add(new LayerSeed(layer, file));
            }
        }
Beispiel #5
0
        private static List <LayerSeed> GetSeedLayers(IEnumerable <LayerInfo> layerinfos, PythonScriptHost pythonhost)
        {
            var seeds = new List <LayerSeed>();
            var dirs  = new List <string>();

            foreach (LayerInfo linfo in layerinfos)
            {
                if (linfo.Directory != null && !dirs.Contains(linfo.Directory))
                {
                    dirs.Add(linfo.Directory);
                }
            }



            GetSeedLayersHelper(dirs, layerinfos, pythonhost, seeds);

            return(seeds);
        }
Beispiel #6
0
 private static void GetPythonLayers(IEnumerable<string> files, List<LayerSeed> seeds, PythonScriptHost host)
 {
     foreach (string file in files)
     {
         string name = System.IO.Path.GetFileName(file);
         string path = System.IO.Path.GetFullPath(file);
         path = System.IO.Path.GetDirectoryName(path);
         host.AddPath(path);
         
         PythonLayer layer = new PythonLayer(host, File.ReadAllText(file), name);
         seeds.Add(new LayerSeed(layer, file));
     }
 }
Beispiel #7
0
        /// <summary>
        /// This method needs updating. 
        /// The assembly needs to be loaded without locking the file,
        /// there's an appropriate solution to this, but I'm just hacking it for now.
        /// See this thread.
        /// http://stackoverflow.com/questions/1031431/system-reflection-assembly-loadfile-locks-file
        /// </summary>
        /// <param name="dirs"></param>
        /// <param name="seeds"></param>
        /// <param name="seedDirs"></param>
		private static void GetSeedLayersHelper(IEnumerable<string> dirs, IEnumerable<LayerInfo> infos, 
            PythonScriptHost pythonhost,
            List<LayerSeed> seeds, Dictionary<Layer, string> seedDirs = null){

            
            foreach (string dir in dirs)
            {
                string[] files = Directory.GetFiles(dir, "*.dll");
                GetDllLayers(files, seeds, dir);


               
                var pyinfos = infos.Where(i => i.Directory.Equals(dir) && i.Name.Contains(".py"));
                var pythonfiles = new List<string>();
                foreach (var info in pyinfos)
                {
                    pythonfiles.Add(info.Directory + "/" + info.Name);
                }
                GetPythonLayers(pythonfiles, seeds, pythonhost);

                if (seedDirs != null)
                {
                    foreach (LayerSeed seed in seeds)
                        seedDirs[seed.Seed] = dir;
                }
            }
		}
Beispiel #8
0
		private static List<LayerSeed> GetSeedLayers(IEnumerable<LayerInfo> layerinfos, PythonScriptHost pythonhost){
            var seeds = new List<LayerSeed>();
            var dirs = new List<string>();
            foreach (LayerInfo linfo in layerinfos)
            {
                if (linfo.Directory != null && !dirs.Contains(linfo.Directory))
                    dirs.Add(linfo.Directory);
            }

            



			GetSeedLayersHelper (dirs, layerinfos, pythonhost, seeds);

			return seeds;
		}