<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using NHibernate.Linq;

namespace Fish.MovieManager.ActorControl
{
    public class Class1
    {
        private static Class1 _instance = new Class1();
        public static Class1 Instance { get { return _instance; } }

        /// <summary>
        /// 根据豆瓣ID，获取其所有主演信息
        /// 现在有缺陷，会返回所有信息，包括导演，需要自己根据导演ID筛选一下。
        /// </summary>
        /// <param name="doubanId">豆瓣ID</param>
        /// <returns>演员信息的List</returns>
        public List<Fish.MovieManager.DoubanActorInfo.Storage.DoubanActorInfo> GetActorByID(int doubanId)
        {
            var ans = new List<Fish.MovieManager.DoubanActorInfo.Storage.DoubanActorInfo>();
            var id = new List<int>();
            using (var session = Fish.MovieManager.Movie2Actor.Storage.StorageManager.Instance.OpenSession())
            {
                var tmp = session.Query<Fish.MovieManager.Movie2Actor.Storage.Movie2Actor>().Where(o => o.id == doubanId).Select(o => o.doubanId).ToList();
                foreach (var item in tmp)
                {
                    id.Add(item);
                    Console.WriteLine(item);
                }
            }
            using (var session = Fish.MovieManager.DoubanActorInfo.Storage.StorageManager.Instance.OpenSession())
            {
                foreach(var item in id)
                {
                    var tmp = session.Query<Fish.MovieManager.DoubanActorInfo.Storage.DoubanActorInfo>().Where(o => o.id == item).SingleOrDefault();
                    if (tmp != null)
                    {
                        ans.Add(tmp);
                    }
                }
            }
            return ans;
        }

        /// <summary>
        /// 根据一个演员的豆瓣ID，从豆瓣抓取信息，添加到数据库中
        /// </summary>
        /// <param name="id">演员的豆瓣ID</param>
        public void AddActorInfo(int id)
        {
            var actor = Fish.MovieManager.DoubanAPI.Class.Instance.GetActorInfo(id);
            using (var session = Fish.MovieManager.DoubanActorInfo.Storage.StorageManager.Instance.OpenSession())
            {
                session.BeginTransaction();
                var tmp = session.Query<Fish.MovieManager.DoubanActorInfo.Storage.DoubanActorInfo>().Where(o => o.id == actor.id).SingleOrDefault();
                if (tmp == null)
                {
                    try
                    {
                        session.Save(actor);
                        session.Transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        session.Transaction.Rollback();
                        throw new Exception("wrong storage.", ex);
                    }
                }
            }
        }

        /// <summary>
        /// 添加一个电影的演员对应关系
        /// </summary>
        /// <param name="m2a">Movie2Actor类型</param>
        public void AddActor(Fish.MovieManager.Movie2Actor.Storage.Movie2Actor m2a)
        {
            using (var session = Fish.MovieManager.Movie2Actor.Storage.StorageManager.Instance.OpenSession())
            {
                session.BeginTransaction();
                var tmp = session.Query<Fish.MovieManager.Movie2Actor.Storage.Movie2Actor>().Where(o => o.id == m2a.id && o.doubanId == m2a.doubanId).SingleOrDefault();
                if (tmp == null)
                {
                    try 
                    {
                        session.Save(m2a);
                        session.Transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        session.Transaction.Rollback();
                        throw new Exception("wrong storage.", ex);
                    }
                }
            }
        }
    }
}
<commit_msg>a little fix.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using NHibernate.Linq;

namespace Fish.MovieManager.ActorControl
{
    public class Class1
    {
        private static Class1 _instance = new Class1();
        public static Class1 Instance { get { return _instance; } }

        /// <summary>
        /// 根据豆瓣ID，获取其所有主演信息
        /// </summary>
        /// <param name="doubanId">豆瓣ID</param>
        /// <returns>演员信息的List</returns>
        public List<Fish.MovieManager.DoubanActorInfo.Storage.DoubanActorInfo> GetActorByID(int doubanId)
        {
            var ans = new List<Fish.MovieManager.DoubanActorInfo.Storage.DoubanActorInfo>();
            var id = new List<int>();
            using (var session = Fish.MovieManager.Movie2Actor.Storage.StorageManager.Instance.OpenSession())
            {
                var tmp = session.Query<Fish.MovieManager.Movie2Actor.Storage.Movie2Actor>().Where(o => o.id == doubanId).Select(o => o.doubanId).ToList();
                foreach (var item in tmp)
                {
                    id.Add(item);
                    Console.WriteLine(item);
                }
            }
            using (var session = Fish.MovieManager.DoubanActorInfo.Storage.StorageManager.Instance.OpenSession())
            {
                foreach(var item in id)
                {
                    var tmp = session.Query<Fish.MovieManager.DoubanActorInfo.Storage.DoubanActorInfo>().Where(o => o.id == item).SingleOrDefault();
                    if (tmp != null)
                    {
                        ans.Add(tmp);
                    }
                }
            }
            return ans;
        }

        /// <summary>
        /// 根据一个演员的豆瓣ID，从豆瓣抓取信息，添加到数据库中
        /// </summary>
        /// <param name="id">演员的豆瓣ID</param>
        public void AddActorInfo(int id)
        {
            var actor = Fish.MovieManager.DoubanAPI.Class.Instance.GetActorInfo(id);
            using (var session = Fish.MovieManager.DoubanActorInfo.Storage.StorageManager.Instance.OpenSession())
            {
                session.BeginTransaction();
                var tmp = session.Query<Fish.MovieManager.DoubanActorInfo.Storage.DoubanActorInfo>().Where(o => o.id == actor.id).SingleOrDefault();
                if (tmp == null)
                {
                    try
                    {
                        session.Save(actor);
                        session.Transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        session.Transaction.Rollback();
                        throw new Exception("wrong storage.", ex);
                    }
                }
            }
        }

        /// <summary>
        /// 添加一个电影的演员对应关系
        /// </summary>
        /// <param name="m2a">Movie2Actor类型</param>
        public void AddActor(Fish.MovieManager.Movie2Actor.Storage.Movie2Actor m2a)
        {
            using (var session = Fish.MovieManager.Movie2Actor.Storage.StorageManager.Instance.OpenSession())
            {
                session.BeginTransaction();
                var tmp = session.Query<Fish.MovieManager.Movie2Actor.Storage.Movie2Actor>().Where(o => o.id == m2a.id && o.doubanId == m2a.doubanId).SingleOrDefault();
                if (tmp == null)
                {
                    try 
                    {
                        session.Save(m2a);
                        session.Transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        session.Transaction.Rollback();
                        throw new Exception("wrong storage.", ex);
                    }
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.1068913480885312, 'fraction_numerical': 0.004527162977867203, 'mean_word_length': 1.2748855835240274, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3741471', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2120, 'n_words': 321}