Exemplo n.º 1
0
        public Word Visit(Graph graph)
        {
            var result = graph.FileName.Accept(this);

            if (IsError(result))
            {
                return(ErrorFactory.GraphError(graph.FileName, "FileName", result));
            }
            PyObj pyObjFileName;

            if (IsMemoryBlock(result))//comentar ese if else si se hace la desereferencia en atomic expr.
            {
                pyObjFileName = ((MemoryBlock)result).Value;
            }
            else
            {
                pyObjFileName = (PyObj)result;
            }
            if (pyObjFileName.GetMyType() != TypeConstants.STRING)
            {
                return(ErrorFactory.GraphError(graph.DotSource, "FileName", result));
            }

            result = graph.DotSource.Accept(this);
            if (IsError(result))
            {
                return(ErrorFactory.GraphError(graph.DotSource, "DotSource", result));
            }
            PyObj pyObjDotSource;

            if (IsMemoryBlock(result))//comentar ese if else si se hace la desereferencia en atomic expr.
            {
                pyObjDotSource = ((MemoryBlock)result).Value;
            }
            else
            {
                pyObjDotSource = (PyObj)result;
            }
            if (pyObjDotSource.GetMyType() != TypeConstants.STRING)
            {
                return(ErrorFactory.GraphError(graph.DotSource, "DotSource", result));
            }

            //Chapuz hacer un nuevo my string con el pyusac type porque graph solo recibe mystrings
            var path = ((MyString)pyObjFileName).StringValue;

            if (path.Length < 1)
            {
                return(ErrorFactory.PathNotValid(graph.FileName, path));
            }
            if ((path[0] != Path.DirectorySeparatorChar) || (path[0] != 'C' && path[0] != 'D' && path[1] != ':'))//tiene que agregar al path la ruta del archivo con el que este nodo fue creado
            {
                path = graph.NodePath.GetParentPath() + Path.DirectorySeparatorChar + PyPath.ReplaceSepartors(path);
            }

            var pyPath = new PyPath(path);

            if (!Directory.Exists(pyPath.GetParentPath()))
            {
                return(ErrorFactory.PathNotValid(graph.FileName, pyPath.GetParentPath()));
            }

            var myStringPath      = new MyString(path);
            var myStringDotSource = (MyString)pyObjDotSource;

            var environmentGraphResult = RuntimeEnvironment.Console.Instance.Graph(myStringPath, myStringDotSource);

            if (environmentGraphResult != null)
            {
                return(ErrorFactory.DotError(graph.DotSource, environmentGraphResult));
            }
            return(null);
        }