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


C# ISession.SessionFactory方法代码示例

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


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

示例1: Api

        Api(ISession session)
            : base("/api")
        {
            Post["/downloaded"] = parameters =>
            {
                if (!Request.Form.ApiKey.HasValue)
                {
                    return new Response {StatusCode = HttpStatusCode.Unauthorized};
                }

                if (!Request.Form.Title.HasValue)
                {
                    return new Response { StatusCode = HttpStatusCode.ExpectationFailed };
                }

                string apiKey = Request.Form.ApiKey.Value;
                //string title = Request.Form.Title.Value;

                using (var db = session.SessionFactory(""))
                {
                    using (var s = db.OpenSession())
                    {
                        using (s.BeginTransaction())
                        {
                            var userSettings = s.QueryOver<UserSettings>().SingleOrDefault<UserSettings>();

                            if (apiKey != userSettings.ApiKey)
                            {
                                return new Response { StatusCode = HttpStatusCode.Forbidden };
                            }

                            return new Response { StatusCode = HttpStatusCode.OK };
                        }
                    }
                }
            };
        }
开发者ID:nrich,项目名称:greasyhands,代码行数:37,代码来源:Api.cs

示例2: Settings

        public Settings(ISession session)
            : base("/settings")
        {
            string dbFile = ConfigurationManager.AppSettings["DBFile"];

            Get["/"] = parameters =>
                           {
                               var args = Environment.GetCommandLineArgs();
                               var model = new
                                               {
                                                   AppPath = args[0],
                                                   Args = String.Join(",", args.Skip(1).Take(args.Count())),
                                                   OS = Environment.OSVersion.ToString(),
                                                   Runtime = Environment.Version.ToString()
                                               };

                               return View["Settings/Index", model];
                           };

            Get["/general"] = parameters =>
                {
                    using (var db = session.SessionFactory(dbFile))
                    {
                        using (var s = db.OpenSession())
                        {
                            var userSettings = s.QueryOver<UserSettings>().SingleOrDefault<UserSettings>();

                            return View["Settings/General", new { userSettings.ApiKey, userSettings.C2CPreference, userSettings.SearchInterval }];

                        }
                    }
                };

            Post["/general"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        using (var transaction = s.BeginTransaction())
                        {
                            var userSettings = s.QueryOver<UserSettings>().SingleOrDefault<UserSettings>();

                            string covertocoverStr = Request.Form.C2CPreference.Value;
                            C2CPreference covertocover;

                            if (!Enum.TryParse(covertocoverStr, false, out covertocover))
                            {
                                throw new ArgumentException("Unknown download provider {0}", covertocoverStr);
                            }

                            userSettings.ApiKey = Request.Form.ApiKey;
                            userSettings.Enabled = true;
                            userSettings.C2CPreference = covertocover;
                            userSettings.SearchInterval = int.Parse(Request.Form.SearchInterval);

                            s.SaveOrUpdate(userSettings);
                            transaction.Commit();

                            return Response.AsRedirect("/settings/general");
                        }
                    }
                }
            };

            Get["/search"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        var searchSettings = s.QueryOver<SearchProviderSettings>().List<SearchProviderSettings>();

                        if (searchSettings.Count == 0)
                        {
                            using (var transaction = s.BeginTransaction())
                            {

                                var userSettings = s.QueryOver<UserSettings>().SingleOrDefault<UserSettings>();

                                var searchSettingsDefault = new SearchProviderSettings
                                                                {
                                                                    ApiKey = "",
                                                                    Type = SearchProviders.NZBINDEXdotNL,
                                                                    Enabled = true,
                                                                    UserSettings = userSettings,
                                                                };

                                transaction.Commit();
                                s.SaveOrUpdate(searchSettingsDefault);
                                searchSettings.Add(searchSettingsDefault);
                            }
                        }

                        return View["Settings/Search",
                            new {
                                Search = searchSettings,
                            }];
                    }
                }
//.........这里部分代码省略.........
开发者ID:nrich,项目名称:greasyhands,代码行数:101,代码来源:Settings.cs

示例3: Publishers

        public Publishers(ISession session)
            : base("/publishers")
        {
            Get["/"] = parameters =>
                           {
                               using (var db = session.SessionFactory(dbFile))
                               {
                                   using (var s = db.OpenSession())
                                   {
                                       var publishers =
                                           s.QueryOver<Publisher>().OrderBy(p => p.Name).Asc.List<Publisher>();
                                       IList list = new ArrayList();

                                       foreach (var publisher in publishers)
                                       {
                                           list.Add(new {publisher.Id, publisher.Name, Titles = publisher.Titles.Count});
                                       }

                                       return View["Publishers/Index", new {Publishers = list}];
                                   }
                               }
                           };

            Get["/titles"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        var titles = s.QueryOver<Title>().Where(t => t.Subscribed == false).OrderBy(t => t.Publisher).Asc.ThenBy(t => t.Name).Asc.List<Title>();
                        IList list = new ArrayList();

                        foreach (var title in titles)
                        {
                            list.Add(new { LatestNum = title.LatestIssue().Num, Latest = title.LatestIssue().Release.Date.NiceDate(), title.Limited, title.Subscribed, title.Name, title.Id, Publisher = new { title.Publisher.Name, title.Publisher.Id }, });
                        }

                        var model = new { titles = list };
                        return View["Publishers/Titles", model];
                    }
                }
            };

            Post["/titles"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        using (var transaction = s.BeginTransaction())
                        {
                            string titles = Request.Form.title;

                            var titlelist = titles.Split(',');

                            foreach (var t in titlelist)
                            {
                                int titleid = int.Parse(t);

                                var title = s.QueryOver<Title>().Where(ti => ti.Id == titleid).SingleOrDefault<Title>();

                                if (title != null)
                                {
                                    title.Subscribed = true;

                                    foreach (var i in title.Issues)
                                    {
                                        if (i.Status == IssueStatus.New)
                                        {
                                            i.Status = IssueStatus.Wanted;
                                            s.SaveOrUpdate(i);
                                        }
                                    }
                                }

                                s.SaveOrUpdate(title);
                            }

                            transaction.Commit();
                            return Response.AsRedirect("/");
                        }
                    }
                }
            };

            Get["/single/{id}"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        int id = int.Parse(parameters.id);
                        var publisher =
                            s.QueryOver<Publisher>().Where(p => p.Id == id).SingleOrDefault<Publisher>();
                        IList list = new ArrayList();

                        foreach (var title in publisher.Titles.OrderBy(t => t.Name))
                        {
                            list.Add(
                                new
//.........这里部分代码省略.........
开发者ID:nrich,项目名称:greasyhands,代码行数:101,代码来源:Publishers.cs

示例4: Titles

        public Titles(ISession session)
            : base("/titles")
        {
            string dbFile = ConfigurationManager.AppSettings["DBFile"];

            Get["/"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        var titles = s.QueryOver<Title>().Where(t => t.Subscribed == false).OrderBy(t => t.Name).Asc.List<Title>();
                        IList list = new ArrayList();

                        foreach (var title in titles)
                        {
                            list.Add(new { LatestNum = title.LatestIssue().Num, Latest = title.LatestIssue().Release.Date.NiceDate(), title.Limited, title.Subscribed, title.Name, title.Id, Publisher = new { title.Publisher.Name, title.Publisher.Id }, });
                        }

                        var model = new { titles = list };
                        return View["Titles/Index", model];
                    }
                }
            };

            Post["/"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        using (var transaction = s.BeginTransaction())
                        {
                            string titles = Request.Form.title;

                            var titlelist = titles.Split(',');

                            foreach (var t in titlelist)
                            {
                                int titleid = int.Parse(t);

                                var title = s.QueryOver<Title>().Where(ti => ti.Id == titleid).SingleOrDefault<Title>();

                                if (title != null)
                                {
                                    title.Subscribed = true;

                                    foreach (var i in title.Issues)
                                    {
                                        if (i.Status == IssueStatus.New)
                                        {
                                            i.Status = IssueStatus.Wanted;
                                            s.SaveOrUpdate(i);
                                        }
                                    }
                                }

                                s.SaveOrUpdate(title);
                            }

                            transaction.Commit();
                            return Response.AsRedirect("/");
                        }
                    }
                }
            };

            Get["/search"] = parameters =>
            {
                return View["Titles/Search", new { Count = 0, Results = new ArrayList(), SearchTerm = "" }];
            };

            Post["/search"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {

                        string search = Request.Form.search;

                        var titles =
                            s.QueryOver<Title>().Where(t => t.Name.IsInsensitiveLike(search, MatchMode.Anywhere)).OrderBy(t => t.Name).Asc.List<Title>();
                        IList results = new ArrayList();

                        foreach (var title in titles)
                        {
                            results.Add(new { title.Limited, title.Subscribed, title.Name, title.Id, Publisher = new {title.Publisher.Name, title.Publisher.Id} });
                        }

                        return View["Titles/Search", new { Results = results, SearchTerm = search }];

                    }
                }
            };

            Get["/single/{id}"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
//.........这里部分代码省略.........
开发者ID:nrich,项目名称:greasyhands,代码行数:101,代码来源:Titles.cs

示例5: Insert

        public bool Insert(ISession session)
        {
            using (var db = session.SessionFactory("test"))
            {
                using (var s = db.OpenSession())
                {
                    using (var transaction = s.BeginTransaction())
                    {
                        var publisher = s.QueryOver<Publisher>().Where(p => p.Name == Publisher).SingleOrDefault<Publisher>();
                        if (publisher == null)
                        {
                            publisher = new Publisher {Name = Publisher};
                            s.SaveOrUpdate(publisher);
                        }

                        var release = s.QueryOver<Release>().Where(r => r.Date == Released).SingleOrDefault<Release>();
                        if (release == null)
                        {
                            release = new Release {Created = DateTime.Now, Date = Released};
                            s.SaveOrUpdate(release);
                        }

                        var title =
                            s.QueryOver<Title>().Where(
                                t => t.Name == Name && t.Publisher == publisher && t.Limited == Limited).SingleOrDefault();

                        if (title == null)
                        {
                            title = new Title
                                        {
                                            Name = Name,
                                            SearchTitle = Name,
                                            GraphicNovel = GraphicNovel,
                                            HardCover = HardCover,
                                            Hidden = false,
                                            Limited = Limited,
                                            Mature = Mature,
                                            OneShot = OneShot,
                                            Publisher = publisher
                                        };
                            s.SaveOrUpdate(title);
                        }

                        var issue = s.QueryOver<Issue>().Where(i => i.Code == Code).SingleOrDefault<Issue>();

                        if (issue == null)
                        {
                            var status = IssueStatus.New;

                            if (title.Subscribed)
                            {
                                status = IssueStatus.Wanted;
                            }

                            issue = new Issue
                                            {
                                                Code = Code,
                                                Num = Num,
                                                Title = title,
                                                Release = release,
                                                Status = status,
                                                Variant = Variant
                                            };

                            s.SaveOrUpdate(issue);
                        }

                        transaction.Commit();

                    }
                }
            }

            return true;
        }
开发者ID:nrich,项目名称:greasyhands,代码行数:75,代码来源:TitleInfo.cs

示例6: Main

        public Main(ISession session)
        {
            string dbFile = ConfigurationManager.AppSettings["DBFile"];

            Get["/"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        var userSettings = s.QueryOver<UserSettings>().SingleOrDefault<UserSettings>();

                        if (userSettings == null || !userSettings.IsConfigured())
                        {
                            return Response.AsRedirect("/settings/wizard");
                        }

                        var titles =
                            s.QueryOver<Title>().Where(t => t.Subscribed).OrderBy(t => t.Name).Asc.List<Title>();
                        IList list = new ArrayList();

                        foreach (var title in titles)
                        {
                            list.Add(new { Latest = title.LatestIssue().Release.Date.NiceDate(), title.Limited, title.Subscribed, title.Name, title.Id, Publisher = new {title.Publisher.Name, title.Publisher.Id }, Have = title.Have(), Total = title.Total()});
                        }

                        var model = new { titles = list };
                        return View["Index", model];

                    }
                }
            };

            Get["/add"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        var userSettings = s.QueryOver<UserSettings>().SingleOrDefault<UserSettings>();

                        if (userSettings == null || !userSettings.IsConfigured())
                        {
                            return Response.AsRedirect("/settings/wizard");
                        }

                        var titles =
                            s.QueryOver<Title>().Where(t => t.Subscribed == false).OrderBy(t => t.Name).Asc.List<Title>();
                        var list = new List<string>();

                        foreach (var title in titles)
                        {
                            list.Add(title.Name);
                        }

                        var serialiser = new JavaScriptSerializer();
                        var model = new { titles = serialiser.Serialize(list) };
                        return View["Add", model];

                    }
                }
            };

            Post["/add"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        using (var transaction = s.BeginTransaction())
                        {
                            string titleName = Request.Form.TitleName;
                            string matchTitleStr = Request.Form.MatchTitle;
                            string issueStatusStr = Request.Form.IssueStatus;

                            MatchTitle matchTitle;
                            IssueStatus issueStatus;

                            if (!Enum.TryParse(matchTitleStr, false, out matchTitle))
                            {
                                throw new ArgumentException("Unknown match title {0}", matchTitleStr);
                            }

                            if (!Enum.TryParse(issueStatusStr, false, out issueStatus))
                            {
                                throw new ArgumentException("Unknown match title {0}", matchTitleStr);
                            }

                            var title = s.QueryOver<Title>().Where(ti => ti.Name == titleName).SingleOrDefault<Title>();

                            if (title != null)
                            {
                                title.Subscribed = true;
                                title.MatchTitle = matchTitle;

                                foreach (var i in title.Issues)
                                {
                                    if (i.Status == IssueStatus.New)
                                    {
                                        i.Status = issueStatus;
//.........这里部分代码省略.........
开发者ID:nrich,项目名称:greasyhands,代码行数:101,代码来源:Main.cs

示例7: Releases

        public Releases(ISession session)
            : base("/releases")
        {
            string dbFile = ConfigurationManager.AppSettings["DBFile"];

            Get["/"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        var issues = s.QueryOver<Issue>().Where(i => i.Status == IssueStatus.Wanted).OrderBy(i => i.Release).Asc.List<Issue>();
                        IList list = new ArrayList();

                        foreach (var issue in issues)
                        {
                            list.Add(new {issue.Id, issue.Num, Released = issue.Release.Date.NiceDate(), Title = new {issue.Title.Id, issue.Title.Name}, Publisher = new {issue.Title.Publisher.Name, issue.Title.Publisher.Id}});
                        }

                        return View["Releases/Index", new {Pending = list}];
                    }
                }
            };

            Get["/history"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        var releases = s.QueryOver<Release>().OrderBy(r => r.Date).Desc.List<Release>();
                        IList list = new ArrayList();

                        foreach (var release in releases)
                        {
                            list.Add(new { release.Id, Grabbed = release.Created.NiceDate(), Released = release.Date.NiceDate(), Issues = release.Issues.Count });
                        }

                        return View["Releases/History", new { Releases = list }];
                    }
                }
            };

            Get["/upload"] = parameters =>
            {
                return View["Releases/Upload"];
            };

            Post["/upload"] = parameters =>
            {
                string weeks = Request.Form.Weeks.Value;
                string url = Request.Form.Url.Value;

                if (weeks.Length > 0)
                {
                    ScheduleUpdater.AddReleaseURL(int.Parse(weeks));
                }

                if (url.Length > 0)
                {
                    ScheduleUpdater.AddReleaseURL(new Uri(url));
                }

                return View["Releases/Upload"];
            };

            Get["/single/{id}"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        int id = int.Parse(parameters.id);
                        //var issues = s.QueryOver<Issue>().Where(i => i.Release.Id == id).OrderBy(i => i.Title.Name).Asc.List<Issue>();
                        var release = s.QueryOver<Release>().Where(i => i.Id == id).SingleOrDefault<Release>();
                        IList list = new ArrayList();

                        var issues =
                            release.Issues.OrderBy(i => i.Title.Name).ThenBy(i => i.Num).ThenBy(i => i.Variant.Length);

                        foreach (var issue in issues)
                        {
                            list.Add(new { issue.Id, issue.Num, issue.Status, issue.Variant, issue.Code, Title = new { issue.Title.Id, issue.Title.Name, Publisher = new { issue.Title.Publisher.Name, issue.Title.Publisher.Id } } });
                        }

                        var model = new { Issues = list, Release = release };

                        return View["Releases/Single", model];

                    }
                }
            };

            Post["/single/{id}"] = parameters =>
            {
                using (var db = session.SessionFactory(dbFile))
                {
                    using (var s = db.OpenSession())
                    {
                        using (var transaction = s.BeginTransaction())
//.........这里部分代码省略.........
开发者ID:nrich,项目名称:greasyhands,代码行数:101,代码来源:Releases.cs


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