private SAMType findCompatibleSAM(Tag aTag)
        {
            SAMType lType = SAMType.Unknown;

            detectedTag = "UNKNOWN";

            if (isNDEFTag(aTag))
            {
                //NDEF Tag
                detectedTag = "NDEF";
            }
            else if (isFelicaTag(aTag))
            {
                lType       = SAMType.Felica;
                detectedTag = "FELICA";
            }
            else if (isMIFAREClassicTag(aTag))
            {
                lType       = SAMType.Mifare;//MIFARE_CLASSIC;
                detectedTag = "MIFARE_CLASSIC";
            }
            else if (isMIFARETag(aTag))
            {
                lType = SAMType.Mifare;
            }
            return(lType);
        }
Beispiel #2
0
        public static ElementType DuplicateByName(this Document document, SAMType samType_Old, BuiltInCategory builtInCategory, string name_New, IEnumerable <string> parameterNames = null)
        {
            if (samType_Old == null || document == null || string.IsNullOrWhiteSpace(name_New) || builtInCategory == BuiltInCategory.INVALID)
            {
                return(null);
            }

            List <ElementType> elementTypes = new FilteredElementCollector(document).OfClass(typeof(ElementType)).OfCategory(builtInCategory).Cast <ElementType>().ToList();

            if (elementTypes == null || elementTypes.Count == 0)
            {
                return(null);
            }

            ElementType elementType = elementTypes.Find(x => x.Name.Equals(name_New));

            if (elementType == null)
            {
                ElementType elementType_ToBeDuplicated = elementTypes.Find(x => x.Name.Equals(samType_Old.Name));
                if (elementType_ToBeDuplicated == null)
                {
                    return(null);
                }

                elementType = elementType_ToBeDuplicated.Duplicate(name_New);
            }

            if (elementType == null)
            {
                return(null);
            }

            SetValues(elementType, samType_Old, parameterNames);

            return(elementType);
        }
        private void tagDetection(Intent intent)
        {
            tagOperationInProgress = true;

            if (samManager == null)
            {
                initSAMManager();
            }

            if (NfcAdapter.ActionNdefDiscovered.Equals(intent.Action) ||
                NfcAdapter.ActionTagDiscovered.Equals(intent.Action) ||
                NfcAdapter.ActionTechDiscovered.Equals(intent.Action))
            {
                Tag     lTag          = (Tag)intent.GetParcelableExtra(NfcAdapter.ExtraTag);
                SAM     sam           = null;
                SAMType samTypeForTag = null;

                samTypeForTag = findCompatibleSAM(lTag);

                string text = detectedTag + " " + GetString(Resource.String.message_tag_detected) + "\n";

                string compatibeSAMText = "";


                foreach (KeyValuePair <int, SAM> entry in presetSAMList)
                {
                    if (entry.Value.SamType == samTypeForTag)
                    {
                        sam = entry.Value;
                        compatibeSAMText += "\n\t" + sam.SamType + "(Slot " + sam.SamIndex + ")";
                    }
                }


                if (presetSAMList.Count > 0)
                {
                    if (compatibeSAMText != "")
                    {
                        text += GetString(Resource.String.message_tag_compatible) + " " + compatibeSAMText;

                        /**
                         * Connect to the appropriate SAM based on the Tag detected.
                         */
                        /**
                         * //Connect [Start]
                         * try
                         * {
                         *   if (!sam.IsConnected)
                         *   {
                         *       sam.Connect();
                         *   }
                         * }
                         * catch (SAMException ex)
                         * {
                         *   SAMResults.GetErrorDescription(ex.Result);
                         * }
                         * //Connect [End]
                         *
                         * //Transceive [Start]
                         *
                         * byte[] response = null;
                         * try
                         * {
                         *   response = sam.Transceive(transceive_apdu_1, (short)0, false);
                         *   response = sam.Transceive(transceive_apdu_2, (short)0, false);
                         *   response = sam.Transceive(transceive_apdu_3, (short)0, false);
                         *   response = sam.Transceive(transceive_apdu_4, (short)0, false);
                         *
                         * }
                         * catch (SAMException ex)
                         * {
                         *   SAMResults.GetErrorDescription(ex.Result);
                         * }
                         * //Transceive [End]
                         *
                         * //Disconnect [Start]
                         * if (sam.IsConnected)
                         * {
                         *   sam.Disconnect();
                         * }
                         * //Disconnect [End]
                         */
                    }
                    else
                    {
                        text += GetString(Resource.String.message_tag_not_compatible);
                    }
                }
                updateStatus(text);
            }
        }