private void ReplicateToFunction(string tableName, JsValue colsAsObject, PatcherOperationScope scope)
        {
            if (tableName == null)
            {
                throw new ArgumentException("tableName parameter is mandatory");
            }

            /* if (colsAsObject == null)
             *   throw new ArgumentException("cols parameter is mandatory");*/

            var itemToReplicates          = scriptResult.Data.GetOrAdd(tableName);
            var dynamicJsonValue          = scope.ToBlittable(colsAsObject.AsObject());
            var blittableJsonReaderObject = _context.ReadObject(dynamicJsonValue, tableName);
            var columns = new List <SqlReplicationColumn>(blittableJsonReaderObject.Count);
            var prop    = new BlittableJsonReaderObject.PropertyDetails();

            for (var i = 0; i < blittableJsonReaderObject.Count; i++)
            {
                blittableJsonReaderObject.GetPropertyByIndex(i, ref prop);
                columns.Add(new SqlReplicationColumn
                {
                    Key   = prop.Name,
                    Value = prop.Value,
                    Type  = prop.Token,
                });
            }
            itemToReplicates.Add(new ItemToReplicate
            {
                DocumentKey = _documentKey,
                Columns     = columns
            });
        }
        protected override void RemoveEngineCustomizations(Engine engine, PatcherOperationScope scope)
        {
            base.RemoveEngineCustomizations(engine, scope);

            engine.Global.Delete("documentId", true);
            engine.Global.Delete("replicateTo", true);
            engine.Global.Delete("varchar", true);
            engine.Global.Delete("nVarchar", true);
            foreach (var sqlReplicationTable in config.SqlReplicationTables)
            {
                engine.Global.Delete("replicateTo" + sqlReplicationTable.TableName, true);
            }
        }
        protected override void CustomizeEngine(Engine engine, PatcherOperationScope scope)
        {
            base.CustomizeEngine(engine, scope);

            engine.SetValue("documentId", _documentKey);
            engine.SetValue("replicateTo", new Action <string, JsValue>((tableName, colsAsObject) => ReplicateToFunction(tableName, colsAsObject, scope)));
            scriptResult.Keys.Add(_documentKey);
            foreach (var sqlReplicationTable in config.SqlReplicationTables)
            {
                var current = sqlReplicationTable;
                engine.SetValue("replicateTo" + sqlReplicationTable.TableName, (Action <JsValue>)(cols =>
                {
                    var tableName = current.TableName;
                    ReplicateToFunction(tableName, cols, scope);
                }));
            }

            engine.SetValue("varchar", (Func <string, double?, ValueTypeLengthTriple>)(ToVarchar));
            engine.SetValue("nVarchar", (Func <string, double?, ValueTypeLengthTriple>)(ToNVarchar));
        }
Example #4
0
 protected override void CustomizeEngine(Engine engine, PatcherOperationScope scope)
 {
     // override to make it "no-op"
 }