当前位置: 首页>>代码示例>>C#>>正文


C# IDocumentSession.Store方法代码示例

本文整理汇总了C#中IDocumentSession.Store方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentSession.Store方法的具体用法?C# IDocumentSession.Store怎么用?C# IDocumentSession.Store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDocumentSession的用法示例。


在下文中一共展示了IDocumentSession.Store方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WelcomeModule

        public WelcomeModule(IDocumentSession session)
            : base("Welcome")
        {
            Get["/"] = p => View["Welcome"];

            Post["/"] = p =>
            {
                var user = this.Bind<User>("Password", "Salt", "Claims");
                user.Claims = new List<string> {"admin"};
                NSembleUserAuthentication.SetUserPassword(user, Request.Form.Password);
                session.Store(user, "users/" + user.Email);

                session.Store(new Dictionary<string, AreaConfigs>
                                      {
                                          //{"/blog", new AreaConfigs { AreaName = "MyBlog", ModuleName = "Blog" }},
                                          //{"/content", new AreaConfigs { AreaName = "MyContent", ModuleName = "ContentPages" }},
                                          {"/auth", new AreaConfigs { AreaName = "Auth", ModuleName = "Membership" }}
                                      }, Constants.AreasDocumentName);

                session.SaveChanges();

                // Refresh the Areas configs
                AreasResolver.Instance.LoadFromStore(session);

                return Response.AsRedirect("/");
            };
        }
开发者ID:synhershko,项目名称:NSemble,代码行数:27,代码来源:WelcomeModule.cs

示例2: InitialiseTest

        public void InitialiseTest()
        {
            documentStore = new EmbeddableDocumentStore
            {
                RunInMemory = true
            };
            documentStore.Initialize();

            session = documentStore.OpenSession();
            var user1 = new User
            {
                FullName = "FullName1",
                Username = "Username1",
                Password = "Password1",
            };
            session.Store(user1);

            var user2 = new User
            {
                FullName = "FullName2",
                Username = "Username2",
                Password = "Password2",
            };
            session.Store(user2);
            session.SaveChanges();
        }
开发者ID:emanuelgidar,项目名称:RecipesMVC4,代码行数:26,代码来源:AccountControllerTests.cs

示例3: SetupUsers

        private static void SetupUsers(IDocumentSession session)
        {
            session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationUser
            {
                Id = "andrea",
                Roles = { "Users", "Administrators" },
            });

            session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationUser
            {
                Id = "administrator",
                Roles = { "Users", "Administrators" },
            });

            //Paolo is a Users with permission for Library/Fake
            session.Store(new client::Raven.Bundles.Authorization.Model.AuthorizationUser
            {
                Id = "paolo",
                Roles = { "Users" },
                Permissions =
                    new List<client::Raven.Bundles.Authorization.Model.OperationPermission>
                    {
                        new client::Raven.Bundles.Authorization.Model.OperationPermission
                        {Allow = true, Operation = "Library/Fake"}
                    }
            });

            session.SaveChanges();
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:29,代码来源:Mojo2.cs

示例4: AddUser

        public void AddUser(User user, IDocumentSession session)
        {
            if (user == null) throw new ArgumentNullException("user");
            if (session == null) throw new ArgumentNullException("session");

            try
            {
                session.Advanced.UseOptimisticConcurrency = true;

                session.Store(user);

                var facebookId = new FacebookId
                                     {
                                         Id = FacebookId.MakeKey(user.FacebookId),
                                         UserId = user.Id
                                     };

                session.Store(facebookId);
                session.SaveChanges();
            }
            finally
            {
                session.Advanced.UseOptimisticConcurrency = false;
            }
        }
开发者ID:rdingwall,项目名称:100books,代码行数:25,代码来源:UserRepository.cs

示例5: TemplatesModule

        public TemplatesModule(IDocumentSession session, IViewLocator viewLocator)
            : base("Templates")
        {
            Get["/"] = p =>
                           {
                               var templates = session.Advanced.LoadStartingWith<ViewTemplate>("NSemble/Views/");
                               return View["List", templates];
                           };

            Get["/new/"] = p => View["Edit", new ViewTemplate {}];

            Get[@"/edit/{viewName*}"] = p =>
                                            {
                                                var viewName = (string) p.viewName;
                                                if (!viewName.StartsWith(Constants.RavenViewDocumentPrefix, StringComparison.InvariantCultureIgnoreCase))
                                                    viewName = Constants.RavenViewDocumentPrefix + viewName;
                                                var template = session.Load<ViewTemplate>(viewName);

                                                // Even if we don't have it stored in the DB, it might still exist as a resource. Try loading it from Nancy.
                                                if (template == null)
                                                {
                                                    var vlr = viewLocator.LocateView(viewName.Substring(Constants.RavenViewDocumentPrefix.Length), Context);
                                                    if (vlr == null)
                                                        return 404;

                                                    template = new ViewTemplate
                                                                   {
                                                                       Location = vlr.Location,
                                                                       Name = vlr.Name,
                                                                       Extension = vlr.Extension,
                                                                       Contents = vlr.Contents.Invoke().ReadToEnd(),
                                                                   };
                                                }

                                                return View["Edit", template];
                                            };

            Post[@"/edit/{viewName*}"] = p =>
                                                   {
                                                       var template = this.Bind<ViewTemplate>();

                                                       var viewName = (string) p.viewName;
                                                       if (!viewName.StartsWith(Constants.RavenViewDocumentPrefix, StringComparison.InvariantCultureIgnoreCase))
                                                           viewName = Constants.RavenViewDocumentPrefix + viewName;

                                                       session.Store(template, string.Concat(Constants.RavenViewDocumentPrefix, template.Location, "/", template.Name, ".", template.Extension));
                                                       session.SaveChanges();

                                                       return "Success";
                                                   };

            Post["/new"] = p =>
                                {
                                    var template = this.Bind<ViewTemplate>();
                                    session.Store(template, string.Concat(Constants.RavenViewDocumentPrefix, template.Location, "/", template.Name, ".", template.Extension));

                                    return Response.AsRedirect("/");
                                };
        }
开发者ID:synhershko,项目名称:NSemble,代码行数:59,代码来源:TemplatesModule.cs

示例6: Reset

 public static void Reset(IDocumentSession session)
 {
     var project = Project.Forge("proj 1", "desc 1");
     session.Store(project);
     foreach (var p in Enumerable.Range(1, 3))
     {
         session.Store(Activity.Forge(project.Id.ToIdentifier(),
                                      "act " + p, "description " + p, 60));
     }
 }
开发者ID:jsbsantos,项目名称:teamworks,代码行数:10,代码来源:ActivitiesControllerTester.cs

示例7: AddTestData

        public void AddTestData(IDocumentSession session)
        {
            const string VIEW_NAME = "Home";
            const string TRANSLATOR = "MockFake";
            // List<WebText> webTexts = new List<WebText>();
            session.Store(new WebText(TRANSLATOR)
                {
                    View = VIEW_NAME,
                    Lang = "en",
                    Name = "LatestNewsHeader",
                    HtmlText = "Latest News "
                });
            session.Store(new WebText(TRANSLATOR)
                {
                    View = VIEW_NAME,
                    Lang = "en",
                    Name = "slide2Txt2",
                    HtmlText = "The Camp is 3 days with Embu competion"
                });
            session.Store(new WebText(TRANSLATOR)
                {
                    View = VIEW_NAME,
                    Lang = "sv",
                    Name = "LatestNewsHeader",
                    HtmlText = "Senaste nytt <span>Vad har hänt</span>"
                });
            session.Store(new WebText(TRANSLATOR)
                {
                    View = VIEW_NAME,
                    Lang = "sv",
                    Name = "slide2Txt2",
                    HtmlText = "Lägret är på 3 dagar med Embu tävling"
                });

            session.Store(new WebText(TRANSLATOR)
                {
                    View = VIEW_NAME,
                    Lang = "ja",
                    Name = "LatestNewsHeader",
                    HtmlText = "最新ニュース"
                });
            session.Store(new WebText(TRANSLATOR)
                {
                    Lang = "ja",
                    View = VIEW_NAME,
                    Name = "slide2Txt2",
                    HtmlText = "合宿はエンブと3日です"
                });

            session.SaveChanges();
        }
开发者ID:pontushaglund,项目名称:TrainingCampSK,代码行数:51,代码来源:WebTextRepo.cs

示例8: LinqIntegrationTests

        public LinqIntegrationTests()
        {
            Document<Entity>()
                .With(x => x.Property)
                .With(x => x.StringProp)
                .With(x => x.TheChild.NestedProperty);
            
            store.Configuration.UseSerializer(new DefaultSerializer());

            session = Using(store.OpenSession());
            session.Store(new Entity { Id = NewId(), Property = 1, StringProp = "Asger" });
            session.Store(new Entity { Id = NewId(), Property = 2, StringProp = "Lars", TheChild = new Entity.Child { NestedProperty = 3.1 } });
            session.Store(new Entity { Id = NewId(), Property = 3, StringProp = null });
            session.SaveChanges();
        }
开发者ID:dcga,项目名称:HybridDb,代码行数:15,代码来源:LinqIntegrationTests.cs

示例9: BlogAdminModule

        public BlogAdminModule(IDocumentSession session)
            : base("Blog")
        {
            Get["/"] = o =>
                           {
                               return "Blog admin";
                           };

            Get["/post-new/"] = p => View["Edit", new BlogPost
                        {
                            ContentType = DynamicContentType.Markdown,
                            AllowComments = true,
                            CurrentState = BlogPost.State.Draft,
                        }];

            Post["/post-new/"] = p =>
            {
                var post = this.Bind<BlogPost>();

                bool validated = true;
                if (!validated)
                {
                    //ModelState.AddModelError("Id", "");
                    return View["Edit", post];
                }

                session.Store(post);
                session.SaveChanges();

                return Response.AsRedirect(string.Concat(AreaRoutePrefix.TrimEnd('/'), "/", post.Id, "/", post.Slug));
            };
        }
开发者ID:jchannon,项目名称:NSemble,代码行数:32,代码来源:BlogAdminModule.cs

示例10: ImportFile

        private static void ImportFile(IDocumentSession session, string filePath, Book book)
        {
            var filename = Path.GetFileNameWithoutExtension(filePath);
            Console.WriteLine("Importing " + filename);

            var parts = filename.Split(new[] { " - " }, System.StringSplitOptions.None);
            if (parts.Length < 2)
            {
                return;
            }

            var artist = parts.First().Trim();
            var name = parts.Last().Trim();

            var content = File.ReadAllText(filePath);

            var tab = new Tab { Artist = artist, Name = name, Content = content, CreatedOn = DateTime.Now };
            session.Store(tab);

            if (book != null)
            {
                var bookTasks = new BookService();
                bookTasks.AddTabToBook(tab.Id, book.Id, session); // add song to Singalong book
            }
        }
开发者ID:mattfrear,项目名称:A4tabRaven,代码行数:25,代码来源:ImportService.cs

示例11: ContactModule

        public ContactModule(IDocumentSession ravenSession)
            : base("/api/contact")
        {
            Get["/"] = parameters =>
                           {
                               var contacts = ravenSession.Query<Contact>()
                                   .OrderBy(x => x.LastName)
                                   .Take(15)
                                   .ToList();

                               return Response.AsJson(contacts);
                           };

            Get["/{id}"] = parameters =>
                               {
                                   string contactId = "contact/" + parameters.id;
                                   var contact = ravenSession.Load<Contact>(contactId);
                                   return Response.AsJson(contact);
                               };

            Post["/"] = parameters =>
                            {
                                Contact newContact = this.Bind();

                                newContact.DateOfDeath = newContact.DateOfDeath == DateTime.MinValue
                                                             ? null
                                                             : newContact.DateOfDeath;

                                ravenSession.Store(newContact);
                                return Response.AsJson(newContact);
                            };
        }
开发者ID:imonthercks,项目名称:phibook,代码行数:32,代码来源:ContactModule.cs

示例12: SetUp

        public void SetUp()
        {
            var _store = new EmbeddableDocumentStore
            {
                RunInMemory = true,
            };

            _store.Initialize();

            RavenSession = _store.OpenSession();

            RavenSession.Store(new User { Id = "users/99", Email = "[email protected]", UserName = "lef", Enabled = true, FullName = "Lars Erik Finhot" });
            RavenSession.Store(new User { Id = "users/98", Email = "[email protected]", UserName = "jalla", Enabled = true, FullName = "Dølle Duck" });
            RavenSession.Store(new Project { Owner = "users/99", Title = "Project99", Id="projects/99", MaxNoteIntervalInDaysBeforeReminder=7, Description="Description text" });
            RavenSession.SaveChanges();
        }
开发者ID:larserikfinholt,项目名称:Logit,代码行数:16,代码来源:ReminderTests.cs

示例13: ValidateUser

        public static string ValidateUser(IDocumentSession ravenSession, string username, string password)
        {
            // try to get a user from the database that matches the given username and password
            var userRecord = ravenSession.Load<User>("users/" + username);
            if (userRecord == null)
            {
                return null;
            }

            // verify password
            var hashedPassword = GenerateSaltedHash(password, userRecord.Salt);
            if (!CompareByteArrays(hashedPassword, userRecord.Password))
                return null;

            // cleanup expired or unusesd tokens
            foreach (var token in ravenSession.Query<ApiKeyToken>().Where(x => x.UserId == userRecord.Id))
            {
                if (DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(7)) > token.LastActivity)
                    ravenSession.Delete(token);
            }

            // now that the user is validated, create an api key that can be used for subsequent requests
            var apiKey = Guid.NewGuid().ToString();
            ravenSession.Store(new ApiKeyToken { UserId = userRecord.Id, SessionStarted = DateTimeOffset.UtcNow, LastActivity = DateTimeOffset.UtcNow }, GetApiKeyDocumentId(apiKey));
            ravenSession.SaveChanges();

            return apiKey;
        }
开发者ID:synhershko,项目名称:NSemble,代码行数:28,代码来源:NSembleUserAuthentication.cs

示例14: CreateOrder

        public static string CreateOrder(IDocumentSession session)
        {
            var random = new Random((int)(DateTime.Now.Ticks % Int32.MaxValue));

            var products = session.Query<Product>().ToList();
            var customers = session.Query<Customer>().ToList();
            if (!customers.Any())
                return "Init required";

            var customer = customers.ElementAt(random.Next() % customers.Count());
            var address = customer.Addresses.SingleOrDefault(a => a.Type == AddressOptions.Home)
                          ?? customer.Addresses.First();

            var order = new Order
            {
                Date = DateTime.Today,
                Customer = customer.Name,
                ShippingAddress = address.AddressDesc + ", " + address.Country + " " + address.PostalCode
            };

            for (var i = 0; i < random.Next(2, 4); i++)
            {
                order.OrderLines.Add(CreateOrderLine(products, random));
            }

            order.GrandTotal = order.OrderLines.Sum(l => l.Total);

            session.Store(order);

            return String.Empty;
        }
开发者ID:plaurin,项目名称:RavenDBDemo,代码行数:31,代码来源:InitRepository.cs

示例15: ContentPagesAdminModule

        public ContentPagesAdminModule(IDocumentSession session)
            : base("ContentPages")
        {
            Get["/"] = p =>
                           {
                               var list = session.Advanced.LoadStartingWith<ContentPage>(DocumentPrefix + ContentPage.FullContentPageId(string.Empty), null, 0, 25);
                               return View["List", list.ToArray()];
                           };

            Get["/create/"] = p => View["Edit", new ContentPage {ContentType = DynamicContentType.Markdown}];

            Post["/create/"] = p =>
                                   {
                                       var cp = this.Bind<ContentPage>();

                                       var pageId = ContentPage.FullContentPageId(DynamicContentHelpers.TitleToSlug(cp.Title));
                                       var page = session.Load<ContentPage>(pageId);
                                       if (page != null)
                                       {
                                           //ModelState.AddModelError("Id", "Page already exists for the slug you're trying to create it under");
                                           return View["Edit", cp];
                                       }

                                       session.Store(cp, pageId);

                                       return Response.AsRedirect(string.Concat(AreaRoutePrefix.TrimEnd('/'), "/", cp.Slug));
                                   };

            Get["/edit/{slug}"] = p =>
                                      {
                                          var cp = session.Load<ContentPage>(DocumentPrefix + ContentPage.FullContentPageId((string) p.slug));
                                          if (cp == null)
                                              return 404;

                                          return View["Edit", cp];
                                      };

            Post["/edit/{slug}"] = p =>
                                      {
                                          var input = this.Bind<ContentPage>();
                                          if (input.Id != (string)p.slug)
                                              return "<h1>Error</h1><p>Slugs mismatch</p>";

                                          var cp = session.Load<ContentPage>(DocumentPrefix + ContentPage.FullContentPageId((string)p.slug));
                                          if (cp == null)
                                              return 404;

                                          cp.Content = input.Content;
                                          cp.ContentType = input.ContentType;
                                          cp.Title = input.Title;
                                          cp.LastChanged = DateTimeOffset.Now;

                                          return Response.AsRedirect(string.Concat(AreaRoutePrefix.TrimEnd('/'), "/", cp.Slug));
                                      };

            //			Post["/delete/{slug}"] = p =>
            //			                             {
            //
            //			                             };
        }
开发者ID:jchannon,项目名称:NSemble,代码行数:60,代码来源:ContentPagesAdminModule.cs


注:本文中的IDocumentSession.Store方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。