Exemple #1
0
        public bool End(usrc_FVI_SLO_MessageBox xusrc_FVI_SLO_MessageBox)
        {
            FiscalSettings = null;
            taxService = null;

            usrc_FVI_SLO_Message xusrc_FVI_SLO_Message_END = new usrc_FVI_SLO_Message(0,usrc_FVI_SLO_Message.eMessage.NONE, null);
            Thread_FVI_Message fvi_message_END = new Thread_FVI_Message(0,Thread_FVI_Message.eMessage.END, null);
            message_box.Post(fvi_message_END);
            long StartTicks = DateTime.Now.Ticks;

            for (;;)
            {
                if (xusrc_FVI_SLO_MessageBox.Get(ref xusrc_FVI_SLO_Message_END)== Result_MessageBox_Get.OK)
                {
                    if (xusrc_FVI_SLO_Message_END.Message == usrc_FVI_SLO_Message.eMessage.Thread_FVI_END)
                    {
                        return true;
                    }
                }
                if ((DateTime.Now.Ticks- StartTicks)>100000000)
                {
                    return false;
                }
            }
        }
        /****** End For DEBUG & TEST PURPOSES ***/
        public FormFURSCommunication(usrc_FVI_SLO Parent, Thread_FVI_Message msg)
        {
            InitializeComponent();

             if (Parent.FursTESTEnvironment)
             {
                lbl_TEST_Environment.Visible = true;
             }
             else
             {
                lbl_TEST_Environment.Visible = false;
             }

            m_usrc_FVI_SLO = Parent;
             m_msg = msg;

             iForm_Default_Height = this.Height;
             iForm_Default_Width = this.Width;

             /****** For DEBUG & TEST PURPOSES ***/
             if (m_usrc_FVI_SLO.DEBUG)
             {
                 default_FormBorderStyle = this.FormBorderStyle;
                 Show_usrc_DEBUG_MessagePreview();
             }
             /****** End For DEBUG & TEST PURPOSES ***/

             //  this.Location = m_parent.ParentForm.Location;
             //   Point p = new Point(m_parent.ParentForm.Width / 2 - this.Width / 2, m_parent.ParentForm.Height / 2 - this.Height / 2);
             //    this.Location = p;
        }
 public usrc_DEBUG_MessagePreview(Thread_FVI_Message xmsg)
 {
     InitializeComponent();
     msg = xmsg;
     lbl_MessageType.Text = msg.MessageType;
     txt_MessageID.Text = msg.Message_ID.ToString();
     txt_MessageXml.Text = msg.XML_Data;
 }
 public CircularBuffer_Thread_FVI_Message(int xLength)
 {
     if (xLength > 0)
     {
         m_Length = xLength;
         m_obuff = new Thread_FVI_Message[m_Length] ;
         for (int i=0;i< m_Length;i++)
         {
             Thread_FVI_Message mfvi = new Thread_FVI_Message(0,Thread_FVI_Message.eMessage.NONE,null);
             m_obuff[i] = mfvi;
         }
     }
     pIn = 0;
     pOut = 0;
 }
 public bool Get(ref Thread_FVI_Message msg)
 {
     if (pOut != pIn)
     {
         msg.Message = m_obuff[pOut].Message;
         msg.XML_Data = m_obuff[pOut].XML_Data;
         msg.Message_ID = m_obuff[pOut].Message_ID;
         m_obuff[pOut].Message = Thread_FVI_Message.eMessage.NONE;
         m_obuff[pOut].XML_Data = null;
         pOut = Next(pOut);
         return true;
     }
     else
     {
         return false;
     }
 }
 public Result_MessageBox_Post Post(Thread_FVI_Message Message)
 {
     Result_MessageBox_Post res = Result_MessageBox_Post.TIMEOUT;
     if (myMutex.WaitOne(3000))
     {
         if (message_buff.PutIn(Message))
         {
             res = Result_MessageBox_Post.OK;
         }
         else
         {
             res = Result_MessageBox_Post.FULL;
         }
         myMutex.ReleaseMutex();
     }
     else
     {
         res = Result_MessageBox_Post.TIMEOUT;
     }
     return res;
 }
 public Result_MessageBox_Get Get(ref Thread_FVI_Message Message)
 {
     Result_MessageBox_Get res = Result_MessageBox_Get.TIMEOUT;
     if (myMutex.WaitOne(3000))
     {
         if (message_buff.Get(ref Message))
         {
             res = Result_MessageBox_Get.OK;
         }
         else
         {
             res = Result_MessageBox_Get.EMPTY;
         }
         myMutex.ReleaseMutex();
     }
     else
     {
         //Timeout !
         res = Result_MessageBox_Get.TIMEOUT;
     }
     return res;
 }
Exemple #8
0
        private void Run(object othdata)
        {
            ThreadData thdata = (ThreadData)othdata;
            usrc_FVI_SLO_MessageBox xusrc_FVI_SLO_MessageBox = thdata.m_usrc_FVI_SLO_MessageBox;
            Thread_FVI_Message fvi_message = new Thread_FVI_Message(0,Thread_FVI_Message.eMessage.NONE,null);
            usrc_FVI_SLO_Message xusrc_FVI_SLO_Message = new usrc_FVI_SLO_Message(0,usrc_FVI_SLO_Message.eMessage.Thread_FVI_START, null);
            xusrc_FVI_SLO_MessageBox.Post(xusrc_FVI_SLO_Message);

            try
            {
                if (File.Exists(thdata.certificateFileName))
                {
                    X509Certificate2 certificate = GetCertFromFile(thdata.certificateFileName, thdata.CertPass);
                    FiscalSettings = Settings.Create(certificate, thdata.fursWebServiceURL, thdata.fursXmlNamespace, thdata.timeOutInSec);
                    taxService = TaxService.Create(FiscalSettings);  //create service with settings
                }
                else
                {
                    xusrc_FVI_SLO_Message.Set(fvi_message.Message_ID, usrc_FVI_SLO_Message.eMessage.ERROR,null, lngRPM.sFileDoesNotExist.s + ":" + thdata.certificateFileName,MessageType.Unknown,null,false,null,null,null);
                    xusrc_FVI_SLO_MessageBox.Post(xusrc_FVI_SLO_Message);
                    return;
                }
            }
            catch (Exception ex)
            {
                xusrc_FVI_SLO_Message.Set(fvi_message.Message_ID, usrc_FVI_SLO_Message.eMessage.ERROR, null, ex.Message, MessageType.Unknown, null, false, null, null, null);
                xusrc_FVI_SLO_MessageBox.Post(xusrc_FVI_SLO_Message);
                return;
            }

            for (;;)
            {
                ReturnValue rv = null;
                string xml_returned = null;
                switch (message_box.Get(ref fvi_message))
                {
                    case Result_MessageBox_Get.OK:
                        switch (fvi_message.Message)
                        {

                            case Thread_FVI_Message.eMessage.POST_ECHO:
                                rv = taxService.Send(fvi_message.XML_Data);
                                xml_returned = prettyXml(rv.originalMessage);
                                xusrc_FVI_SLO_Message.Set(fvi_message.Message_ID, usrc_FVI_SLO_Message.eMessage.FVI_RESPONSE_ECHO, xml_returned);
                                xusrc_FVI_SLO_Message.Success = rv.Success;
                                xusrc_FVI_SLO_MessageBox.Post(xusrc_FVI_SLO_Message);
                                break;

                            case Thread_FVI_Message.eMessage.POST_SINGLE_INVOICE:
                                rv = taxService.Send(fvi_message.XML_Data);
                                xml_returned = prettyXml(rv.originalMessage);
                                if (rv.BarCodes!=null)
                                {
                                    string BarCodeValue = rv.BarCodes.BarCodeValue;
                                    if (BarCodeValue != null)
                                    {
                                        Image img_QRCode = rv.BarCodes.DrawQRCode(Properties.Settings.Default.QRImageWidth, System.Drawing.Imaging.ImageFormat.Png);
                                        xusrc_FVI_SLO_Message.Set(fvi_message.Message_ID, usrc_FVI_SLO_Message.eMessage.FVI_RESPONSE_SINGLE_INVOICE,
                                                                  xml_returned,
                                                                  rv.ErrorMessage,
                                                                  rv.MessageType,
                                                                  rv.ProtectedID,
                                                                  rv.Success,
                                                                  rv.UniqueInvoiceID,
                                                                  BarCodeValue,
                                                                  img_QRCode);

                                    }
                                    else
                                    {
                                        xusrc_FVI_SLO_Message.Set(fvi_message.Message_ID, usrc_FVI_SLO_Message.eMessage.FVI_RESPONSE_SINGLE_INVOICE,
                                                                 xml_returned,
                                                                 rv.ErrorMessage,
                                                                 rv.MessageType,
                                                                 rv.ProtectedID,
                                                                 rv.Success,
                                                                 rv.UniqueInvoiceID,
                                                                 null,
                                                                 null);
                                    }
                                }
                                else
                                {
                                    xusrc_FVI_SLO_Message.Set(fvi_message.Message_ID, usrc_FVI_SLO_Message.eMessage.FVI_RESPONSE_SINGLE_INVOICE,
                                                                xml_returned,
                                                                rv.ErrorMessage,
                                                                rv.MessageType,
                                                                rv.ProtectedID,
                                                                rv.Success,
                                                                rv.UniqueInvoiceID,
                                                                null,
                                                                null);
                                }

                                xusrc_FVI_SLO_MessageBox.Post(xusrc_FVI_SLO_Message);
                                break;

                            case Thread_FVI_Message.eMessage.POST_BUSINESSPREMISE:
                                rv = taxService.Send(fvi_message.XML_Data);
                                xml_returned = prettyXml(rv.originalMessage);
                                xusrc_FVI_SLO_Message.Set(fvi_message.Message_ID, usrc_FVI_SLO_Message.eMessage.FVI_RESPONSE_PP, xml_returned);
                                xusrc_FVI_SLO_Message.Success = rv.Success;
                                xusrc_FVI_SLO_Message.ErrorMessage  = rv.ErrorMessage;
                                xusrc_FVI_SLO_MessageBox.Post(xusrc_FVI_SLO_Message);
                                break;

                            case Thread_FVI_Message.eMessage.POST_MANY_INVOICES:
                                rv = taxService.Send(fvi_message.XML_Data);
                                xml_returned = prettyXml(rv.originalMessage);
                                xusrc_FVI_SLO_Message.Set(fvi_message.Message_ID, usrc_FVI_SLO_Message.eMessage.FVI_RESPONSE_SINGLE_INVOICE, xml_returned);
                                xusrc_FVI_SLO_MessageBox.Post(xusrc_FVI_SLO_Message);
                                break;

                            case Thread_FVI_Message.eMessage.END:
                                xusrc_FVI_SLO_Message.Set(0,usrc_FVI_SLO_Message.eMessage.Thread_FVI_END, null);
                                xusrc_FVI_SLO_MessageBox.Post(xusrc_FVI_SLO_Message);
                                return;
                        }
                        break;
                    case Result_MessageBox_Get.TIMEOUT:
                        break;
                }
            }
        }
 public bool PutIn(Thread_FVI_Message msg)
 {
     int pInNext = Next(pIn);
     if (pInNext == pOut)
     {
         return false;
     }
     else
     {
         m_obuff[pIn].Message = msg.Message;
         m_obuff[pIn].XML_Data = msg.XML_Data;
         m_obuff[pIn].Message_ID = msg.Message_ID;
         pIn = pInNext;
         return true;
     }
 }