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


C# IDocumentSession.Load方法代码示例

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


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

示例1: 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

示例2: 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

示例3: RobotProjectionModule

        public RobotProjectionModule(IDocumentSession documentSession)
        {
            Get["/robot/{name}"] = parameters =>
            {
                if (string.IsNullOrWhiteSpace(parameters.name))
                    return HttpStatusCode.BadRequest;

                var robotResult = documentSession.Load<Robot>(Robot.GetRobotIdFromName(parameters.name));
                if (robotResult == null)
                    return HttpStatusCode.NotFound;

                return Response.AsJson(robotResult as object);
            };

            Get["/robot/byowner/{email}"] = parameters =>
            {
                if (string.IsNullOrWhiteSpace(parameters.email))
                    return HttpStatusCode.BadRequest;

                string email = parameters.email;
                var robotResult = documentSession.Query<Robot>().FirstOrDefault(x => x.OwnerEMail.Equals(email, StringComparison.CurrentCultureIgnoreCase));
                if (robotResult == null)
                    return HttpStatusCode.NotFound;

                return Response.AsJson(robotResult as object);
            };
        }
开发者ID:emilcardell,项目名称:ForeverRobot,代码行数:27,代码来源:RobotProjectionModule.cs

示例4: GetUser

        public User GetUser(string userId, IDocumentSession session)
        {
            if (userId == null) throw new ArgumentNullException("userId");
            if (session == null) throw new ArgumentNullException("session");

            return session.Load<User>(userId);
        }
开发者ID:rdingwall,项目名称:100books,代码行数:7,代码来源:UserRepository.cs

示例5: DinnerModule

        public DinnerModule(IDocumentSession documentSession)
        {
            this.documentSession = documentSession;
            const string basePath = "/dinners";

            Get[basePath] = Dinners;
            Get[basePath + "/page/{pagenumber}"] = Dinners;

            Get[basePath + "/{id}"] = parameters =>
            {
                if (!parameters.id.HasValue && String.IsNullOrWhiteSpace(parameters.id))
                {
                    return 404;
                }

                Dinner dinner = documentSession.Load<Dinner>((int)parameters.id);

                if (dinner == null)
                {
                    return 404;
                }

                base.Page.Title = dinner.Title;
                base.Model.Dinner = dinner;

                return View["Dinners/Details", base.Model];
            };
        }
开发者ID:jcolebrand,项目名称:DinnerParty,代码行数:28,代码来源:DinnerModule.cs

示例6: 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

示例7: GetSubscriptions

        static IEnumerable<Subscription> GetSubscriptions(IEnumerable<MessageType> messageTypes, IDocumentSession session)
        {
            var ids = messageTypes
                .Select(Subscription.FormatId);

            return session.Load<Subscription>(ids).Where(s => s != null);
        }
开发者ID:hanin,项目名称:NServiceBus.RavenDB,代码行数:7,代码来源:SubscriptionPersister.cs

示例8: ContentPagesModule

        public ContentPagesModule(IDocumentSession session)
            : base("ContentPages")
        {
            Get["/{slug*}"] = p =>
                                 {
                                     var slug = (string)p.slug;
                                     if (string.IsNullOrWhiteSpace(slug))
                                         slug = HomepageSlug;

                                     // For fastest loading, we define the content page ID to be the slug. Therefore, slugs have to be < 50 chars, probably
                                     // much shorter for readability.
                                     var cp = session.Load<ContentPage>(DocumentPrefix + ContentPage.FullContentPageId(slug));
                                     if (cp == null)
                                         return "<p>The requested content page was not found</p>"; // we will return a 404 instead once the system stabilizes...

                                     Model.ContentPage = cp;
                                     ((PageModel) Model.Page).Title = cp.Title;

                                     return View["Read", Model];
                                 };

            Get["/error"] = o =>
                                {
                                    throw new NotSupportedException("foo");
                                };
        }
开发者ID:synhershko,项目名称:NSemble,代码行数:26,代码来源:ContentPagesModule.cs

示例9: UpdateExistingMessage

        void UpdateExistingMessage(IDocumentSession session, string id, TransportMessage message)
        {
            var failedMessage = session.Load<Message>(id);
            
            var timeOfFailure = DateTimeExtensions.ToUtcDateTime(message.Headers["NServiceBus.TimeOfFailure"]);

            if (failedMessage.FailureDetails.TimeOfFailure == timeOfFailure)
            {
                return;
            }

            if (failedMessage.Status == MessageStatus.Successful && timeOfFailure > failedMessage.ProcessedAt)
            {
                throw new InvalidOperationException("A message can't first be processed successfully and then fail, Id: " + failedMessage.Id);
            }

            if (failedMessage.Status == MessageStatus.Successful)
            {
                failedMessage.FailureDetails = new FailureDetails(message);
            }
            else
            {
                failedMessage.Status = MessageStatus.RepeatedFailure;

                failedMessage.FailureDetails.RegisterException(message);
            }

            session.SaveChanges();
        }
开发者ID:raelyard,项目名称:ServiceBus.Management,代码行数:29,代码来源:ErrorImportSatellite.cs

示例10: 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

示例11: Execute

 public void Execute(IDocumentSession session, Action reply)
 {
     var program = session.Load<Program>(_id);
     var version = program.Versions.SingleOrDefault(x => x.Version == _version);
     if (version != null)
         program.Versions.Remove(version);
     reply();
 }
开发者ID:henninga,项目名称:AssetTracker,代码行数:8,代码来源:DeleteVersion.cs

示例12: LoadFromStore

 public void LoadFromStore(IDocumentSession session)
 {
     var d = session.Load<IDictionary<string, AreaConfigs>>(AreasDocumentName);
     AreasByRoute.Clear();
     foreach (var areaConfig in d)
     {
         RegisterArea(areaConfig.Key, areaConfig.Value);
     }
 }
开发者ID:jchannon,项目名称:NSemble,代码行数:9,代码来源:AreasResolver.cs

示例13: GetChallengeName

 public static string GetChallengeName(IDocumentSession session, string challengeId)
 {
     var challenge = session.Load<Challenge>(challengeId); 
     if (challenge != null)
     {
         return challenge.Text;
     }
     return string.Empty;
 }
开发者ID:meridiumlabs,项目名称:Meridium.Onboarding,代码行数:9,代码来源:RavenService.cs

示例14: SubmitToRedditStrategy

        public SubmitToRedditStrategy(IDocumentSession session)
        {
            _session = session;
            var blogConfig = _session.Load<BlogConfig>(BlogConfig.Key);
            _credentials = RedditHelper.GetCredentials(blogConfig);
            _subredditNames = RedditHelper.ParseSubreddits(blogConfig);

            InitializeRedditService();
        }
开发者ID:ayende,项目名称:RaccoonBlog,代码行数:9,代码来源:SubmitToRedditStrategy.cs

示例15: Execute

        public void Execute(IDocumentSession session, Action reply)
        {
            var program = session.Load<Program>(_id);

            program.Name = _name;
            program.Notes = _notes;

            reply();
        }
开发者ID:henninga,项目名称:AssetTracker,代码行数:9,代码来源:EditProgram.cs


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