Example #1
0
 string ITermColor.ProvideFallback(TermPosition position, bool foreground)
 {
     return(AsANSIEscapeCode(foreground));
 }
        public ActionResult ImportPost(int id, string terms)
        {
            if (!Services.Authorizer.Authorize(Permissions.CreateTaxonomy, T("Couldn't import terms")))
            {
                return(new HttpUnauthorizedResult());
            }

            var taxonomy = _taxonomyService.GetTaxonomy(id);

            if (taxonomy == null)
            {
                return(HttpNotFound());
            }

            var topTerm = new TermPosition();

            using (var reader = new StringReader(terms)) {
                string       line;
                var          previousLevel = 0;
                var          parents       = new Stack <TermPosition>();
                TermPosition parentTerm    = null;
                while (null != (line = reader.ReadLine()))
                {
                    // ignore empty lines
                    if (String.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    // compute level from tabs
                    var level = 0;
                    while (line[level] == '\t')
                    {
                        level++;                         // number of tabs to know the level
                    }
                    // create a new term content item
                    var term = _taxonomyService.NewTerm(taxonomy);

                    // detect parent term
                    if (level == previousLevel + 1)
                    {
                        parentTerm = parents.Peek();
                        parents.Push(new TermPosition {
                            Term = term
                        });
                    }
                    else if (level == previousLevel)
                    {
                        // same parent term
                        if (parents.Any())
                        {
                            parents.Pop();
                        }

                        parents.Push(new TermPosition {
                            Term = term
                        });
                    }
                    else if (level < previousLevel)
                    {
                        for (var i = previousLevel; i >= level; i--)
                        {
                            parents.Pop();
                        }

                        parentTerm = parents.Any() ? parents.Peek() : null;
                        parents.Push(new TermPosition {
                            Term = term
                        });
                    }

                    // increment number of children
                    if (parentTerm == null)
                    {
                        parentTerm = topTerm;
                    }

                    parentTerm.Position++;
                    term.Weight = 10 - parentTerm.Position;

                    term.Container = parentTerm.Term == null ? taxonomy.ContentItem : parentTerm.Term.ContentItem;

                    line = line.Trim();
                    var scIndex = line.IndexOf(';'); // seek first semi-colon to extract term and slug

                    // is there a semi-colon
                    if (scIndex != -1)
                    {
                        term.Name = line.Substring(0, scIndex);
                        term.Slug = line.Substring(scIndex + 1);
                    }
                    else
                    {
                        term.Name = line;
                    }

                    var existing = _taxonomyService.GetTermByName(id, term.Name);

                    // a different term exist under the same parent term ?
                    if (existing != null && existing.Container.ContentItem.Record == term.Container.ContentItem.Record)
                    {
                        Services.Notifier.Error(T("The term {0} already exists at this level", term.Name));
                        Services.TransactionManager.Cancel();
                        return(View(new ImportViewModel {
                            Taxonomy = taxonomy, Terms = terms
                        }));
                    }

                    _taxonomyService.ProcessPath(term);
                    Services.ContentManager.Create(term, VersionOptions.Published);

                    previousLevel = level;
                }
            }

            Services.Notifier.Information(T("The terms have been imported successfully."));

            return(RedirectToAction("Index", "TermAdmin", new { taxonomyId = id }));
        }
Example #3
0
 public virtual System.ConsoleColor?ProvideFallback(TermPosition position, bool foreground) =>
 throw new System.Exception();
Example #4
0
 public override System.ConsoleColor?ProvideFallback(TermPosition position, bool foreground)
 {
     return(color);
 }
Example #5
0
 public override string ProvideFallback(TermPosition position, bool foreground)
 {
     return(AsANSIEscapeCode(foreground));
 }
Example #6
0
 public override string ProvideFallback(TermPosition position, bool foreground)
 {
     return(provider(position, foreground));
 }
Example #7
0
 public virtual string ProvideFallback(TermPosition position, bool foreground) =>
 throw new System.Exception();
Example #8
0
        public static void Main(string[] args)
        {
            if (false && resv.Y >= 80)
            {
                DrawYohane();
                return;
            }
            // get a surface at 8,10 with size of 10x40 real characters
            var surface0 = fucksManager.CreateAndInitializeSurface(new TermPosition(8, 10), new TermResolution(30, 80, 1, 2));
            // get a surface at 0,0 with a scaled size (two real characters per Y cell) of 10x20 characters, and set the "skipped" cells to ' '
            var surface1 = fucksManager.CreateAndInitializeSurface(
                TermPosition.Origin,
                new TermResolution(10, 40, 1, 2),
                new char[, ] {
                { ' ', FucksSurfaceManager.FillValue }
            }
                );

            surface1.defaultProvider = new StaticTermColorProvider(new string[] { "122", "245", "43" }, new string[] { "12", "145", "143" });
            // set the default color scheme of the first surface (foreground is black, background is gray)
            surface0.defaultProvider = new StaticTermColorProvider(new string[] { "8" }, new string[] { "255" });

            // write "Hello, world" starting at 1,2 of the first surface
            var pos = new TermPosition(1, 2);

            surface0.PutString("Hello, World", ref pos);
            // make the 'd' background green
            surface0.SetBackColor(pos, BasicColor.Green);

            // put a '!' after the 'd'
            pos.advanceRight(surface0.bounds);
            surface0.PutChar('!', pos);

            // put the string "hane" starting at 2,3 of the second surface
            pos.Set(2, 3);
            surface1.PutString("hane", ref pos);

            // put a '*' where the 'e' would be if it were rendered in the first surface
            surface0.PutChar('*', ref pos);

            // draw a frame for both windows
            surface0.drawBounds();
            surface1.drawBounds();
            TermPosition termPosition = new TermPosition(1, 1);

            // render one iteration

            // burrow three cells and spread them in a nice surface next to each other
            using (var tempSurface = surface1.burrowCells(true, new TermPosition(2, 2), new TermPosition(3, 3), new TermPosition(4, 4))) {
                // write "Yo" "ha" "ne" in those individual cells
                var posv = TermPosition.Origin;
                tempSurface.PutString("Yohane", ref posv);
                // the cells will be automatically merged back into the main surface when this block ends
            }
            // Generate a linear repr of a full circle (ordered clockwise),
            using (var tempSurface = surface0.burrowCells(false, Utils.GenerateArc(15, 20, 10, 0, 359)))
            {
                var posv = TermPosition.Origin;
                tempSurface.PutString(new string('0', 50), ref posv);
            }
            fucksManager.renderOnce();
            while (true)
            {
                // intercept a key from the terminal
                var key = System.Console.ReadKey(true);

                // move the surface around if it's an arrow key
                // otherwise just write it to the surface
                switch (key.Key)
                {
                case System.ConsoleKey.UpArrow:
                    fucksManager.Translate(surface0, -1, 0);
                    break;

                case System.ConsoleKey.DownArrow:
                    fucksManager.Translate(surface0, 1, 0);
                    break;

                case System.ConsoleKey.LeftArrow:
                    fucksManager.Translate(surface0, 0, -1);
                    break;

                case System.ConsoleKey.RightArrow:
                    fucksManager.Translate(surface0, 0, 1);
                    break;

                default:
                    fucksManager.PutChar(surface0, key.KeyChar, ref termPosition);
                    break;
                }
                // render all the surfaces
                fucksManager.renderOnce();
            }
        }
Example #9
0
 public System.ConsoleColor?ProvideFallback(TermPosition position, bool foreground)
 {
     return(foreground ? System.ConsoleColor.Black : System.ConsoleColor.White);
 }