예제 #1
0
        private Object syncObj = new Object();                          //定义一个静态对象用于线程部份代码块的锁定,用于lock操作
        public NormalIPCManager(IPCType _ipctype, Func <string, Dictionary <string, string>, string> _funcExecCmd, Action <string> _actionReceiveData)
        {
            IPCType           = _ipctype;
            funcExecCmd       = _funcExecCmd;
            actionReceiveData = _actionReceiveData;
            ipcw = new IPCWriteHelper();
            ipcr = new IPCReceiveHelper();

            Action <string> action = ((string text) =>
            {
                if (CmdObject.AnalysisCmdText(text).typestr == "cmd")
                {
                    ExecuteCmd(text);
                }
                else if (CmdObject.AnalysisCmdText(text).typestr == "data")
                {
                    ReceiveData(text);
                }
                else
                {
                    return;//无效的文本
                }
            });

            ipcr.Init(action, _ipctype, _ipctype);
        }
예제 #2
0
        public static TContract CreateChannel <TContract>(IPCType ipcType, string address)
        {
            Binding binding;

            switch (ipcType)
            {
            case IPCType.NamedPipe:
                binding = new NetNamedPipeBinding("");
                break;

            case IPCType.TCP:
                binding = new NetTcpBinding("")
                {
                    Security =
                    {
                        Mode = SecurityMode.None
                    }
                };
                break;

            default:
                throw new InvalidEnumArgumentException(nameof(ipcType), (int)ipcType, ipcType.GetType());
            }

            var factory = new ChannelFactory <TContract>(binding, address);

            return(factory.CreateChannel());
        }
예제 #3
0
        public static ServiceHost CreateService(IPCType ipcType, Type serviceType, Type contractType, out Uri uri)
        {
            switch (ipcType)
            {
            case IPCType.NamedPipe:
                return(CreateNamedPipeService(serviceType, contractType, out uri));

            case IPCType.TCP:
                return(CreateTcpService(serviceType, contractType, out uri));

            default:
                throw new InvalidEnumArgumentException(nameof(ipcType), (int)ipcType, ipcType.GetType());
            }
        }
예제 #4
0
        //得到共享地址
        public static uint GetshareAddress(IPCType type)
        {
            switch (type)
            {
            case IPCType.efwplusBase:
                return(0x0002);

            case IPCType.efwplusWebAPI:
                return(0x1002);

            case IPCType.efwplusRoute:
                return(0x2002);
            }
            return(0x0002);
        }
예제 #5
0
        public static string GetProcessName(IPCType type)
        {
            switch (type)
            {
            case IPCType.efwplusBase:
                return("efwplusbase");

            case IPCType.efwplusRoute:
                return("efwplusroute");

            case IPCType.efwplusWebAPI:
                return("efwpluswebapi");

            case IPCType.efwplusServer:
                return("efwplusserver");
            }
            return("");
        }
예제 #6
0
        Action <string> dataAction;//数据委托
        ///<summary>
        /// 初始化共享内存数据 创建一个共享内存
        ///</summary>
        public void Init(Action <string> _dataAction, IPCType type, IPCType addrtype)
        {
            dataAction = _dataAction;

            m_Write = new Semaphore(1, 1, IPCName.GetWriteMapName(type)); //开始的时候有一个可以写
            m_Read  = new Semaphore(0, 1, IPCName.GetReadMapName(type));  //没有数据可读
            //mapLength = 10240000;
            IntPtr hFile = new IntPtr(INVALID_HANDLE_VALUE);

            handle = CreateFileMapping(hFile, 0, PAGE_READWRITE, 0, IPCName.mapLength, IPCName.GetshareMemoryName(type));
            addr   = MapViewOfFile(handle, IPCName.GetshareAddress(addrtype), 0, 0, 0);

            //handle = OpenFileMapping(0x0002, 0, "shareMemory");
            //addr = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);

            threadRed = new Thread(new ThreadStart(ReceiveData));
            threadRed.Start();
        }
예제 #7
0
        public static string GetshareMemoryName(IPCType type)
        {
            switch (type)
            {
            case IPCType.efwplusBase:
                return("shareMemory_efwplusBase");

            case IPCType.efwplusRoute:
                return("shareMemory_efwplusRoute");

            case IPCType.efwplusWebAPI:
                return("shareMemory_efwplusWebAPI");

            case IPCType.efwplusServer:
                return("shareMemory_efwplusServer");
                //case IPCType.efwplusServerCmd:
                //    return "shareMemory_efwplusServerCmd";
            }
            return("shareMemory");
        }
예제 #8
0
        public static string GetReadMapName(IPCType type)
        {
            switch (type)
            {
            case IPCType.efwplusBase:
                return("ReadMap_efwplusBase");

            case IPCType.efwplusRoute:
                return("ReadMap_efwplusRoute");

            case IPCType.efwplusWebAPI:
                return("ReadMap_efwplusWebAPI");

            case IPCType.efwplusServer:
                return("ReadMap_efwplusServer");
                //case IPCType.efwplusServerCmd:
                //    return "ReadMap_efwplusServerCmd";
            }
            return("ReadMap");
        }
예제 #9
0
        private IntPtr addr;       //共享内存地址
        //uint mapLength=10240000;            //共享内存长

        //Thread threadRed;

        public void WriteData(string data, IPCType type, IPCType addrtype)
        {
            try
            {
                m_Write = Semaphore.OpenExisting(IPCName.GetWriteMapName(type));
                m_Read  = Semaphore.OpenExisting(IPCName.GetReadMapName(type));
                handle  = OpenFileMapping(FILE_MAP_WRITE, 0, IPCName.GetshareMemoryName(type));
                addr    = MapViewOfFile(handle, IPCName.GetshareAddress(addrtype), 0, 0, 0);

                m_Write.WaitOne();
                byte[] sendStr = Encoding.Default.GetBytes(data + '\0');
                //如果要是超长的话,应另外处理,最好是分配足够的内存
                if (sendStr.Length < IPCName.mapLength)
                {
                    Copy(sendStr, addr);
                }

                m_Read.Release();
            }
            catch
            {
                //throw new Exception("不存在系统信号量!");
            }
        }