Inheritance: DefaultMenuAction, MenuAction
        private static string GetCurrentUrlWithTags(TemplateContext context, TagAction action, string groupName, string value)
        {
            var themeAdaptor = (ShopifyLiquidThemeEngine)context.TemplateLoader;
            var workContext  = themeAdaptor.WorkContext;

            var criteria = workContext.CurrentProductSearchCriteria.Clone() as ProductSearchCriteria;
            var term     = new Term {
                Name = groupName, Value = value
            };

            switch (action)
            {
            case TagAction.Add:
                criteria.Terms.Add(term);
                break;

            case TagAction.Remove:
                criteria.Terms.Remove(term);
                break;

            case TagAction.Replace:
                criteria.Terms.Clear();
                if (!string.IsNullOrEmpty(groupName))
                {
                    criteria.Terms.Add(term);
                }
                break;
            }
            var result = workContext.RequestUrl.SetQueryParameters(criteria);

            return(result.PathAndQuery);
        }
Esempio n. 2
0
        private void UpdateTags(TagAction action, IReadOnlyCollection <string> hashes, string tag)
        {
            _lock.Write(() =>
            {
                var touched = new List <ItemPreviewModel>();
                foreach (var hash in hashes)
                {
                    if (_previewModels.TryGetValue(hash, out var item))
                    {
                        if (action == TagAction.Add)
                        {
                            item.Tags.Add(tag);
                            _tagManager.Add(tag);
                        }
                        else
                        {
                            item.Tags.Remove(tag);
                        }

                        touched.Add(item);
                    }
                }

                _previewStreams.ForEach(s => s.Update(touched));
            });
        }
Esempio n. 3
0
        public void ExtractTagsFromName()
        {
            string[] files =
            {
                @"Bullet For My Valentine - Cries in Vain.mp3",
                @"Ciao Adios - Anne-Mari.mp3"
            };

            List <string[]> expectedValues = new List <string[]>
            {
                new[] { "Bullet For My Valentine", "Cries in Vain" },
                new[] { "Ciao Adios", "Anne-Mari" }
            };

            IActionStrategy tagAction = new TagAction();

            int i = 0;

            foreach (string file in files)
            {
                TestableMp3File mp3File = new TestableMp3File(file);

                tagAction.Process(mp3File);

                Assert.AreEqual(expectedValues[i][0], mp3File.Artist);
                Assert.AreEqual(expectedValues[i][1], mp3File.Title);
                Assert.AreEqual(true, mp3File.Saved);
                i++;
            }
        }
Esempio n. 4
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append("filename: " + Filename + " ");
            sb.Append("action: " + TagAction.ToString() + " ");
            sb.Append("tag: " + TagData.TagYMLFormatted());
            return(sb.ToString());
        }
Esempio n. 5
0
        private static string BuildTagActionTitle(TagAction action, string tagLabel)
        {
            switch (action)
            {
            case TagAction.Remove:
                return("Remove tag " + tagLabel);

            default:
                return("Show products matching tag " + tagLabel);
            }
        }
Esempio n. 6
0
        public async Task When_changing_tags_around_randomly(TagAction action, string tagName, string expected)
        {
            var response = action == TagAction.Add
                                ? await Handler.Handle(new AddToggleTagRequest(Editor, Locator, tagName), CancellationToken.None)
                                : await Handler.Handle(new RemoveToggleTagRequest(Editor, Locator, tagName), CancellationToken.None);

            var expectedTags = string.IsNullOrWhiteSpace(expected)
                                ? Array.Empty <string>()
                                : expected.Split(",");

            response.Tags.ShouldBe(expectedTags, ignoreOrder: true);
        }
Esempio n. 7
0
 private void AddToEntries(TagAction action, object value)
 {
     if (value is ICollection icol)
     {
         foreach (object o in icol)
         {
             this.AddToEntries(action, o);
         }
     }
     else if (Context.TagManager.TryGetTag(value, out Tag tag))
     {
         this.Entries.Add(new TagEntry(tag, action));
     }
 }
Esempio n. 8
0
        public async Task RunMfocAsync(List <File> keys, string tmpFileMfd, TagAction act)
        {
            try
            {
                StopScanTag();
                ValidateActions(false);
                ShowAbortButton();
                string arguments = "";
                tmpFileMfd = "dumps\\" + tmpFileMfd;

                var tmpFileUnk = "dumps\\" + t.TMPFILE_UNK;

                if (System.IO.File.Exists(tmpFileUnk))
                {
                    arguments += $" -D \"{tmpFileUnk}\"";
                }

                foreach (var key in keys.Select(k => k.FileName))
                {
                    arguments += $" -f \"keys\\{key}\"";
                }
                arguments += $" -O\"{tmpFileMfd}\"";
                ProcessCTS = new CancellationTokenSource();
                LogAppend($"mfoc {arguments}");
                var result = await Cli.Wrap("nfctools\\mfoc.exe").SetArguments(arguments).SetWorkingDirectory(t.DefaultWorkingDir)
                             .SetStandardOutputCallback(l => LogAppend(l))
                             .SetStandardErrorCallback(l => LogAppend(l))
                             .SetCancellationToken(ProcessCTS.Token)
                             .ExecuteAsync();

                StdOutMfoc = result.StandardOutput;
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                PeriodicScanTag();
            }
            finally
            {
                ValidateActions(true);
                ShowAbortButton(false);
                ProcessCTS.Dispose();
            }
        }
Esempio n. 9
0
 public async Task RunNfcMfclassicAsync(TagAction act, bool bWriteBlock0, bool useKeyA, bool haltOnError, TagType tagType)
 {
     try
     {
         StopScanTag();
         ValidateActions(false);
         ShowAbortButton();
         var  sourceDump   = "dumps\\" + t.TMPFILESOURCE_MFD;
         var  targetDump   = "dumps\\" + t.TMPFILE_TARGETMFD;
         char writeMode    = bWriteBlock0 == true ? 'W' : 'w';
         char useKey       = useKeyA == true ? 'A' : 'B';
         char cHaltOnError = haltOnError == true ? useKey = char.ToLower(useKey) : char.ToUpper(useKey);
         if (tagType == TagType.UnlockedGen1)
         {
             writeMode = 'W';
         }
         else if (tagType == TagType.DirectCUIDgen2)
         {
             writeMode = 'C';
         }
         ProcessCTS = new CancellationTokenSource();
         var arguments = $"{writeMode} {cHaltOnError} u \"{sourceDump}\" \"{targetDump}\"";
         LogAppend($"nfc-mfclassic {arguments}");
         var result = await Cli.Wrap("nfctools\\nfc-mfclassic.exe").SetArguments(arguments)
                      .SetStandardOutputCallback(l => LogAppend(l))
                      .SetStandardErrorCallback(l => LogAppend(l))
                      .SetCancellationToken(ProcessCTS.Token)
                      .ExecuteAsync();
     }
     catch (OperationCanceledException)
     {
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         ProcessCTS.Dispose();
         ValidateActions(true);
         ShowAbortButton(false);
     }
 }
Esempio n. 10
0
        private static string GetCurrentUrlWithTags(TagAction action, string groupName, string value)
        {
            var themeEngine = (ShopifyLiquidThemeEngine)Template.FileSystem;
            var workContext = themeEngine.WorkContext;

            var terms = workContext.CurrentProductSearchCriteria.Terms
                        .Select(t => new Term {
                Name = t.Name, Value = t.Value
            })
                        .ToList();

            switch (action)
            {
            case TagAction.Add:
                terms.Add(new Term {
                    Name = groupName, Value = value
                });
                break;

            case TagAction.Remove:
                terms.RemoveAll(t =>
                                string.Equals(t.Name, groupName, StringComparison.OrdinalIgnoreCase) &&
                                string.Equals(t.Value, value, StringComparison.OrdinalIgnoreCase));
                break;

            case TagAction.Replace:
                terms.Clear();

                if (!string.IsNullOrEmpty(groupName))
                {
                    terms.Add(new Term {
                        Name = groupName, Value = value
                    });
                }
                break;
            }

            var termsString = terms.Any() ? string.Join(";", terms.ToStrings()) : null;
            var url         = workContext.RequestUrl.SetQueryParameter("terms", termsString);

            return(url.AbsoluteUri);
        }
Esempio n. 11
0
 private void UpdateTags(TagAction action, IEnumerable <string> hashes, string tag)
 {
     WriteLocked(() =>
     {
         foreach (var hash in hashes)
         {
             if (_previewModels.TryGetValue(hash, out var item))
             {
                 if (action == TagAction.Add)
                 {
                     item.Tags.Add(tag);
                     _trie.Insert(tag);
                 }
                 else
                 {
                     item.Tags.Remove(tag);
                 }
             }
         }
     });
 }
        public void StartElement(HtmlNode node)
        {
            labelStacks.AddItem(null);
            TagAction ta = tagActions.Get(node.Name);

            if (ta != null)
            {
                if (ta.ChangesTagLevel())
                {
                    tagLevel++;
                }
                flush = ta.Start(this, node.Name, node.Attributes) | flush;
            }
            else
            {
                tagLevel++;
                flush = true;
            }
            lastEvent    = NBoilerpipeContentHandler.Event.START_TAG;
            lastStartTag = node.Name;
        }
Esempio n. 13
0
        private static string BuildTagLink(TagAction action, object tagObject, object input)
        {
            var href  = string.Empty;
            var title = string.Empty;
            var label = input.ToString();

            if (tagObject == null)
            {
                title = "Remove all tags";
                href  = GetCurrentUrlWithTags(TagAction.Replace, null, null);
            }
            else
            {
                var tag = tagObject as shopifyModel.Tag;

                if (tag != null)
                {
                    href  = GetCurrentUrlWithTags(action, tag.GroupName, tag.Value);
                    title = BuildTagActionTitle(action, tag.Label);

                    label = tag.Label;

                    if (tag.Count > 0)
                    {
                        label += string.Format(" ({0})", tag.Count);
                    }
                }
                else
                {
                    // TODO: Parse tag string
                }
            }

            var result = string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" title=\"{1}\">{2}</a>",
                                       HttpUtility.HtmlAttributeEncode(href),
                                       HttpUtility.HtmlAttributeEncode(title),
                                       HttpUtility.HtmlEncode(label));

            return(result);
        }
        public void EndElement(HtmlNode node)
        {
            TagAction ta = tagActions.Get(node.Name);

            if (ta != null)
            {
                flush = ta.End(this, node.Name) | flush;
            }
            else
            {
                flush = true;
            }
            if (ta == null || ta.ChangesTagLevel())
            {
                tagLevel--;
            }
            if (flush)
            {
                FlushBlock();
            }
            lastEvent  = NBoilerpipeContentHandler.Event.END_TAG;
            lastEndTag = node.Name;
            labelStacks.RemoveLast();
        }
Esempio n. 15
0
        private static string BuildTagLink(TemplateContext context, TagAction action, object tagObject, object input)
        {
            var href  = string.Empty;
            var title = string.Empty;
            var label = input.ToString();

            if (tagObject == null)
            {
                title = "Remove all tags";
                href  = GetCurrentUrlWithTags(context, TagAction.Replace, null, null);
            }
            else
            {
                if (tagObject is AggregationItem aggregationItem)
                {
                    href  = GetCurrentUrlWithTags(context, action, aggregationItem.GroupLabel, aggregationItem.Value.ToString());
                    title = BuildTagActionTitle(action, label);

                    if (aggregationItem.Count > 0)
                    {
                        label = $"{label} ({aggregationItem.Count})";
                    }
                }
                else
                {
                    // TODO: Parse tag string
                }
            }

            var result = string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" title=\"{1}\">{2}</a>",
                                       HttpUtility.HtmlAttributeEncode(href),
                                       HttpUtility.HtmlAttributeEncode(title),
                                       HttpUtility.HtmlEncode(label));

            return(result);
        }
Esempio n. 16
0
 public Chained(TagAction t1, TagAction t2)
 {
     this.t1 = t1;
     this.t2 = t2;
 }
Esempio n. 17
0
			public Chained(TagAction t1, TagAction t2)
			{
				this.t1 = t1;
				this.t2 = t2;
			}
Esempio n. 18
0
 public TagEntry(Tag tag, TagAction action)
 {
     this.Action = action;
     this.Id     = tag.Id;
 }
Esempio n. 19
0
        private static string BuildTagLink(TagAction action, object tagObject, object input)
        {
            var href = string.Empty;
            var title = string.Empty;
            var label = input.ToString();

            if (tagObject == null)
            {
                title = "Remove all tags";
                href = GetCurrentUrlWithTags(TagAction.Replace, null, null);
            }
            else
            {
                var tag = tagObject as shopifyModel.Tag;

                if (tag != null)
                {
                    href = GetCurrentUrlWithTags(action, tag.GroupName, tag.Value);
                    title = BuildTagActionTitle(action, tag.Label);

                    label = tag.Label;

                    if (tag.Count > 0)
                    {
                        label += string.Format(" ({0})", tag.Count);
                    }
                }
                else
                {
                    // TODO: Parse tag string
                }
            }

            var result = string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" title=\"{1}\">{2}</a>",
                HttpUtility.HtmlAttributeEncode(href),
                HttpUtility.HtmlAttributeEncode(title),
                HttpUtility.HtmlEncode(label));

            return result;
        }
Esempio n. 20
0
 private static string BuildTagActionTitle(TagAction action, string tagLabel)
 {
     switch (action)
     {
         case TagAction.Remove:
             return "Remove tag " + tagLabel;
         default:
             return "Show products matching tag " + tagLabel;
     }
 }
Esempio n. 21
0
        private async Task ReadTagAsync(TagAction act)
        {
            if (t.running)
            {
                return;
            }
            DumpFound = false;
            if (!TagFound && !ScanTagRunning)
            {
                PeriodicScanTag();
            }

            if (!ckEnablePeriodicTagScan.IsChecked.HasValue || !ckEnablePeriodicTagScan.IsChecked.Value)
            {
                await RunNfcListAsync();
            }

            if (!string.IsNullOrWhiteSpace(t.CurrentUID))
            {
                if (act == TagAction.ReadSource)
                {
                    t.mySourceUID       = t.CurrentUID;
                    t.TMPFILE_UNK       = $"mfc_{ t.mySourceUID}_unknownMfocSectorInfo.txt";
                    t.TMPFILESOURCE_MFD = $"mfc_{ t.mySourceUID}.dump";
                    t.TMPFILE_FND       = $"mfc_{ t.mySourceUID}_foundKeys.txt";
                    if (t.CheckAndUseDumpIfExists(t.TMPFILESOURCE_MFD))
                    {
                        DumpFound = true;
                    }
                }
                else if (act == TagAction.ReadTarget)
                {
                    t.myTargetUID       = t.CurrentUID;
                    t.TMPFILE_UNK       = $"mfc_{ t.myTargetUID}_unknownMfocSectorInfo.txt";
                    t.TMPFILE_TARGETMFD = $"mfc_{ t.myTargetUID}.dump";
                    t.TMPFILE_FND       = $"mfc_{ t.myTargetUID}_foundKeys.txt";
                    if (t.CheckAndUseDumpIfExists(t.TMPFILE_TARGETMFD))
                    {
                        DumpFound = true;
                    }
                }
            }

            if (TagFound)
            {
                StopScanTag();
                if (act == TagAction.ReadSource)
                {
                    if (!DumpFound)
                    {
                        MapKeyToSectorWindow mtsWin = new MapKeyToSectorWindow(this, t, Translate.Key(nameof(MifareWindowsTool.Properties.Resources.UsedForSourceMapping)), Translate.Key(nameof(MifareWindowsTool.Properties.Resources.Source)));
                        var ret = mtsWin.ShowDialog();
                        if (ret.HasValue && ret.Value)
                        {
                            await RunMfocAsync(SelectedKeys, t.TMPFILESOURCE_MFD, act);

                            if (StdOutMfoc.Contains($"dumping keys to a file"))
                            {
                                ShowDump("dumps\\" + t.TMPFILESOURCE_MFD);
                                StdOutMfoc = string.Empty;
                            }
                        }
                        else
                        {
                            PeriodicScanTag();
                        }
                    }
                    else
                    {
                        ShowDump("dumps\\" + t.TMPFILESOURCE_MFD);
                    }
                }
                else if (act == TagAction.ReadTarget)
                {
                    if (!DumpFound)
                    {
                        MapKeyToSectorWindow mtsWin = new MapKeyToSectorWindow(this, t, Translate.Key(nameof(MifareWindowsTool.Properties.Resources.UsedForTargetMapping)), Translate.Key(nameof(MifareWindowsTool.Properties.Resources.Target)));
                        var ret = mtsWin.ShowDialog();
                        if (ret.HasValue && ret.Value)
                        {
                            await RunMfocAsync(SelectedKeys, t.TMPFILE_TARGETMFD, act);

                            if (StdOutMfoc.Contains($"dumping"))
                            {
                                OpenWriteDumpWindow();
                                StdOutMfoc = string.Empty;
                            }
                        }
                        else
                        {
                            PeriodicScanTag();
                        }
                    }
                    else
                    {
                        OpenWriteDumpWindow();
                    }
                }
            }
            else
            {
                LogAppend(Translate.Key(nameof(MifareWindowsTool.Properties.Resources.NoTagDetectedOnReader)));
            }
        }
Esempio n. 22
0
        private static string GetCurrentUrlWithTags(TagAction action, string groupName, string value)
        {
            var themeEngine = (ShopifyLiquidThemeEngine)Template.FileSystem;
            var workContext = themeEngine.WorkContext;

            var terms = workContext.CurrentCatalogSearchCriteria.Terms
                .Select(t => new Term { Name = t.Name, Value = t.Value })
                .ToList();

            switch (action)
            {
                case TagAction.Add:
                    terms.Add(new Term { Name = groupName, Value = value });
                    break;
                case TagAction.Remove:
                    terms.RemoveAll(t =>
                        string.Equals(t.Name, groupName, StringComparison.OrdinalIgnoreCase) &&
                        string.Equals(t.Value, value, StringComparison.OrdinalIgnoreCase));
                    break;
                case TagAction.Replace:
                    terms.Clear();

                    if (!string.IsNullOrEmpty(groupName))
                    {
                        terms.Add(new Term { Name = groupName, Value = value });
                    }
                    break;
            }

            var termsString = terms.Any() ? string.Join(";", terms.ToStrings()) : null;
            var url = workContext.RequestUrl.SetQueryParameter("terms", termsString);

            return url.AbsoluteUri;
        }
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="TagAction" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => TagAction.CreateFrom(sourceValue);
Esempio n. 24
0
        public async Task RunMfocAsync(List <File> keys, string tmpFileMfd, TagAction act)
        {
            try
            {
                bool showDump = false;
                StopScanTag();
                ValidateActions(false);
                ShowAbortButton();
                string arguments = "";
                tmpFileMfd = "dumps\\" + tmpFileMfd;

                var tmpFileUnk = "dumps\\" + t.TMPFILE_UNK;

                if (System.IO.File.Exists(tmpFileUnk))
                {
                    arguments += $" -D \"{tmpFileUnk}\"";
                }

                foreach (var key in keys.Select(k => k.FileName))
                {
                    arguments += $" -f \"keys\\{key}\"";
                }
                arguments += $" -O\"{tmpFileMfd}\"";
                ProcessCTS = new CancellationTokenSource();
                LogAppend($"mfoc {arguments}");
                var cmd = Cli.Wrap("nfctools\\mfoc.exe").WithArguments(arguments).WithWorkingDirectory(t.DefaultWorkingDir).WithValidation(CommandResultValidation.None);

                await foreach (CommandEvent cmdEvent in cmd.ListenAsync(ProcessCTS.Token))
                {
                    switch (cmdEvent)
                    {
                    case StandardOutputCommandEvent stdOut:
                        LogAppend(stdOut.Text);
                        if (act == TagAction.ReadSource)
                        {
                            if (stdOut.Text.Contains($"dumping keys to a file"))
                            {
                                showDump = true;
                            }
                            else if (act == TagAction.ReadTarget)
                            {
                                if (stdOut.Text.Contains($"dumping"))
                                {
                                    OpenWriteDumpWindow();
                                }
                            }
                        }
                        break;

                    case StandardErrorCommandEvent stdErr:
                        ErrorAppend(stdErr.Text);
                        break;

                    case ExitedCommandEvent exited:
                        if (showDump)
                        {
                            ShowDump("dumps\\" + t.TMPFILESOURCE_MFD);
                        }
                        break;
                    }
                }
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                PeriodicScanTag();
            }
            finally
            {
                ValidateActions(true);
                ShowAbortButton(false);
                //ProcessCTS.Dispose();
            }
        }
Esempio n. 25
0
 /// <summary>
 /// Sets the <see cref="Action"/> property to the specified value and
 /// returns this <see cref="TagGuiCommand"/> instance.
 /// </summary>
 /// <param name="value">
 /// The new value for the <see cref="Action"/> property.
 /// </param>
 /// <returns>
 /// This <see cref="TagGuiCommand"/> instance.
 /// </returns>
 /// <remarks>
 /// This method is part of the fluent interface.
 /// </remarks>
 public TagGuiCommand WithAction(TagAction value)
 {
     Action = value;
     return(this);
 }