Example #1
0
 int replaceOccurencesOfText(IContentCommon c, string find, string replace, bool caseSensitive, bool searchHtmlSource)
 {
     int count = 0;
     string s;
     if (c is ContentBase) {
         s = ((ContentBase)c).Name;
         count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
         ((ContentBase)c).Name = s;
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.LongTextProperty)) {
         LongStringPropertyValue pv = (LongStringPropertyValue)p;
         s = pv.Value;
         count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
         pv.Value = s;
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.HTMLProperty)) {
         HTMLPropertyValue pv = (HTMLPropertyValue)p;
         if (!searchHtmlSource) {
             s = pv.Value;
             count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
             pv.Value = s;
             //HtmlNode htmlMain = new HtmlNode(pv.Value, HtmlFilter.TextFilter);
             //// count += replaceOccurencesOfText(textOnly, find, replace, caseSensitive);
             //throw new NotImplementedException("Non HTML source replace in HTML field is not supported yet. ");
         } else {
             s = pv.Value;
             count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
             pv.Value = s;
         }
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.ShortTextProperty)) {
         if (p is ShortStringPropertyValue) {
             ShortStringPropertyValue pv = (ShortStringPropertyValue)p;
             s = pv.Value;
             count += replaceOccurencesOfText(ref s, find, replace, caseSensitive);
             pv.Value = s;
         }
     }
     foreach (IInnerContentsPropertyValue icp in c.GetAllPropertyValues(PropertyBaseClass.InnerContents)) {
         foreach (IInnerContent ic in icp.GetAllContents()) {
             count += replaceOccurencesOfText(ic, find, replace, caseSensitive, searchHtmlSource);
         }
     }
     return count;
 }
Example #2
0
 void resizeImages(IContentCommon ic, int max)
 {
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.FileProperty)) {
         if (WFContext.BreakExecution) return;
         var fp = (FilePropertyValue)f;
         if (fp.IsImage()) {
             WFContext.Caption = "Rescaling images...";
             WFContext.Description = _countContents + " contents examined. " + _countResized + " images rescaled. Before: " + Utils.GetByteSizeString(bytesBefore) + ". After: " + Utils.GetByteSizeString(bytesAfter);
             _totalCount++;
             int pixels = fp.ImageHeight * fp.ImageWidth;
             if (pixels > max) {
                 double ration = Math.Sqrt((double)pixels / (double)max);
                 int newHeight = (int)Math.Round((double)fp.ImageHeight / ration);
                 int newWidth = (int)Math.Round((double)fp.ImageWidth / ration);
                 string tempFilePath = Engine.FileTempPath + Guid.NewGuid();
                 ImageAdjustments ia = new ImageAdjustments();
                 ia.CanvasX = newWidth;
                 ia.CanvasY = newHeight;
                 bytesBefore += WAFRuntime.FileSystem.GetFileInfo(fp.GetFilePath()).Length;
                 WAFRuntime.FileSystem.FileCopy(fp.GetFilePath(ia), tempFilePath);
                 bytesAfter += WAFRuntime.FileSystem.GetFileInfo(tempFilePath).Length;
                 string newFileName = fp.FileName.Replace("%20", "_").Replace(" ", "_") + "_" + fp.FileExtension;
                 fp.SetFile(tempFilePath, newFileName, true);
                 _countResized++;
             }
         }
     }
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.FileFolderProperty)) {
         var fp = (IInnerContentsPropertyValue)f;
         foreach (var ff in fp.GetAllContents()) resizeImages(ff, max);
     }
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.InnerContents)) {
         var fp = (IInnerContentsPropertyValue)f;
         foreach (var ff in fp.GetAllContents()) resizeImages(ff, max);
     }
 }
Example #3
0
 int countOccurencesOfText(IContentCommon c, string find, bool caseSensitive, bool searchHtmlSource)
 {
     int count = 0;
     if (c is ContentBase) {
         count += countOccurencesOfText(((ContentBase)c).Name, find, caseSensitive);
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.LongTextProperty)) {
         try {
             LongStringPropertyValue pv = (LongStringPropertyValue)p;
             count += countOccurencesOfText(pv.Value, find, caseSensitive);
         } catch {
         }
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.HTMLProperty)) {
         HTMLPropertyValue pv = (HTMLPropertyValue)p;
         if (!searchHtmlSource) {
             string textOnly = new HtmlNode(pv.Value, HtmlFilter.TextFilter).ToString();
             count += countOccurencesOfText(textOnly, find, caseSensitive);
         } else {
             count += countOccurencesOfText(pv.Value, find, caseSensitive);
         }
     }
     foreach (object p in c.GetAllPropertyValues(PropertyBaseClass.ShortTextProperty)) {
         if (p is ShortStringPropertyValue) {
             ShortStringPropertyValue pv = (ShortStringPropertyValue)p;
             count += countOccurencesOfText(pv.Value, find, caseSensitive);
         }
     }
     foreach (IInnerContentsPropertyValue icp in c.GetAllPropertyValues(PropertyBaseClass.InnerContents)) {
         foreach (IInnerContent ic in icp.GetAllContents()) {
             count += countOccurencesOfText(ic, find, caseSensitive, searchHtmlSource);
         }
     }
     return count;
 }
Example #4
0
 void resetVideoEncoding(IContentCommon ic)
 {
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.FileProperty)) {
         if (WFContext.BreakExecution) return;
         var fp = (FilePropertyValue)f;
         if (fp.IsVideo()) {
             WFContext.Caption = "Resetting encoding video files...";
             WFContext.Description = _countContents + " contents examined. " + _countReset + " video files reset. ";
             _totalCount++;
             string tempFilePath = Engine.FileTempPath + Guid.NewGuid();
             string newFileName = fp.FileName.Replace("%20", "_").Replace(" ", "_") + "_" + fp.FileExtension;
             WAFRuntime.FileSystem.FileMove(fp.GetFilePath(), tempFilePath);
             fp.SetFile(tempFilePath, newFileName, true);
             _countReset++;
         }
     }
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.FileFolderProperty)) {
         var fp = (IInnerContentsPropertyValue)f;
         foreach (var ff in fp.GetAllContents()) resetVideoEncoding(ff);
     }
     foreach (var f in ic.GetAllPropertyValues(PropertyBaseClass.InnerContents)) {
         var fp = (IInnerContentsPropertyValue)f;
         foreach (var ff in fp.GetAllContents()) resetVideoEncoding(ff);
     }
 }