Exemplo n.º 1
0
        /// <summary>
        /// Original line-endings in the text are respected.
        /// </summary>
        /// <param name="text"> to wrap </param>
        /// <param name="lineLength"> no line will exceed this length </param>
        /// <returns> the text where no line exceeds the specified length </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public static String wrapText(final String text, final int lineLength)
        public static string WrapText(string text, int lineLength)
        {
            IList <string> lines = Arrays.asList(text.Split("\r?\n", true));

//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            return(lines.Select(l => l.length() > lineLength ? WordUtils.wrap(l, lineLength) : l).collect(Collectors.joining(_newline)));
        }
Exemplo n.º 2
0
        public void Can_TitleCase_Simple_Double_Word_Title()
        {
            string test   = "QUICK brown";
            string result = WordUtils.ToTitleCase(test);

            Assert.AreEqual("Quick Brown", result);
        }
Exemplo n.º 3
0
        public void Can_TitleCase_Simple_Single_Word_Title()
        {
            string test   = "quick";
            string result = WordUtils.ToTitleCase(test);

            Assert.AreEqual("Quick", result);
        }
Exemplo n.º 4
0
        public void Can_TitleCase_Simple_Multi_Word_Title()
        {
            string test   = "QUICK brown FOX JuMps DoG";
            string result = WordUtils.ToTitleCase(test);

            Assert.AreEqual("Quick Brown Fox Jumps Dog", result);
        }
Exemplo n.º 5
0
        public void FormatCaseWordTest()
        {
            IWordUtils wordUtils = new WordUtils();

            Assert.Equal("лайков", wordUtils.FormatCaseWord(0, "лайков", "лайк", "лайка"));
            Assert.Equal("лайк", wordUtils.FormatCaseWord(1, "лайков", "лайк", "лайка"));
            Assert.Equal("лайка", wordUtils.FormatCaseWord(2, "лайков", "лайк", "лайка"));
            Assert.Equal("лайка", wordUtils.FormatCaseWord(3, "лайков", "лайк", "лайка"));
            Assert.Equal("лайка", wordUtils.FormatCaseWord(4, "лайков", "лайк", "лайка"));

            for (var i = 5; i <= 20; i++)
            {
                Assert.Equal("лайков", wordUtils.FormatCaseWord(i, "лайков", "лайк", "лайка"));
            }

            Assert.Equal("лайк", wordUtils.FormatCaseWord(21, "лайков", "лайк", "лайка"));
            Assert.Equal("лайка", wordUtils.FormatCaseWord(22, "лайков", "лайк", "лайка"));
            Assert.Equal("лайка", wordUtils.FormatCaseWord(23, "лайков", "лайк", "лайка"));
            Assert.Equal("лайка", wordUtils.FormatCaseWord(24, "лайков", "лайк", "лайка"));

            Assert.Equal("лайков", wordUtils.FormatCaseWord(25, "лайков", "лайк", "лайка"));
            Assert.Equal("лайков", wordUtils.FormatCaseWord(125, "лайков", "лайк", "лайка"));
            Assert.Equal("лайков", wordUtils.FormatCaseWord(1025, "лайков", "лайк", "лайка"));
            Assert.Equal("лайков", wordUtils.FormatCaseWord(1125, "лайков", "лайк", "лайка"));
            Assert.Equal("лайков", wordUtils.FormatCaseWord(10025, "лайков", "лайк", "лайка"));
            Assert.Equal("лайков", wordUtils.FormatCaseWord(10125, "лайков", "лайк", "лайка"));
            Assert.Equal("лайков", wordUtils.FormatCaseWord(11125, "лайков", "лайк", "лайка"));
        }
Exemplo n.º 6
0
        public void Can_TitleCase_Title_Beginning_With_Article_Conjunction_Preposition()
        {
            string test   = "the quick brown fox";
            string result = WordUtils.ToTitleCase(test);

            Assert.AreEqual("The Quick Brown Fox", result);
        }
Exemplo n.º 7
0
            /// <summary>
            /// Return the ith row of the column as a set of wrapped strings, each at
            /// most wrapWidth in length.
            /// </summary>
            internal virtual string[] GetRow(int idx)
            {
                string raw = rows[idx];

                // Line-wrap if it's too long
                string[] lines = new string[] { raw };
                if (wrap)
                {
                    lines = WordUtils.Wrap(lines[0], wrapWidth, "\n", true).Split("\n");
                }
                for (int i = 0; i < lines.Length; i++)
                {
                    if (justification == TableListing.Justification.Left)
                    {
                        lines[i] = StringUtils.RightPad(lines[i], maxWidth);
                    }
                    else
                    {
                        if (justification == TableListing.Justification.Right)
                        {
                            lines[i] = StringUtils.LeftPad(lines[i], maxWidth);
                        }
                    }
                }
                return(lines);
            }
Exemplo n.º 8
0
        public void Can_TitleCase_Title_Ending_With_Article_Conjunction_Preposition()
        {
            string test   = "quick brown fox where from";
            string result = WordUtils.ToTitleCase(test);

            Assert.AreEqual("Quick Brown Fox Where From", result);
        }
Exemplo n.º 9
0
        public void Can_TitleCase_Title_With_Article_Conjunction_Preposition_After_Punctuation()
        {
            string test   = "quick brown fox: a jumper";
            string result = WordUtils.ToTitleCase(test);

            Assert.AreEqual("Quick Brown Fox: A Jumper", result);
        }
Exemplo n.º 10
0
        public void ContainsSections()
        {
            var data          = new List <KnowlegeData>();
            var inputFilePath = GetDataPath();

            using (var reader = XmlReader.Create(inputFilePath))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("page"))
                    {
                        var outerXml = reader.ReadOuterXml();

                        var infoboxes = outerXml.Split(WordUtils.Infobox, System.StringSplitOptions.RemoveEmptyEntries).Skip(1);
                        var geoboxes  = outerXml.Split(WordUtils.Geobox, System.StringSplitOptions.RemoveEmptyEntries).Skip(1);
                        var citations = outerXml.Split(WordUtils.Citacia, System.StringSplitOptions.RemoveEmptyEntries).Skip(1);

                        if (infoboxes.Any() || geoboxes.Any() || citations.Any())
                        {
                            WordUtils.TrimBoxes <Infobox>(infoboxes, ref data);
                            WordUtils.TrimBoxes <Geobox>(geoboxes, ref data);
                            WordUtils.TrimBoxes <Citation>(citations, ref data);

                            break;
                        }
                    }
                }
            }

            Assert.IsTrue(data.Any());
        }
Exemplo n.º 11
0
        public void Can_TitelCase_Title_With_Article_Conjunction_Preposition()
        {
            string test   = "QUICK BROWN foX IS A dog JUMPER";
            string result = WordUtils.ToTitleCase(test);

            Assert.AreEqual("Quick Brown Fox Is a Dog Jumper", result);
        }
Exemplo n.º 12
0
        public bool UploadWordSwfUpload(out string message, out string fileName)
        {
            message = fileName = string.Empty;

            if (Request.Files["Filedata"] == null)
            {
                return(false);
            }
            var postedFile = Request.Files["Filedata"];

            try
            {
                fileName = postedFile.FileName;
                var extendName = fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal)).ToLower();
                if (extendName == ".doc" || extendName == ".docx")
                {
                    var filePath = WordUtils.GetWordFilePath(fileName);
                    postedFile.SaveAs(filePath);
                    return(true);
                }
                message = "请选择Word文件上传!";
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(false);
        }
Exemplo n.º 13
0
        protected override object Process()
        {
            var fileName = AuthRequest.HttpRequest["fileName"];

            var fileCount = AuthRequest.HttpRequest.Files.Count;

            string filePath = null;

            if (fileCount > 0)
            {
                var file = AuthRequest.HttpRequest.Files[0];

                //var fileName = Path.GetFileName(file.FileName);
                //var path = context.Server.MapPath("~/upload/" + fileName);

                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = Path.GetFileName(file.FileName);
                }

                var extendName = fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal)).ToLower();
                if (extendName == ".doc" || extendName == ".docx")
                {
                    filePath = WordUtils.GetWordFilePath(fileName);
                    file.SaveAs(filePath);
                }
            }

            return(GetResponseObject(fileName, filePath));
        }
Exemplo n.º 14
0
        private void InitializeLogin()
        {
            try
            {
                loginControl1.ToReveal = uxArticlePanel;
                loginControl1.ShowLogin();


                if (!SitecoreClient.IsAvailable())
                {
                    SitecoreUser.GetUser().Logout();
                }
                if (SitecoreUser.GetUser().IsLoggedIn)
                {
                    _wordUtils = new WordUtils();
                    loginControl1.HideLogin();
                    UpdateFieldsUsingSitecore();
                }
            }
            catch (UnauthorizedAccessException uax)
            {
                Globals.SitecoreAddin.LogException("ArticleDetail.InitializeLogin: Unauthorized access to API handler. Must re-login", uax);
                throw uax;
            }
            catch (Exception ex)
            {
                var ax = new ApplicationException("ArticleDetail.InitializeLogin: Error setting up the login screen!", ex);
                Globals.SitecoreAddin.LogException(ax.Message, ex);
                throw ax;
            }
        }
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            var fileNames = Request.Form["fileNames"];

            if (!string.IsNullOrEmpty(fileNames))
            {
                fileNames = fileNames.Trim('|');
                var builder = new StringBuilder();

                foreach (var fileName in fileNames.Split('|'))
                {
                    var filePath    = PathUtils.GetTemporaryFilesPath(fileName);
                    var wordContent = WordUtils.Parse(SiteId, filePath, CbIsClearFormat.Checked, CbIsFirstLineIndent.Checked, CbIsClearFontSize.Checked, CbIsClearFontFamily.Checked, CbIsClearImages.Checked);
                    wordContent = ContentUtility.TextEditorContentDecode(SiteInfo, wordContent, true);
                    builder.Append(wordContent);
                    FileUtils.DeleteFileIfExists(filePath);
                }
                var script = "parent." + UEditorUtils.GetInsertHtmlScript(_attributeName, builder.ToString());
                LayerUtils.CloseWithoutRefresh(Page, script);
            }
            else
            {
                FailMessage("请选择Word文件上传!");
            }
        }
Exemplo n.º 16
0
        public void AddWordAndExample(WordAndExampleDto dto)
        {
            _unitOfWork.BeginTransaction();
            var description     = dto.Description;
            var distinctedWords = WordUtils.ExtractDistinct(description);
            //var tokens = Regex.Split(dto.Description, "\r\n").Where(x => x.Trim() != string.Empty).ToArray();
            //if (tokens.Length % 2 != 0)
            //{
            //    var errors = new List<string>() { "Khong the luu description" };

            //    throw new HttpResponseException(new HttpResponseMessage() {
            //        Content = new StringContent("Khong the luu description"), StatusCode = HttpStatusCode.BadRequest });
            //}
            var idxSub  = description.Length > 200 ? description.Substring(0, 200) : description.Substring(0, description.Length / 2);
            var example = _exampleRepos.Create(new Example
            {
                Name        = idxSub,
                Description = description,
                CreatedAt   = DateTimeOffset.Now,
                Url         = dto.Url
            });
            var wordsInExample = CheckWords(distinctedWords);

            _unitOfWork.Save();
            var newWordExample = wordsInExample.Select(x => new WordExample
            {
                ExampleId = example.Id,
                WordId    = x.Id
            });

            _wordExampleRepos.AddListWordExample(newWordExample);
            _unitOfWork.Save();
            _unitOfWork.Commit();
        }
Exemplo n.º 17
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            var fileCount = TranslateUtils.ToInt(Request.Form["File_Count"]);

            if (fileCount == 1)
            {
                var fileName    = Request.Form["fileName_1"];
                var redirectUrl = WebUtils.GetContentAddUploadWordUrl(SiteId, _channelInfo, CbIsFirstLineTitle.Checked, CbIsFirstLineRemove.Checked, CbIsClearFormat.Checked, CbIsFirstLineIndent.Checked, CbIsClearFontSize.Checked, CbIsClearFontFamily.Checked, CbIsClearImages.Checked, TranslateUtils.ToIntWithNagetive(DdlContentLevel.SelectedValue), fileName, _returnUrl);
                LayerUtils.CloseAndRedirect(Page, redirectUrl);

                return;
            }
            if (fileCount > 1)
            {
                var tableName         = ChannelManager.GetTableName(SiteInfo, _channelInfo);
                var relatedIdentities = RelatedIdentities.GetChannelRelatedIdentities(SiteId, _channelInfo.Id);
                var styleInfoList     = TableStyleManager.GetTableStyleInfoList(tableName, relatedIdentities);

                for (var index = 1; index <= fileCount; index++)
                {
                    var fileName = Request.Form["fileName_" + index];
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        var formCollection = WordUtils.GetWordNameValueCollection(SiteId, CbIsFirstLineTitle.Checked, CbIsFirstLineRemove.Checked, CbIsClearFormat.Checked, CbIsFirstLineIndent.Checked, CbIsClearFontSize.Checked, CbIsClearFontFamily.Checked, CbIsClearImages.Checked, TranslateUtils.ToInt(DdlContentLevel.SelectedValue), fileName);

                        if (!string.IsNullOrEmpty(formCollection[ContentAttribute.Title]))
                        {
                            var contentInfo = new ContentInfo();

                            BackgroundInputTypeParser.SaveAttributes(contentInfo, SiteInfo, styleInfoList, formCollection, ContentAttribute.AllAttributesLowercase);

                            contentInfo.ChannelId        = _channelInfo.Id;
                            contentInfo.SiteId           = SiteId;
                            contentInfo.AddUserName      = Body.AdminName;
                            contentInfo.AddDate          = DateTime.Now;
                            contentInfo.LastEditUserName = contentInfo.AddUserName;
                            contentInfo.LastEditDate     = contentInfo.AddDate;

                            contentInfo.CheckedLevel = TranslateUtils.ToIntWithNagetive(DdlContentLevel.SelectedValue);
                            contentInfo.IsChecked    = contentInfo.CheckedLevel >= SiteInfo.Additional.CheckContentLevel;

                            contentInfo.Id = DataProvider.ContentDao.Insert(tableName, SiteInfo, contentInfo);

                            if (contentInfo.IsChecked)
                            {
                                CreateManager.CreateContentAndTrigger(SiteId, _channelInfo.Id, contentInfo.Id);
                            }
                        }
                    }
                }
            }

            LayerUtils.Close(Page);
        }
        public LibraryTextInfo Create()
        {
            var auth = new AuthenticatedRequest();

            if (!auth.IsAdminLoggin ||
                !auth.AdminPermissionsImpl.HasSitePermissions(auth.SiteId,
                                                              ConfigManager.SitePermissions.Library))
            {
                return(Request.Unauthorized <LibraryTextInfo>());
            }

            var library = new LibraryTextInfo
            {
                GroupId = auth.GetQueryInt("groupId")
            };

            var fileName  = auth.HttpRequest["fileName"];
            var fileCount = auth.HttpRequest.Files.Count;

            if (fileCount == 0)
            {
                return(Request.BadRequest <LibraryTextInfo>("请选择有效的文件上传"));
            }

            var file = auth.HttpRequest.Files[0];

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = Path.GetFileName(file.FileName);
            }

            var sExt = PathUtils.GetExtension(fileName);

            if (!StringUtils.EqualsIgnoreCase(sExt, ".doc") && !StringUtils.EqualsIgnoreCase(sExt, ".docx") && !StringUtils.EqualsIgnoreCase(sExt, ".wps"))
            {
                return(Request.BadRequest <LibraryTextInfo>("文件只能是 Word 格式,请选择有效的文件上传!"));
            }

            var libraryFileName      = PathUtils.GetLibraryFileName(fileName);
            var virtualDirectoryPath = PathUtils.GetLibraryVirtualPath(EUploadType.Image, libraryFileName);

            var directoryPath = PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, virtualDirectoryPath);
            var filePath      = PathUtils.Combine(directoryPath, libraryFileName);

            DirectoryUtils.CreateDirectoryIfNotExists(filePath);
            file.SaveAs(filePath);

            var wordContent = WordUtils.Parse(auth.SiteId, filePath, true, true, true, true, false);

            FileUtils.DeleteFileIfExists(filePath);

            library.Title   = fileName;
            library.Content = wordContent;
            library.Id      = DataProvider.LibraryTextDao.Insert(library);

            return(library);
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            String docFile    = @"D:\资料备份\资料\工作\测试\anythingToImage\from\test.doc";
            String docxFile   = @"D:\资料备份\资料\工作\测试\anythingToImage\from\test.docx";
            String outputFile = @"D:\资料备份\资料\工作\测试\anythingToImage\to\";

            WordUtils.ConvertToPDF(docFile, outputFile + docFile.Substring(docFile.LastIndexOf("\\")) + ".pdf");
            WordUtils.ConvertToPDF(docxFile, outputFile + docxFile.Substring(docxFile.LastIndexOf("\\")) + ".pdf");
        }
Exemplo n.º 20
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                var fileCount = TranslateUtils.ToInt(Request.Form["File_Count"]);
                if (fileCount == 1)
                {
                    var fileName    = Request.Form["fileName_1"];
                    var redirectUrl = WebUtils.GetContentAddUploadWordUrl(PublishmentSystemId, _nodeInfo, cbIsFirstLineTitle.Checked, cbIsFirstLineRemove.Checked, cbIsClearFormat.Checked, cbIsFirstLineIndent.Checked, cbIsClearFontSize.Checked, cbIsClearFontFamily.Checked, cbIsClearImages.Checked, TranslateUtils.ToIntWithNagetive(rblContentLevel.SelectedValue), fileName, _returnUrl);
                    PageUtils.CloseModalPageAndRedirect(Page, redirectUrl);

                    return;
                }
                if (fileCount > 1)
                {
                    var tableStyle        = NodeManager.GetTableStyle(PublishmentSystemInfo, _nodeInfo);
                    var tableName         = NodeManager.GetTableName(PublishmentSystemInfo, _nodeInfo);
                    var relatedIdentities = RelatedIdentities.GetChannelRelatedIdentities(PublishmentSystemId, _nodeInfo.NodeId);

                    for (var index = 1; index <= fileCount; index++)
                    {
                        var fileName = Request.Form["fileName_" + index];
                        if (!string.IsNullOrEmpty(fileName))
                        {
                            var formCollection = WordUtils.GetWordNameValueCollection(PublishmentSystemId, _nodeInfo.ContentModelId, cbIsFirstLineTitle.Checked, cbIsFirstLineRemove.Checked, cbIsClearFormat.Checked, cbIsFirstLineIndent.Checked, cbIsClearFontSize.Checked, cbIsClearFontFamily.Checked, cbIsClearImages.Checked, TranslateUtils.ToInt(rblContentLevel.SelectedValue), fileName);

                            if (!string.IsNullOrEmpty(formCollection[ContentAttribute.Title]))
                            {
                                var contentInfo = ContentUtility.GetContentInfo(tableStyle);

                                BackgroundInputTypeParser.AddValuesToAttributes(tableStyle, tableName, PublishmentSystemInfo, relatedIdentities, formCollection, contentInfo.Attributes, ContentAttribute.HiddenAttributes);

                                contentInfo.NodeId = _nodeInfo.NodeId;
                                contentInfo.PublishmentSystemId = PublishmentSystemId;
                                contentInfo.AddUserName         = Body.AdministratorName;
                                contentInfo.AddDate             = DateTime.Now;
                                contentInfo.LastEditUserName    = contentInfo.AddUserName;
                                contentInfo.LastEditDate        = contentInfo.AddDate;

                                contentInfo.CheckedLevel = TranslateUtils.ToIntWithNagetive(rblContentLevel.SelectedValue);
                                contentInfo.IsChecked    = contentInfo.CheckedLevel >= PublishmentSystemInfo.CheckContentLevel;

                                contentInfo.Id = DataProvider.ContentDao.Insert(tableName, PublishmentSystemInfo, contentInfo);

                                if (contentInfo.IsChecked)
                                {
                                    CreateManager.CreateContentAndTrigger(PublishmentSystemId, _nodeInfo.NodeId, contentInfo.Id);
                                }
                            }
                        }
                    }
                }

                PageUtils.CloseModalPage(Page);
            }
        }
Exemplo n.º 21
0
            public virtual string GetLongUsage()
            {
                TableListing listing = AdminHelper.GetOptionDescriptionListing();

                listing.AddRow("-stats", "Display additional cache pool statistics.");
                listing.AddRow("<name>", "If specified, list only the named cache pool.");
                return(GetShortUsage() + "\n" + WordUtils.Wrap("Display information about one or more cache pools, "
                                                               + "e.g. name, owner, group, permissions, etc.", AdminHelper.MaxLineWidth) + "\n\n"
                       + listing.ToString());
            }
Exemplo n.º 22
0
        /// <summary>
        /// Deal hyperlinks in document are the same as the Sitecore token, so thus should
        /// be transferred to Sitecore as is if the author does not edit the hyperlink text
        /// </summary>
        /// <param name="hyperlink"></param>
        /// <returns></returns>
        public static bool IsADealHyperlink(Hyperlink hyperlink)
        {
            if (!WordUtils.IsHyperlinkValid(hyperlink))
            {
                return(false);
            }

            return(hyperlink != null &&
                   (hyperlink.ScreenTip != null &&
                    (hyperlink.ScreenTip.Equals(DealTooltip))));
        }
Exemplo n.º 23
0
        private void PopulateFieldsOnAuthentication(object sender, EventArgs e)
        {
            SuspendLayout();
            _wordUtils = new WordUtils();
            InitializeFields();
            ESRibbon ribbon = Globals.Ribbons.GetRibbon <ESRibbon>();

            ribbon?.IsLoggedIn();
            UpdateFieldsUsingSitecore();
            ResetChangedStatus();
            ResumeLayout();
            CloseOnSuccessfulLock = false; //no longer close on lock; only try once
        }
Exemplo n.º 24
0
        internal virtual object GetField(NamedAndTyped relationship)
        {
            object o = this.map.Get(relationship);

            if (o is BeanProperty)
            {
                return(GetMessageBeanPart().GetField(WordUtils.Uncapitalize(((BeanProperty)o).Name)));
            }
            else
            {
                throw new MarshallingException("Relationship " + relationship.Name + " of " + ToString() + " does not resolve to a bean property"
                                               );
            }
        }
Exemplo n.º 25
0
        private Hashtable Upload()
        {
            var success  = false;
            var fileName = string.Empty;
            var message  = "Word上传失败";

            if (Request.Files["filedata"] != null)
            {
                var postedFile = Request.Files["filedata"];
                try
                {
                    if (!string.IsNullOrEmpty(postedFile?.FileName))
                    {
                        fileName = postedFile.FileName;
                        var extendName = fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal)).ToLower();
                        if (extendName == ".doc" || extendName == ".docx")
                        {
                            var filePath = WordUtils.GetWordFilePath(fileName);
                            postedFile.SaveAs(filePath);

                            success = true;
                        }
                        else
                        {
                            FailMessage("请选择Word文件上传!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }
            }

            var jsonAttributes = new Hashtable();

            if (success)
            {
                jsonAttributes.Add("success", "true");
                jsonAttributes.Add("fileName", fileName);
            }
            else
            {
                jsonAttributes.Add("success", "false");
                jsonAttributes.Add("message", message);
            }

            return(jsonAttributes);
        }
Exemplo n.º 26
0
            public virtual string GetLongUsage()
            {
                TableListing listing = AdminHelper.GetOptionDescriptionListing();

                listing.AddRow("<name>", "Name of the pool to modify.");
                listing.AddRow("<owner>", "Username of the owner of the pool");
                listing.AddRow("<group>", "Groupname of the group of the pool.");
                listing.AddRow("<mode>", "Unix-style permissions of the pool in octal.");
                listing.AddRow("<limit>", "Maximum number of bytes that can be cached " + "by this pool."
                               );
                listing.AddRow("<maxTtl>", "The maximum allowed time-to-live for " + "directives being added to the pool."
                               );
                return(GetShortUsage() + "\n" + WordUtils.Wrap("Modifies the metadata of an existing cache pool. "
                                                               + "See usage of " + CacheAdmin.AddCachePoolCommand.Name + " for more details.",
                                                               AdminHelper.MaxLineWidth) + "\n\n" + listing.ToString());
            }
Exemplo n.º 27
0
        public static String ToPath(String path)
        {
            StringBuilder builder = new StringBuilder();

            String[] parts = StringUtils.Split(path, ".");
            bool     first = true;

            foreach (String part in parts)
            {
                if (!first)
                {
                    builder.Append(".");
                }
                builder.Append(WordUtils.Capitalize(part));
                first = false;
            }
            return(builder.ToString());
        }
Exemplo n.º 28
0
        private void PrintInstanceHelp(TextWriter @out, Command instance)
        {
            @out.WriteLine(instance.GetUsage() + " :");
            TableListing listing = null;
            string       prefix  = "  ";

            foreach (string line in instance.GetDescription().Split("\n"))
            {
                if (line.Matches("^[ \t]*[-<].*$"))
                {
                    string[] segments = line.Split(":");
                    if (segments.Length == 2)
                    {
                        if (listing == null)
                        {
                            listing = CreateOptionTableListing();
                        }
                        listing.AddRow(segments[0].Trim(), segments[1].Trim());
                        continue;
                    }
                }
                // Normal literal description.
                if (listing != null)
                {
                    foreach (string listingLine in listing.ToString().Split("\n"))
                    {
                        @out.WriteLine(prefix + listingLine);
                    }
                    listing = null;
                }
                foreach (string descLine in WordUtils.Wrap(line, MaxLineWidth, "\n", true).Split(
                             "\n"))
                {
                    @out.WriteLine(prefix + descLine);
                }
            }
            if (listing != null)
            {
                foreach (string listingLine in listing.ToString().Split("\n"))
                {
                    @out.WriteLine(prefix + listingLine);
                }
            }
        }
Exemplo n.º 29
0
        public void Execute()
        {
            Interval      confines = _view.GetLimitFields();
            List <Book>   books    = _context.GetAllBooks();
            List <string> outputs  = new List <string>();

            foreach (Book book in books)
            {
                if (book.Limit.from >= confines.from && book.Limit.till <= confines.till)
                {
                    string value = $"\"{book.Title}\" : {book.Limit.ToString()}";
                    _view.SetOutputField(value);
                    outputs.Add(value);
                }
            }

            string filename = _view.GetFileNameField();

            WordUtils.PrintToWord(outputs, filename);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Load items from KnowledgeData part - split by '|' and decoding type of item
        /// </summary>
        /// <returns></returns>
        private Dictionary <RegexKeyType, string[]> LoadItems()
        {
            var items = new Dictionary <RegexKeyType, string[]>();

            this.Content = this.Content.Replace("|", " | ");

            Regex.Split(this.Content, @"\s\| ")
            .Where(word => word.Contains("=")).ToList()
            .ForEach(item =>
            {
                var word = Regex.Split(item, "=");
                if (word.Count() == 2)
                {
                    var key   = WordUtils.TrimWhiteSpaces(word[0]);
                    var value = WordUtils.TrimWhiteSpaces(word[1]);

                    if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value))
                    {
                        var values = SplitMultipleValues(value);
                        var type   = new RegexKeyType();
                        type.Value = key;

                        try
                        {
                            items.Add(type, values);
                        }
                        catch { }
                    }
                }
            });

            return(items.Where(i => Attributes.Any(a => Regex.IsMatch(i.Key.Value, a.Value)))
                   .ToDictionary(i => {
                var key = i.Key;
                key.Type = Attributes.FirstOrDefault(a => Regex.Match(key.Value, a.Value).Success).Type;
                return key;
            },
                                 i => i.Value));
            //Attributes.FirstOrDefault(a => Regex.Match(i.Key, a).Success)
        }