Example #1
0
        protected async override Task <JArray> ExecuteAsync(AsyncCodeActivityContext 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);

            var dt = DataTable.Get(context);

            var items = new List <JObject>();

            foreach (DataRow row in dt.Rows)
            {
                if (row.RowState == DataRowState.Deleted)
                {
                    var _id = row["_id", DataRowVersion.Original].ToString();
                    await global.webSocketClient.DeleteOne(collection, _id);
                }
                else if (row.RowState == DataRowState.Added || row.RowState == DataRowState.Modified)
                {
                    var settings = new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore,
                        Converters        = { new DataRowConverter() },
                    };
                    var rowJson = JsonConvert.SerializeObject(row, Formatting.Indented, settings);
                    var result  = JObject.Parse(rowJson);
                    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;
                    }
                    items.Add(result);
                }
            }
            await global.webSocketClient.InsertOrUpdateMany <JObject>(collection, 1, false, uniqueness, true, items.ToArray());

            dt.AcceptChanges();
            System.Windows.Forms.Application.DoEvents();
            return(new JArray(results));
        }
Example #2
0
        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 uniqeness  = Uniqeness.Get(context);
            var uniqueness = Uniqueness.Get(context);

            if (string.IsNullOrEmpty(uniqueness))
            {
                uniqueness = uniqeness;
            }
            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;
            }
            result = await global.webSocketClient.InsertOrUpdateOne(collection, 1, false, uniqeness, result);

            System.Windows.Forms.Application.DoEvents();
            return(result);
        }