virtual public bool ActivateAcceptor(IOHandler pIOHandler)
        {
            switch (pIOHandler.Type)
            {
            case IOHandlerType.IOHT_ACCEPTOR:
            {
                var pAcceptor = (TCPAcceptor)pIOHandler;
                pAcceptor.Application = this;
                return(pAcceptor.StartAccept());
            }

            case IOHandlerType.IOHT_UDP_CARRIER:
            {
                var pUDPCarrier = (UDPCarrier)pIOHandler;
                pUDPCarrier.Protocol.NearEndpoint.Application = this;
                return(pUDPCarrier.StartAccept());
            }

            default:
            {
                Logger.FATAL("Invalid acceptor type");
                return(false);
            }
            }
        }
Пример #2
0
 /// <summary>
 /// Execute a command line tool.
 /// </summary>
 /// <param name="toolPath">Tool to execute.</param>
 /// <param name="arguments">String to pass to the tools' command line.</param>
 /// <param name="workingDirectory">Directory to execute the tool from.</param>
 /// <param name="envVars">Additional environment variables to set for the command.</param>
 /// <param name="ioHandler">Allows a caller to provide interactive input and also handle
 /// both output and error streams from a single delegate.</param>
 /// <returns>CommandLineTool result if successful, raises an exception if it's not
 /// possible to execute the tool.</returns>
 public static Result Run(string toolPath, string arguments, string workingDirectory = null,
                          Dictionary <string, string> envVars = null,
                          IOHandler ioHandler = null)
 {
     return(RunViaShell(toolPath, arguments, workingDirectory: workingDirectory,
                        envVars: envVars, ioHandler: ioHandler, useShellExecution: false));
 }
Пример #3
0
 void Start()
 {
     _bigSize   = new Vector3(BigSize, BigSize, BigSize);
     _smallSize = new Vector3(SmallSize, SmallSize, SmallSize);
     _aud       = GetComponent <AudioSource>();
     IO         = new IOHandler();
 }
    public void Save()
    {
        var piList = new List <CorrectableQuad.PointInfomation>();

        for (var i = 0; i < Points.Length; i++)
        {
            var p  = Points[i];
            var uv = new Vector2(
                EMath.Map(p.x, -aspect.x / 2f, aspect.x / 2f, 0, 1),
                EMath.Map(p.y, -aspect.y / 2f, aspect.y / 2f, 0, 1)
                );
            var pi = new CorrectableQuad.PointInfomation
            {
                position = p,
                uv       = uv
            };
            piList.Add(pi);
            print(i + " : " + uv);
        }

        var setting = new QuadCorrectionSetting();

        setting.LeftTop     = new CorrectableQuad.JPointInfomation(piList[0]);
        setting.RightTop    = new CorrectableQuad.JPointInfomation(piList[1]);
        setting.RightBottom = new CorrectableQuad.JPointInfomation(piList[2]);
        setting.LeftBottom  = new CorrectableQuad.JPointInfomation(piList[3]);
        CorrectEvent?.Invoke(setting);
        IOHandler.SaveJson(IOHandler.IntoStreamingAssets(settingFileName), setting);
    }
Пример #5
0
 /// <summary>
 /// Initialize the instance.
 /// </summary>
 /// <param name="handler">Called for each line read.</param>
 public LineReader(IOHandler handler = null)
 {
     if (handler != null)
     {
         LineHandler += handler;
     }
 }
Пример #6
0
        public string AddImage(HttpPostedFileBase file, int id)
        {
            using (var db = new groubel_dbEntities1())
            {
                var us = db.UserImages.FirstOrDefault(i => i.UserId == id);

                var upload = new IOHandler("~/Uploads/ProfileImages/");

                var name = upload.Save(file);

                if (us == null)
                {
                    db.UserImages.Add(new UserImage {
                        UserId = id, Image = name, Sort = 0, IsMain = false, AddDate = DateTime.Now
                    });
                }
                else
                {
                    us.Image = name;
                }

                db.SaveChanges();

                return(name);
            }
        }
Пример #7
0
        public void AttachHandler(IOHandler h)
        {
            handler = h;

            if (!XLibHelper.IsAvailable)
            {
                MessageDialog.ShowError("libX11 library not found");
                return;
            }

            int pid;

            try
            {
                pid = source.ParentWindow.Id;
            }
            catch (DllNotFoundException)
            {
                MessageDialog.ShowError("gdk x11 library not found");
                return;
            }

            XLibHelper.GrabCursorByWindow(pid);
            XLibHelper.MoveCursorAbsolute(pid, (int)(source.ParentWindow.Size.Width / 2), (int)(source.ParentWindow.Size.Height / 2));

            XLibHelper.StartEventListenerLoop(this);
        }
Пример #8
0
 public void Send(ref IOHandler handler)
 {
     Console.WriteLine("SEND");
     string json = JsonConvert.SerializeObject(payload);
     handler.WriteString(json);
     handler.Flush(0);
 }
Пример #9
0
    public virtual void Save(string path)
    {
        var intrinsicInfo = new IntrinsicInfo(cameraMatrix, distCoeffs, rvecs, tvecs);

        IOHandler.SaveJson(path, intrinsicInfo);
        SavedEvent?.Invoke();
    }
Пример #10
0
    private void Init()
    {
        Clients = new List <uOscClient>();
        Servers = new List <uOscServer>();
        var setting = IOHandler.LoadJson <OSCSetting>(IOHandler.IntoStreamingAssets(settingFileName));

        if (setting == null)
        {
            return;
        }
        if (setting.servers != null)
        {
            foreach (var serverSetting in setting.servers)
            {
                var go = new GameObject();
                go.transform.SetParent(this.transform, false);
                var component = go.AddComponent <uOscServer>();
                component.Play(serverSetting);
                component.DataReceveEvent += OnDataReceived;
                Servers.Add(component);
            }
        }

        if (setting.clients != null)
        {
            foreach (var clientSetting in setting.clients)
            {
                var go = new GameObject();
                go.transform.SetParent(this.transform, false);
                var component = go.AddComponent <uOscClient>();
                component.Play(clientSetting);
                Clients.Add(component);
            }
        }
    }
Пример #11
0
        public string UploadImage(HttpPostedFileBase file)
        {
            var upload = new IOHandler("~/Uploads/RoomFiles/");

            var name = upload.Save(file);

            return(name);
        }
Пример #12
0
        public Memory()
        {
            BootROM9 = new BootROM.ARM9();

            BootROM11 = new BootROM.ARM11();

            IO = new IOHandler();
        }
Пример #13
0
 public override void Read(ref IOHandler handler, byte[] buffer)
 {
     protocolVersion = handler.ReadVarInt(buffer);
     int addressLength = handler.ReadVarInt(buffer);
     address = handler.ReadString(buffer, addressLength);
     clientPort = handler.ReadShort(buffer);
     nextState = handler.ReadVarInt(buffer);
 }
Пример #14
0
 void Start()
 {
     IO = new IOHandler();
     displayPanel(PANEL_MAIN);
     setButtonState(ToggleMusic, IO.getMusic());
     setButtonState(ToggleSFX, IO.getSFX());
     updateScoreText();
 }
Пример #15
0
        public Machine(Machine copy, IOHandler listener)
        {
            this.prog = new long[copy.prog.Length];
            System.Array.Copy(copy.prog, this.prog, copy.prog.Length);

            this.mem      = new Dictionary <long, long>(copy.mem);
            this.listener = listener;
        }
Пример #16
0
        public string UploadTemp(HttpPostedFileBase file)
        {
            var upload = new IOHandler("~/Uploads/PostAttachements/");

            var name = upload.Save(file);

            return(name);
        }
Пример #17
0
        private void SetupData()
        {
            List <List <int> > coordinates = IOHandler.ReadInCoordinates();

            for (int i = 0; i < coordinates.Count(); i++)
            {
                this.Route.Add(new Town(coordinates[i].FirstOrDefault(), coordinates[i].LastOrDefault()));
            }
        }
Пример #18
0
 public Calc()
 {
     IOHandler iohandler = new IOHandler();
     iohandler.SetOperands();
     iohandler.SetOperator();
     Engine engine = new Engine(iohandler.GetFirstOperand(), iohandler.GetSecondOperand(), iohandler.GetOperator());
     result = engine.calculate();
     iohandler.ShowResult(result);
 }
Пример #19
0
    private void Save()
    {
        var sceneInfo = new SceneInfo
        {
            SceneName = SceneManager.GetActiveScene().name
        };

        IOHandler.SaveJson(IOHandler.IntoStreamingAssets(fileName), sceneInfo);
    }
Пример #20
0
 /// <summary>
 /// Saves the map to the maps folder in resources
 /// </summary>
 public void SaveMap()
 {
     Task.Factory.StartNew(() =>
     {
         string path = CreateMapPath(_mapData.MapName);
         IOHandler.WriteToFile(path, CreateMapToJSON());
         MessageBox.Show("The map has been saved!");
     });
 }
Пример #21
0
 public override void Dispose()
 {
     base.Dispose();
     if (IOHandler != null)
     {
         IOHandler.Protocol = null;
         IOHandler.Dispose();
     }
 }
        public string GetServiceInfo(IOHandler pIOHandler)
        {
            if ((pIOHandler.Type != IOHandlerType.IOHT_ACCEPTOR) &&
                (pIOHandler.Type != IOHandlerType.IOHT_UDP_CARRIER))
            {
                return("");
            }
            if (pIOHandler.Type == IOHandlerType.IOHT_ACCEPTOR)
            {
                if ((((TCPAcceptor )pIOHandler).Application == null) ||
                    (((TCPAcceptor )pIOHandler).Application.Id != Id))
                {
                    return("");
                }
            }
            else
            {
                if ((pIOHandler.Protocol == null) ||
                    (pIOHandler.Protocol.NearEndpoint.Application == null) ||
                    (pIOHandler.Protocol.NearEndpoint.Application.Id != Id))
                {
                    return("");
                }
            }

            var _params = pIOHandler.Type == IOHandlerType.IOHT_ACCEPTOR
                        ? ((TCPAcceptor)pIOHandler).Parameters
                        : ((UDPCarrier)pIOHandler).Parameters;

            if (_params.Children.Count == 0)
            {
                return("");
            }
            string ss = "";

            ss += "+---+---------------+-----+-------------------------+-------------------------+" + Environment.NewLine;
            ss += "|";
            ss += (pIOHandler.Type == IOHandlerType.IOHT_ACCEPTOR ? "tcp" : "udp");
            ss += "|";
            string s = _params[Defines.CONF_IP];

            ss += s.PadRight(3 * 4 + 3, ' ');
            ss += "|";
            int p = _params[Defines.CONF_PORT];

            s   = p + "";
            ss += s.PadRight(5, ' ');
            ss += "|";
            s   = _params[Defines.CONF_PROTOCOL];
            ss += s.PadRight(25, ' ');
            ss += "|";
            ss += Name.PadRight(25, ' ');
            ss += "|";
            ss += Environment.NewLine;
            return(ss);
        }
        public void AttachHandler(IOHandler h)
        {
            handler = h;

            source.MouseMoved     += HandleMouseMoved;
            source.ButtonPressed  += HandleButtonPressed;
            source.ButtonReleased += HandleButtonReleased;
            source.KeyPressed     += HandleKeyPressed;
            source.KeyReleased    += HandleKeyReleased;
        }
Пример #24
0
    void LoadAutoCalibrationSetting()
    {
        var setting = IOHandler.LoadJson <AutoCalibrationSetting>(autoCalibrationSettingFileName);

        if (setting == null)
        {
            return;
        }
        this.autoCalibrationSetting = setting;
    }
Пример #25
0
 public override void Dispose()
 {
     base.Dispose();
     if (IOHandler == null)
     {
         return;
     }
     IOHandler.Protocol = null;
     IOHandler.Dispose();
 }
Пример #26
0
    private void Restore()
    {
        var setting = IOHandler.LoadJson <QuadCorrectionSetting>(IOHandler.IntoStreamingAssets(fileName));

        if (setting == null)
        {
            return;
        }
        Restore(setting);
    }
Пример #27
0
    private void Remind()
    {
        var sceneInfo = IOHandler.LoadJson <SceneMemorizer.SceneInfo>(IOHandler.IntoStreamingAssets(fileName));

        if (sceneInfo == null)
        {
            return;
        }
        SceneManager.LoadScene(sceneInfo.SceneName);
    }
Пример #28
0
        public static void startComm(int teamNum, String fallback)
        {
            Console.WriteLine("starting comm protocol");
            IPAddress resolved = resolveRio(teamNum, fallback);

            Console.WriteLine("starting IOhandler thread");
            if (resolved != null)
            {
                IOHandler.start(resolved);
            }
        }
Пример #29
0
        private void SetupData()
        {
            Dictionary <double, double> data = IOHandler.ReadInSalaryData();

            foreach (var pair in data)
            {
                this.Persons.Add(new Person(pair.Key, pair.Value));
            }
            this.Solutions     = IOHandler.ReadInPossibleWorkSolutions();
            this.RequestedTime = IOHandler.ReadInWorkHours();
        }
Пример #30
0
 public FrameBufferDisplayWidget()
 {
     base.BoundsChanged += (sender, e) =>
     {
         drawMethod      = CalculateDrawMethod();
         ActualImageArea = CalculateActualImageRectangle();
     };
     handler                       = new IOHandler(this);
     handler.GrabConfirm          += ShowGrabConfirmationDialog;
     handler.PointerInputAttached += HandleNewPointerDevice;
 }
Пример #31
0
 public MainViewModel()
 {
     Notes = new ObservableCollection <Note>(IOHandler.DeserializeNotes());
     SelectedTags.CollectionChanged += (s, e) =>
     {
         FilteredNotes.Filter = x => Filter((Note)x);
     };
     SelectedNotes.CollectionChanged += (s, e) =>
     {
         FilteredNotes.Filter = x => Filter((Note)x);
     };
 }
Пример #32
0
        private void startServer(int port)
        {
            IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            TcpListener serverSocket = new TcpListener(ipAddress,port);
            serverSocket.Start();
            logger.info("Socket server started!");

            while (true)
            {
                IOHandler handler = null;
                TcpClient clientSocket = serverSocket.AcceptTcpClient();

                try
                {

                    NetworkStream networkStream = clientSocket.GetStream();
                    byte[] buffer = new byte[4096];

                    foreach (var ioHandler in handlerList)
                    {
                        if (clientSocket.Client.LocalEndPoint.Equals(ioHandler.clientSocket.Client.LocalEndPoint))
                        {
                            //Handler is already in the list
                            handler = ioHandler;
                        }
                    }

                    networkStream.Read(buffer, 0,buffer.Length);

                    if (handler == null)
                    {
                        handler =  new IOHandler(networkStream, clientSocket);
                        handlerList.Add(handler);
                    }

                    var length = handler.ReadVarInt(buffer);
                    var packetID = handler.ReadVarInt(buffer);

                    Packet packet = Packet.getByType(packetID, length);
                    packet.Read(ref handler,buffer);
                    packet.Handle(ref handler);
                    Console.WriteLine("Received packet! " + packet);

                }
                catch (Exception)
                {
                    Console.WriteLine("Error! Disconnecting client! ");
                    clientSocket.Close();
                    if (handlerList.Contains(handler)) handlerList.Remove(handler);
                }
            }
        }
Пример #33
0
    public void Save()
    {
        if (string.IsNullOrEmpty(settingFileName))
        {
            return;
        }
        var info = new OrthograhicCameraInfo();

        info.OrthograhicSize = cam.orthographicSize;
        info.transformInfo   = new TransformInfo(this.transform);
        IOHandler.SaveJson(IOHandler.IntoStreamingAssets(settingFileName), info);
    }
Пример #34
0
        public void Load(GLWindow window)
        {
            Console.WriteLine($"Loading data from {_pathGifts}");
            var gifts = IOHandler.Load(_pathGifts);

            // preprocessing
            Console.WriteLine("Preprocessing data");
            var minLong   = (float)-Math.PI;
            var maxLong   = (float)Math.PI;
            var minLat    = (float)-Math.PI / 2;
            var maxLat    = (float)Math.PI / 2;
            var n         = gifts.Length;
            var vertGifts = new List <Gift>(n + 1);

            vertGifts.Add(new Gift(0, 90, 0, 0));
            vertGifts.AddRange(gifts);

            var vertices = vertGifts.SelectMany(x => new[]
            {
                ToNormalRange((float)x.Longitude, minLong, maxLong),
                ToNormalRange((float)x.Latitute, minLat, maxLat)
            }).ToArray();

            // showing gifts
            Console.WriteLine("Showing data");
            window.SetVertices(vertices, n + 1);

            //window.RunBackground(() =>
            //{
            // create initial solution
            Console.WriteLine("Creating initial solution");
            var initial = Utils.GenerateClusteredSolutionByLongitude(new List <Gift>(gifts),
                                                                     new double[] { 0.02, 0.04 }, new double[] { 0.04, 0.06 }, 980); //TODO adjust

            Console.WriteLine(Utils.CalcAllPenalty(initial));
            Console.WriteLine("Initial solution completed");
            var tours = initial.Select(list => new Tour(list)).ToList();

            window.SetTour(tours.Select(tour => tour.Gifts.Select(gift => gift.Id).ToArray()).ToList());

            // optimize solution
            Console.WriteLine("Optimize solution");
            tours = tours.AsParallel().Select(HillClimber.Run).ToList();
            Console.WriteLine("Solution completed");
            window.SetTour(tours.Select(tour => tour.Gifts.Select(gift => gift.Id).ToArray()).ToList());

            Console.WriteLine($"Total score: {tours.Sum(tour => tour.Cost)}");
            Console.WriteLine($"Saving solution in {_pathSolution}");
            IOHandler.Save(_pathSolution, n, tours);
            Console.WriteLine($"Done");
            //});
        }
Пример #35
0
 public override void Handle(ref IOHandler handler)
 {
     //Check state
     Console.WriteLine("REQUEST STATE:"  + handler.State);
     if (handler.State == 1)
     {
         //Send list ping
         Console.WriteLine("Sending list ping!");
         new ListPing(new PingPayload(
             new VersionPayload(47, "Spigot"),
             new PlayersPayload(20, 2, null),
             "Test", null
             )).Send(ref handler);
        }
 }
Пример #36
0
 public void AddHandler(IntPtr fd, IOHandler handler, EpollEvents events)
 {
     handlers [fd] = handler;
     Register (fd, events | EPOLL_ERROR_EVENTS);
 }
Пример #37
0
 public override void Read(ref IOHandler handler, byte[] buffer)
 {
     //Nothing to read
 }
        /// <summary>
        /// Execute a command line tool.
        /// </summary>
        /// <param name="toolPath">Tool to execute.</param>
        /// <param name="arguments">String to pass to the tools' command line.</param>
        /// <param name="workingDirectory">Directory to execute the tool from.</param>
        /// <param name="envVars">Additional environment variables to set for the command.</param>
        /// <param name="ioHandler">Allows a caller to provide interactive input and also handle
        /// both output and error streams from a single delegate.</param>
        /// <returns>CommandLineTool result if successful, raises an exception if it's not
        /// possible to execute the tool.</returns>
        public static Result Run(string toolPath, string arguments, string workingDirectory = null,
                                 Dictionary<string, string> envVars = null,
                                 IOHandler ioHandler = null)
        {
            System.Text.Encoding inputEncoding = Console.InputEncoding;
            System.Text.Encoding outputEncoding = Console.OutputEncoding;
            Console.InputEncoding = System.Text.Encoding.UTF8;
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.Arguments = arguments;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            if (envVars != null)
            {
                foreach (var env in envVars)
                {
                    process.StartInfo.EnvironmentVariables[env.Key] = env.Value;
                }
            }
            process.StartInfo.RedirectStandardInput = (ioHandler != null);
            process.StartInfo.FileName = toolPath;
            process.StartInfo.WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory;

            process.Start();

            // If an I/O handler was specified, call it with no data to provide a process and stdin
            // handle before output data is sent to it.
            if (ioHandler != null) ioHandler(process, process.StandardInput, StreamData.Empty);

            AutoResetEvent complete = new AutoResetEvent(false);
            List<string>[] stdouterr = new List<string>[] { new List<string>(),
                                                            new List<string>() };
            // Read raw output from the process.
            AsyncStreamReader[] readers = AsyncStreamReader.CreateFromStreams(
                new Stream[] { process.StandardOutput.BaseStream,
                               process.StandardError.BaseStream }, 1);
            new AsyncStreamReaderMultiplexer(
                readers,
                (StreamData data) => {
                    stdouterr[data.handle].Add(data.text);
                    if (ioHandler != null) ioHandler(process, process.StandardInput, data);
                },
                complete: () => { complete.Set(); });
            foreach (AsyncStreamReader reader in readers) reader.Start();

            process.WaitForExit();
            // Wait for the reading threads to complete.
            complete.WaitOne();

            Result result = new Result();
            result.stdout = String.Join("", stdouterr[0].ToArray());
            result.stderr = String.Join("", stdouterr[1].ToArray());
            result.exitCode = process.ExitCode;
            Console.InputEncoding = inputEncoding;
            Console.OutputEncoding = outputEncoding;
            return result;
        }
 /// <summary>
 /// Initialize the instance.
 /// </summary>
 /// <param name="handler">Called for each line read.</param>
 public LineReader(IOHandler handler = null)
 {
     if (handler != null) LineHandler += handler;
 }
Пример #40
0
 public override void Handle(ref IOHandler handler)
 {
 }
Пример #41
0
 public override void Read(ref IOHandler handler, byte[] buffer)
 {
 }
 /// <summary>
 /// Asynchronously execute a command line tool, calling the specified delegate on
 /// completion.
 /// </summary>
 /// <param name="toolPath">Tool to execute.</param>
 /// <param name="arguments">String to pass to the tools' command line.</param>
 /// <param name="completionDelegate">Called when the tool completes.</param>
 /// <param name="workingDirectory">Directory to execute the tool from.</param>
 /// <param name="envVars">Additional environment variables to set for the command.</param>
 /// <param name="ioHandler">Allows a caller to provide interactive input and also handle
 /// both output and error streams from a single delegate.</param>
 public static void RunAsync(
     string toolPath, string arguments, CompletionHandler completionDelegate,
     string workingDirectory = null,
     Dictionary<string, string> envVars = null,
     IOHandler ioHandler = null)
 {
     Thread thread = new Thread(new ThreadStart(() => {
             Result result = Run(toolPath, arguments, workingDirectory, envVars: envVars,
                                 ioHandler: ioHandler);
             completionDelegate(result);
         }));
     thread.Start();
 }
Пример #43
0
 public override void Handle(ref IOHandler handler)
 {
     //Set next state
     Console.WriteLine("Setting state");
     handler.State = nextState;
 }