public static void Main()
        {
            var documents = new List<Manuscript>();
            var formatter = new StandardFormatter(); // new BackwardsFormatter();

            var faq = new Faq(formatter) { Title = "The Bridge Pattern FAQ" };
            faq.Questions.Add("What is it?", "A design pattern");
            faq.Questions.Add("When do we use it?", "When you need to separate an abstraction from an implementation.");
            documents.Add(faq);

            var book = new Book(formatter)
            {
                Title = "Lots of Patterns",
                Author = "John Sonmez",
                Text = "Blah blah blah..."
            };
            documents.Add(book);

            var paper = new TermPaper(formatter)
            {
                Class = "Design Patterns",
                Student = "Joe N00b",
                Text = "Blah blah blah...",
                References = "GOF"
            };
            documents.Add(paper);

            foreach (var doc in documents)
            {
                doc.Print();
            }

            // Wait for user
            Console.ReadKey();
        }
Exemple #2
0
 public override void Visit(ExportText exportColumn)
 {
     if (!String.IsNullOrEmpty(exportColumn.FormatString))
     {
         StandardFormatter.FormatOutput(exportColumn);
     }
 }
        public static void Main()
        {
            var document          = new List <Manuscript>();
            var fancyFormatter    = new FancyFormatter();
            var standardFormatter = new StandardFormatter();

            var faq = new FAQ(standardFormatter)
            {
                Title = Constants.FaqTitle
            };

            faq.Questions.Add(Constants.FaqQuestionOne, Constants.FaqQuestionOneAnswer);
            faq.Questions.Add(Constants.FaqQuestionTwo, Constants.FaqQuestionTwoAnswer);
            document.Add(faq);

            var book = new Book(fancyFormatter)
            {
                Author = Constants.BookAuthor,
                Title  = Constants.BookTitle,
                Text   = Constants.BookText,
            };

            document.Add(book);

            foreach (var doc in document)
            {
                doc.Print();
            }
        }
Exemple #4
0
        public void Test_PrintAllManuscripts()
        {
            // Entities always derive from Manuscript class - this does not change
            // But formatting implementation can be changed and it doesn't require changing base class
            List <Manuscript> manuscripts = new List <Manuscript>();

            BridgePattern.ICustomFormatter standardFormatter = new StandardFormatter();

            Book book = new Book(standardFormatter);

            book.Title  = "Book title";
            book.Author = "Anonymous";
            manuscripts.Add(book);

            Faq faq = new Faq(standardFormatter);

            faq.SectionTitle = "Important";
            faq.Questions    = new List <string> {
                "First", "Second"
            };
            manuscripts.Add(faq);

            foreach (var elem in manuscripts)
            {
                elem.Print();
            }
        }
Exemple #5
0
        static void Main(string[] args)
        {
            // Decouple an abstraction from its implementation so that the two can vary independently.
            // Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy.
            var formatter  = new StandardFormatter();
            var normalBook = new Book(formatter)
            {
                Title         = "A Brief History on Mankind",
                Description   = "A good introduction to the history of mankind from stone age to present day.",
                TotalPages    = "500",
                YearPublished = "1998"
            };

            normalBook.Print();

            Console.WriteLine("==========================================================================");

            var crypticFormatter = new CrypticFormatter();
            var crypticBook      = new Book(crypticFormatter)
            {
                Title         = "Opium War: Why China Lost the War",
                Description   = "In-depth analysis on the first and second opium war.",
                TotalPages    = "365",
                YearPublished = "2012"
            };

            crypticBook.Print();

            Console.ReadKey();
        }
Exemple #6
0
        public static void Main()
        {
            var manuscripts       = new List <Manuscript>();
            var fancyFormatter    = new FancyFormatter();
            var standardFormatter = new StandardFormatter();

            var faq = new FAQ(standardFormatter)
            {
                Title = Constants.Title
            };

            faq.Questions.Add(Constants.QuestionOne, Constants.QuestionOneAnswer);
            faq.Questions.Add(Constants.QuestionTwo, Constants.QuestionTwoAnswer);
            manuscripts.Add(faq);

            var book = new Book(fancyFormatter)
            {
                Author = Constants.BookAuthor,
                Title  = Constants.BookTitle,
                Text   = Constants.BookText,
            };

            manuscripts.Add(book);

            foreach (var page in manuscripts)
            {
                page.Print();
            }
        }
Exemple #7
0
        public void Empty_Input_Returns_NullValue()
        {
            string toFormat = string.Empty;;
            string format   = "dd/MM/yy";
            var    result   = StandardFormatter.FormatOutput(toFormat, format, stringType, nullValue);

            Assert.That(result, Is.EqualTo(nullValue));
        }
Exemple #8
0
        public void TimeSpan_HH_mm()
        {
            string toFormat = "5:50:10";
            string format   = "HH:mm";
            var    result   = StandardFormatter.FormatOutput(toFormat, format, dateTimetype, nullValue);

            Assert.That(result, Is.EqualTo("05:50"));
        }
Exemple #9
0
        public void TypeDateTimeOfResultIsString()
        {
            string toFormat = "2012/02/12";
            string format   = "dd.MM.yy";
            var    result   = StandardFormatter.FormatOutput(toFormat, format, dateTimetype, nullValue);

            Assert.That(result, Is.TypeOf(typeof(string)));
        }
Exemple #10
0
 public override void Visit(ExportText exportColumn)
 {
     Console.WriteLine(exportColumn.Text);
     if (!String.IsNullOrEmpty(exportColumn.FormatString))
     {
         StandardFormatter.FormatOutput(exportColumn);
     }
 }
Exemple #11
0
        public void DateTime_dd_MM_YY()
        {
            string toFormat = "2012/02/12";
            string format   = "dd.MM.yy";
            var    result   = StandardFormatter.FormatOutput(toFormat, format, dateTimetype, nullValue);

            Assert.That(result, Is.EqualTo("12.02.12"));
        }
Exemple #12
0
        public void TypeOfTimeSpanResultIsString()
        {
            string toFormat = "5,50,10";
            string format   = "H:mm:ss";
            var    result   = StandardFormatter.FormatOutput(toFormat, format, dateTimetype, nullValue);

            Assert.That(result, Is.TypeOf(typeof(string)));
        }
Exemple #13
0
        public void String_Is_Not_Formatted()
        {
            string toFormat = "Hello World";
            string format   = "dd/MM/yy";
            var    result   = StandardFormatter.FormatOutput(toFormat, format, stringType, nullValue);

            Assert.That(result, Is.EqualTo(toFormat));
        }
Exemple #14
0
        public void NegativeTimeSpan_HH_mm_ss()
        {
            string toFormat = "-5:50:10";
            string format   = "H:mm:ss";
            var    result   = StandardFormatter.FormatOutput(toFormat, format, dateTimetype, nullValue);

            Assert.That(result, Is.EqualTo("-5:50:10"));
        }
Exemple #15
0
        public override void DrawItem(PdfWriter pdfWriter,
                                      ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter)
        {
            if (pdfWriter == null)
            {
                throw new ArgumentNullException("pdfWriter");
            }
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }
            base.DrawItem(pdfWriter, converter);

            iTextSharp.text.Font font = null;

            if (this.StyleDecorator.Font.Unit == GraphicsUnit.Point)
            {
                font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
                                           BaseFont.IDENTITY_H,
                                           this.StyleDecorator.Font.Size,
                                           (int)this.StyleDecorator.Font.Style,
                                           this.StyleDecorator.PdfForeColor);
            }
            else
            {
                font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
                                           BaseFont.IDENTITY_H,
                                           UnitConverter.FromPixel(this.StyleDecorator.Font.Size).Point,
                                           (int)this.StyleDecorator.Font.Style,
                                           this.StyleDecorator.PdfForeColor);
            }

            base.Decorate();

            PdfContentByte contentByte = base.PdfWriter.DirectContent;

            CalculatePdfFormat pdfFormat = new CalculatePdfFormat(this.StyleDecorator, font);

            ColumnText columnText = new ColumnText(contentByte);

            iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle();
            columnText.SetSimpleColumn(r.Left, r.Top, r.Left + r.Width, r.Top - r.Height, pdfFormat.Leading, pdfFormat.Alignment);

            string formatedText = this.text;

            if (!String.IsNullOrEmpty(StyleDecorator.FormatString))
            {
                formatedText = StandardFormatter.FormatOutput(this.text, this.StyleDecorator.FormatString,
                                                              this.StyleDecorator.DataType, String.Empty);
            }

            Chunk chunk = new Chunk(formatedText, font);

            columnText.AddText(chunk);

            columnText.Go();
        }
Exemple #16
0
        public void StandardFormatter_WhenCustomerHaveMultipleRentals_ShouldPass()
        {
            var      customer          = CustomerFactory.GetCustomer();
            var      standardFormatter = new StandardFormatter();
            var      serializedData    = customer.GetStatement(standardFormatter);
            Customer actual            = standardFormatter.Deserialize(serializedData);

            Assert.True(customer.Equals(actual));
        }
Exemple #17
0
        public static void Main(string[] args)
        {
            var documents = new List <Document.Document>();
            var formatter = new StandardFormatter();

            foreach (var doc in documents)
            {
                doc.Print();
            }
        }
Exemple #18
0
        public void StandardFormatter()
        {
            var formatter = new StandardFormatter();

            CreateManuscriptsWith(formatter);
            foreach (var doc in _documents)
            {
                doc.Print();
            }
        }
        public void FormatTimeSpanfromTime()
        {
            var ti = new BaseTextItem();

            ti.DataType     = "System.TimeSpan";
            ti.FormatString = "hh:mm:ss";
            ti.Text         = new TimeSpan(7, 17, 20).ToString();
            var exportColumn = (ExportText)ti.CreateExportColumn();

            StandardFormatter.FormatOutput(exportColumn);
            Assert.That(ti.Text, Is.EqualTo("07:17:20"));
        }
Exemple #20
0
        public void ConvertResultToDateTime()
        {
            DateTime date;
            string   toFormat = "2012/02/12";
            string   format   = "dd.MM.yy";
            var      result   = StandardFormatter.FormatOutput(toFormat, format, dateTimetype, nullValue);


            bool valid = DateTime.TryParse(toFormat, out date);

            Assert.That(valid, Is.True);
            Assert.That(date, Is.EqualTo(new DateTime(2012, 02, 12)));
        }
        public void NegativeTimeSpan_HH_mm_ss()
        {
            TimeSpan time;
            string   toFormat = "-5:50:10";
            string   format   = "H:mm:ss";
            var      result   = StandardFormatter.FormatOutput(toFormat, format, dateTimetype, nullValue);

            Assert.That(result, Is.EqualTo("-5:50:10"));
            bool valid = TimeSpan.TryParseExact(result,
                                                "c",
                                                CultureInfo.CurrentCulture,
                                                out time);

            Assert.That(valid, Is.True);
        }
Exemple #22
0
        public void ConvertResultToTimeSpan()
        {
            TimeSpan time;
            string   toFormat = "5:50:10";
            string   format   = "H:mm:ss";
            var      result   = StandardFormatter.FormatOutput(toFormat, format, dateTimetype, nullValue);

            bool valid = TimeSpan.TryParseExact(result,
                                                "c",
                                                CultureInfo.CurrentCulture,
                                                out time);

            Assert.That(valid, Is.True);
            Assert.That(time, Is.EqualTo(new TimeSpan(5, 50, 10)));
        }
        public ActionResult Get()
        {
            try
            {
                StringBuilder     sb        = new StringBuilder();
                List <Manuscript> documents = new List <Manuscript>();
                var formatter = new StandardFormatter();

                var faq = new FAQ(formatter);
                faq.Title = "The Bridge Pattern FAQ";
                faq.Questions.Add("What is it?", "A design pattern");
                faq.Questions.Add("When do we use it?", "When you need to separate an abstraction from an implementation.");
                documents.Add(faq);

                var book = new Book(formatter)
                {
                    Title  = "Lots of Patterns",
                    Author = "Alfonso Gomez",
                    Text   = "Blah blah blah..."
                };
                documents.Add(book);

                var paper = new TermPaper(formatter)
                {
                    Class      = "Design Patterns",
                    Student    = "Jose Sanchez",
                    Text       = "Blah blah blah...",
                    References = "GOF"
                };
                documents.Add(paper);


                foreach (var doc in documents)
                {
                    sb.Append(doc.Print());
                }

                return(Ok(sb.ToString()));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemple #24
0
        public override void DrawItem(PdfWriter pdfWriter,
                                      ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter)
        {
            if (pdfWriter == null)
            {
                throw new ArgumentNullException("pdfWriter");
            }
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }
            base.DrawItem(pdfWriter, converter);

            base.Decorate();

            PdfContentByte contentByte = base.PdfWriter.DirectContent;

            iTextSharp.text.Font font      = CreateFontFromFactory(this.StyleDecorator);
            CalculatePdfFormat   pdfFormat = new CalculatePdfFormat(this.StyleDecorator, font);

            ColumnText columnText = new ColumnText(contentByte);

            if (StyleDecorator.RightToLeft.ToString() == "Yes")
            {
                columnText.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
            }

            iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle();
            columnText.SetSimpleColumn(r.Left, r.Top, r.Left + r.Width, r.Top - r.Height, pdfFormat.Leading, pdfFormat.Alignment);

            string formatedText = this.Text;

            if (!String.IsNullOrEmpty(StyleDecorator.FormatString))
            {
                formatedText = StandardFormatter.FormatOutput(this.Text, this.StyleDecorator.FormatString,
                                                              this.StyleDecorator.DataType, String.Empty);
            }

            Chunk chunk = new Chunk(formatedText, font);

            columnText.AddText(chunk);

            columnText.Go();
        }
Exemple #25
0
        public void CompositeFormatter_WhenCustomerHaveMultipleRentals_ShouldPass()
        {
            var jsonFormatter      = new JsonFormatter();
            var xmlFormatter       = new XmlFormatter();
            var standardFormatter  = new StandardFormatter();
            var compositeFormatter = new CompositeFormatter();

            compositeFormatter.AddFormatter(new JsonFormatter());
            compositeFormatter.AddFormatter(new StandardFormatter());
            compositeFormatter.AddFormatter(new XmlFormatter());

            var      customer           = CustomerFactory.GetCustomer();
            var      serializedData     = customer.GetStatement(compositeFormatter);
            Customer actualFromJson     = jsonFormatter.Deserialize(serializedData);
            Customer actualFromXml      = xmlFormatter.Deserialize(serializedData);
            Customer actualFromStandard = standardFormatter.Deserialize(serializedData);

            Assert.True(customer.Equals(actualFromJson));
            Assert.True(customer.Equals(actualFromXml));
            Assert.True(customer.Equals(actualFromStandard));
        }
Exemple #26
0
        static void Main(string[] args)
        {
            List <Document>  documents = new List <Document>();
            IFormatterBridge formatter = new StandardFormatter();

            var book = new Book(formatter)
            {
                Author = "Dan Brown",
                Title  = "The Da Vinci Code",
                Text   = "Blah blah blah ..."
            };

            documents.Add(book);

            var paper = new TermPaper(formatter)
            {
                Class      = "Software Engineering",
                Student    = "Jeremy Hall, Clara Knight",
                References = "SWE101",
                Text       = "Blah blah blah ..."
            };

            documents.Add(paper);

            var faq = new FAQ(formatter)
            {
                Title = "Design Patterns"
            };

            faq.Questions.Add("Who owns this?", "No one");
            faq.Questions.Add("Who created this?", "No one");
            documents.Add(faq);

            foreach (var document in documents)
            {
                document.Print();
            }

            System.Console.ReadLine();
        }
Exemple #27
0
        static void Main(string[] args)
        {
            List <Referral> authorizations = new List <Referral>();

            var standard  = new StandardFormatter();
            var executive = new ExecutiveFormatter();
            var fancy     = new FancyFormatter();

            var pharmacyReferral = new Pharmacy(standard);

            pharmacyReferral.PharmacyReferralId = 9;
            pharmacyReferral.Member             = "Clarence Worley";
            pharmacyReferral.NationalDrugCode.Add("313", "Medicine");
            authorizations.Add(pharmacyReferral);

            var externalReferral = new External(executive);

            externalReferral.ExternalId = 7;
            externalReferral.Member     = "Jim Morrison";
            externalReferral.Procedures.Add("757", "Evaluation");
            authorizations.Add(externalReferral);

            var internalReferral = new Internal(fancy)
            {
                Member     = "Pedro De Pacas",
                InternalId = 9,
                Symptoms   = "Flu"
            };

            authorizations.Add(internalReferral);

            foreach (var auth in authorizations)
            {
                auth.Print();
            }

            Console.ReadKey();
        }
Exemple #28
0
        static void Main(string[] args)
        {
            var documents        = new List <Manuscript>();
            var formatter        = new StandardFormatter();
            var reverseFormatter = new ReverseFormatter();

            var faq = new FAQ(formatter);

            faq.Title = "The Bridge Pattern FAQ";
            faq.Questions.Add("What is it?", "A design pattern");
            faq.Questions.Add("When do we use it?", "When you need to separate an bastraction from an implementation");
            documents.Add(faq);

            var book = new Book(formatter)
            {
                Title  = "Lots of Patterns",
                Author = "John Sonmez",
                Text   = "Bla bla bla"
            };

            documents.Add(book);

            var paper = new TermPaper(reverseFormatter)
            {
                Class      = "Design Patterns",
                Student    = "Joe N00b",
                Text       = "Bla bla bla",
                References = "GOF"
            };

            documents.Add(paper);

            foreach (var doc in documents)
            {
                doc.Print();
            }
        }
Exemple #29
0
        public override void DrawItem(PdfWriter pdfWriter,
                                      ICSharpCode.Reports.Core.Exporter.ExportRenderer.PdfUnitConverter converter)
        {
            if (pdfWriter == null)
            {
                throw new ArgumentNullException("pdfWriter");
            }
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }
            base.DrawItem(pdfWriter, converter);

            iTextSharp.text.Font font = null;

            if (this.StyleDecorator.Font.Unit == GraphicsUnit.Point)
            {
                font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
                                           BaseFont.IDENTITY_H,
                                           this.StyleDecorator.Font.Size,
                                           (int)this.StyleDecorator.Font.Style,
                                           this.StyleDecorator.PdfForeColor);
            }
            else
            {
                font = FontFactory.GetFont(this.StyleDecorator.Font.FontFamily.Name,
                                           BaseFont.IDENTITY_H,
                                           UnitConverter.FromPixel(this.StyleDecorator.Font.Size).Point,
                                           (int)this.StyleDecorator.Font.Style,
                                           this.StyleDecorator.PdfForeColor);
            }
//
//			http://www.google.de/search?hl=de&q=itextsharp+%2B+measure+text&start=10&sa=N
//			http://www.mikesdotnetting.com/Article/82/iTextSharp-Adding-Text-with-Chunks-Phrases-and-Paragraphs
//			http://www.mikesdotnetting.com/Category/20

//	itextsharp + columntext + textheight
//itextsharp + columntext + rectangle

//itextsharp + simulate
//http://www.mail-archive.com/[email protected]/msg04747.html
            base.Decorate();
            PdfContentByte contentByte = base.PdfWriter.DirectContent;

            iTextSharp.text.Rectangle r = base.ConvertToPdfRectangle();
            ColumnText columnText       = new ColumnText(contentByte);
            PdfFormat  pdfFormat        = new PdfFormat(this.StyleDecorator, font);

            columnText.SetSimpleColumn(r.Left, r.Top, r.Left + r.Width, r.Height, pdfFormat.Leading, pdfFormat.Alignment);
//			int a = Convert.ToInt16((r.Height/font.Size) + 1);
//			columnText.SetSimpleColumn(r.Left, r.Top , r.Left + r.Width,r.Height,a,pdfFormat.Alignment);
            string formated = StandardFormatter.FormatOutput(this.text, this.StyleDecorator.FormatString,
                                                             this.StyleDecorator.DataType, String.Empty);

            Chunk chunk = new Chunk(formated, font);

            columnText.AddText(chunk);

            columnText.Go();
            int i = columnText.LinesWritten;

            if (i > 1)
            {
                Console.WriteLine("{0} - {1}", i, this.text);
                Console.WriteLine("dif {0}", r.Height / font.Size);
            }
        }