Exemplo n.º 1
0
        private KeyValuePair <byte[], int> read_binary(Int16 maxLe, Int16 offset = 0x00)
        {
            KeyValuePair <byte[], int> pair;

            byte[] buffOut = new byte[256];
            int    outSize = 300;

            byte[] byBuffIn   = new byte[] { 0x00, 0xB0, (byte)(offset >> 8), (byte)offset, (byte)maxLe };
            int    returnCode = CSC.CSC_ISOCommand(byBuffIn, byBuffIn.Length, buffOut, ref outSize);

            if (returnCode == CSC.RCSC_Ok && outSize > 2 && buffOut[outSize - 2] == 0x90 &&
                buffOut[outSize - 1] == 0x00)
            {
                Console.WriteLine("read binary");
                var res = new byte[outSize - 3];
                for (var i = 1; i < outSize - 2; i++)
                {
                    res[i - 1] = buffOut[i];
                }

                return(new KeyValuePair <byte[], int>(res, outSize - 3));
            }
            Console.WriteLine("offset : " + offset + " maxLe : " + maxLe);
            throw new Exception("read binary failed " + CSC.ToStringN(buffOut));
        }
Exemplo n.º 2
0
 private void button2_Click(object sender, EventArgs e)
 {
     CSC.ResetText();
     CSM.ResetText();
     DNTT.ResetText();
     TT.ResetText();
     TTCV.ResetText();
 }
Exemplo n.º 3
0
        private void select_file(byte[] file)
        {
            byte[] buffOut = new byte[256];
            int    outSize = 300;

            byte[] byBuffIn   = new byte[] { 0x00, 0xA4, 0x00, 0x0C, 0x02, file[0], file[1] };
            int    returnCode = CSC.CSC_ISOCommand(byBuffIn, byBuffIn.Length, buffOut, ref outSize);

            if (returnCode == CSC.RCSC_Ok && outSize > 2 && buffOut[outSize - 2] == 0x90 &&
                buffOut[outSize - 1] == 0x00)
            {
                Console.WriteLine("selected file");
                return;
            }

            throw new Exception("select failed " + returnCode);
        }
Exemplo n.º 4
0
        private void select_appli()
        {
            byte[] byBuffIn   = new byte[] { 0x00, 0xA4, 0x04, 0x00, 0x07, 0xD2, 0x76, 0x00, 0x00, 0X85, 0x01, 0x01, 0x00 };
            byte[] buffOut    = new byte[200];
            int    outSize    = 300;
            int    returnCode = CSC.CSC_ISOCommand(byBuffIn, byBuffIn.Length, buffOut, ref outSize);

            Console.WriteLine("return code : " + returnCode);
            Console.WriteLine("buffout : " + CSC.ToStringN(buffOut));

            if (returnCode == CSC.RCSC_Ok && outSize > 2 && buffOut[outSize - 2] == 0x90 &&
                buffOut[outSize - 1] == 0x00)
            {
                Console.WriteLine("selected appli : " + CSC.ToStringN(buffOut));
                return;
            }

            throw new Exception("select failed " + returnCode);
        }
Exemplo n.º 5
0
        private void testWriteContent()
        {
            //create global buff in
            //byte[] byBuffIn = new byte[35] { 0x00, 0xD6, 0x00, 0x00, 0x00, 0x34, 0x91, 0x01, 0x11, 0x55, 0x01, 0x70, 0x61, 0x72, 0x61, 0x67, 0x6F, 0x6E, 0x2D, 0x72, 0x66, 0x69, 0x64, 0x2E, 0x63, 0x6F, 0x6D, 0x51, 0x01, 0x04, 0x54, 0x00, 0x50, 0x49, 0x44};
            //byte[] byBuffIn = new byte[10] { 0x00, 0xD6, 0x00, 0x00, 0x05, 0x00, 0x03, 0xD0, 0x00, 0x00 };

            byte[] byBuffIn = new byte[] { 0x00, 0xD6, 0x00, 0x00, 0x2D, 0x00, 0x2B, 0x91, 0x01, 0x0B, 0x55, 0x01, 0x67, 0x6F, 0x6F, 0x67, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x11, 0x01, 0x11, 0x54, 0x02, 0x66, 0x72, 0x43, 0x6F, 0x75, 0x63, 0x6F, 0x75, 0x20, 0x54, 0x69, 0x62, 0x6F, 0x77, 0x20, 0x21, 0x51, 0x00, 0x04, 0x31, 0x32, 0x33, 0x34, 0x65, 0xA9 };
            byte[] buffOut  = new byte[200];
            int    outSize  = 300;

            Console.WriteLine("buffIn : " + CSC.ToStringN(byBuffIn));
            int returnCode = CSC.CSC_ISOCommand(byBuffIn, byBuffIn.Length, buffOut, ref outSize);

            Console.WriteLine("buffout : " + CSC.ToStringN(buffOut));


            if (returnCode == CSC.RCSC_Ok && outSize > 2 && buffOut[outSize - 2] == 0x90 &&
                buffOut[outSize - 1] == 0x00)
            {
                Console.WriteLine("have been written");
                return;
            }
            throw new Exception("write failed " + returnCode);
        }
        public DbActionResult <IssueManagementCommentLog> Post(IssueManagementCommentLog items)
        {
            var    result     = new DbActionResult <IssueManagementCommentLog>();
            bool   EFlag      = false;
            string EmailTo    = "";
            string AncEmail   = "";
            string EmailCC    = "";
            string AnchorName = "";

            try
            {
                var data = items;

                string[] emailRegex = { "-", "<", ">", ";", "'" };
                for (var i = 0; i < emailRegex.Length; i++)
                {
                    if (data.ID_Comments != null)
                    {
                        data.ID_Comments = data.ID_Comments.Replace(emailRegex[i], " ");
                    }
                }

                var csc = new CSC();
                using (var dbcontext = new Teckraft.Data.Sql.InitiativeHubFinalEntities())
                {
                    //var chap = dbcontext.ChapterMasters.FirstOrDefault(it => it.ChapterNameFromSystem == data.id_System_Name && it.EmailFlag == true);
                    //if (chap != null)
                    //{
                    //    data.id_System_Name = chap.ChapterNameFromSystem;
                    //    EFlag = chap.EmailFlag.Value;
                    //    EmailTo = chap.EmailTo;
                    //}

                    var chap1 = dbcontext.ChapterMasters.FirstOrDefault(it => it.ChapterNameFromSystem == data.id_System_Name);
                    if (chap1 != null)
                    {
                        if (chap1.ChapterNameFromSystem == "Dealer Feedback" || chap1.ChapterNameFromSystem == "WSS Service Cell" || chap1.ChapterNameFromSystem == "MyPidilite" || chap1.ChapterNameFromSystem == "Customer Service Cell")
                        {
                            var em = dbcontext.ChapterMasters.FirstOrDefault(o => o.ChapterNameFromSystem == data.id_System_Name);
                            EmailCC  = em.EmailCC;
                            AncEmail = em.EmailTo;
                        }
                        else
                        {
                            string AncData = dbcontext.ChapterOwnerMappings.FirstOrDefault(it => it.ChapterId == chap1.Id).ChapterOwner.ToString();
                            AncEmail = dbcontext.UserDetails.FirstOrDefault(p => p.UserName == AncData).Email.ToString();
                        }
                        //for getting Anchor Name
                        var q = (from pd in dbcontext.ChapterOwnerMappings
                                 join od in dbcontext.UserDetails on pd.ChapterOwner equals od.UserName
                                 where pd.ChapterId == chap1.Id
                                 select new
                        {
                            od.Title,
                        }).FirstOrDefault();
                        if (q != null)
                        {
                            AnchorName = q.Title;
                        }
                    }


                    if (items.id_System_Name == "Customer Service Cell")
                    {
                        var cs = dbcontext.GetCSCDataBYRequestNo(items.ID_Request).FirstOrDefault();
                        csc.ContactEmail = cs.ContactEmail;
                        csc.ContactNo    = cs.contactNo;
                    }
                }

                data.RCB = _userservice.GetCurrentUser();
                data     = IssueService.Add(data);
                //if (EFlag == true) {
                //    if (data.EmailFlag == true && EmailTo != null) {
                //        var tmplt1 = templateService.GetTemplateforComments(data);
                //       // emailService.SendEmail(tmplt1, "*****@*****.**", EmailTo, "", "");
                //        emailService.SendEmail(tmplt1, "*****@*****.**", EmailTo, "*****@*****.**", "");
                //    }
                //}



                var tmplt1 = templateService.GetTemplateforAnchor(data, AnchorName, csc);
                //emailService.SendEmail(tmplt1, "[email protected] ", "*****@*****.**","", "");
                if (tmplt1.Subject != "")
                {
                    //emailService.SendEmail(tmplt1, "[email protected] ", "*****@*****.**", "", "");
                    emailService.SendEmail(tmplt1, "[email protected] ", AncEmail, EmailCC, "");
                }

                result.Success = true;
                result.Message = "Comments added successfully";
            }
            catch (Exception ex)
            {
                result.Success   = false;
                result.Message   = "Unable to Save Record!";
                result.Exception = ex;
            }

            return(result);
        }
Exemplo n.º 7
0
        public static EmailTemplate GetTemplateforAnchor(this IService <EmailTemplate> service, IssueManagementCommentLog item, string AnchorName, CSC csc)
        {
            string status = "";

            if (item.id_System_Name == "MyPidilite" || item.id_System_Name == "WSS Service Cell" || item.id_System_Name == "Dealer Feedback")
            {
                if (item.ID_Status != "" || item.ID_Status != null)
                {
                    if (item.ID_Status.ToLower() == "in progress")
                    {
                        status = "Open";
                    }
                    if (item.ID_Status.ToLower() == "completed")
                    {
                        status = "Closed";
                    }
                }
                return(new EmailTemplate("CWP - Comments update - by - " + item.RCB.Title)
                {
                    TemplateBody = "Dear " + AnchorName + "/Team, <br/> <br/> " +
                                   "Below is the comment added by " + item.RCB.Title + " for SR Number " + item.ID_Request +
                                   " - Please make relevant updates on your system for relevant action. <br/><br/>" +
                                   "Chapter Name:<b>: " + item.id_System_Name + " </b> <br/><br/> " +
                                   "Date and Time Stamp: <b>" + DateTime.Now + "</b><br/><br/>" +
                                   "Comments: <b>" + item.ID_Comments + "</b><br/><br/>" +
                                   "Status: <b>" + status + "</b> <br/><br/><br/><br/>" +
                                   "This is an auto generated mail, do not reply.  <br/><br/>"
                });
            }
            else if (item.id_System_Name == "Customer Service Cell")
            {
                if (item.ID_Status != "" || item.ID_Status != null)
                {
                    if (item.ID_Status.ToLower() == "in progress")
                    {
                        status = "Open";
                    }
                    if (item.ID_Status.ToLower() == "completed")
                    {
                        status = "Closed";
                    }
                }
                return(new EmailTemplate("CWP - Comments update - by - " + item.RCB.Title)
                {
                    TemplateBody = "Dear " + AnchorName + "/Team, <br/> <br/> " +
                                   "Below is the comment added by " + item.RCB.Title + " for SR Number " + item.ID_Request +
                                   " - Please make relevant updates on your system for relevant action. <br/><br/>" +
                                   "Chapter Name:<b>: " + item.id_System_Name + " </b> <br/><br/> " +
                                   "Date and Time Stamp: <b>" + DateTime.Now + "</b><br/><br/>" +
                                   "Comments: <b>" + item.ID_Comments + "</b><br/><br/>" +
                                   "Status: <b>" + status + "</b> <br/><br/>" +
                                   "Customer Mobile Number: <b>" + csc.ContactNo + "</b> <br/><br/>" +
                                   "Customer Email: <b>" + csc.ContactEmail + "</b> <br/><br/><br/><br/>" +
                                   "This is an auto generated mail, do not reply.  <br/><br/>"
                });
            }
            //else if (item.id_System_Name == "Dealer Feedback")
            //{
            //    return new EmailTemplate("CWP - Comments update - by - " + item.RCB.Title)
            //    {

            //        TemplateBody = "Dear " + AnchorName + "/Team, <br/> <br/> " +
            //        "Below is the comment added by " + item.RCB.Title + " for SR Number " + item.ID_Request +
            //        " - Please make relevant updates on your system for relevant action. <br/><br/>" +
            //        "Chapter Name:<b>: " + item.id_System_Name + " </b> <br/><br/> " +
            //        "Date and Time Stamp: <b>" + DateTime.Now + "</b><br/><br/>" +
            //        "Comments: <b>" + item.ID_Comments + "</b> <br/><br/><br/><br/>" +
            //        "This is an auto generated mail, do not reply.  <br/><br/>"
            //    };
            //}
            else
            {
                return(new EmailTemplate(""));
                //return new EmailTemplate("CWP - Comments update - by - " + item.RCB.Title)
                //{

                //    TemplateBody = "Dear " + AnchorName + "/Team, <br/> <br/> " +
                //    "Below is the comment added by " + item.RCB.Title + " for SR Number " + item.ID_Request +
                //    " - Please make relevant updates on your system for relevant action. <br/><br/>" +
                //    "Chapter Name:<b>: " + item.id_System_Name + " </b> <br/><br/> " +
                //    "Date and Time Stamp: <b>" + DateTime.Now + "</b><br/><br/>" +
                //    "Comments: <b>" + item.ID_Comments + "</b> <br/><br/><br/><br/>" +
                //    "This is an auto generated mail, do not reply.  <br/><br/>"

                //};
            }
            var query = new ListQuery <EmailTemplate>();

            query.PageSize    = 1;
            query.CurrentPage = 1;
            // query.AddParameter(new QueryParameter() { Name = "taskid", Value = TaskId.ToString() });
            return(service.GetByQuery(query).Items.FirstOrDefault());
        }
Exemplo n.º 8
0
		/// <summary>
		/// Returns whether a test previously succeeded.
		/// </summary>
		private bool GetPreviouslySucceeded(
			CSC.BuildService.Model.ProjectRunner.TestResult testResult, 
			IDictionary<string, TestResult> previousTestResults)
		{
			if (previousTestResults == null)
				return false;

			TestResult prevTestResult;
			previousTestResults.TryGetValue
			(
				$"{testResult.ClassName}.{testResult.TestName}", 
				out prevTestResult
			);

			if (prevTestResult != null)
			{
				return prevTestResult.Succeeded;
			}

			return false;
		}
Exemplo n.º 9
0
        /*
         * READING CODE
         */
        private void button2_Click(object sender, EventArgs e)
        {
            results.Clear();
            CSC.sCARD_SearchExtTag SearchExtender;
            int Status;

            byte[] ATR;
            ATR = new byte[200];
            int lgATR;

            lgATR = 200;
            int Com = 0;
            int SearchMask;

            txtCom.Text  = "";
            txtCard.Text = "";

            try
            {
                CSC.SearchCSC();
                // user can also use line below to speed up coupler connection
                //AskReaderLib.CSC.Open ("COM2");

                // Define type of card to be detected: number of occurence for each loop
                SearchExtender.CONT   = 0;
                SearchExtender.ISOB   = 2;
                SearchExtender.ISOA   = 2;
                SearchExtender.TICK   = 0;
                SearchExtender.INNO   = 0;
                SearchExtender.MIFARE = 0;
                SearchExtender.MV4k   = 0;
                SearchExtender.MV5k   = 0;
                SearchExtender.MONO   = 0;
                Status = CSC.CSC_EHP_PARAMS_EXT(1, 1, 0, 0, 0, 0, 0, 0, null, 0, 0);
                // Define type of card to be detected
                SearchMask = CSC.SEARCH_MASK_ISOB | CSC.SEARCH_MASK_ISOA;
                Status     = CSC.SearchCardExt(ref SearchExtender, SearchMask, 1, 20, ref Com, ref lgATR, ATR);
                Console.WriteLine("lgATr " + lgATR);
                Console.WriteLine("SearchExtender " + SearchExtender.ISOA + " " + SearchExtender.ISOB);
                Console.WriteLine("ATR", CSC.ToStringN(ATR));
                Console.WriteLine("Status " + Status);
                if (Status != CSC.RCSC_Ok)
                {
                    txtCom.Text = "Error :" + Status.ToString("X");
                }
                else
                {
                    txtCom.Text = Com.ToString("X");
                }
                if (Com == 2)
                {
                    txtCard.Text = "ISO14443A-4 no Calypso";
                }
                else if (Com == 3)
                {
                    txtCard.Text = "INNOVATRON";
                }
                else if (Com == 4)
                {
                    txtCard.Text = "ISOB14443B-4 Calypso";
                }
                else if (Com == 5)
                {
                    txtCard.Text = "Mifare";
                }
                else if (Com == 6)
                {
                    txtCard.Text = "CTS or CTM";
                }
                else if (Com == 8)
                {
                    txtCard.Text = "ISO14443A-3 ";
                }
                else if (Com == 9)
                {
                    txtCard.Text = "ISOB14443B-4 Calypso";
                }
                else if (Com == 12)
                {
                    txtCard.Text = "ISO14443A-4 Calypso";
                }
                else if (Com == 0x6F)
                {
                    txtCard.Text = "Card not found";
                }
                else
                {
                    txtCard.Text = "";
                }


                select_appli();
                select_file(new byte[] { 0xE1, 0x03 });
                var result = read_binary(0x0F);

                byte[] buffOut   = result.Key;
                int    read      = result.Value;
                short  maxLe     = (short)(buffOut[3] << 8 | buffOut[4]);
                int    maxLc     = buffOut[5] << 8 | buffOut[6];
                byte[] lid       = new byte[] { buffOut[9], buffOut[10] };
                int    maxLength = buffOut[11] << 8 | buffOut[12];

                select_file(new byte[] { lid[0], lid[1] });
                Console.WriteLine("maxLength : " + maxLength);
                Console.WriteLine("maxLe : " + maxLe);
                Console.WriteLine("maxLc : " + maxLc);

                //multiple readbinary in order to have the complete message
                var fileData = new List <byte>();
                for (Int16 i = 0; i < maxLength; i += maxLe)
                {
                    result = read_binary((Int16)Math.Min(maxLe, maxLength - i), i);
                    fileData.AddRange(result.Key);
                }


                Console.WriteLine(CSC.ToStringN(fileData.ToArray()) + "\n aa" + fileData.Count);
                readContent(fileData.ToArray());
            }
            catch (Exception exp)
            {
                Console.WriteLine("error :" + exp);
                MessageBox.Show("Error on trying do deal with reader");
            }

            AskReaderLib.CSC.Close();
        }
Exemplo n.º 10
0
        /*
         * WRITING CODE
         */
        private void Button1_Click(object sender, EventArgs e)
        {
            results.Clear();
            CSC.sCARD_SearchExtTag SearchExtender;
            int Status;

            byte[] ATR;
            ATR = new byte[200];
            int lgATR;

            lgATR = 200;
            int Com = 0;
            int SearchMask;

            txtCom.Text  = "";
            txtCard.Text = "";

            try
            {
                CSC.SearchCSC();
                // user can also use line below to speed up coupler connection
                //AskReaderLib.CSC.Open ("COM2");

                // Define type of card to be detected: number of occurence for each loop
                SearchExtender.CONT   = 0;
                SearchExtender.ISOB   = 2;
                SearchExtender.ISOA   = 2;
                SearchExtender.TICK   = 0;
                SearchExtender.INNO   = 0;
                SearchExtender.MIFARE = 0;
                SearchExtender.MV4k   = 0;
                SearchExtender.MV5k   = 0;
                SearchExtender.MONO   = 0;
                Status = CSC.CSC_EHP_PARAMS_EXT(1, 1, 0, 0, 0, 0, 0, 0, null, 0, 0);
                // Define type of card to be detected
                SearchMask = CSC.SEARCH_MASK_ISOB | CSC.SEARCH_MASK_ISOA;
                Status     = CSC.SearchCardExt(ref SearchExtender, SearchMask, 1, 20, ref Com, ref lgATR, ATR);
                Console.WriteLine("lgATr " + lgATR);
                Console.WriteLine("SearchExtender " + SearchExtender.ISOA + " " + SearchExtender.ISOB);
                Console.WriteLine("ATR", CSC.ToStringN(ATR));
                Console.WriteLine("Status " + Status);
                if (Status != CSC.RCSC_Ok)
                {
                    txtCom.Text = "Error :" + Status.ToString("X");
                }
                else
                {
                    txtCom.Text = Com.ToString("X");
                }
                if (Com == 2)
                {
                    txtCard.Text = "ISO14443A-4 no Calypso";
                }
                else if (Com == 3)
                {
                    txtCard.Text = "INNOVATRON";
                }
                else if (Com == 4)
                {
                    txtCard.Text = "ISOB14443B-4 Calypso";
                }
                else if (Com == 5)
                {
                    txtCard.Text = "Mifare";
                }
                else if (Com == 6)
                {
                    txtCard.Text = "CTS or CTM";
                }
                else if (Com == 8)
                {
                    txtCard.Text = "ISO14443A-3 ";
                }
                else if (Com == 9)
                {
                    txtCard.Text = "ISOB14443B-4 Calypso";
                }
                else if (Com == 12)
                {
                    txtCard.Text = "ISO14443A-4 Calypso";
                }
                else if (Com == 0x6F)
                {
                    txtCard.Text = "Card not found";
                }
                else
                {
                    txtCard.Text = "";
                }


                select_appli();
                select_file(new byte[] { 0xE1, 0x03 });
                var result = read_binary(0x0F);

                byte[] buffOut   = result.Key;
                int    read      = result.Value;
                short  maxLe     = (short)(buffOut[3] << 8 | buffOut[4]);
                int    maxLc     = buffOut[5] << 8 | buffOut[6];
                byte[] lid       = new byte[] { buffOut[9], buffOut[10] };
                int    maxLength = buffOut[11] << 8 | buffOut[12];

                select_file(new byte[] { lid[0], lid[1] });
                Console.WriteLine("maxLength : " + maxLength);
                Console.WriteLine("maxLe : " + maxLe);
                Console.WriteLine("maxLc : " + maxLc);

                //get infos from box in UI
                string texte    = RawBox.Text;
                string data     = TextBox.Text;
                string uri      = UriBox.Text;
                string protocol = listBox1.Text;


                writeContent(maxLc, uri, texte, data, protocol);
                //testWriteContent();

                Console.WriteLine("outOfwrite");
            }
            catch (Exception exp)
            {
                Console.WriteLine("error :" + exp);
                MessageBox.Show("Error on trying do deal with reader");
            }

            AskReaderLib.CSC.Close();
        }
Exemplo n.º 11
0
        private void writeContent(int maxLc, string uri, string texte, string data, string protocol)
        {
            byte protocolId = 0x00;

            switch (protocol)
            {
            case "http://www.":
                protocolId = 0x01;
                break;

            case "https://www.":
                protocolId = 0x02;
                break;

            case "http://":
                protocolId = 0x03;
                break;

            case "https://":
                protocolId = 0x04;
                break;
            }

            Console.WriteLine("protocolId : " + protocolId);

            byte[] uriBytes  = Encoding.UTF8.GetBytes(uri);
            byte[] textBytes = Encoding.UTF8.GetBytes(texte);
            byte[] dataBytes = Encoding.UTF8.GetBytes(data);

            //creating total uri bytes bloc
            //TO DO add uri identifier in parameters of function.
            byte[] totalUriBytes = new byte[5 + uriBytes.Length];
            //dansle cas particulier de apple.com
            byte[] uriCommand = new byte[] { 0x91, 0x01, (byte)(uriBytes.Length + 1) /*length*/, 0x55, protocolId };
            uriCommand.CopyTo(totalUriBytes, 0);
            uriBytes.CopyTo(totalUriBytes, uriCommand.Length);
            Console.WriteLine("totalUriBytes : " + CSC.ToStringN(totalUriBytes) + " nbr:" + totalUriBytes.Length);

            //creating total data bytes bloc
            byte[] totalDataBytes = new byte[7 + dataBytes.Length];
            byte[] dataCommand    = new byte[] { 0x11, 0x01, (byte)(dataBytes.Length + 3) /*length*/, 0x54 /*T*/, 0x02 /*UTF8*/, 0x66, 0x72 };
            dataCommand.CopyTo(totalDataBytes, 0);
            dataBytes.CopyTo(totalDataBytes, dataCommand.Length);
            Console.WriteLine("totalDatabytes : " + CSC.ToStringN(totalDataBytes) + " nbr:" + totalDataBytes.Length);


            //creating raw data
            byte[] totalTextBytes = new byte[textBytes.Length + 3];
            byte[] textCommand    = new byte[] { 0x51, 0x00, (byte)(textBytes.Length) };
            textCommand.CopyTo(totalTextBytes, 0);
            textBytes.CopyTo(totalTextBytes, textCommand.Length);
            Console.WriteLine("totalTextbytes : " + CSC.ToStringN(totalTextBytes) + " nbr:" + totalTextBytes.Length);


            //data
            byte[] dataToWrite = new byte[totalUriBytes.Length + totalDataBytes.Length + totalTextBytes.Length];
            totalUriBytes.CopyTo(dataToWrite, 0);
            totalDataBytes.CopyTo(dataToWrite, totalUriBytes.Length);
            totalTextBytes.CopyTo(dataToWrite, totalUriBytes.Length + totalDataBytes.Length);

            //command
            byte[] command = new byte[] { 0x00, 0xD6 };
            //offset
            byte[] offset = new byte[] { 0x00, 0x00 };
            //total length
            byte[] totalLength = new byte[] { (byte)(dataToWrite.Length + 2), 0x00, (byte)(dataToWrite.Length) };

            //create global buff in
            byte[] byBuffIn = new byte[command.Length + offset.Length + totalLength.Length /*+ header.Length*/ + dataToWrite.Length];
            command.CopyTo(byBuffIn, 0);
            offset.CopyTo(byBuffIn, command.Length);
            totalLength.CopyTo(byBuffIn, command.Length + offset.Length);
            dataToWrite.CopyTo(byBuffIn, command.Length + offset.Length + totalLength.Length /*+ header.Length*/);

            byte[] buffOut = new byte[200];
            int    outSize = 300;

            Console.WriteLine("buffIn : " + CSC.ToStringN(byBuffIn));
            int returnCode = CSC.CSC_ISOCommand(byBuffIn, byBuffIn.Length, buffOut, ref outSize);

            Console.WriteLine("buffout : " + CSC.ToStringN(buffOut));


            if (returnCode == CSC.RCSC_Ok && outSize > 2 && buffOut[outSize - 2] == 0x90 &&
                buffOut[outSize - 1] == 0x00)
            {
                Console.WriteLine("have been written");
                return;
            }
            throw new Exception("write failed " + returnCode);
        }
Exemplo n.º 12
0
        private long getNextMessage(byte[] bytes, long startIndex)
        {
            var  header   = bytes[++startIndex];
            var  bitArray = new BitArray(new byte[] { header });
            var  mb       = bitArray[7];
            var  me       = bitArray[6];
            var  cf       = bitArray[5];
            var  sr       = bitArray[4];
            var  il       = bitArray[3];
            byte tnf      = (byte)(header & 0x07);

            Console.WriteLine("mb: " + mb + " me: " + me + " cf: " + cf + " sr: " + sr + " il: " + il + " tnf: " + Convert.ToString(tnf, 2).PadLeft(3, '0'));

            //champ type length
            var typeLength = bytes[++startIndex];

            Console.WriteLine("typeLength = " + typeLength);

            //champ payload length
            long payloadLength = 0;

            if (sr)
            {
                payloadLength = bytes[++startIndex];
            }
            else
            {
                var subArray = slice(bytes, startIndex, startIndex + 3);
                payloadLength = convertByteArrayToInt(subArray);
                startIndex   += 4;
            }
            //Console.WriteLine("payloadLength = " + payloadLength);

            int idLength = 0;

            if (il)
            {
                idLength = bytes[++startIndex];
            }
            //Console.WriteLine("idLength = " + idLength);
            //champs type
            byte[] type = slice(bytes, startIndex + 1, startIndex + typeLength); //indice à changer pour la suite
            //Console.WriteLine("type : " + CSC.ToStringN(type));
            //Console.WriteLine("type : " + convertByteArrayToInt( type));
            startIndex += typeLength;

            //champs id
            byte[] id = new byte[idLength];
            if (il)
            {
                //id en fonction de idLength
                id          = slice(bytes, startIndex + 1, startIndex + idLength);
                startIndex += idLength;
                //Console.WriteLine("id : " + CSC.ToStringN(id));
                results.Add("id : " + CSC.ToStringN(id));
            }



            if (typeLength == 1)
            {
                startIndex++;
                if (type[0] == 0x54)
                {
                    //Console.WriteLine("type is text");
                    //Console.WriteLine("next : " + bytes[startIndex]);
                    var isUTF16Encoded = false;
                    var languageLength = bytes[startIndex];
                    if (isUTF16Encoded)
                    {
                        languageLength--;
                    }
                    var language = "";
                    if (languageLength != 0)
                    {
                        language = Encoding.UTF8.GetString(slice(bytes, startIndex, startIndex + languageLength));
                    }
                    //Console.WriteLine("language : " + language);

                    var message = "";
                    if (isUTF16Encoded)
                    {
                        message = System.Text.Encoding.Unicode.GetString(slice(bytes, startIndex + languageLength + 1, startIndex + payloadLength - 1));
                        //Console.WriteLine("message utf16 : " + message);
                        results.Add("message utf16: " + message + ".Language is " + language);
                    }
                    else
                    {
                        message = System.Text.Encoding.UTF8.GetString(slice(bytes, startIndex + languageLength + 1, startIndex + payloadLength - 1));
                        //Console.WriteLine("message utf8 : " + message);
                        results.Add("message utf8 : message = " + message + ", Language = " + language);
                    }
                    startIndex += payloadLength - 1;
                }
                else if (type[0] == 0x55)
                {
                    //Console.WriteLine("type is URI");

                    var UriIdentifier = "";

                    switch (bytes[startIndex])
                    {
                    case 0x00:
                        UriIdentifier = "N/A";
                        break;

                    case 0x01:
                        UriIdentifier = "http://www.";
                        break;

                    case 0x02:
                        UriIdentifier = "https://www.";
                        break;

                    case 0x03:
                        UriIdentifier = "http://";
                        break;

                    case 0x04:
                        UriIdentifier = "https://";
                        break;
                    }
                    //Console.WriteLine("UriIdentifier : " + UriIdentifier);
                    var uri = slice(bytes, startIndex + 1, startIndex + payloadLength - 1);
                    //Console.WriteLine("uri : " + Encoding.UTF8.GetString(uri));
                    startIndex += payloadLength - 1;
                    results.Add("Uri : " + UriIdentifier + Encoding.UTF8.GetString(uri));
                }
                else
                {
                    //Console.WriteLine("type not supported and should probably be URI or Text");
                    results.Add("type not supported and should probably be smart poster");
                }
            }
            else if (typeLength == 2)
            {
                if ((type[1] == 0x70) && (type[0] == 0x53))
                {
                    //Console.WriteLine("type is smart poster");
                    results.Add("smartposter");
                }
                else
                {
                    //Console.WriteLine("type not supported and should probably be smart poster");
                    results.Add("type not supported and should probably be smart poster");
                }
            }
            else
            {
                //Console.WriteLine("type is Raw");
                var message = Encoding.UTF8.GetString(slice(bytes, startIndex + 1, startIndex + payloadLength));
                //Console.WriteLine("message : " + message);
                startIndex += payloadLength - 1;
                results.Add("Raw : message = " + message);
            }

            return(startIndex);
        }