예제 #1
0
        public Text AddToHeader(Guid headerId, Text text)
        {
            if (HeaderRepository.Exists(headerId))
            {
                Header header = HeaderRepository.GetById(headerId);
                header.StyleClass = null;

                Header headerForText = header;

                Content contentOfHeader = headerForText.Content;

                IEnumerable <Text> headerTexts = TextRepository.GetByContent(contentOfHeader);

                if (headerTexts.Count() == 0)
                {
                    text.Id                 = Guid.NewGuid();
                    text.Position           = 0;
                    text.ContentThatBelongs = contentOfHeader;
                    TextRepository.Add(text);

                    return(text);
                }
                else
                {
                    throw new ExistingTextException("There is an existing text in the selected header.");
                }
            }
            else
            {
                throw new MissingHeaderException("This header does not exist in the database");
            }
        }
 public void LogModificationToText(Guid textId)
 {
     if (TextRepository.Exists(textId))
     {
         Text    textOfModdedDocument    = TextRepository.GetById(textId);
         Content contentOfModdedDocument = textOfModdedDocument.ContentThatBelongs;
         if (HeaderRepository.ExistsWithContent(contentOfModdedDocument))
         {
             Header headerOfModdedDocument = HeaderRepository.GetByContent(contentOfModdedDocument);
             LogModificationToDocument(headerOfModdedDocument.DocumentThatBelongs.Id);
         }
         else if (ParagraphRepository.ExistsWithContent(contentOfModdedDocument))
         {
             Paragraph paragraphOfModdedDocument = ParagraphRepository.GetByContent(contentOfModdedDocument);
             LogModificationToDocument(paragraphOfModdedDocument.DocumentThatBelongs.Id);
         }
         else if (FooterRepository.ExistsWithContent(contentOfModdedDocument))
         {
             Footer footerOfModdedDocument = FooterRepository.GetByContent(contentOfModdedDocument);
             LogModificationToDocument(footerOfModdedDocument.DocumentThatBelongs.Id);
         }
     }
     else
     {
         throw new MissingTextException("This text is not in the database.");
     }
 }
예제 #3
0
        public async Task Add_Test()
        {
            var header = new HeaderModel
            {
                HeaderName  = "Header",
                HeaderValue = "Value"
            };

            var query = new QueryModel
            {
                InsertDate      = DateTime.Now,
                QueryParamName  = "Param",
                QueryParamValue = "Value"
            };

            query.Headers = new List <HeaderModel>();

            query.Headers.Add(header);

            header.Query = query;

            var target = new HeaderRepository(this.dataContext);

            var result = await target.Add(header);

            Assert.IsNotNull(result);
            Assert.AreNotEqual(0, result.Id);
            Assert.AreNotEqual(0, result.Query.Id);
        }
 public void Delete(Guid headerId)
 {
     if (HeaderRepository.Exists(headerId))
     {
         HeaderRepository.Delete(headerId);
     }
     else
     {
         throw new MissingHeaderException("This header is not in the database.");
     }
 }
 public void LogModificationToHeader(Guid headerId)
 {
     if (HeaderRepository.Exists(headerId))
     {
         Header headerOfModdedDocument = HeaderRepository.GetById(headerId);
         LogModificationToDocument(headerOfModdedDocument.DocumentThatBelongs.Id);
     }
     else
     {
         throw new MissingHeaderException("This header is not in the database.");
     }
 }
 public void Update(Guid headerId, Header newHeaderData)
 {
     if (HeaderRepository.Exists(headerId))
     {
         Header headerToUpdate = HeaderRepository.GetById(headerId);
         if (newHeaderData.StyleClass != null && !StyleClassRepository.Exists(newHeaderData.StyleClass.Name))
         {
             newHeaderData.StyleClass = null;
         }
         headerToUpdate.StyleClass = newHeaderData.StyleClass;
         HeaderRepository.Update(headerToUpdate);
     }
     else
     {
         throw new MissingHeaderException("The header is not in the database.");
     }
 }
 public Header GetByDocument(Guid documentId)
 {
     if (DocumentRepository.Exists(documentId))
     {
         if (HeaderRepository.ExistsForDocument(documentId))
         {
             return(HeaderRepository.GetByDocument(documentId));
         }
         else
         {
             throw new MissingHeaderException("This header is not in the database");
         }
     }
     else
     {
         throw new MissingDocumentException("This document is not on the database.");
     }
 }
예제 #8
0
 public Text GetByHeader(Guid headerId)
 {
     if (HeaderRepository.Exists(headerId))
     {
         Header             headerForText   = HeaderRepository.GetById(headerId);
         Content            contentOfHeader = headerForText.Content;
         IEnumerable <Text> headerTexts     = TextRepository.GetByContent(contentOfHeader);
         if (headerTexts.Count() != 0)
         {
             return(headerTexts.First());
         }
         else
         {
             throw new MissingTextException("This text is not in the database");
         }
     }
     else
     {
         throw new MissingHeaderException("This header does not exist in the database");
     }
 }
        public Header Add(Guid documentId, Header header)
        {
            if (DocumentRepository.Exists(documentId))
            {
                if (!HeaderRepository.ExistsForDocument(documentId))
                {
                    Document documentThatBelongs = DocumentRepository.GetById(documentId);
                    documentThatBelongs.StyleClass = null;

                    header.DocumentThatBelongs = documentThatBelongs;

                    header.Id = Guid.NewGuid();

                    header.Content = new Content()
                    {
                        Id = Guid.NewGuid()
                    };

                    if (header.StyleClass != null && !StyleClassRepository.Exists(header.StyleClass.Name))
                    {
                        header.StyleClass = null;
                    }

                    ContentRepository.Add(header.Content);
                    HeaderRepository.Add(header);

                    return(header);
                }
                else
                {
                    throw new ExistingHeaderException("This document already has a header.");
                }
            }
            else
            {
                throw new MissingDocumentException("This document is not in the database.");
            }
        }
        private string ApplyDocumentStyle(Document document, Format format)
        {
            IEnumerable <Style> currentStyles = GetStylesWithInheritance(document.StyleClass, format);

            string appliedHtmlCode = "";

            if (!HeaderRepository.ExistsForDocument(document.Id) && !FooterRepository.ExistsForDocument(document.Id))
            {
                appliedHtmlCode = "" + ApplyParagraphStyles(ParagraphRepository.GetAllByDocument(document.Id), format, currentStyles);
            }
            else if (!FooterRepository.ExistsForDocument(document.Id))
            {
                appliedHtmlCode = "" + ApplyHeaderStyle(HeaderRepository.GetByDocument(document.Id), format, currentStyles)
                                  + "<br>" + ApplyParagraphStyles(ParagraphRepository.GetAllByDocument(document.Id), format, currentStyles);
            }
            else
            {
                appliedHtmlCode = "" + ApplyHeaderStyle(HeaderRepository.GetByDocument(document.Id), format, currentStyles)
                                  + "<br>" + ApplyParagraphStyles(ParagraphRepository.GetAllByDocument(document.Id), format, currentStyles)
                                  + "<br>" + ApplyFooterStyles(FooterRepository.GetByDocument(document.Id), format, currentStyles);
            }

            return(appliedHtmlCode);
        }
예제 #11
0
        public IActionResult NewHeaderInspector(Inspector inspector)
        {
            // Here we have the logics for when the user clicks the "Inspect" button to get the results.
            if (ModelState.IsValid)
            {
                // Send the users input into our Repository
                HeaderRepository.AddInspector(inspector);

                List <string> headerKeys   = new List <string>();
                List <string> headerValues = new List <string>();

                // Users entered url.
                var             url      = inspector.Url;
                HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(url);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                string   enteredExcludedHeaders = inspector.ExcludedHeaders;
                string[] excludedHeadersArray   = enteredExcludedHeaders.Split(",");


                //Dictionary<object, string> theDictionary = new Dictionary<object, string>();
                //foreach (var item in response.Headers)
                //{
                //    if (!excludedHeadersArray.Contains(item))
                //    {
                //        for (int i = 0; i < response.Headers.Count; ++i)
                //        {
                //            theDictionary.Add(item, response.Headers[i]);
                //        }
                //    }
                //    else { continue; }
                //}
                //ViewBag.DictionaryTest = theDictionary;

                List <KeyValuePair <string, string> > testList = new List <KeyValuePair <string, string> >();
                foreach (string item in response.Headers)
                {
                    if (!excludedHeadersArray.Contains(item))
                    {
                        testList.Add(new KeyValuePair <string, string>(item, response.Headers[item]));
                    }
                    else
                    {
                        continue;
                    }
                }
                ViewBag.TestList = testList;
                for (int i = 0; i < testList.Count; ++i)
                {
                    var toPrint = testList[i];
                    ViewBag.ToPrint = toPrint;
                }



                foreach (string key in response.Headers)
                {
                    if (!excludedHeadersArray.Contains(key))
                    {
                        // To add the Key to the list.
                        headerKeys.Add(key);
                        // To add the Value to the list.
                        headerValues.Add(response.Headers[key]);
                    }
                    else
                    {
                        continue;
                    }
                }
                ViewBag.headKeys   = headerKeys;
                ViewBag.headValues = headerValues;

                // Sends us to the "HeaderInspectorResults.cshtml" view
                // Along with the new info (users input saved in the "inspector" variable) as the model to the view.
                return(View("HeaderInspectorResults", inspector));
            }
            else
            {
                // Something is wrong with the model - will return the original NewHeaderInspector.cshtml view.
                return(View());
            }
        }