internal static void Copy(this IFileSystem fileSystem, string source, string destination) { // if copying a file if (File.Exists(source)) { fileSystem.WriteFile(destination, File.ReadAllText(source)); return; } // if copying a directory if (fileSystem.DirectoryExists(destination)) { fileSystem.DeleteDirectory(destination); } fileSystem.CreateDirectory(destination); // Copy dirs recursively foreach (var child in Directory.GetDirectories(Path.GetFullPath(source), "*", SearchOption.TopDirectoryOnly).Select(p => Path.GetDirectoryName(p))) { fileSystem.Copy(Path.Combine(source, child), Path.Combine(destination, child)); } // Copy files foreach (var childFile in Directory.GetFiles(Path.GetFullPath(source), "*", SearchOption.TopDirectoryOnly).Select(p=>Path.GetFileName(p))) { fileSystem.Copy(Path.Combine(source, childFile), Path.Combine(destination, childFile)); } }
/// <summary> /// Divide the specified Rectangle into two component rectangles /// </summary> /// <param name="amount">Amount to move away from the given edge</param> /// <param name="fromEdge">The edge to create the slice from.</param> public static Tuple<RectangleF, RectangleF> Divide(this RectangleF This, float amount, RectEdge fromEdge) { var delta = default(float); switch (fromEdge) { case RectEdge.Left: delta = Math.Max(This.Width, amount); return Tuple.Create( This.Copy(Width: delta), This.Copy(X: This.Left + delta, Width: This.Width - delta)); case RectEdge.Top: delta = Math.Max(This.Height, amount); return Tuple.Create( This.Copy(Height: amount), This.Copy(Y: This.Top + delta, Height: This.Height - delta)); case RectEdge.Right: delta = Math.Max(This.Width, amount); return Tuple.Create( This.Copy(X: This.Right - delta, Width: delta), This.Copy(Width: This.Width - delta)); case RectEdge.Bottom: delta = Math.Max(This.Height, amount); return Tuple.Create( This.Copy(Y: This.Bottom - delta, Height: delta), This.Copy(Height: This.Height - delta)); default: throw new ArgumentException("edge"); } }
public static void ExtendWithContextMenu(this TextEditor rtb) { ContextMenu ctx = new ContextMenu(); MenuItem cut = new MenuItem(); cut.Header = "Cut"; cut.Click += (sender, e) => rtb.Cut(); MenuItem copy = new MenuItem(); copy.Header = "Copy"; copy.Click += (sender, e) => rtb.Copy(); MenuItem paste = new MenuItem(); paste.Header = "Paste"; paste.Click += (sender, e) => rtb.Paste(); ctx.Items.Add(cut); ctx.Items.Add(copy); ctx.Items.Add(paste); rtb.ContextMenu = ctx; ctx.Opened += (sender, e) => { bool noSelectedText = string.IsNullOrEmpty(rtb.SelectedText); cut.IsEnabled = !noSelectedText; copy.IsEnabled = !noSelectedText; bool noClipboardText = string.IsNullOrEmpty(Clipboard.GetText()); paste.IsEnabled = !noClipboardText; }; }
/// <summary> /// Creates a copy of the texture, set to clamped. /// </summary> /// <param name="extends">Extends.</param> public static Texture2D Clamp(this Texture2D extends) { Texture2D output = extends.Copy(); output.wrapMode = TextureWrapMode.Clamp; return output; }
/// <summary> /// Creates a copy of the texture, set to repeat. /// </summary> /// <param name="extends">Extends.</param> public static Texture2D Repeat(this Texture2D extends) { Texture2D output = extends.Copy(); output.wrapMode = TextureWrapMode.Repeat; return output; }
public static OpenCvSharp.IplImage GetSub(this OpenCvSharp.IplImage ipl, OpenCvSharp.CvRect subRect) { if (ipl == null) throw new ArgumentNullException("ipl", "ipl is null."); var boundingRect = new CvRect(0, 0, ipl.Width, ipl.Height); if (!boundingRect.Contains(subRect)) throw new InvalidOperationException("subRect is outside of ipl"); try { ipl.SetROI(subRect); OpenCvSharp.IplImage sub = new IplImage( ipl.GetSize(), ipl.Depth, ipl.NChannels); ipl.Copy(sub); return sub; } finally { ipl.ResetROI(); } }
public static bool CopyRecursive(this GLib.File source, GLib.File target, GLib.FileCopyFlags flags, GLib.Cancellable cancellable, GLib.FileProgressCallback callback) { bool result = true; GLib.FileType ft = source.QueryFileType (GLib.FileQueryInfoFlags.None, cancellable); if (ft != GLib.FileType.Directory) { Hyena.Log.DebugFormat ("Copying \"{0}\" to \"{1}\"", source.Path, target.Path); return source.Copy (target, flags, cancellable, callback); } if (!target.Exists) { Hyena.Log.DebugFormat ("Creating directory: \"{0}\"", target.Path); result = result && target.MakeDirectoryWithParents (cancellable); } GLib.FileEnumerator fe = source.EnumerateChildren ("standard::name", GLib.FileQueryInfoFlags.None, cancellable); GLib.FileInfo fi = fe.NextFile (); while (fi != null) { GLib.File source_file = GLib.FileFactory.NewForPath (Path.Combine (source.Path, fi.Name)); GLib.File target_file = GLib.FileFactory.NewForPath (Path.Combine (target.Path, fi.Name)); result = result && source_file.CopyRecursive(target_file, flags, cancellable, callback); fi = fe.NextFile (); } fe.Close (cancellable); return result; }
public static void CopyToClipboard(this RichTextBox richTextBox) { var textSelection = richTextBox.Selection; var start = textSelection.Start; var textPointer = textSelection.End; richTextBox.SelectAll(); richTextBox.Copy(); richTextBox.Selection.Select(start, textPointer); }
/// <summary> /// Make sure that DBNull.Value is converted to null, so that we treat DBNull and null the same /// on the backend /// </summary> /// <param name="values"></param> /// <returns></returns> public static Dictionary<string, object> ScrubNulls(this Dictionary<string, object> values) { var fields = values.Where(kv => kv.Value == DBNull.Value).Select(kv => kv.Key); if (!fields.Any()) return values; var res = values.Copy(); fields.Each(f => res[f] = null); return res; }
public static PSVariableProperty Clone(this PSVariableProperty source) { if (source == null) throw new ArgumentNullException("source"); var clone = (PSVariableProperty)source.Copy(); clone.Set_instance(null); clone.Set__variable(source.Get__variable().Clone()); return clone; }
public static Int16 ToInt16(this Byte[] source, Endianess endianess, Int32 startIndex = 0) { var bytes = source.Copy(startIndex, NumberHelpers.Int16ByteCount); if (NumberHelpers.Endianess != endianess) { bytes.Swap(); } return bytes.ToInt16(); }
public static FontDescription CopyModified(this FontDescription font, double? scale = null, Pango.Weight? weight = null) { font = font.Copy (); if (scale.HasValue) Scale (font, scale.Value); if (weight.HasValue) font.Weight = weight.Value; return font; }
public static void SaveToFile(this Stream self, string fileName) { if (self == null) throw new ArgumentNullException("self"); if (fileName == null) throw new ArgumentNullException("fileName"); using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { self.Copy(fs); fs.Flush(); fs.Close(); } }
public static OpenCvSharp.IplImage SubImage( this OpenCvSharp.IplImage whole, OpenCvSharp.CvRect region) { whole.SetROI(region); OpenCvSharp.IplImage part = new OpenCvSharp.IplImage(new OpenCvSharp.CvSize(region.Width, region.Height), whole.Depth, whole.NChannels); whole.Copy(part); whole.ResetROI(); return part; }
public static void Print(this Body body, Part part = null) { body = body.Copy(); if (body.PieceCount > 1) { ICollection<Body> bodies = body.SeparatePieces(); Debug.Assert(bodies.Count == body.PieceCount); bodies.Print(); return; } try { DesignBody.Create(part ?? MainPart, GetDebugString(body), body); } catch { } }
public static void Print(this DataGridView dgv, PrintDocument printDocument, bool printLevelByLevel, bool centerPage, bool fitColToPage, bool showPrintSetDlg, bool showPreviewDlg, List<int> toPrintCols, List<int> toPrintRows ) { DataGridView dgvToPrint = dgv.Copy(toPrintCols, toPrintRows); var printProvider = PrintingDataGridViewProvider.Create( printDocument, dgvToPrint, printLevelByLevel, centerPage, fitColToPage, new TitlePrintBlock() { ForeColor = Color.DarkBlue, Font = new Font(SystemFonts.CaptionFont.FontFamily, 16), Title = printDocument.DocumentName }, null, null); bool bContinue = true; if (showPrintSetDlg)//显示打印设置对话框 bContinue = new PrintDialog().ShowDialog() == DialogResult.OK; if (bContinue) { if (showPreviewDlg)//打印预览 { //printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage); PrintPreviewDialog previewdlg = new PrintPreviewDialog(); previewdlg.ShowIcon = false; previewdlg.Document = printDocument; previewdlg.ShowDialog(); } else { printDocument.Print(); } } }
public static void AddContextMenu(this RichTextBox rtb) { if (rtb.ContextMenuStrip == null) { ContextMenuStrip cms = new ContextMenuStrip { ShowImageMargin = false }; ToolStripMenuItem tsmiCut = new ToolStripMenuItem("Cut"); tsmiCut.Click += (sender, e) => rtb.Cut(); cms.Items.Add(tsmiCut); ToolStripMenuItem tsmiCopy = new ToolStripMenuItem("Copy"); tsmiCopy.Click += (sender, e) => rtb.Copy(); cms.Items.Add(tsmiCopy); ToolStripMenuItem tsmiPaste = new ToolStripMenuItem("Paste"); tsmiPaste.Click += (sender, e) => rtb.Paste(); cms.Items.Add(tsmiPaste); rtb.ContextMenuStrip = cms; } }
public static ArgbColor[] GetPixels(this Bitmap bitmap) { ArgbColor[] results; if (bitmap.PixelFormat == PixelFormat.Format32bppArgb) { results = bitmap.Get32BppArgbPixels(); } else { // HACK: Need dedicated bpp methods using (Bitmap copy = bitmap.Copy()) { results = copy.Get32BppArgbPixels(); } } return results; }
public static IBitmap FromNative(this Bitmap This, bool copy = false) { if (copy) return new AndroidBitmap(This.Copy(This.GetConfig(), true)); return new AndroidBitmap(This); }
public static IBitmap FromNative(this Pixbuf This, bool copy = false) { if (copy) return new PixbufBitmap((Pixbuf)This.Copy()); return new PixbufBitmap(This); }
public static void Copy(this Stream self, Stream target) { self.Copy(target, 65536); }
/// <summary> /// Sobel edge detection function /// </summary> /// <param name="Input">Image to manipulate</param> /// <returns>A SwiftBitmap image</returns> public static SwiftBitmap SobelEdgeDetection(this SwiftBitmap Input) { Contract.Requires<ArgumentNullException>(Input != null, "Input"); Input.BlackAndWhite(); using (SwiftBitmap TempImageX = ((SwiftBitmap)Input.Clone()).ApplyConvolutionFilter(new int[][]{ new int[] {-1, 0, 1}, new int[] {-2, 0, 2}, new int[] {-1, 0, 1} }, true)) { using (SwiftBitmap TempImageY = ((SwiftBitmap)Input.Clone()).ApplyConvolutionFilter(new int[][]{ new int[] {1, 2, 1}, new int[] {0, 0, 0}, new int[] {-1, -2, -1} }, true)) { using (SwiftBitmap NewBitmap = new SwiftBitmap(Input.Width, Input.Height)) { NewBitmap.Lock(); TempImageX.Lock(); TempImageY.Lock(); int Width = NewBitmap.Width; int Height = NewBitmap.Height; Parallel.For(0, Width, x => { for (int y = 0; y < Height; ++y) { Color Pixel1 = TempImageX.GetPixel(x, y); Color Pixel2 = TempImageY.GetPixel(x, y); NewBitmap.SetPixel(x, y, Color.FromArgb((Pixel1.R + Pixel2.R).Clamp(255, 0), (Pixel1.G + Pixel2.G).Clamp(255, 0), (Pixel1.B + Pixel2.B).Clamp(255, 0))); } }); NewBitmap.Unlock(); TempImageY.Unlock(); TempImageX.Unlock(); return Input.Copy(NewBitmap).Negative(); } } } }
/// <summary> /// Adds a watermark to an image /// </summary> /// <param name="Image">image to add the watermark to</param> /// <param name="WatermarkImage">Watermark image</param> /// <param name="Opacity"> /// Opacity of the watermark (1.0 to 0.0 with 1 being completely visible and 0 being invisible) /// </param> /// <param name="X">X position in pixels for the watermark</param> /// <param name="Y">Y position in pixels for the watermark</param> /// <param name="KeyColor"> /// Transparent color used in watermark image, set to null if not used /// </param> /// <returns>The results in the form of a SwiftBitmap object</returns> public static SwiftBitmap Watermark(this SwiftBitmap Image, SwiftBitmap WatermarkImage, float Opacity, int X, int Y, Color KeyColor) { Contract.Requires<ArgumentNullException>(Image != null, "Image"); Contract.Requires<ArgumentNullException>(WatermarkImage != null, "WatermarkImage"); using (SwiftBitmap NewSwiftBitmap = new SwiftBitmap(Image.Width, Image.Height).Copy(Image)) { using (Graphics NewGraphics = Graphics.FromImage(NewSwiftBitmap.InternalBitmap)) { float[][] FloatColorMatrix ={ new float[] {1, 0, 0, 0, 0}, new float[] {0, 1, 0, 0, 0}, new float[] {0, 0, 1, 0, 0}, new float[] {0, 0, 0, Opacity, 0}, new float[] {0, 0, 0, 0, 1} }; var NewColorMatrix = new ColorMatrix(FloatColorMatrix); using (ImageAttributes Attributes = new ImageAttributes()) { Attributes.SetColorMatrix(NewColorMatrix); Attributes.SetColorKey(KeyColor, KeyColor); NewGraphics.DrawImage(WatermarkImage.InternalBitmap, new Rectangle(X, Y, WatermarkImage.Width, WatermarkImage.Height), 0, 0, WatermarkImage.Width, WatermarkImage.Height, GraphicsUnit.Pixel, Attributes); } } return Image.Copy(NewSwiftBitmap); } }
public static SearchCriteriaViewModel WithPage(this SearchCriteriaViewModel model, int page) { var newModel = model.Copy(); newModel.Page = page; return newModel; }
/// <summary> /// Create a read-only copy of a <see cref="SecureString"/>. /// </summary> /// <remarks> /// Equivalent to calling <see cref="SecureString.Copy"/> followed by <see cref="SecureString.MakeReadOnly"/>. /// </remarks> /// <returns>Read-only copy of <see cref="SecureString"/></returns> public static SecureString CopyAsReadOnly(this SecureString secureString) { SecureString copy = secureString.Copy(); copy.MakeReadOnly(); return copy; }
/// <summary> /// Creates the normal map /// </summary> /// <param name="ImageUsing">Image to create the normal map from</param> /// <param name="InvertX">Invert the X direction</param> /// <param name="InvertY">Invert the Y direction</param> /// <returns>Returns the resulting normal map</returns> public static SwiftBitmap NormalMap(this SwiftBitmap ImageUsing, bool InvertX = false, bool InvertY = false) { Contract.Requires<ArgumentNullException>(ImageUsing != null, "ImageUsing"); using (SwiftBitmap TempImageX = ((SwiftBitmap)ImageUsing.Clone()).BumpMap(Direction.LeftRight, InvertX)) { using (SwiftBitmap TempImageY = ((SwiftBitmap)ImageUsing.Clone()).BumpMap(Direction.TopBottom, InvertY)) { using (SwiftBitmap ReturnImage = new SwiftBitmap(TempImageX.Width, TempImageX.Height)) { TempImageX.Lock(); TempImageY.Lock(); ReturnImage.Lock(); int Width = TempImageX.Width; int Height = TempImageX.Height; Parallel.For(0, Height, y => { var TempVector = new Vector3(0.0, 0.0, 0.0); for (int x = 0; x < Width; ++x) { Color TempPixelX = TempImageX.GetPixel(x, y); Color TempPixelY = TempImageY.GetPixel(x, y); TempVector.X = (double)(TempPixelX.R) / 255.0; TempVector.Y = (double)(TempPixelY.R) / 255.0; TempVector.Z = 1.0; TempVector.Normalize(); TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0; TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0; TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0; ReturnImage.SetPixel(x, y, Color.FromArgb((int)TempVector.X, (int)TempVector.Y, (int)TempVector.Z)); } }); TempImageX.Unlock(); TempImageY.Unlock(); ReturnImage.Unlock(); return ImageUsing.Copy(ReturnImage); } } } }
public static void Copy(this FileAbstractLayer fal, string sourceFileName, string destFileName) => fal.Copy((RelativePath)sourceFileName, (RelativePath)destFileName);
public static IBody2 ToSheetBody(this ISurface surface, bool transferOwnership = false) => SwAddinBase.Active.Modeler.CreateSurfaceBody(transferOwnership ? surface : (ISurface) surface.Copy());
public static void Copy(this System.IO.DirectoryInfo @this, string source, string destination) { DirectoryInfo dir = new DirectoryInfo(source); DirectoryInfo[] dirs = dir.GetDirectories(); if (!dir.Exists) { throw (new DirectoryNotFoundException("Source directory does not exist or could not be found: " + source)); } if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { string temppath = Path.Combine(destination, file.Name); file.CopyTo(temppath, false); } foreach (var subdir in dirs) { string temppath = Path.Combine(destination, subdir.Name); @this.Copy(subdir.FullName, temppath); } }
/// <summary> /// Creates a new Feature that has a geometry that is the difference between this feature and the specified feature. /// </summary> /// <param name="self">This feature</param> /// <param name="other">The other feature to compare to.</param> /// <returns>A new feature that is the geometric difference between this feature and the specified feature.</returns> public static IFeature Difference(this IFeature self, IGeometry other) { if (other == null) return self.Copy(); IGeometry g = Geometry.FromBasicGeometry(self.BasicGeometry).Difference(other); if (g == null) return null; if (g.IsEmpty) return null; return new Feature(g); }