private void IntercommsMessageHandler(string message)
        {
            try
            {
                switch (message)
                {
                case "MNG_CON":
                    _isManageconnected = true;
                    _intercommsClient.Send("SERVICE_CON", "PDFSCANMANAGEPIPE");
                    break;

                case "MNG_DIS":
                    _isManageconnected = false;
                    break;

                    /*case "PROC_START":
                     *      DoPDFSplitStart();
                     *      break;
                     * case "PROC_STOP":
                     *      DoPDFSplitStop();
                     *      break;*/
                }
                ServiceLog.WriteLog("Intercomms Server Received Message, " + message + "[Length: " + message.Length + "], Connected : " + _isManageconnected.ToString());
            }
            catch (Exception ex)
            {
                ServiceLog.WriteLog("Intercomms Server Received Error, " + ex.Message);
            }
        }
Exemplo n.º 2
0
        private void WaitForConnectionCallBack(IAsyncResult iar)
        {
            try
            {
                NamedPipeServerStream pipeServer = (NamedPipeServerStream)iar.AsyncState; // Get the pipe
                pipeServer.EndWaitForConnection(iar);                                     // End waiting for the connection
                byte[] buffer = new byte[255];

                string stringData = "";
                while (pipeServer.Read(buffer, 0, 255) > 0)                 // Read the incoming message
                {
                    int len = 0;
                    while (len < 255 && buffer[len] != '\0')
                    {
                        len++;
                    }
                    stringData += Encoding.UTF8.GetString(buffer, 0, len /*buffer.Length*/);                    // Convert byte buffer to string
                    //ServiceLog.WriteLog("Intercomms Server Buffer, " + len.ToString());
                    buffer = new byte[255];
                }
                IntercommsMessage.Invoke(stringData); // Pass message back to calling form
                pipeServer.Close();                   // Kill original sever and create new wait server
                pipeServer = null;
                pipeServer = new NamedPipeServerStream(_pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
                pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer);                 // Recursively wait for the connection again and again....
            }
            catch (Exception oEX)
            {
                ServiceLog.WriteLog("[Service] Intercomms Server WaitForConnectionCallBack Error, " + oEX.Message);
                return;
            }
        }
        public static bool SetLicense(bool silent)
        {
            try
            {
                // TODO: Change this to use your license file and developer key */
                string licenseFilePath = AppDomain.CurrentDomain.BaseDirectory + "\\full_license.lic";
                string developerKey    = "gcxLXptTi5bPbVDDR9E+k4CRC8BLLm0IuN383qJp6jPqoMTYamOe1yuYzHqrCmFEN5zDcumaaCTXpO9GpeGal0wjSKF8nxnu";
                var    lic             = File.ReadAllBytes(licenseFilePath);
                RasterSupport.SetLicense(lic, developerKey);
                //RasterSupport.SetLicense(licenseFilePath, developerKey);
            }
            catch (Exception ex)
            {
                //System.Diagnostics.Debug.Write(ex.Message);
                ServiceLog.WriteLog("Set License Error, " + ex.Message);
            }

            if (RasterSupport.KernelExpired)
            {
                if (silent == false)
                {
                    string msg    = "Your license file is missing, invalid or expired. LEADTOOLS will not function. Please contact LEAD Sales for information on obtaining a valid license.";
                    string logmsg = string.Format("*** NOTE: {0} ***{1}", msg, Environment.NewLine);
                    ServiceLog.WriteLog("*******************************************************************************" + Environment.NewLine);
                    ServiceLog.WriteLog(logmsg);
                    ServiceLog.WriteLog("*******************************************************************************" + Environment.NewLine);
                }

                return(false);
            }
            return(true);
        }
        public void OnPDFSplitterMsgEvent(object sender, PDFSplitterEventArgs args)
        {
            int listindex = GetDirectoryIndexById(args.DirID);

            DirectoryData[] dirData = _directorySettings.GetDirectoryData();

            if (args.Kind == 1 && listindex > -1)
            {
                switch (args.Msg)
                {
                case "Stopped":
                    dirData[listindex].Status = false;
                    break;
                }
            }

            string strmsg = args.DirID.ToString() + "|" + args.Kind.ToString() + "|" + args.Msg + "|" + ((int)args.Evtype).ToString();

            try
            {
                if (_isManageconnected)
                {
                    _intercommsClient.Send(strmsg, "PDFSCANMANAGEPIPE");
                }
                else
                {
                    ServiceLog.WriteLog("Intercomms Client Send Data, " + strmsg);
                }
            }
            catch (Exception ex)
            {
                ServiceLog.WriteLog("Intercomms Client Send Error, " + ex.Message + ", " + strmsg);
            }

            for (int i = 0; i < dirData.Length; i++)
            {
                if (dirData[i].Status)
                {
                    return;
                }
            }

            for (int i = 0; i < _pdfSplitters.Length; i++)
            {
                if (splitThreads[i] != null)
                {
                    splitThreads[i].Abort();
                }
                _pdfSplitters[i] = null;
            }

            _pdfSplitters = null;
            splitThreads  = null;
        }
Exemplo n.º 5
0
 public void Listen(string PipeName)
 {
     try
     {
         _pipeName = PipeName;                                                                                                                             // Set to class level var so we can re-use in the async callback method
         NamedPipeServerStream pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); // Create the new async pipe
         pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer);                                                      // Wait for a connection
     }
     catch (Exception oEX)
     {
         ServiceLog.WriteLog("[Service] Intercomms Server Listen Error, " + oEX.Message);
     }
 }
 public void Send(string SendStr, string PipeName, int TimeOut = 1000)
 {
     try
     {
         NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", PipeName, PipeDirection.Out, PipeOptions.Asynchronous);
         pipeStream.Connect(TimeOut);
         byte[] _buffer = Encoding.UTF8.GetBytes(SendStr);
         pipeStream.BeginWrite(_buffer, 0, _buffer.Length, AsyncSend, pipeStream);
     }
     catch (TimeoutException oEX)
     {
         ServiceLog.WriteLog("[Service] Intercomms Client Send Error, " + oEX.Message + ", " + SendStr + ", " + PipeName);
     }
 }
 private void AsyncSend(IAsyncResult iar)
 {
     try
     {
         NamedPipeClientStream pipeStream = (NamedPipeClientStream)iar.AsyncState; // Get the pipe
         pipeStream.EndWrite(iar);                                                 // End the write
         pipeStream.Flush();
         pipeStream.Close();
         pipeStream.Dispose();
     }
     catch (Exception oEX)
     {
         ServiceLog.WriteLog("[Service] Intercomms Client AsyncSend Error," + oEX.Message);
     }
 }
        protected override void OnStart(string[] args)
        {
            _barcodeOptions = BarcodeOptions.Load();

            //BarcodeSymbology[] supportedSymbologies = BarcodeEngine.GetSupportedSymbologies();
            Console.WriteLine(string.Format("{0} Supported symbologies:", _barcodeOptions.ReadOptionsSymbologies.Length));
            foreach (BarcodeSymbology symbology in _barcodeOptions.ReadOptionsSymbologies)
            {
                Console.WriteLine(string.Format("{0}: {1}", symbology, BarcodeEngine.GetSymbologyFriendlyName(symbology)));
            }

            _directorySettings.Load();
            DoPDFSplitStart();

            ServiceLog.WriteLog("Service started");
        }
        public MainService()
        {
            InitializeComponent();

            ServiceLog.InitLog();

            _isManageconnected = false;

            _intercommsServer = new IntercommsServer();
            _intercommsServer.IntercommsMessage += new IntercommsMessageDelegate(IntercommsMessageHandler);
            _intercommsClient = new IntercommsClient();

            _intercommsServer.Listen("PDFSCANSERVICEPIPE");
            ServiceLog.WriteLog("Intercomms Server Listening Started");

            _directorySettings = new DirectorySettings();
        }
        protected override void OnStop()
        {
            DoPDFSplitStop();

            ServiceLog.WriteLog("Service stopped");
        }