private static void DisplayLogEntries(List <byte[]> entries, List <Tag> format) { for (int i = 0; i < format.Count; i++) { Console.Write($"{TagList.Tags.Where(m => m.TagNumber == format[i].TagNumber).FirstOrDefault()?.Description} | "); } Console.WriteLine(); foreach (var entry in entries) { int index = 0; for (int i = 0; i < format.Count; i++) { var data = entry.AsSpan().Slice(index, format[i].Data[0]); var tg = new TagDetails(new Tag() { TagNumber = format[i].TagNumber, Data = data.ToArray() }); Console.Write($"{tg.ToString()} | "); index += format[i].Data[0]; } Console.WriteLine(); } }
protected void btnCreateTag_Click(object sender, EventArgs e) { if (SessionManager.IsUserAuthenticated(Context)) { if (txtTag.Text.ToString().Equals("")) { lblTagError.Visible = true; lblTagError.Text = GetLocalResourceObject("lblTagError.Text").ToString(); } else { Int32 productId = Convert.ToInt32(Request.Params.Get("productId")); TagDetails newTag = new TagDetails(txtTag.Text); try { lblTagError.Visible = false; long tagId = SessionManager.TagService.AddNewTag(newTag); SessionManager.TagService.TagProduct(productId, tagId); InitializeProductTags(); txtTag.Text = null; Response.Redirect(Request.RawUrl.ToString()); } catch (DuplicateInstanceException) { lblTagError.Visible = true; lblTagError.Text = GetLocalResourceObject("TagExists").ToString(); } } } else { lblAuntenticated.Visible = true; } }
private static void DisplayTags(List <Tag> tagToDisplay, int levels) { foreach (var tagparent in tagToDisplay) { Console.Write(AddSpace(levels) + $"{tagparent.TagNumber.ToString("X4")}-{TagList.Tags.Where(m => m.TagNumber == tagparent.TagNumber).FirstOrDefault()?.Description}"); var isTemplate = TagList.Tags.Where(m => m.TagNumber == tagparent.TagNumber).FirstOrDefault(); if ((isTemplate?.IsTemplate == true) || (isTemplate?.IsConstructed == true)) { Console.WriteLine(); DisplayTags(tagparent.Tags, levels + 1); } else if (isTemplate?.IsDol == true) { // In this case, all the data inside are 1 byte only Console.WriteLine(", Data Object Length elements:"); foreach (var dt in tagparent.Tags) { Console.Write(AddSpace(levels + 1) + $"{dt.TagNumber.ToString("X4")}-{TagList.Tags.Where(m => m.TagNumber == dt.TagNumber).FirstOrDefault()?.Description}"); Console.WriteLine($", data length: {dt.Data[0]}"); } } else { TagDetails tg = new TagDetails(tagparent); Console.WriteLine($": {tg.ToString()}"); } } }
public TagDetails GetTagDetails(Tag tag) { TagDetails details = new TagDetails(); details.TagName = tag.Name; details.TagID = tag.ID; using (SqlConnection conn = new SqlConnection(_connectionString)) { conn.Open(); string command_string = "select min(Captured), max(Captured), count(*), max(Photos.ID) from Photos " + "INNER JOIN PhotoTags ON Photos.ID = PhotoTags.Photo_ID " + "INNER JOIN Tags ON PhotoTags.Tag_ID = Tags.ID " + "where PhotoTags.Tag_ID = @tagID"; using (SqlCommand command = new SqlCommand(command_string, conn)) { command.Parameters.AddWithValue("@tagID", tag.ID); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { details.First = reader.GetDateTime(0); details.Last = reader.GetDateTime(1); details.PhotoCount = reader.GetInt32(2); details.LastPhotoID = reader.GetInt64(3); } } } } return(details); }
protected virtual TagDetails ExtractTagData(IValidationResult validationResult) { var tag = validationResult.Tag; var tagDetails = new TagDetails(); if (ReferenceEquals(tag, null)) { return(tagDetails); } if (tag is string) { return(tagDetails); } var type = tag.GetType(); var lineProperty = type.GetPropertyEx("Line"); tagDetails.Line = lineProperty?.GetValue(tag, new object[0]) as int?; var columnNameProperty = type.GetPropertyEx("ColumnName"); tagDetails.ColumnName = columnNameProperty?.GetValue(tag, new object[0]) as string; var columnIndexProperty = type.GetPropertyEx("ColumnIndex"); tagDetails.ColumnIndex = columnIndexProperty?.GetValue(tag, new object[0]) as int?; return(tagDetails); }
public static PSTag ToPSTag(this TagDetails tag) { return(new PSTag() { Count = tag.Count.Value, Name = tag.Name, Values = tag.Values.Select(v => v.ToPSTagValue()).ToList(), ValuesTable = ConstructTagValuesTable(tag.Values.ToList()) }); }
public JsonResult AddTagReference([FromBody] TagDetails tagDetails) { var userId = GetUser(); if (tagDetails.TagId == null) { tagDetails.TagId = _tagRepository.Upload(userId, tagDetails.Tag, 2, tagDetails.Color); } _tagRepository.UploadReference(userId, (int)tagDetails.TagId, tagDetails.YouTubeId); return(Json("")); }
private void LoadTags() { List <TagDetails> tags = SessionManager.GetAllTags(); TagDetails tag1 = new TagDetails(-1, "Select a tag", 0); tags.Add(tag1); tagList.DataSource = tags; tagList.DataTextField = "name"; tagList.DataValueField = "tagId"; tagList.DataBind(); tagList.SelectedValue = "-1"; }
private void LoadUntag() { Int32 productId = Convert.ToInt32(Request.Params.Get("productId")); List <TagDetails> tags = SessionManager.TagService.GetTagsByProduct(productId); TagDetails tag1 = new TagDetails(-1, "Select a tag", 0); tags.Add(tag1); untagList.DataSource = tags; untagList.DataTextField = "name"; untagList.DataValueField = "tagId"; untagList.DataBind(); untagList.SelectedValue = "-1"; }
public TagDetails FinTagById(long tagId) { Tag tag = null; TagDetails tagDetail = null; try { tag = TagDao.Find(tagId); tagDetail = new TagDetails(tag.tagId, tag.name, tag.timesUsed); } catch (InstanceNotFoundException e) { throw new InstanceNotFoundException(tagId, "Tag no encontrada"); } return(tagDetail); }
public static TagDetailsResource ToResource(this TagDetails model) { if (model == null) { return(null); } return(new TagDetailsResource { Id = model.Id, Label = model.Label, NotificationIds = model.NotificationIds, IndexerIds = model.IndexerIds, IndexerProxyIds = model.IndexerProxyIds }); }
public static TagDetailsResource ToResource(this TagDetails model) { if (model == null) { return(null); } return(new TagDetailsResource { Id = model.Id, Label = model.Label, DelayProfileIds = model.DelayProfileIds, NotificationIds = model.NotificationIds, RestrictionIds = model.RestrictionIds, SeriesIds = model.SeriesIds }); }
private ThumbnailModel GetDetailsForTag(Tag tag) { TagDetails details = PhotoRepository.GetTagDetails(tag); details.CoverPhotoID = details.LastPhotoID; return(new ThumbnailModel() { ID = details.TagID, Name = details.TagName, First = details.First, Last = details.Last, PhotoCount = details.PhotoCount, CoverPhotoID = details.CoverPhotoID, Link = "/search/index?tag=" + details.TagName }); }
public static TagDetailsResource ToResource(this TagDetails model) { if (model == null) { return(null); } return(new TagDetailsResource { Id = model.Id, Label = model.Label, DelayProfileIds = model.DelayProfileIds, NotificationIds = model.NotificationIds, RestrictionIds = model.RestrictionIds, ImportListIds = model.ImportListIds, MovieIds = model.MovieIds, IndexerIds = model.IndexerIds }); }
public long AddNewTag(TagDetails newTag) { Tag tag = null; try { Tag t = TagDao.GetTagByName(newTag.name); throw new DuplicateInstanceException(newTag.name, typeof(Tag).FullName); } catch (InstanceNotFoundException) { tag = new Tag(); tag.name = newTag.name; tag.timesUsed = 0; TagDao.Create(tag); } return(tag.tagId); }
public void Get_WhenFound_ReturnsTagDetails() { // arrange const int TAG_ID = 123; var expectedDetails = new TagDetails { Id = TAG_ID }; _mockTagRepository.Setup(r => r.Fetch(It.IsAny <long>())).Returns(expectedDetails); // act var result = _tagsController.Get(TAG_ID); // assert Assert.IsInstanceOfType(result, typeof(JsonResult)); var jsonResult = (JsonResult)result; Assert.IsInstanceOfType(jsonResult.Value, typeof(TagDetails)); var actualDetails = (TagDetails)jsonResult.Value; Assert.AreEqual(TAG_ID, actualDetails.Id); }
private int IsPopular(TagDetails tagD) { int pos = -1; List <TagDetails> tagDetails = SessionManager.TagService.GetMostPopularTags(8); int count = 0; foreach (TagDetails tag in tagDetails) { if (tag.tagId == tagD.tagId && count < 3) { pos = 1; break; } else if (tag.tagId == tagD.tagId && count > 2) { pos = 2; break; } count++; } return(pos); }
/// <summary> /// Wait for the NFC reader to get the credit card data /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult <JObject> GetNfcAuthentication(string id) { byte[] retData = null; var ccAuth = new CreditCardAuthenticated(); dynamic resp = new JObject(); CreditCard creditCard = null; try { if (_nfcWrapper.HasNfc) { // This try/catch allow this method to work on any machine, even if come does not work. // So if it does not work (i.e. error caught, then a dummy object is returned) DateTimeOffset timeout = DateTimeOffset.Now.AddMilliseconds(TimeOutNfcAuthenticationMillisecond); while ((timeout > DateTimeOffset.Now)) { // PollingType.InnovisionJewel, PollingType.DepActive106kbps, PollingType.DepPassive106kbps,PollingType.Passive106kbpsISO144443_4A, PollingType.Passive106kbpsISO144443_4A, PollingType.GenericPassive106kbps, PollingType.MifareCard, PollingType.Passive106kbps retData = _nfc.AutoPoll(5, 300, new PollingType[] { PollingType.Passive106kbpsISO144443_4B }); if (retData != null) { break; } // Give time to PN532 to process Thread.Sleep(50); } if (retData == null) { resp.status = false; resp.value = "Could not read the card"; return(resp); } if (retData.Length < 3) { resp.status = false; resp.value = "Could not read the card"; return(resp); } //Check how many tags and the type // Console.WriteLine($"Num tags: {retData[0]}, Type: {(PollingType)retData[1]}"); var decrypted = _nfc.TryDecodeData106kbpsTypeB(retData.AsSpan().Slice(3)); if (decrypted != null) { //Console.WriteLine($"{decrypted.TargetNumber}, Serial: {BitConverter.ToString(decrypted.NfcId)}, App Data: {BitConverter.ToString(decrypted.ApplicationData)}, " + // $"{decrypted.ApplicationType}, Bit Rates: {decrypted.BitRates}, CID {decrypted.CidSupported}, Command: {decrypted.Command}, FWT: {decrypted.FrameWaitingTime}, " + // $"ISO144443 compliance: {decrypted.ISO14443_4Compliance}, Max Frame size: {decrypted.MaxFrameSize}, NAD: {decrypted.NadSupported}"); creditCard = new CreditCard(_nfc, decrypted.TargetNumber); } } else if (_nfcWrapper.HasSmartCard) { DateTimeOffset timeout = DateTimeOffset.Now.AddMilliseconds(TimeOutNfcAuthenticationMillisecond); while ((timeout > DateTimeOffset.Now)) { if (_nfcWrapper.SmartCard.IsCardPResent) { creditCard = new CreditCard(_nfcWrapper.SmartCard, 0, 2); break; } } } if (creditCard != null) { creditCard.ReadCreditCardInformation(); // Console.WriteLine("All Tags for the Credit Card:"); // Find 0x5A = PAN = Credit Card number var ccForAuth = new CreditCardForAuthentication(); var searchedTag = Tag.SearchTag(creditCard.Tags, 0x5A); if (searchedTag.Count > 0) { TagDetails tg = new TagDetails(searchedTag.FirstOrDefault()); ccForAuth.CardNumber = CleanText(tg.ToString()); // 0x59 expiration date searchedTag = Tag.SearchTag(creditCard.Tags, 0x59); if (searchedTag.Count == 0) { // 0x59 expiration date searchedTag = Tag.SearchTag(creditCard.Tags, 0x5F24); } if (searchedTag.Count > 0) { tg = new TagDetails(searchedTag.FirstOrDefault()); ccForAuth.Expiration = new DateTimeOffset(2000 + BcdToInt(tg.Data[0]), BcdToInt(tg.Data[1]), BcdToInt(tg.Data[2]), 0, 0, 0, TimeSpan.Zero); } } if (String.IsNullOrEmpty(ccForAuth.CardNumber)) { // Find 0x57 Track2 if no 5A searchedTag = Tag.SearchTag(creditCard.Tags, 0x57); // The Date is encoded with a separated car like XX XX XX XX XX XX XX XX DY YM MX if (searchedTag.Count > 0) { var data = searchedTag.FirstOrDefault().Data; ccForAuth.CardNumber = BitConverter.ToString(data, 0, 8); ccForAuth.CardNumber = CleanText(ccForAuth.CardNumber); // The Date is encoded with a separated car like XX XX XX XX XX XX XX XX DY YM MX var year = 2000 + BcdToInt((byte)(data[8] << 8 + (data[9] >> 8))); var month = BcdToInt((byte)(data[9] << 8 + (data[10] >> 8))); ccForAuth.Expiration = new DateTimeOffset(year, month, 1, 0, 0, 0, TimeSpan.Zero); } } if (String.IsNullOrEmpty(ccForAuth.CardNumber)) { resp.status = false; resp.value = "No card number found"; return(resp); } // TODO: Call for the authentication // http://bankioskapi.azurewebsites.net/api/customers/getbycard/5255591532318986 HttpClient client = new HttpClient(); client.BaseAddress = new Uri(_apiUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync($"customers/getbycard/{ccForAuth.CardNumber}").GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { // Parse the response body. var customer = response.Content.ReadAsAsync <Customer>().Result; //Make sure to add a reference to System.Net.Http.Formatting.dll Debug.WriteLine($"Found customer {customer?.RowKey} {customer?.FirstName} {customer?.Surname}"); if (customer == null) { resp.status = false; resp.value = "No customer with this card found"; return(resp); } // Do we really have someone? if ((String.IsNullOrEmpty(customer.FirstName)) && (String.IsNullOrEmpty(customer.FirstName))) { resp.status = false; resp.value = "No customer with this card found"; return(resp); } // Is it the same ID? if (customer.RowKey.ToLower() != id.ToLower()) { resp.status = false; resp.value = "Customer id mismatch"; return(resp); } } else { Debug.WriteLine($"Error {response.StatusCode} ({response.ReasonPhrase})"); resp.status = false; resp.value = "Could not find a customer with this id - or the service failed"; return(resp); } // Let's assume we are authenticated ccAuth.IsAuthenticated = true; // Find all 0x9F36 tag Transaction count searchedTag = Tag.SearchTag(creditCard.Tags, 0x9F36); if (searchedTag.Count > 0) { ccAuth.NumberOperation = 0; for (int i = 0; i < searchedTag.Count; i++) { ccAuth.NumberOperation = BinaryPrimitives.ReadUInt16BigEndian(searchedTag[i].Data); } } // Find 0x9F17 PinTry Counter searchedTag = Tag.SearchTag(creditCard.Tags, 0x9F17); if (searchedTag.Count > 0) { ccAuth.PinRetryLeft = searchedTag.FirstOrDefault().Data[0]; } ccAuth.ExpirationDate = ccForAuth.Expiration; resp.status = true; resp.value = JsonConvert.SerializeObject(ccAuth); return(resp); } else { // No NFC => send dummy data resp.status = true; ccAuth.ExpirationDate = DateTimeOffset.Now.AddYears(2); ccAuth.IsAuthenticated = true; ccAuth.NumberOperation = 340; ccAuth.PinRetryLeft = 2; resp.value = JsonConvert.SerializeObject(ccAuth); return(resp); } } catch (Exception ex) { resp.status = false; resp.value = $"Exception: {ex.ToString()}"; return(resp); } }
public List <TagExperimentAnalysis> GetTestEx2Data(int totalParticipants, TagModel[] tags, SculptureModel[] sculptures) { this.Tags = tags.Select(t => t.Name).ToList(); this.Sculptures = sculptures.Select(s => s.SculptureId).ToList(); var analysisDatas = new List <TagExperimentAnalysis>(); for (int p = 0; p < totalParticipants; p++) { TagExperimentAnalysis analysisData = new TagExperimentAnalysis(); analysisData.ParticipantIdentifier = Guid.NewGuid(); analysisData.TotalTime = new TimeSpan(0, rand.Next(1, 35), 0); //start with groups var totalGroups = rand.Next(1, this.Sculptures.Count) + 1; analysisData.Groups = new GroupDetails[totalGroups]; List <Guid> localSculptures = new List <Guid>(this.Sculptures); var sculpturesInGroup = (int)Math.Floor(Sculptures.Count / (float)totalGroups); for (int i = 0; i < totalGroups; i++) { var group = new GroupDetails(); group.Sculptures = new Guid[sculpturesInGroup]; for (int j = 0; j < sculpturesInGroup; j++) { group.Sculptures[j] = localSculptures[0]; localSculptures.RemoveAt(0); } var tagsApplied = rand.Next(1, this.Tags.Count); group.Tags = new string[tagsApplied]; for (int j = 0; j < tagsApplied; j++) { group.Tags[j] = Tags[j]; } analysisData.Groups[i] = group; } //for tags we need to choose a random number of items var totalTagsUsed = rand.Next(1, this.Tags.Count); analysisData.Tags = new TagDetails[totalTagsUsed]; for (int i = 0; i < totalTagsUsed; i++) { string tag = this.Tags[i]; var tagDetails = new TagDetails(); tagDetails.Tag = tag; var totalSculptures = rand.Next(1, this.Sculptures.Count); tagDetails.Sculptures = new Guid[totalSculptures]; for (int j = 0; j < totalSculptures; j++) { tagDetails.Sculptures[j] = Sculptures[j]; } analysisData.Tags[i] = tagDetails; } //for sculptures then for all items - choose random tags - don't worry that this won't match the above data - it will on real data analysisData.Sculptures = new SculptureDetails[this.Sculptures.Count]; for (int i = 0; i < this.Sculptures.Count; i++) { var sculpture = this.Sculptures[i]; var sculptureDetails = new SculptureDetails(); sculptureDetails.SculptureId = sculpture; var tagsApplied = rand.Next(1, this.Tags.Count); sculptureDetails.Tags = new string[tagsApplied]; for (int j = 0; j < tagsApplied; j++) { var tag = Tags[j]; sculptureDetails.Tags[j] = tag; } analysisData.Sculptures[i] = sculptureDetails; } analysisData.QuestionnaireResponses = new Dictionary <string, object>() { // { "gender", rand.NextDouble() < 0.5 ? "edfa539c-1f2c-4d6b-b795-fe24c2dafa62" : "89788977-120A-45C5-A8CB-EE75801A3222" }, { "art-museum", GetExpertiseValue() }, // "94867d8b-f024-4821-a69b-840ac823de7a" }, { "age", rand.Next(18, 55) }, { "art-book", GetExpertiseValue() }, // "bcbd312a-7cbe-402a-b442-3c8a14e5a73c" }, { "art-practice", GetExpertiseValue() }, // "be4f2907-6387-46db-ba96-e94bc24e2cca" }, { "sculpture-1-rate", rand.Next(0, 10) }, { "sculpture-2-rate", rand.Next(0, 10) }, { "sculpture-3-rate", rand.Next(0, 10) }, { "sculpture-4-rate", rand.Next(0, 10) }, { "sculpture-5-rate", rand.Next(0, 10) }, { "sculpture-6-rate", rand.Next(0, 10) }, { "sculpture-7-rate", rand.Next(0, 10) }, { "sculpture-8-rate", rand.Next(0, 10) }, { "sculpture-9-rate", rand.Next(0, 10) }, { "sculpture-10-rate", rand.Next(0, 10) }, { "sculpture-11-rate", rand.Next(0, 10) }, { "sculpture-12-rate", rand.Next(0, 10) }, { "sculpture-13-rate", rand.Next(0, 10) }, { "sculpture-14-rate", rand.Next(0, 10) }, { "sculpture-15-rate", rand.Next(0, 10) }, { "sculpture-16-rate", rand.Next(0, 10) }, { "sculpture-17-rate", rand.Next(0, 10) }, { "sculpture-18-rate", rand.Next(0, 10) }, { "tags-suitable", rand.Next(0, 10) }, { "suggested-tags", "colors, blue" }, { "motion-sickness", rand.Next(0, 10) }, { "control-move", rand.Next(0, 10) }, { "control-fly", rand.Next(0, 10) }, { "control-scale", rand.Next(0, 10) }, { "recommend", rand.Next(0, 10) }, }; analysisDatas.Add(analysisData); } return(analysisDatas); }
public static TagDetails LoadTags(string filename) { var extension = Path.GetExtension(filename); if (extension == null) { return(null); } if (extension.ToLower() != ".mp3") { return(null); } lock (_tagDetails) { if (_tagDetails.ContainsKey(filename)) { return(_tagDetails[filename]); } } var tags = BassTags.BASS_TAG_GetFromFile(filename); if (tags == null) { throw new Exception("Cannot load tags for file " + filename); } var tagDetails = new TagDetails { Title = tags.title, Artist = tags.artist, Album = tags.album, AlbumArtist = tags.albumartist, Genre = tags.genre, Gain = tags.replaygain_track_peak }; var key = tags.NativeTag("InitialKey"); if (key != "") { tagDetails.Key = key; } decimal bpm; if (decimal.TryParse(tags.bpm, out bpm)) { tagDetails.Bpm = BpmHelper.NormaliseBpm(bpm); } var duration = TimeSpan.FromSeconds(tags.duration); if (duration.TotalMilliseconds != 0) { tagDetails.Length = (decimal)duration.TotalMilliseconds / 1000; } int trackNumber; var trackNumberTag = (tags.track + "/").Split('/')[0].Trim(); if (int.TryParse(trackNumberTag, out trackNumber)) { tagDetails.TrackNumber = trackNumber; } if (tagDetails.AlbumArtist == "") { tagDetails.AlbumArtist = tagDetails.Artist; } if (tagDetails.Title.Contains("/")) { var data = tagDetails.Title.Split('/').ToList(); tagDetails.Artist = data[0].Trim(); tagDetails.Title = data[1].Trim(); } lock (_tagDetails) { if (!_tagDetails.ContainsKey(filename)) { _tagDetails.Add(filename, tagDetails); } } return(tagDetails); }
public static TagDetails LoadTags(string filename) { var extension = Path.GetExtension(filename); if (extension == null ) return null; if (extension.ToLower() != ".mp3") return null; lock (_tagDetails) { if (_tagDetails.ContainsKey(filename)) { return _tagDetails[filename]; } } var tags = BassTags.BASS_TAG_GetFromFile(filename); if (tags == null) throw new Exception("Cannot load tags for file " + filename); var tagDetails = new TagDetails { Title = tags.title, Artist = tags.artist, Album = tags.album, AlbumArtist = tags.albumartist, Genre = tags.genre, Gain = tags.replaygain_track_peak }; var key = tags.NativeTag("InitialKey"); if (key != "") tagDetails.Key = key; decimal bpm; if(decimal.TryParse(tags.bpm, out bpm)) tagDetails.Bpm = BpmHelper.NormaliseBpm(bpm); var duration = TimeSpan.FromSeconds(tags.duration); if(duration.TotalMilliseconds != 0) tagDetails.Length = (decimal)duration.TotalMilliseconds / 1000; int trackNumber; var trackNumberTag = (tags.track + "/").Split('/')[0].Trim(); if (int.TryParse(trackNumberTag, out trackNumber)) tagDetails.TrackNumber = trackNumber; if (tagDetails.AlbumArtist == "") tagDetails.AlbumArtist = tagDetails.Artist; if (tagDetails.Title.Contains("/")) { var data = tagDetails.Title.Split('/').ToList(); tagDetails.Artist = data[0].Trim(); tagDetails.Title = data[1].Trim(); } lock (_tagDetails) { if (!_tagDetails.ContainsKey(filename)) { _tagDetails.Add(filename, tagDetails); } } return tagDetails; }