示例#1
1
        // TODO: hack
        public RubyIO(RubyContext/*!*/ context, StreamReader reader, StreamWriter writer, string/*!*/ modeString)
            : this(context) {
            _mode = ParseIOMode(modeString, out _preserveEndOfLines);
            _stream = new DuplexStream(reader, writer);

            ResetLineNumbersForReadOnlyFiles(context);
        }
示例#2
0
 /// <summary>
 /// 注册所需监视的Socket对象
 /// </summary>
 /// <param name="mode">需要监视的事件</param>
 /// <param name="sock">需要监视的Socket</param>
 /// <param name="func">监视的Socket发生监视的事件时的回调方法</param>
 public static void Register(IOMode mode, Socket sock, Action <Socket, IOMode> func)
 {
     if ((mode & IOMode.recv) > 0)
     {
         if (!RecvList.Contains(sock.Handle))
         {
             RecvList.Add(sock.Handle, sock);
         }
     }
     if ((mode & IOMode.send) > 0)
     {
         if (!SendList.Contains(sock.Handle))
         {
             SendList.Add(sock.Handle, sock);
         }
     }
     if ((mode & IOMode.error) > 0)
     {
         if (!ErrorList.Contains(sock.Handle))
         {
             ErrorList.Add(sock.Handle, sock);
         }
     }
     try
     {
         EventCallback.Add(sock, func);
     }
     catch
     {
         EventCallback[sock] = func;
     }
 }
示例#3
0
        public static StringIO /*!*/ Create(RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ initialString,
                                            [DefaultProtocol, Optional, NotNull] MutableString mode)
        {
            IOMode ioMode = IOModeEnum.Parse(mode, initialString.IsFrozen ? IOMode.ReadOnly : IOMode.ReadWrite) | IOMode.PreserveEndOfLines;

            return(new StringIO(CheckContent(initialString, ioMode), ioMode));
        }
 /// <summary>
 /// Constructor for a parameter
 /// </summary>
 /// <param name="mode"></param>
 /// <param name="variableType"></param>
 public Parameter(string name,IOMode mode, VariableType variableType,int size)
 {
     this.mode = mode;
     this.variableType = variableType;
     this.name = name;
     this.size = size;
 }
示例#5
0
文件: IoOps.cs 项目: ltwlf/IronSP
        public static RubyIO /*!*/ OpenPipe(
            RubyContext /*!*/ context,
            MutableString /*!*/ command,
            IOMode mode)
        {
            bool redirectStandardInput  = mode.CanWrite();
            bool redirectStandardOutput = mode.CanRead();

            Process process = RubyProcess.CreateProcess(context, command, redirectStandardInput, redirectStandardOutput, false);

            StreamReader reader = null;
            StreamWriter writer = null;

            if (redirectStandardOutput)
            {
                reader = process.StandardOutput;
            }

            if (redirectStandardInput)
            {
                writer = process.StandardInput;
            }

            return(new RubyIO(context, reader, writer, mode));
        }
示例#6
0
文件: IO.cs 项目: gaybro8777/ironruby
        // TODO: hack
        public RubyIO(RubyContext /*!*/ context, StreamReader reader, StreamWriter writer, string /*!*/ modeString)
            : this(context) {
            _mode   = ParseIOMode(modeString, out _preserveEndOfLines);
            _stream = new DuplexStream(reader, writer);

            ResetLineNumbersForReadOnlyFiles(context);
        }
示例#7
0
        public static StringIO /*!*/ Reopen(StringIO /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ content, int mode)
        {
            IOMode ioMode = (IOMode)mode | IOMode.PreserveEndOfLines;

            self.SetContent(CheckContent(content, ioMode));
            self._mode = ioMode;
            return(self);
        }
示例#8
0
 public RubyIO(RubyContext /*!*/ context, Stream /*!*/ stream, int descriptor, IOMode mode)
     : this(context) {
     ContractUtils.RequiresNotNull(context, "context");
     ContractUtils.RequiresNotNull(stream, "stream");
     SetStream(stream);
     _mode           = mode;
     _fileDescriptor = descriptor;
 }
 public DbContextOption(IOMode mode, RepositoryType type, string connectionStringName = "", IDbContext context = null, Type dbContextType = null)
 {
     this.ConnectionStringName = connectionStringName;
     this.DbContext            = context;
     this.IOMode         = mode;
     this.RepositoryType = type;
     this.DbContextType  = dbContextType;
 }
示例#10
0
        public static Stream/*!*/ OpenFileStream(RubyContext/*!*/ context, string/*!*/ path, IOMode mode) {
            ContractUtils.RequiresNotNull(path, "path");
            FileAccess access = mode.ToFileAccess();

            FileMode fileMode;
  
            if ((mode & IOMode.CreateIfNotExists) != 0) {
                if ((mode & IOMode.ErrorIfExists) != 0) {
                    access |= FileAccess.Write;
                    fileMode = FileMode.CreateNew;
                } else {
                    fileMode = FileMode.OpenOrCreate;
                }
            } else {
                fileMode = FileMode.Open;
            }

            if ((mode & IOMode.Truncate) != 0 && (access & FileAccess.Write) == 0) {
                throw RubyExceptions.CreateEINVAL("cannot truncate a file opened for reading only");
            }

            if ((mode & IOMode.WriteAppends) != 0 && (access & FileAccess.Write) == 0) {
                throw RubyExceptions.CreateEINVAL("cannot append to a file opened for reading only");
            }

            if (String.IsNullOrEmpty(path)) {
                throw RubyExceptions.CreateEINVAL();
            }

            Stream stream;
            if (path == "NUL") {
                stream = Stream.Null;
            } else {
                try {
                    stream = context.DomainManager.Platform.OpenInputFileStream(path, fileMode, access, FileShare.ReadWrite);
                } catch (FileNotFoundException) {
                    throw RubyExceptions.CreateENOENT(String.Format("No such file or directory - {0}", path));
                } catch (DirectoryNotFoundException e) {
                    throw RubyExceptions.CreateENOENT(e.Message, e);
                } catch (PathTooLongException e) {
                    throw RubyExceptions.CreateENOENT(e.Message, e);
                } catch (IOException) {
                    if ((mode & IOMode.ErrorIfExists) != 0) {
                        throw RubyExceptions.CreateEEXIST(path);
                    } else {
                        throw;
                    }
                } catch (ArgumentException e) {
                    throw RubyExceptions.CreateEINVAL(e.Message, e);
                }
            }

            if ((mode & IOMode.Truncate) != 0) {
                stream.SetLength(0);
            }

            return stream;
        }
示例#11
0
        /// <summary>
        /// Gets the <see cref="IOMode"/> corresponding to the provided mode Id and IO line.
        /// </summary>
        /// <param name="dumb"></param>
        /// <param name="modeID">The ID of the <see cref="IOMode"/> to retrieve.</param>
        /// <param name="ioline">The IO line to retrieve its <see cref="IOMode"/></param>
        /// <returns>The <see cref="IOMode"/> corresponding to the provided mode ID and IO line.</returns>
        public static IOMode GetIOMode(this IOMode dumb, int modeID, IOLine ioline)
        {
            if (modeID == lookupTable[IOMode.ADC].Id)
            {
                return(ioline != IOLine.UNKNOWN && ioline.HasPWMCapability() ? IOMode.PWM : IOMode.ADC);
            }

            return(lookupTable.Where(io => io.Value.Id == modeID).Select(io => io.Key).FirstOrDefault());
        }
示例#12
0
        public static StringIO /*!*/ Reopen(StringIO /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ content,
                                            [DefaultProtocol, NotNull] MutableString mode)
        {
            IOMode ioMode = IOModeEnum.Parse(mode, content.IsFrozen ? IOMode.ReadOnly : IOMode.ReadWrite) | IOMode.PreserveEndOfLines;

            self.SetContent(CheckContent(content, ioMode));
            self._mode = ioMode;
            return(self);
        }
示例#13
0
文件: IO.cs 项目: gaybro8777/ironruby
        public RubyIO(RubyContext /*!*/ context, Stream /*!*/ stream, RubyFileMode mode)
            : this(context) {
            ContractUtils.RequiresNotNull(stream, "stream");

            _mode   = ParseIOMode(mode, out _preserveEndOfLines);
            _stream = stream;

            ResetLineNumbersForReadOnlyFiles(context);
        }
示例#14
0
文件: RubyIO.cs 项目: TerabyteX/main
 public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, int descriptor, IOMode mode)
     : this(context)
 {
     ContractUtils.RequiresNotNull(context, "context");
     ContractUtils.RequiresNotNull(stream, "stream");
     SetStream(stream);
     _mode = mode;
     _fileDescriptor = descriptor;
 }
示例#15
0
        private static MutableString/*!*/ CheckContent(MutableString/*!*/ content, IOMode mode) {
            if (content.IsFrozen && mode.CanWrite()) {
                throw Errno.CreateEACCES("Permission denied");
            }

            if ((mode & IOMode.Truncate) != 0) {
                content.Clear();
            }
            return content;
        }
示例#16
0
        public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, string/*!*/ modeString)
            : this(context) {
            ContractUtils.RequiresNotNull(stream, "stream");
            ContractUtils.RequiresNotNull(modeString, "modeString");

            _mode = ParseIOMode(modeString, out _preserveEndOfLines);
            _stream = stream;

            ResetLineNumbersForReadOnlyFiles(context);
        }
示例#17
0
 // Constructor
 public IOElements(object element, IOMode ioMode, int currentIndex, string title, params object[] args)
 {
     this.element      = element;
     this.ioMode       = ioMode;
     this.currentIndex = currentIndex;
     this.Text         = title;
     this.args         = args;
     this.TopLevel     = true;
     //
     InitializeComponent();
 }
示例#18
0
        private static MutableString /*!*/ CheckContent(MutableString /*!*/ content, IOMode mode)
        {
            if (content.IsFrozen && mode.CanWrite())
            {
                throw Errno.CreateEACCES("Permission denied");
            }

            if ((mode & IOMode.Truncate) != 0)
            {
                content.Clear();
            }
            return(content);
        }
示例#19
0
        public void Close()
        {
            int fd = _fileDescriptor;

            _mode           = _mode.Close();
            _fileDescriptor = -1;

            if (_stream != null)
            {
                _stream = null;
                _context.CloseStream(fd);
            }
        }
示例#20
0
        public static FileAccess ToFileAccess(this IOMode mode)
        {
            switch (mode & IOMode.ReadWriteMask)
            {
            case IOMode.WriteOnly: return(FileAccess.Write);

            case IOMode.ReadOnly: return(FileAccess.Read);

            case IOMode.ReadWrite: return(FileAccess.ReadWrite);

            default: throw RubyExceptions.CreateEINVAL("illegal access mode {0}", mode);
            }
        }
示例#21
0
        public static Direction ToDirection(this IOMode io)
        {
            switch (io)
            {
            case IOMode.Read:
                return(Direction.In);

            case IOMode.Write:
                return(Direction.Out);

            default:
                throw new InvalidEnumArgumentException(nameof(io));
            }
        }
示例#22
0
        public static IOMode Parse(string mode)
        {
            IOMode result = IOMode.Default;

            if (String.IsNullOrEmpty(mode))
            {
                return(result);
            }

            int i = mode.Length - 1;

            bool plus = (mode[i] == '+');

            if (plus)
            {
                i--;
            }

            if (i < 0)
            {
                throw IllegalMode(mode);
            }

            if (mode[i] == 'b')
            {
                result |= IOMode.PreserveEndOfLines;
                i--;
            }

            if (i != 0)
            {
                throw IllegalMode(mode);
            }

            switch (mode[0])
            {
            case 'r':
                return(result | (plus ? IOMode.ReadWrite : IOMode.ReadOnly));

            case 'w':
                return(result | (plus ? IOMode.ReadWrite : IOMode.WriteOnly) | IOMode.Truncate | IOMode.CreateIfNotExists);

            case 'a':
                return(result | (plus ? IOMode.ReadWrite : IOMode.WriteOnly) | IOMode.WriteAppends | IOMode.CreateIfNotExists);

            default:
                throw IllegalMode(mode);
            }
        }
示例#23
0
        public static RubyIO /*!*/ OpenPipe(RubyContext /*!*/ context, RubyClass /*!*/ self,
                                            [DefaultProtocol, NotNull] MutableString /*!*/ command, [DefaultProtocol, Optional, NotNull] MutableString modeString)
        {
            bool   preserveEndOfLines;
            IOMode mode = RubyIO.ParseIOMode(modeString.ConvertToString(), out preserveEndOfLines);

            ProcessStartInfo startInfo = KernelOps.GetShell(context, command);

            startInfo.UseShellExecute = false;

            if (mode == IOMode.ReadOnlyFromStart)
            {
                startInfo.RedirectStandardOutput = true;
            }
            else if (mode == IOMode.WriteOnlyAppend || mode == IOMode.WriteOnlyTruncate)
            {
                startInfo.RedirectStandardInput = true;
            }
            else
            {
                startInfo.RedirectStandardOutput = true;
                startInfo.RedirectStandardInput  = true;
            }

            Process process;

            try {
                process = Process.Start(startInfo);
            } catch (Exception e) {
                throw new Errno.NoEntryError(startInfo.FileName, e);
            }

            context.ChildProcessExitStatus = new RubyProcess.Status(process);

            StreamReader reader = null;
            StreamWriter writer = null;

            if (startInfo.RedirectStandardOutput)
            {
                reader = process.StandardOutput;
            }

            if (startInfo.RedirectStandardInput)
            {
                writer = process.StandardInput;
            }

            return(new RubyIO(context, reader, writer, modeString.ConvertToString()));
        }
示例#24
0
 //Analog Input
 public void AssignAxis(A3200HC a3200, IAnalogInput iAnalogInput)
 {
     _a3200        = a3200;
     _iAnalogInput = iAnalogInput;
     _ioMode       = IOMode.AnalogInput;
     if (_a3200 != null)
     {
         try
         {
             _analogValue = _a3200.GetRawValue(iAnalogInput).ToString();
         }
         catch (Exception ex)
         { }
     }
 }
示例#25
0
        public void CanSetIOMode(IOMode io, PinMode expected)
        {
            //arrange
            var gpio = Substitute.For <IGpioController>();

            //act
            var pinInterface = new SystemPinInterface(123, gpio)
            {
                Enabled = true,
                IOMode  = io
            };

            //assert
            gpio.Received().SetPinMode(123, expected);
        }
示例#26
0
        public void CanGetIOMode(string value, IOMode expected)
        {
            //arrange
            var fs = Substitute.For <IFileSystem>();

            fs.Read("/sys/class/gpio/gpio123/direction").Returns(value);

            var pinInterface = new LinuxPinInterface(123, fs);

            //act
            var io = pinInterface.IOMode;

            //assert
            Assert.Equal(expected, io);
        }
    public void CanGetIOMode(PinMode value, IOMode expected)
    {
        //arrange
        var gpio = Substitute.For <IGpioController>();

        gpio.GetPinMode(123).Returns(value);
        var pwm          = Substitute.For <IPwmChannel>();
        var pinInterface = new SystemPinInterface(123, gpio, pwm);

        //act
        var io = pinInterface.IOMode;

        //assert
        Assert.Equal(expected, io);
    }
示例#28
0
        public void CanSetIOMode(IOMode io, string expected)
        {
            //arrange
            var fs = Substitute.For <IFileSystem>();

            //act
            var pinInterface = new LinuxPinInterface(123, fs)
            {
                Enabled = true,
                IOMode  = io
            };

            //assert
            fs.Received().Write("/sys/class/gpio/gpio123/direction", expected);
        }
示例#29
0
        internal RubyInputProvider(RubyContext/*!*/ context, ICollection<string>/*!*/ arguments, RubyEncoding/*!*/ encoding) {
            Assert.NotNull(context, encoding);
            Assert.NotNullItems(arguments);
            _context = context;

            var args = new RubyArray();
            foreach (var arg in arguments) {
                ExpandArgument(args, arg, encoding);
            }

            _commandLineArguments = args;
            _lastInputLineNumber = 1;
            _currentFileIndex = -1;
            _singleton = new object();
            _defaultMode = IOMode.ReadOnly;
        }
    public void CanSetIOMode(IOMode io, PinMode expected)
    {
        //arrange
        var gpio = Substitute.For <IGpioController>();
        var pwm  = Substitute.For <IPwmChannel>();

        //act
        var pinInterface = new SystemPinInterface(123, gpio, pwm)
        {
            Enabled = true,
            IOMode  = io
        };

        //assert
        Assert.NotNull(pinInterface);
        gpio.Received().SetPinMode(123, expected);
    }
示例#31
0
        /// <summary>
        /// Configures the IO pin according to IO mode value.
        /// </summary>
        /// <param name="pin">The output pin to be set or reset.</param>
        /// <param name="mode">The IO pin mode to configure.</param>
        public void IOConfig(IOPins pin, IOMode mode)
        {
            switch (mode)
            {
            case IOMode.Input:
                InitializePin(pin, IODirection.In);
                break;

            case IOMode.Output:
                InitializePin(pin, IODirection.Out);
                break;

            case IOMode.InterruptRisingEdge:
                EnableGlobalInterrupt();
                //EnablePinInterrupt(pin);
                InitializePin(pin, IODirection.In);
                //IOSetEdgeMode(pin, Edge.Rising);
                break;

            case IOMode.InterruptFallingEdge:
                EnableGlobalInterrupt();
                //EnablePinInterrupt(pin);
                InitializePin(pin, IODirection.In);
                //IOSetEdgeMode(pin, Edge.Falling);
                break;

            case IOMode.InterruptLowLevel:
                EnableGlobalInterrupt();
                //EnablePinInterrupt(pin);
                InitializePin(pin, IODirection.In);
                SetInterruptType(InterruptType.Level);
                SetInterruptPolarity(InterruptPolarity.Low);
                break;

            case IOMode.InterruptHighLevel:
                EnableGlobalInterrupt();
                //EnablePinInterrupt(pin);
                InitializePin(pin, IODirection.In);
                SetInterruptType(InterruptType.Level);
                SetInterruptPolarity(InterruptPolarity.High);
                break;

            default:
                throw new ArgumentException();
            }
        }
示例#32
0
            //Input
            public void AssignAxis(A3200HC a3200, int card, int bit)
            {
                _a3200  = a3200;
                _card   = card;
                _bit    = bit;
                _ioMode = IOMode.Input;
                IDigitalInput digitalInput = HSTMachine.Workcell._ioManifest.GetDigitalInput(_bit + (_card * 8));

                if (_a3200 != null)
                {
                    try
                    {
                        _iostate = _a3200.GetState(digitalInput) == DigitalIOState.On ? true : false;
                    }
                    catch (Exception ex)
                    { }
                }
            }
示例#33
0
        internal RubyInputProvider(RubyContext /*!*/ context, ICollection <string> /*!*/ arguments, RubyEncoding /*!*/ encoding)
        {
            Assert.NotNull(context, encoding);
            Assert.NotNullItems(arguments);
            _context = context;

            var args = new RubyArray();

            foreach (var arg in arguments)
            {
                ExpandArgument(args, arg, encoding);
            }

            _commandLineArguments = args;
            _lastInputLineNumber  = 1;
            _currentFileIndex     = -1;
            _singleton            = new object();
            _defaultMode          = IOMode.ReadOnly;
        }
示例#34
0
        public void CloseReader()
        {
            var duplex = GetStream().BaseStream as DuplexStream;

            if (duplex == null && _mode.CanWrite() || duplex != null && !_mode.CanRead())
            {
                throw RubyExceptions.CreateIOError("closing non-duplex IO for reading");
            }

            if (duplex != null)
            {
                duplex.Reader.Close();
            }

            _mode = _mode.CloseRead();
            if (_mode.IsClosed())
            {
                Close();
            }
        }
示例#35
0
        Node CteateIO(ValueType valueType, string name, IOMode mode, out bool createdNewOne)
        {
            createdNewOne = false;
            NodeCollector.NodeInfo info = NodeCollector.IOTypes[(int)valueType];
            if (info == null)
            {
                throw new Exception("Wrong ValueType");
            }
            ValueNode vn;

            if (!TempIONodes.TryGetValue(name, out vn))
            {
                vn            = (ValueNode)CreateNode(info.TypeID);
                vn.ValueName  = name;
                createdNewOne = true;
            }
            else
            {
                TempIONodes.Remove(name);
            }

            vn.IOMode = mode;
            return(vn);
        }
示例#36
0
 public static IOMode Parse(MutableString mode, IOMode defaultMode) {
     return (mode != null) ? IOModeEnum.Parse(mode.ToString()) : defaultMode;
 }
示例#37
0
 public StringIO(MutableString/*!*/ content, IOMode mode) {
     ContractUtils.RequiresNotNull(content, "content");
     _content = content;
     _mode = mode;
 }
示例#38
0
 private void Close() {
     _mode = _mode.Close();
 }
示例#39
0
 public static bool IsReadable(IOMode mode) {
     return (mode == IOMode.ReadOnlyFromStart || 
         mode == IOMode.ReadWriteAppend || 
         mode == IOMode.ReadWriteFromStart || 
         mode == IOMode.ReadWriteTruncate);
 }
示例#40
0
 public AppDbContext(IOMode mode = IOMode.Read, string connectionName = "") : base(new App.Common.Data.MSSQL.MSSQLConnectionString(connectionName), mode)
 {
     Database.SetInitializer <AppDbContext>(new DropCreateDatabaseIfModelChanges <AppDbContext>());
 }
示例#41
0
        public static RubyIO/*!*/ OpenPipe(
            RubyContext/*!*/ context, 
            MutableString/*!*/ command, 
            IOMode mode) {

            bool redirectStandardInput = mode.CanWrite();
            bool redirectStandardOutput = mode.CanRead();

            Process process = RubyProcess.CreateProcess(context, command, redirectStandardInput, redirectStandardOutput, false);

            StreamReader reader = null;
            StreamWriter writer = null;
            if (redirectStandardOutput) {
                reader = process.StandardOutput;
            }

            if (redirectStandardInput) {
                writer = process.StandardInput;
            }

            return new RubyIO(context, reader, writer, mode);
        }
示例#42
0
        public override void Write(bool state)
        {
            Mode = IOMode.Output;

            _port.Write(state);
        }
示例#43
0
 private List<Parameter> BuildParameterList(List<string> identifierList, TypeRecord variableType,
     IOMode ioMode,List<Parameter> parameterList)
 {
     foreach (string name in identifierList)
     {
         parameterList.Add(new Parameter(name,ioMode, variableType.variableType,1));
     }
     return parameterList;
 }
示例#44
0
 public RubyIO(RubyContext/*!*/ context, StreamReader reader, StreamWriter writer, IOMode mode)
     : this(context, new DuplexStream(reader, writer), mode) {
 }
示例#45
0
 public void Reset(Stream/*!*/ stream, IOMode mode) {
     _mode = mode;
     SetStream(stream);
     SetFileDescriptor(Context.AllocateFileDescriptor(stream));
 }
示例#46
0
 public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, IOMode mode) 
     : this(context, stream, context.AllocateFileDescriptor(stream), mode) {
 }
示例#47
0
        public void CloseReader() {
            var duplex = GetStream().BaseStream as DuplexStream;
            if (duplex == null && _mode.CanWrite() || duplex != null && !_mode.CanRead()) {
                throw RubyExceptions.CreateIOError("closing non-duplex IO for reading");
            } 
            
            if (duplex != null) {
                duplex.Reader.Close();
            }

            _mode = _mode.CloseRead();
            if (_mode.IsClosed()) {
                Close();
            }
        }
示例#48
0
        public void Close() {
            int fd = _fileDescriptor;
            _mode = _mode.Close();
            _fileDescriptor = -1;

            if (_stream != null) {
                _stream = null;
                _context.CloseStream(fd);
            }
        }
示例#49
0
 public IOInfo(IOMode mode) 
     : this(mode, null, null) {
 }
示例#50
0
 public RubyFile(RubyContext/*!*/ context, string/*!*/ path, IOMode mode)
     : base(context, OpenFileStream(context, path, mode), mode) {
     _path = path;
 }
示例#51
0
 public IOInfo(IOMode? mode, RubyEncoding externalEncoding, RubyEncoding internalEncoding) {
     _mode = mode;
     _externalEncoding = externalEncoding;
     _internalEncoding = internalEncoding;
 }
示例#52
0
 public RubyFile(RubyContext/*!*/ context, Stream/*!*/ stream, int descriptor, IOMode mode)
     : base(context, stream, descriptor, mode) {
     _path = null;
 }
示例#53
0
    void Show(IOMode mode)
    {
        buttons.Clear();
        active = true;
        gameObject.SetActive(true);
        window.SetActive(true);
        newWorldStack.SetActive(mode == IOMode.Write || mode == IOMode.WriteShipJSON || mode == IOMode.WriteWaveJSON);
        DestroyAllButtons();
        this.mode = mode;
        string[] directories = null;

        readButton.gameObject.SetActive(mode == IOMode.Read || mode == IOMode.Write);

        switch (mode)
        {
        case IOMode.Read:
            readButton.text       = "Read world";
            worldPathName.text    = "If you select a world, its name will appear here.";
            authors.text          = "";
            description.text      = "";
            defaultBlueprint.text = "";
            authors.placeholder.GetComponent <Text>().text          = "World authors appear here";
            description.placeholder.GetComponent <Text>().text      = "World description appears here";
            defaultBlueprint.placeholder.GetComponent <Text>().text = "Default blueprint appears here";
            directories = Directory.GetDirectories(Application.streamingAssetsPath + "\\Sectors");
            break;

        case IOMode.Write:
            readButton.text       = "Write world";
            worldPathName.text    = "If you select a world, its name will appear here.";
            authors.text          = "";
            description.text      = "";
            defaultBlueprint.text = "";
            authors.placeholder.GetComponent <Text>().text          = "Enter world authors here";
            description.placeholder.GetComponent <Text>().text      = "Enter world description here";
            defaultBlueprint.placeholder.GetComponent <Text>().text = "Enter default blueprint here";
            directories = Directory.GetDirectories(Application.streamingAssetsPath + "\\Sectors");
            break;

        case IOMode.ReadShipJSON:
        case IOMode.WriteShipJSON:
            directories = Directory.GetFiles(Application.streamingAssetsPath + "\\EntityPlaceholder");
            break;

        case IOMode.ReadWaveJSON:
        case IOMode.WriteWaveJSON:
            directories = Directory.GetFiles(Application.streamingAssetsPath + "\\WavePlaceholder");
            break;
        }

        foreach (var dir in directories)
        {
            if (!dir.Contains("TestWorld") && !dir.Contains("meta"))
            {
                AddButton(dir, new UnityEngine.Events.UnityAction(() => {
                    switch (mode)
                    {
                    case IOMode.Read:
                    case IOMode.Write:
                        SetWorldIndicators(dir);
                        break;

                    case IOMode.ReadShipJSON:
                        builder.LoadBlueprint(System.IO.File.ReadAllText(dir));
                        Hide();
                        break;

                    case IOMode.WriteShipJSON:
                        ShipBuilder.SaveBlueprint(null, dir, builder.GetCurrentJSON());
                        Hide();
                        break;

                    case IOMode.ReadWaveJSON:
                        waveBuilder.ReadWaves(JsonUtility.FromJson <WaveSet>(System.IO.File.ReadAllText(dir)));
                        Hide();
                        break;

                    case IOMode.WriteWaveJSON:
                        waveBuilder.ParseWaves(dir);
                        Hide();
                        break;
                    }
                }));
            }
        }
    }
		/**
		 * Sets the configuration of the given IO line of this XBee device.
		 * 
		 * @param ioLine The IO line to configure.
		 * @param ioMode The IO mode to set to the IO line.
		 * 
		 * @throws InterfaceNotOpenException if this device connection is not open.
		 * @throws ArgumentNullException if {@code ioLine == null} or
		 *                              if {@code ioMode == null}.
		 * @throws TimeoutException if there is a timeout sending the set 
		 *                          configuration command.
		 * @throws XBeeException if there is any other XBee related exception.
		 * 
		 * @see #getIOConfiguration(IOLine)
		 * @see com.digi.xbee.api.io.IOLine
		 * @see com.digi.xbee.api.io.IOMode
		 */
		public void setIOConfiguration(IOLine ioLine, IOMode ioMode)/*throws TimeoutException, XBeeException */{
			// Check IO line.
			if (ioLine == null)
				throw new ArgumentNullException("IO line cannot be null.");
			if (ioMode == null)
				throw new ArgumentNullException("IO mode cannot be null.");
			// Check connection.
			if (!connectionInterface.SerialPort.IsOpen)
				throw new InterfaceNotOpenException();

			SetParameter(ioLine.GetConfigurationATCommand(), new byte[] { (byte)ioMode.GetId() });
		}
示例#55
0
 public void ResetIOMode(string/*!*/ modeString) {
     _mode = ParseIOMode(modeString, out _preserveEndOfLines);
 }
示例#56
0
        private static RubyIO CheckOpenPipe(RubyContext/*!*/ context, MutableString path, IOMode mode) {
            string fileName = path.ConvertToString();
            if (fileName.Length > 0 && fileName[0] == '|') {
#if SILVERLIGHT
                throw new NotSupportedException("open cannot create a subprocess");
#else
                if (fileName.Length > 1 && fileName[1] == '-') {
                    throw new NotImplementedError("forking a process is not supported");
                }
                return RubyIOOps.OpenPipe(context, path.GetSlice(1), (IOMode)mode);
#endif
            }
            return null;
        }
示例#57
0
 public RubyFile(RubyContext/*!*/ context, MutableString/*!*/ path, IOMode mode)
     : this(context, context.DecodePath(path), mode) {
 }
示例#58
0
        public override bool Read()
        {
            Mode = IOMode.Input;

            return _port.Read();
        }