internal static void MergeImagesList(List <Image> imgArr, string outputFilePath, System.Drawing.Imaging.ImageFormat imageFormat) { using (ListDisposable <Image> images = (ListDisposable <Image>)imgArr) //<== List is now Disposable, and "using block" can be applied { int width = 0; int height = 0; foreach (Image picture in images) { width += picture.Width; height = Math.Max(height, picture.Height); } using (Bitmap imageOut3 = new Bitmap(width, height)) { using (Graphics g = Graphics.FromImage(imageOut3)) { g.Clear(Color.Black); int currentX = 0; for (int i = 0; i < images.Count; i++) { g.DrawImage(images[i], new Point(currentX, 0)); currentX += images[i].Width; } imageOut3.Save(outputFilePath, imageFormat); } } //images.Dispose(); <== instead of implicit calls } }
public static IStream <T> MergeWith <T>(this IStream <T> stream, params IStream <T>[] others) { return(new AnonymousStream <T>((Action <T> reaction, Priority p) => { ListDisposable disp = new ListDisposable(); disp.Add(stream.Listen(reaction, p)); foreach (var other in others) { disp.Add(other.Listen(reaction, p)); } return disp; })); }
public static IEmptyStream MergeWith(this IEmptyStream stream, params IEmptyStream[] others) { return(new AnonymousEmptyStream((reaction, p) => { ListDisposable disp = new ListDisposable(); disp.Add(stream.Listen(reaction, p)); foreach (var other in others) { disp.Add(other.Listen(reaction, p)); } return disp; })); }
public static IDisposable WhateverBind <T>(this ICell <T> cell, Action <T, ConnectionCollector> action, Priority p = Priority.Normal) { var collector = new ConnectionCollector(); var disps = new ListDisposable { collector, cell.Bind(val => { collector.DisconnectAll(); action(val, collector); }, p) }; return(disps); }
public static IDisposable ProcessEach <T>(this IObservableCollection <T> self, Action <T> func, Action <T> onRemove = null) { foreach (var item in self) { func(item); } var finalDisp = new ListDisposable(); var collection = new Collection <T>(); finalDisp.Add(self.ObserveReset().Listen(unit => { if (onRemove != null) { foreach (var element in collection) { onRemove(element); } } collection.Clear(); })); finalDisp.Add(self.ObserveAdd().Listen(add => { func(add.Value); collection.Add(add.Value); })); finalDisp.Add(self.ObserveReplace().Listen(replaceEvent => { collection.Add(replaceEvent.NewValue); collection.Remove(replaceEvent.OldValue); func(replaceEvent.NewValue); if (onRemove != null) { onRemove(replaceEvent.OldValue); } })); if (onRemove != null) { finalDisp.Add(self.ObserveRemove().Listen(remove => { onRemove(remove.Value); collection.Remove(remove.Value); })); } return(finalDisp); }
static public IStream <T> Join <T>(this IStream <IStream <T> > stream) { return(new AnonymousStream <T>((Action <T> reaction, Priority p) => { SingleAssignmentDisposable mainDisposable = new SingleAssignmentDisposable(); SingleAssignmentDisposable inner = new SingleAssignmentDisposable(); ListDisposable group = new ListDisposable { mainDisposable, inner }; mainDisposable.Disposable = stream.Listen((IStream <T> innerStream) => { var newDisp = innerStream.Listen(val => { reaction(val); }, p); inner.Dispose(); inner.Disposable = newDisp; }, p); return group; })); }
public ServicesHome() { _dc = new ecommersEntities(); _result = new DataHomeSite(); ListDisposable.Add(_dc); }