Пример #1
0
        private ICommunicator CreateCommunicator(CommunicatorType type, string user, string env, string application, bool isFromApplicatonProcess = false)
        {
            var           key  = string.Format(KEY_FORMAT, user, env, application, isFromApplicatonProcess ? "_App" : "");
            ICommunicator comm = null;

            switch (type)
            {
            case CommunicatorType.MappedFileType:
                comm = new MemoryMappedFileCommunicator(user, env, application, isFromApplicatonProcess);
                break;

            default:
                break;
            }
            if (comm != null)
            {
                lock (lockObj)
                {
                    commList.Add(key, comm);
                }
                comm.StartReader();
            }
            //logger.DebugFormat("CreateCommunicator, Key = {0}", key);
            return(comm);
        }
Пример #2
0
        static void Main(string[] args)
        {
            MemoryMappedFileCommunicator communicator = new MemoryMappedFileCommunicator("MemoryMappedShare", 4096);

            // This process reads data that begins in the position 2000 and writes starting from the position 0.
            communicator.ReadPosition  = 2000;
            communicator.WritePosition = 0;

            // Creates an handler for the event that is raised when data are available in the
            // MemoryMappedFile.
            communicator.DataReceived += new EventHandler <MemoryMappedDataReceivedEventArgs>(communicator_DataReceived);
            communicator.StartReader();

            bool quit = false;

            Console.WriteLine("Write messages and press ENTER to send (empty to terminate): ");
            while (!quit)
            {
                string message = Console.ReadLine();
                if (!string.IsNullOrEmpty(message))
                {
                    var data = System.Text.Encoding.UTF8.GetBytes(message);
                    communicator.Write(data);
                }
                else
                {
                    quit = true;
                }
            }

            communicator.Dispose();
            communicator = null;
        }
Пример #3
0
        static void Main(string[] args)
        {
            communicator.ReadPosition  = 0;
            communicator.WritePosition = 0;

            communicator.DataReceived += new EventHandler <MemoryMappedDataReceivedEventArgs>(Communicator_DataReceived);
            communicator.StartReader();

            var t = new Task(() =>
            {
                Web = new WebServer(WebServer.Lorule, ServiceAPI);
                Web.Run();
                {
                    try
                    {
                        if (File.Exists(ContextPath))
                        {
                            WebServer.Info = JsonConvert.DeserializeObject <ServerInformation>(File.ReadAllText(ContextPath));
                            WebServer.Info.Debug("Web Info Recovered.");
                        }
                    }
                    finally
                    {
                    }
                }
            });

            t.Start();

            Process.Start(ServiceAPI);

            Thread.CurrentThread.Join();
        }
        void InitializeCommunicator()
        {
            Communicator = new MemoryMappedFileCommunicator($"Sakuno/HeavenlyWind({HostProcessID})", 4096);
            Communicator.ReadPosition  = 2048;
            Communicator.WritePosition = 0;

            Messages = Communicator.GetMessageObservable().Publish();
            Messages.Connect();

            Communicator.StartReader();
        }
Пример #5
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            communicator = new MemoryMappedFileCommunicator("MemoryMappedShare", 4096);

            // This process reads data that begins in the position 0 and writes starting from the position 2000.
            communicator.ReadPosition  = 0;
            communicator.WritePosition = 2000;

            // Creates an handler for the event that is raised when data are available in the
            // MemoryMappedFile.
            communicator.DataReceived += new EventHandler <MemoryMappedDataReceivedEventArgs>(communicator_DataReceived);
            communicator.StartReader();
        }
Пример #6
0
        public void Initialize(string name, long capacity, bool isOwner)
        {
            if (isOwner)
            {
                communicator = new MemoryMappedFileCommunicator(name, capacity);
                communicator.ReadPosition  = 2000;
                communicator.WritePosition = 0;
                communicator.StartReader();
            }
            else
            {
                communicator = new MemoryMappedFileCommunicator(name, capacity);
                communicator.WritePosition = 2000;
                communicator.ReadPosition  = 0;
                communicator.StartReader();
            }

            communicator.DataReceived += Communicator_DataReceived;
        }
Пример #7
0
 public void Start()
 {
     communicator.StartReader();
 }