コード例 #1
0
        public override void Up()
        {
            ForAllEmployees(result =>
            {
                var value = result["Vacations"];
                if (value != null && (value.Type == Newtonsoft.Json.Linq.JTokenType.String || value.Type == Newtonsoft.Json.Linq.JTokenType.Null))
                {
                    var patchs = new List <PatchRequest>()
                    {
                        new PatchRequest()
                        {
                            Type = PatchCommandType.Unset,
                            Name = "Vacations"
                        },
                        new PatchRequest()
                        {
                            Type   = PatchCommandType.Modify,
                            Name   = "@metadata",
                            Value  = new RavenJObject(),
                            Nested = new []
                            {
                                new PatchRequest()
                                {
                                    Type  = PatchCommandType.Set,
                                    Name  = UpBackupKey,
                                    Value = value,
                                },
                                new PatchRequest()
                                {
                                    Type = PatchCommandType.Unset,
                                    Name = DownBackupKey,
                                }
                            }
                        }
                    };

                    var metadata = result["@metadata"] as RavenJObject;
                    RavenJToken newData;

                    if (metadata == null || !metadata.TryGetValue(DownBackupKey, out newData) || newData == null || newData.Type != Newtonsoft.Json.Linq.JTokenType.Array)
                    {
                        newData = new global::Raven.Json.Linq.RavenJArray();
                    }

                    patchs.Add(new PatchRequest()
                    {
                        Type  = PatchCommandType.Set,
                        Name  = "Vacations",
                        Value = newData
                    });

                    DocumentStore.DatabaseCommands.Patch(
                        result["@metadata"].Value <string>("@id").ToString(),
                        patchs.ToArray());
                }
            });
        }
コード例 #2
0
        public override void Up()
        {
            ForAllEmployees(result =>
            {
                var value = result["Vacations"];
                if (value != null && (value.Type == Newtonsoft.Json.Linq.JTokenType.String || value.Type == Newtonsoft.Json.Linq.JTokenType.Null))
                {
                    var patchs = new List<PatchRequest>() {
                        new PatchRequest()
                        {
                            Type = PatchCommandType.Unset,
                            Name = "Vacations"
                        },
                        new PatchRequest()
                        {
                            Type = PatchCommandType.Modify,
                            Name = "@metadata",
                            Value = new RavenJObject(),
                            Nested = new []
                            {
                                new PatchRequest()
                                {
                                    Type = PatchCommandType.Set,
                                    Name = UpBackupKey,
                                    Value = value,
                                },
                                new PatchRequest()
                                {
                                    Type = PatchCommandType.Unset,
                                    Name = DownBackupKey,
                                }
                            }
                        }
                    };

                    var metadata = result["@metadata"] as RavenJObject;
                    RavenJToken newData;

                    if (metadata == null || !metadata.TryGetValue(DownBackupKey, out newData) || newData == null || newData.Type != Newtonsoft.Json.Linq.JTokenType.Array)
                        newData = new global::Raven.Json.Linq.RavenJArray();

                    patchs.Add(new PatchRequest()
                    {
                        Type = PatchCommandType.Set,
                        Name = "Vacations",
                        Value = newData
                    });

                    DocumentStore.DatabaseCommands.Patch(
                        result["@metadata"].Value<string>("@id").ToString(),
                        patchs.ToArray());
                }
            });
        }