public TagViewModel(NfcTag model)
 {
     this.Model = model;
     _dirtyFlag = new DirtyState();
     _dirtyFlag.SetComparer(() => DirtyStateBuilder.BuildComparisonString(this.Tag,
                                                                          this.IsLocked));
 }
        public void DeleteNfcTag(NfcTag nfcTag)
        {
            if (!Directory.Exists(NfcTagsPath))
                throw new DirectoryNotFoundException("The Nfc Tag Directory is not valid.");

            var fileName = ConvertIdToFileName(NfcTagsPath, nfcTag.Id);

            try
            {
                if (File.Exists(fileName))
                    File.Delete(fileName);
            }
            catch (Exception e)
            {
                throw new Exception("An error occurred during the cleanup of the nfc tag file. Please try again.", e);
            }
        }
 public void RemoveNfcTag(NfcTag nfcTag)
 {
     lock (_lock)
     {
         this._dataService.GetDataSource().DeleteNfcTag(nfcTag);
         CollectionChanged();
     }
 }
 public void EditNfcTag(NfcTag nfcTag)
 {
     lock (_lock)
     {
         this._dataService.GetDataSource().SaveNfcTag(nfcTag);
         CollectionChanged();
     }
 }
        public NfcTag CreateNfcTag()
        {
            var nfcTag = new NfcTag();
            nfcTag.Id = String.Empty;
            nfcTag.IsLocked = false;
            nfcTag.Tag = String.Empty;
            nfcTag.UserId = String.Empty;

            return nfcTag;
        }
 public NfcTag CreateCopy(NfcTag tag)
 {
     return new NfcTag()
     {
         Id = tag.Id,
         IsLocked = tag.IsLocked,
         Tag = tag.Tag,
         UserId = tag.UserId
     };
 }
        public void SaveNfcTagCreateNewTest()
        {
            var dataSource = new NFCAccessControlDataSources.XMLDataSource.XmlDataSource();

            var nfcTag = new NfcTag();

            nfcTag.Tag = Guid.NewGuid().ToString();
            nfcTag.IsLocked = false;

            dataSource.SaveNfcTag(nfcTag);
        }
        public void SaveNfcTag(NfcTag nfcTag)
        {
            if (!Directory.Exists(NfcTagsPath))
                throw new DirectoryNotFoundException("The Nfc Tags Directory is not valid.");

            if (String.IsNullOrEmpty(nfcTag.Id))
                nfcTag.Id = Guid.NewGuid().ToString();

            var fileName = ConvertIdToFileName(NfcTagsPath, nfcTag.Id);

            try
            {
                XmlSerializer mySerializer = new XmlSerializer(typeof(NfcTag));

                using (StreamWriter myWriter = new StreamWriter(fileName))
                {
                    mySerializer.Serialize(myWriter, nfcTag);
                }

                SignXmlFile(fileName);
            }
            catch (Exception e)
            {
                throw new Exception("An error occurred during the save process. Please try again.", e);
            }
        }