protected override void Execute(CodeActivityContext context) { string text = Text.Get(context); System.Drawing.Bitmap image = Image.Get(context); try { System.Threading.Thread staThread = new System.Threading.Thread(() => { if (!string.IsNullOrEmpty(text)) { System.Windows.Clipboard.SetDataObject(text, true); } if (image != null) { System.Windows.Clipboard.SetDataObject(image, true); } }); staThread.SetApartmentState(System.Threading.ApartmentState.STA); staThread.Start(); staThread.Join(); } catch (Exception ex) { if (IgnoreErrors.Get(context)) { Log.Debug(ex.Message); return; } throw; } }
protected async override Task <JObject[]> ExecuteAsync(AsyncCodeActivityContext context) { var ignoreErrors = IgnoreErrors.Get(context); var collection = Collection.Get(context); var querystring = QueryString.Get(context); var projection = Projection.Get(context); var top = Top.Get(context); var skip = Skip.Get(context); if (top < 1) { top = 100; } if (skip < 0) { skip = 0; } var orderby = Orderby.Get(context); if (string.IsNullOrEmpty(collection)) { collection = "entities"; } JObject[] result = null; result = await global.webSocketClient.Query <JObject>(collection, querystring, projection, top, skip, orderby); System.Windows.Forms.Application.DoEvents(); return(result); }
protected async override Task <object> ExecuteAsync(AsyncCodeActivityContext context) { var filename = Filename.Get(context); var id = _id.Get(context); var ignoreerrors = IgnoreErrors.Get(context); var q = "{\"_id\": \"" + id + "\"}"; if (!string.IsNullOrEmpty(filename)) { q = "{\"filename\":\"" + filename + "\"}"; } // await global.webSocketClient.DeleteOne("files", q); var rows = await global.webSocketClient.Query <JObject>("fs.files", q); if (rows.Length == 0) { if (!ignoreerrors) { throw new Exception("File not found"); } return(42); } foreach (var row in rows) { var _id = row["_id"].ToString(); await global.webSocketClient.DeleteOne("fs.files", _id); } return(42); }
protected async override Task <JObject> ExecuteAsync(AsyncCodeActivityContext context) { var ignoreErrors = IgnoreErrors.Get(context); var encrypt = EncryptFields.Get(context); if (encrypt == null) { encrypt = ""; } var collection = Collection.Get(context); if (string.IsNullOrEmpty(collection)) { collection = "entities"; } var type = Type.Get(context); JObject result = null; var o = Item.Get(context); if (o.GetType() != typeof(JObject)) { var t = Task.Factory.StartNew(() => { result = JObject.FromObject(o); }); t.Wait(); } else { result = (JObject)o; } if (!string.IsNullOrEmpty(encrypt)) { result["_encrypt"] = encrypt; } var name = result.GetValue("name", StringComparison.OrdinalIgnoreCase)?.Value <string>(); result["name"] = name; if (!string.IsNullOrEmpty(type)) { result["_type"] = type; } var id = result.GetValue("_id"); if (id != null) { var _id = id.ToString(); result = await global.webSocketClient.UpdateOne(collection, 1, false, result); } else { result = await global.webSocketClient.InsertOne(collection, 1, false, result); } System.Windows.Forms.Application.DoEvents(); return(result); }
public void OpenErrorDoesNotHappenAgainOnMoveNext() { using (IgnoreErrors ie = new IgnoreErrors(Path.GetRandomFileName())) { Assert.Equal(1, ie.ErrorCount); Assert.False(ie.MoveNext()); Assert.Equal(1, ie.ErrorCount); } }
protected async override Task <JObject[]> ExecuteAsync(AsyncCodeActivityContext context) { var ignoreErrors = IgnoreErrors.Get(context); var encrypt = EncryptFields.Get(context); if (encrypt == null) { encrypt = ""; } var collection = Collection.Get(context); if (string.IsNullOrEmpty(collection)) { collection = "entities"; } var type = Type.Get(context); var uniqueness = Uniqueness.Get(context); // JObject[] result = null; var results = new List <JObject>(); var items = Items.Get(context); foreach (var o in items) { JObject result = null; if (o.GetType() != typeof(JObject)) { var t = Task.Factory.StartNew(() => { result = JObject.FromObject(o); }); t.Wait(); } else { result = (JObject)o; } if (!string.IsNullOrEmpty(encrypt)) { result["_encrypt"] = encrypt; } var name = result.GetValue("name", StringComparison.OrdinalIgnoreCase)?.Value <string>(); result["name"] = name; if (!string.IsNullOrEmpty(type)) { result["_type"] = type; } results.Add(result); } var _result = await global.webSocketClient.InsertOrUpdateMany(collection, 1, false, uniqueness, SkipResult.Get(context), results.ToArray()); System.Windows.Forms.Application.DoEvents(); return(_result); }
public void OpenErrorDoesNotHappenAgainOnMoveNext() { // What we're checking for here is that we don't try to enumerate when we // couldn't even open the root directory (e.g. open the handle again, try // to get data, etc.) using (IgnoreErrors ie = new IgnoreErrors(Path.GetRandomFileName())) { Assert.Equal(1, ie.ErrorCount); Assert.False(ie.MoveNext()); Assert.Equal(1, ie.ErrorCount); // Since we didn't start, the directory shouldn't finish. Assert.Null(ie.DirectoryFinished); } }
protected async override Task <JObject[]> ExecuteAsync(AsyncCodeActivityContext context) { var ignoreErrors = IgnoreErrors.Get(context); var collection = Collection.Get(context); var querystring = QueryString.Get(context); if (string.IsNullOrEmpty(collection)) { collection = "entities"; } JObject[] result = null; result = await global.webSocketClient.Query <JObject>(collection, querystring); System.Windows.Forms.Application.DoEvents(); return(result); }
protected async override Task <bool> ExecuteAsync(AsyncCodeActivityContext context) { var ignoreErrors = IgnoreErrors.Get(context); var collection = Collection.Get(context); if (string.IsNullOrEmpty(collection)) { collection = "entities"; } JObject result = null; var o = Item.Get(context); string id = null; if (o != null) { if (o.GetType() != typeof(JObject)) { var t = Task.Factory.StartNew(() => { result = JObject.FromObject(o); }); t.Wait(); } else { result = (JObject)o; } var tempid = result.GetValue("_id"); if (tempid != null) { id = tempid.ToString(); } if (string.IsNullOrEmpty(id)) { throw new Exception("object has no _id field"); } } else { id = _id.Get(context); } await global.webSocketClient.DeleteOne(collection, id); System.Windows.Forms.Application.DoEvents(); return(true); }
public void DeleteDirectoryAfterOpening() { // We shouldn't prevent the directory from being deleted, even though we've // opened (and are holding) the handle. On Windows this means we've opened // the handle with file share of delete. DirectoryInfo info = Directory.CreateDirectory(GetTestFilePath()); using (IgnoreErrors ie = new IgnoreErrors(info.FullName)) { Assert.Equal(0, ie.ErrorCount); Directory.Delete(info.FullName); Assert.False(ie.MoveNext()); // This doesn't cause an error as the directory is still valid until the // the enumerator is closed (as we have an open handle) Assert.Equal(0, ie.ErrorCount); Assert.Equal(info.FullName, ie.DirectoryFinished); } }
public GlitchConfig(GlitchConfigSection section) { if (section == null) { return; } WithApiUrl(section.ApiUrl); WithApiKey(section.ApiKey); WithNotificationsMaxBatchSize(section.NotificationsMaxBatchSize); WithNotificationsMaxInterval(TimeSpan.FromMinutes(section.NotificationsMaxIntervalInMinutes)); SendNotifications(section.Notify); foreach (var contentFilter in section.IgnoreContent) { IgnoreContent.FromDataGroupWithKeysContaining(contentFilter.DataGroup, contentFilter.KeyContains); } foreach (var exceptionFilter in section.IgnoreErrors) { IgnoreErrors.WithFilter(exceptionFilter.CreateFilter()); } }