public GroupMessageSettingViewModel(IEnumerable <IAutoAnswer> answers)
        {
            Answers  = answers;
            Settings = answers.Select(x => new SettingInfo {
                Name = x.Name, Key = x.SettingKey
            }).ToList();
            Items        = OrmManager.Fetch <GroupInfo>(x => x.StillIn && x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ));
            SavedCommand = new Command(() => {
                foreach (var setting in Settings)
                {
                    SelectedItem.SetState(setting.Key, setting.Selected);
                }
                OrmManager.Update(SelectedItem);
            });
            SelectedCommand = new Command(() => {
                if (string.IsNullOrEmpty(SelectedItem.State))
                {
                    SelectedItem.State = WorkContext.GetState <QQState>(Constract.CurrentQQState).State;
                }
                for (int i = 0; i < Settings.Count; i++)
                {
                    Settings[i].Selected = SelectedItem.GetState <bool>(Settings[i].Key);
                }

                RaisePropertyChanged(nameof(Settings));
                PrevSelectedItem = SelectedItem;
            }, () => SelectedItem != PrevSelectedItem && SelectedItem != null);
        }
Пример #2
0
        private void Client_Logined(object sender, LoginSucessedEventArgs e)
        {
            var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);

            state.Logined = true;
            state.SetCookies(Constract.LoginCookies, e.JsonResult);
            // state.SetCookies(Constract.QQSession, e.Session);
            OrmManager.Update(state);
            var clientManager = ClientManager.GetClientManagerUser(Container, state);

            clientManager.QQ.Logined          = true;
            clientManager.QQ.State            = state.State;
            clientManager.Client.DefaultState = state.State;
            if (e.ShowMainWindow)
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    new MainWindow(Container).Show();
                    Logger.Debug("MainWindow has been created and displayed.");
                    // 3.Closes the SignIn window.
                    (Application.Current.Resources[LoginWindow.Key] as LoginWindow)?.Close();
                    Logger.Debug("LoginWindow has been closed.");
                });
            }
        }
 private void SyncThemeAndColor()
 {
     Setting.Color    = this.SelectedAccentColor.Name;
     Setting.Theme    = this.SelectedTheme.DisplayName;
     Setting.FontSize = Theme.GetThemeFrontSizeByFont(AppearanceManager.Current.FontSize).Name;
     OrmManager.Update(Setting);
 }
 public ListDisscussionViewModel(ILoggerFacade logger) //,ISmartService smartService: base(container)IUnityContainer container
 {
     Logger          = logger;
     Items           = OrmManager.Fetch <DiscussInfo>(x => x.StillIn);
     SelectedCommand = new Command(() => {
         Logger.Debug(SelectedItem.Name);
     }, () => SelectedItem != null);
     RefreshBasicCommand = new Command(() => {
         var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
         state?.GetClient().InitDisscussList();
         Items = OrmManager.Fetch <DiscussInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ) && x.StillIn);
         RaisePropertyChanged(nameof(Items));
     });
     RefreshDetailCommand = new Command(() => {
         Task.Run(() => {
             foreach (var group in Items)
             {
                 var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
                 state?.GetClient().InitDisscussInfo(group.Did);
                 // smartService.InitDisscussInfo(group.Did);
             }
         });
         Items = OrmManager.Fetch <DiscussInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ) && x.StillIn);
         RaisePropertyChanged(nameof(Items));
     }, () => Items.Count() > 0);
     RefreshSelectedCommand = new Command(() => {
         // Logger.Debug(SelectedItem.Name);
         var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
         state?.GetClient().InitDisscussInfo(SelectedItem.Did);
         //smartService.InitDisscussInfo(SelectedItem.Did);
         Items = OrmManager.Fetch <DiscussInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ) && x.StillIn);
         RaisePropertyChanged(nameof(Items));
     }, () => SelectedItem != null);
 }
Пример #5
0
        public void Uninstall(string feature)
        {
            // Logger.Information("Uninstalling feature: {0}.", feature);

            var migrations = GetDataMigrations(feature);

            // apply update methods to each migration class for the module
            foreach (var migration in migrations)
            {
                // copy the object for the Linq query
                var tempMigration = migration;

                // get current version for this migration
                var dataMigrationRecord = GetDataMigrationRecord(tempMigration);

                var uninstallMethod = GetUninstallMethod(migration);
                if (uninstallMethod != null)
                {
                    uninstallMethod.Invoke(migration, new object[0]);
                }

                if (dataMigrationRecord == null)
                {
                    continue;
                }

                OrmManager.Delete(dataMigrationRecord);
                //_dataMigrationRepository.Flush();
            }
        }
Пример #6
0
        public DefaultMessageSettingViewModel(IEnumerable <IAutoAnswer> answers)
        {
            Answers  = answers;
            Settings = answers.Select(x => new SettingInfo {
                Name = x.Name, Key = x.SettingKey
            }).ToList();
            Items        = OrmManager.Fetch <QQState>(x => x.Id > 0);
            SavedCommand = new Command(() => {
                foreach (var setting in Settings)
                {
                    SelectedItem.SetState(setting.Key, setting.Selected);
                }
                OrmManager.Update(SelectedItem);
                var client = SelectedItem.GetClient();
                if (client != null)
                {
                    client.DefaultState = SelectedItem.State;
                }
            });
            SelectedCommand = new Command(() => {
                if (string.IsNullOrEmpty(SelectedItem.State))
                {
                    SelectedItem.State = "{}";
                }
                for (int i = 0; i < Settings.Count; i++)
                {
                    Settings[i].Selected = SelectedItem.GetState <bool>(Settings[i].Key);
                }

                RaisePropertyChanged(nameof(Settings));
                PrevSelectedItem = SelectedItem;
            }, () => SelectedItem != PrevSelectedItem && SelectedItem != null);
        }
Пример #7
0
        internal void SetOneToManyEntity()
        {
            Type collection        = PropertyInfo.PropertyType;
            Type foreignEntityType = collection.GetGenericArguments()[0];

            OneToMany.Entity = OrmManager.GetEntity(foreignEntityType);
        }
Пример #8
0
 protected override void OnLoaded()
 {
     TotalPage = (OrmManager.Count <SystemLogData>() + PageSize - 1) / PageSize;
     // base.OnLoaded();
     Logs = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip((CurrentPage - 1) * PageSize).Take(PageSize);
     RaisePropertyChanged(nameof(TotalPage));
     RaisePropertyChanged(nameof(Logs));
 }
Пример #9
0
        //http://www.itokit.com/2012/0721/74607.html
        public static string Post(string url, string data, string Referer = "http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2", int timeout = 100000, Encoding encode = null)
        {
            string         dat = "";
            HttpWebRequest req;

            try
            {
                req = WebRequest.Create(url) as HttpWebRequest;
                req.CookieContainer = cookies;
                req.ContentType     = "application/x-www-form-urlencoded";
                req.Method          = "POST";
                req.Proxy           = null;
                req.Timeout         = timeout;
                req.UserAgent       = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2372.400 QQBrowser/9.5.10548.400";
                req.Accept          = "*/*";

                //req.UserAgent = "Mozilla/5.0 (Windows NT 10.0;%20WOW64; rv:47.0) Gecko/20100101 Firefox/47.0";
                req.ProtocolVersion = HttpVersion.Version11;
                req.Referer         = Referer;
                req.Headers.Add("Origin", "");
                byte[] mybyte = Encoding.Default.GetBytes(data);
                req.ContentLength = mybyte.Length;

                Stream stream = req.GetRequestStream();
                stream.Write(mybyte, 0, mybyte.Length);


                HttpWebResponse res = req.GetResponse() as HttpWebResponse;
                cookies.Add(res.Cookies);
                stream.Close();

                StreamReader SR = new StreamReader(res.GetResponseStream(), encode == null ? Encoding.UTF8 : encode);
                dat = SR.ReadToEnd();
                res.Close();
                req.Abort();
            }
            catch (HttpException e)
            {
                OrmManager.Insert(new SystemLogData {
                    OriginData = e.Message, Message = "网络故障"
                });
                return("");
            }
            catch (WebException e)
            {
                OrmManager.Insert(new SystemLogData {
                    OriginData = e.Message, Message = "网络故障"
                });
                return("");
            }
            if (!dat.Equals(""))
            {
                // OrmManager.Insert(new SystemLogData { OriginData = dat.Replace(';',' '), Message = "System" });
            }
            return(dat);
        }
Пример #10
0
        /// <summary>
        /// 从服务器获取AI的回复
        /// </summary>
        /// <param name="message">源语句</param>
        /// <param name="QQNum">发言用户的QQ</param>
        /// <param name="QunNum">发言的群</param>
        /// <returns></returns>
        private static string AIGet(string message, long QQNum, long QunNum = 0)
        {
            var study = OrmManager.Get <StudyWords>(x => x.SourceQQNum == QQNum && x.GroupId == QunNum && x.Source == message && x.Pass);

            if (study == null)
            {
                return("");
            }
            return(study.Aim);
        }
Пример #11
0
        static Repository()
        {
            Entity entity = OrmManager.GetEntity(typeof(T));

            if (entity == null)
            {
                throw new TableNotFoundException();
            }

            Entity = entity;
        }
Пример #12
0
        internal static void SetConnection(Assembly assembly, string filename)
        {
            UriBuilder uri = new UriBuilder(assembly.CodeBase);

            string directory = Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path));

            directory = Directory.GetParent(Directory.GetParent(directory).ToString()).ToString();

            StringBuilder stringBuilder = new StringBuilder()
                                          .Append(directory)
                                          .Append("\\")
                                          .Append(string.Format("{0}", filename));

            directory = stringBuilder.ToString();

            try
            {
                using (XmlReader reader = XmlReader.Create(directory))
                {
                    Connection currentConnection = null;

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            switch (reader.LocalName)
                            {
                            case "MySqlConnection":
                                currentConnection = GetMySqlConnection(reader);
                                break;

                            case "XmlConnection":
                                currentConnection = GetXmlConnection(reader);
                                break;

                            case "Table":
                                Entity entity = OrmManager.GetEntity(reader.GetAttribute("name"));
                                entity.Connection = currentConnection;
                                break;
                            }
                        }
                    }
                }
            }
            catch (FileNotFoundException exc)
            {
                throw new ConfigurationException(directory);
            }
            catch (Exception exc)
            {
                throw new ConfigurationException();
            }
        }
Пример #13
0
 private void AddFields()
 {
     InheritedEntity = OrmManager.GetBaseEntity(Class);
     if (Table.TableType == TableType.InheritedFieldsToChild)
     {
         OrmManager.Entities.Remove(InheritedEntity);
         AddFields(BindingFlags.NonPublic | BindingFlags.Instance);
     }
     else
     {
         AddFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
     }
 }
Пример #14
0
        public void Answer(AnswerContext context)
        {
            if (!context.CanAnswer)
            {
                return;
            }
            var anwer = "";

            if (CommandKey.Any(x => context.Message.StartsWith(x)))
            {
                //  bool EnableFlag = false;
                //  if (context.State != null && context.GetState<bool>(SettingKey))
                //  {
                //      EnableFlag = true;
                //  }
                //  else if(context.MessageType=="message"){
                //      EnableFlag = true;
                // }
                // if (EnableFlag)
                //  {

                string[] tmp = context.Message.Split(' ');

                if (tmp.Length == 2)
                {
                    anwer = GetStock(tmp[1], "");
                }
                else if (tmp.Length == 3)
                {
                    anwer = GetStock(tmp[1], tmp[2]);
                }
                else
                {
                    context.Alerts.AddRange(Example());
                }
                if (!string.IsNullOrEmpty(anwer))
                {
                    context.Answers.Add(anwer);
                    var newlog = new AutoAnswerMessageLog();
                    newlog.FromUin     = context.SendToId;
                    newlog.ToUin       = context.FromUin;
                    newlog.MessageType = "stock";
                    newlog.P1          = tmp[tmp.Length - 1];
                    newlog.Data        = anwer;
                    OrmManager.Insert(newlog);

                    // }
                }
            }
        }
Пример #15
0
 public ListSystemMessageLogViewModel(ILoggerFacade logger)  //: base(container)IUnityContainer container
 {
     Logger    = logger;
     Logs      = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Take(PageSize);
     TotalPage = (OrmManager.Count <SystemLogData>() + PageSize - 1) / PageSize;
     RaisePropertyChanged(nameof(CurrentPage));
     RaisePropertyChanged(nameof(Logs));
     SelectedCommand = new Command <TextBlock>(detailData => {
         detailData.Text = SelectedLog.OriginData;
         Logger.Log(SelectedLog.OriginData, Category.Debug, Priority.High);
     }, detailData => SelectedLog != null);
     GoToPageCommand = new Command(() => {
         Logs = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage >= 1);
     FirstPageCommand = new Command(() => {
         CurrentPage = 1;
         Logs        = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage != 1 && CurrentPage <= TotalPage);
     NextPageCommand = new Command(() => {
         CurrentPage++;
         if (CurrentPage > TotalPage)
         {
             CurrentPage = TotalPage;
         }
         Logs = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage < TotalPage);
     PrevPageCommand = new Command(() => {
         CurrentPage--;
         Logs = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage > 1 && CurrentPage <= TotalPage);
     LastPageCommand = new Command(() => {
         CurrentPage = TotalPage;
         Logs        = OrmManager.Fetch <SystemLogData>(x => x.Id > 0).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
         RaisePropertyChanged(nameof(CurrentPage));
         RaisePropertyChanged(nameof(Logs));
         Logger.Log(CurrentPage.ToString(), Category.Debug, Priority.High);
     }, () => CurrentPage < TotalPage);
 }
Пример #16
0
        public IEnumerable <string> GetFeaturesThatNeedUpdate()
        {
            var currentVersions = OrmManager.GetAll <Tables.OrmTablesInfo>().ToDictionary(r => r.DataMigrationClass);

            var outOfDateMigrations = _dataMigrations.Where(dataMigration => {
                Tables.OrmTablesInfo record;
                if (currentVersions.TryGetValue(dataMigration.GetType().FullName, out record))
                {
                    return(CreateUpgradeLookupTable(dataMigration).ContainsKey(record.Version));
                }

                return(GetCreateMethod(dataMigration) != null);
            });

            return(outOfDateMigrations.Select(m => m.GetType().Assembly.FullName).ToList());
        }
Пример #17
0
        public static string PostJsonData(string url, string data, int timeout = 100000, Encoding encode = null)
        {
            string         dat = "";
            HttpWebRequest req;

            try
            {
                req                 = WebRequest.Create(url) as HttpWebRequest;
                req.ContentType     = "application/json;charset=utf-8";
                req.Method          = "POST";
                req.Proxy           = null;
                req.Timeout         = timeout;
                req.UserAgent       = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2372.400 QQBrowser/9.5.10548.400";
                req.ProtocolVersion = HttpVersion.Version11;

                byte[] mybyte = Encoding.Default.GetBytes(data);
                req.ContentLength = mybyte.Length;

                Stream stream = req.GetRequestStream();
                stream.Write(mybyte, 0, mybyte.Length);


                HttpWebResponse res = req.GetResponse() as HttpWebResponse;

                stream.Close();

                StreamReader SR = new StreamReader(res.GetResponseStream(), encode == null ? Encoding.UTF8 : encode);
                dat = SR.ReadToEnd();
                res.Close();
                req.Abort();
            }
            catch (HttpException)
            {
                return("");
            }
            catch (WebException)
            {
                return("");
            }
            if (!dat.Equals(""))
            {
                OrmManager.Insert(new SystemLogData {
                    OriginData = dat.Replace(';', ' '), Message = "System"
                });
            }
            return(dat);
        }
Пример #18
0
        /// <summary>
        /// 从服务器获取AI的回复
        /// </summary>
        /// <param name="message">源语句</param>
        /// <param name="QQNum">发言用户的QQ</param>
        /// <param name="QunNum">发言的群</param>
        /// <returns></returns>
        private static string AIGet(string message)
        {
            var study = OrmManager.Get <StudyWords>(x => x.Source == message);

            if (study == null)
            {
                return("");
            }
            else
            {
                if (!study.Pass)
                {
                    return("None3");
                }
            }
            return(study.Aim);
        }
Пример #19
0
        public void Answer(AnswerContext context)
        {
            if (!context.CanAnswer)
            {
                return;
            }

            //var message = context.Message.ToLower();
            if (CommandKey.Any(x => context.Message.IndexOf(x, StringComparison.InvariantCultureIgnoreCase) >= 0))
            {
                bool EnableFlag = false;
                if (context.State != null && context.GetState <bool>(SettingKey))
                {
                    EnableFlag = true;
                }
                else if (context.MessageType == "message")
                {
                    EnableFlag = true;
                }
                if (EnableFlag)
                {
                    var result = GetResult(context.Message);
                    if (result.Count() == 1 && string.IsNullOrEmpty(result[0]))
                    {
                        return;
                    }
                    else
                    {
                        context.Answers.AddRange(result);
                        try
                        {
                            var newlog = new AutoAnswerMessageLog();
                            newlog.FromUin     = context.SendToId;
                            newlog.ToUin       = context.FromUin;
                            newlog.MessageType = "orchard";
                            newlog.P1          = context.Message;
                            newlog.Data        = string.Join("回复了:", result);
                            OrmManager.Insert(newlog);
                        }
                        catch
                        { }
                    }
                }
            }
        }
Пример #20
0
        public void Answer(AnswerContext context)
        {
            if (!context.CanAnswer)
            {
                return;
            }
            List <string> anwer = null;

            if (CommandKey.Any(x => context.Message.StartsWith(x)))
            {
                bool EnableFlag = false;
                if (context.State != null && context.GetState <bool>(SettingKey))
                {
                    EnableFlag = true;
                }
                else if (context.MessageType == "message")
                {
                    EnableFlag = true;
                }
                if (EnableFlag)
                {
                    string[] tmp = context.Message.Trim().Split(' ');
                    if (tmp.Length == 2)
                    {
                        anwer = GetWeather(tmp[1]);
                    }
                    else
                    {
                        context.Alerts.AddRange(Example());
                    }

                    if (anwer != null && anwer.Count > 0)
                    {
                        context.Answers.AddRange(anwer);
                        var newlog = new AutoAnswerMessageLog();
                        newlog.FromUin     = context.SendToId;
                        newlog.ToUin       = context.FromUin;
                        newlog.MessageType = "weather";
                        newlog.P1          = tmp[1];
                        newlog.Data        = string.Join(",", anwer);
                        OrmManager.Insert(newlog);
                    }
                }
            }
        }
Пример #21
0
        static void Main(string[] args)
        {
            //List<>list=new List<>();
            //foreach(object foreignObject in foreignObjects)
            //{
            //    list.Add(foreignObject);
            //}
            //obj.field = list;

            OrmManager.Start("OrmConfig.xml");
            User u = new User();

            u.UserId    = 1;
            u.FirstName = "imie1";

            Ord o1 = new Ord();

            o1.OrdId = 1;
            o1.User  = u;
            o1.Name  = "product1";

            Ord o2 = new Ord();

            o2.OrdId = 2;
            o2.User  = u;
            o2.Name  = "product2";

            Repository <Ord> .Save(o1);

            Repository <Ord> .Save(o2);

            Repository <User> .Save(u);

            Predicate <Ord> orderPredicate = ValidOrder;

            Console.WriteLine("OrmFramework: Zamowienia");

            foreach (Ord order in Repository <Ord> .GetIterator(10, orderPredicate))
            {
                Console.WriteLine(order.Name);
            }

            Console.ReadLine();
        }
        public void Answer(AnswerContext context)
        {
            bool EnableFlag = false;

            if (context.State != null && context.GetState <bool>(SettingKey))
            {
                EnableFlag = true;
            }
            else if (context.MessageType == "message")
            {
                EnableFlag = true;
            }
            if (EnableFlag)
            {
                var words = OrmManager.Fetch <BadWords>(x => x.QQNum == context.CurrentQQ).Select(x => x.Word);
                if (words == null || words.Count() == 0)
                {
                    return;
                }
                else
                {
                    context.Answers.RemoveAll(x => string.IsNullOrEmpty(x));
                    for (int i = 0; i < context.Answers.Count; i++)
                    {
                        foreach (var word in words)
                        {
                            if (context.Answers[i].Contains(word))
                            {
                                var newlog = new AutoAnswerMessageLog();
                                newlog.FromUin     = context.SendToId;
                                newlog.ToUin       = context.FromUin;
                                newlog.MessageType = "badword";
                                newlog.P1          = word;
                                newlog.Data        = context.Answers[i];
                                OrmManager.Insert(newlog);
                                context.Answers[i] = context.Answers[i].Replace(word, "***");
                            }
                        }
                    }
                }
            }
        }
Пример #23
0
 public ListFriendsViewModel() //ISmartService smartService: base(container)IUnityContainer container
 {
     Friends         = OrmManager.Fetch <FriendInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ));
     SelectedCommand = new Command(() => {
         Logger.Log(SelectedFriend.Nick, Prism.Logging.Category.Debug, Prism.Logging.Priority.High);
     }, () => SelectedFriend != null);
     RefreshCommand = new Command(() => {
         var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
         state?.GetClient().InitFriendList();
         //smartService.InitFriendList();
         Friends = OrmManager.Fetch <FriendInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ));
         RaisePropertyChanged(nameof(Friends));
     });
     RefreshSelectedCommand = new Command(() => {
         var state = WorkContext.GetState <QQState>(Constract.CurrentQQState);
         state?.GetClient().InitGroupInfo(SelectedFriend.Uin);
         // smartService.InitFriendInfo(SelectedFriend.Uin);
         Friends = OrmManager.Fetch <FriendInfo>(x => x.QQNum == WorkContext.GetState <long>(Constract.CurrentQQ));
         RaisePropertyChanged(nameof(Friends));
     }, () => SelectedFriend != null);
 }
Пример #24
0
        /// <summary>
        /// 向服务器提交AI学习请求
        /// </summary>
        /// <param name="source">源语句</param>
        /// <param name="aim">目标语句</param>
        /// <param name="QQNum">发起学习用户的QQ</param>
        /// <param name="QunNum">发起学习的群</param>
        /// <param name="superstudy">是否为特权学习</param>
        /// <returns>用户友好的提示语</returns>
        public string AIStudy(string source, string aim, long QQNum, long QunNum = 0, bool superstudy = false)
        {
            var study = new StudyWords();

            study.SourceQQNum = QQNum;
            study.QQNum       = WorkContext.GetState <long>(Constract.CurrentQQ);
            study.GroupId     = QunNum;
            study.Source      = source;
            study.Aim         = aim;
            if (superstudy)
            {
                study.Pass  = true;
                study.Reson = "特权学习";
            }
            else
            {
            }
            if (OrmManager.Count <BadWords>(x => string.Equals(x.Word, source, StringComparison.InvariantCultureIgnoreCase)) > 0 || OrmManager.Count <BadWords>(x => string.Equals(x.Word, aim, StringComparison.InvariantCultureIgnoreCase)) > 0)
            {
                return("ForbiddenWord");
            }
            if (OrmManager.Count <StudyWords>(x => x.SourceQQNum == QQNum && x.GroupId == QunNum && x.Source == source && x.Pass) > 0)
            {
                return("Forbidden");
            }
            else if (OrmManager.Count <StudyWords>(x => x.SourceQQNum == QQNum && x.GroupId == QunNum && x.Source == source && !x.Pass) > 0)
            {
                return("Waitting");
            }
            OrmManager.Insert(study);
            if (!study.Pass)
            {
                return("pending");
            }
            else
            {
                return("Success");
            }
        }
        public void Answer(AnswerContext context)
        {
            bool EnableFlag = false;

            if (context.State != null && context.GetState <bool>(SettingKey))
            {
                EnableFlag = true;
            }
            else if (context.MessageType == "message")
            {
                EnableFlag = true;
            }
            if (EnableFlag)
            {
                var words = OrmManager.Fetch <BadWords>(x => x.QQNum == context.CurrentQQ && context.Message.Contains(x.Word)).Select(x => x.Word);
                if (words == null || words.Count() == 0)
                {
                    return;
                }
                else
                {
                    var template = "{0} 含有禁用词 {1},提出警告";
                    foreach (var word in words)
                    {
                        context.Alerts.Add(string.Format(template, context.FromUin, word));
                    }

                    var newlog = new AutoAnswerMessageLog();

                    newlog.FromUin     = context.SendToId;
                    newlog.ToUin       = context.FromUin;
                    newlog.MessageType = "badword";
                    newlog.P1          = string.Join(",", words);
                    newlog.Data        = context.Message;
                    OrmManager.Insert(newlog);
                    context.CanAnswer = false;
                }
            }
        }
        public SettingsAppearanceViewModel()//:base(container)IUnityContainer container
        {
            Setting = OrmManager.GetDefault <SettingModel>();
            if (Setting == null)
            {
                OrmManager.Insert(new SettingModel());
                Setting = OrmManager.GetDefault <SettingModel>();
            }
            foreach (var theme in Theme.GetThemes())
            {
                this.themes.Add(new Link {
                    DisplayName = theme.Name, Source = new Uri(theme.Path, UriKind.Relative)
                });
            }
            colors                   = Theme.GetThemeColors();
            FontSizes                = Theme.GetThemeFrontSizes().Select(x => x.Name);
            this.SelectedFontSize    = Setting.FontSize;
            this.SelectedTheme       = this.themes.FirstOrDefault(l => l.DisplayName.Equals(Setting.Theme, StringComparison.InvariantCultureIgnoreCase));
            this.SelectedAccentColor = this.colors.FirstOrDefault(x => x.Name.Equals(Setting.Color, StringComparison.InvariantCultureIgnoreCase));
            SyncThemeAndColor();

            AppearanceManager.Current.PropertyChanged += OnAppearanceManagerPropertyChanged;
        }
Пример #27
0
        public ListQQStateViewModel(IUnityContainer container) //ISmartService smartService: base(container)IUnityContainer container
        {
            Container       = container;
            Logger          = container.Resolve <ILoggerFacade>();
            States          = OrmManager.Fetch <QQState>(x => x.Id > 0);
            SelectedCommand = new Command(() => {
                Logger.Log(SelectedState.QQNum.ToString(), Prism.Logging.Category.Debug, Prism.Logging.Priority.High);
            }, () => SelectedState != null);
            RefreshCommand = new Command(() => {
                States = OrmManager.Fetch <QQState>(x => x.Id > 0);
                RaisePropertyChanged(nameof(States));
                // Logger.Log(SelectedGroup.Name, Prism.Logging.Category.Debug, Prism.Logging.Priority.High);
            });
            TryLoginSelectedCommand = new Command(() => {
                Message = "开始登录";
                RaisePropertyChanged(nameof(Message));
                // var state = WorkContext.GetState<QQState>(Constract.CurrentQQState);
                // state?.GetClient().InitFriendList();
                var clientManager = ClientManager.GetClientManagerUser(container, SelectedState);
                WorkContext.SetState(Constract.CurrentQQState, SelectedState);
                WorkContext.SetState(Constract.CurrentQQ, SelectedState.QQNum);
                clientManager.Client.Logined += Client_Logined;
                if (clientManager.Client.TryLogin(SelectedState))
                {
                    Message = "登录成功";
                    RaisePropertyChanged(nameof(Message));
                }
                else
                {
                    Message = "登录失败";
                    RaisePropertyChanged(nameof(Message));
                }
                // States = OrmManager.Fetch<QQState>(x => x.Id > 0);

                Logger.Log(SelectedState.QQNum.ToString(), Prism.Logging.Category.Debug, Prism.Logging.Priority.High);
            }, () => SelectedState != null);
        }
Пример #28
0
        private void Client_Logined(object sender, LoginSucessedEventArgs e)
        {
            // OrmManager.Update(state);
            var state = OrmManager.Get <Models.QQState>(x => x.QQNum == e.Session.QQNum);

            var clientManager = ClientManager.GetClientManagerUser(Container, new Models.QQState());

            clientManager.QQ.QQNum   = e.Session.QQNum;
            clientManager.QQ.Logined = true;
            clientManager.QQ.SetCookies(Constract.LoginCookies, e.JsonResult);
            //clientManager.QQ.SetCookies(Constract.QQSession, e.Session);
            if (state != null)
            {
                clientManager.QQ.Id = state.Id;
                OrmManager.Update(clientManager.QQ);
            }
            else
            {
                OrmManager.Insert(clientManager.QQ);
            }
            WorkContext.SetState(Constract.CurrentQQState, clientManager.QQ);
            WorkContext.SetState(Constract.CurrentQQ, clientManager.QQ.QQNum);
            clientManager.Client.DefaultState = clientManager.QQ.State;
            ClientManager.ResetKey();
            //throw new NotImplementedException();
            if (e.ShowMainWindow)
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    new MainWindow(Container).Show();
                    Logger.Debug("MainWindow has been created and displayed.");
                    // 3.Closes the SignIn window.
                    (Application.Current.Resources[LoginWindow.Key] as LoginWindow)?.Close();
                    Logger.Debug("LoginWindow has been closed.");
                });
            }
        }
Пример #29
0
        public void Answer(AnswerContext context)
        {
            if (!context.CanAnswer)
            {
                return;
            }
            var anwer = new SearchResult();

            if (CommandKey.Any(x => context.Message.StartsWith(x)))
            {
                bool EnableFlag = false;
                if (context.State != null && context.GetState <bool>(SettingKey))
                {
                    EnableFlag = true;
                }
                else if (context.MessageType == "message")
                {
                    EnableFlag = true;
                }
                if (EnableFlag)
                {
                    string[] tmp = context.Message.Trim().Split(' ');

                    if (tmp.Length == 2)
                    {
                        var keyword = tmp[1];
                        // anwer = GetWiki(tmp[1], "");
                        switch (tmp[0])
                        {
                        case "互动百科":
                        case "互动":
                        {
                            string url  = "http://www.baike.com/wiki/" + keyword;
                            string temp = QQClient.Get(url);
                            if (temp.Contains("尚未收录"))
                            {
                                anwer.Answer = "没有找到这个词条哦~";
                                break;
                            }
                            temp = temp.Replace("<meta content=\"", "&");
                            temp = temp.Replace("\" name=\"description\">", "&");
                            string[] result = temp.Split('&');
                            if (!result[1].Equals(""))
                            {
                                anwer.Answer = result[1];
                                anwer.Url    = "http://www.baike.com/wiki/" + HttpUtility.UrlEncode(keyword);
                            }
                            break;
                        }

                        case "维基百科":
                        case "维基":
                        {
                            string                 url    = "https://zh.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&exsentences=2&exintro=&explaintext=&exsectionformat=plain&exvariant=zh&titles=" + keyword;
                            string                 temp   = QQClient.Get(url);
                            JsonWikipediaModel     temp1  = (JsonWikipediaModel)JsonConvert.DeserializeObject(temp, typeof(JsonWikipediaModel));
                            string[]               result = temp1.query.pages.ToString().Split("{}".ToCharArray());
                            JsonWikipediaPageModel pages  = (JsonWikipediaPageModel)JsonConvert.DeserializeObject("{" + tmp[2] + "}", typeof(JsonWikipediaPageModel));

                            if (pages.extract != null)
                            {
                                anwer.Answer = pages.extract;
                                anwer.Url    = "https://zh.wikipedia.org/wiki/" + HttpUtility.UrlEncode(keyword);
                            }
                            else
                            {
                                anwer.Answer = "没有找到这个Wiki哦~";
                            }

                            break;
                        }

                        case "百度百科":
                        case "百科":
                        default:
                        {
                            string url  = "http://wapbaike.baidu.com/item/" + keyword;
                            string temp = QQClient.Get(url);

                            if (temp.Contains("您所访问的页面不存在"))
                            {
                                anwer.Answer = "没有找到这个词条哦~";
                            }
                            if (temp.Contains("百科名片"))
                            {
                                temp = temp.Replace("&quot;", "");
                                temp = temp.Replace("&", "");
                                temp = temp.Replace("百科名片", "&");
                                string[] result = temp.Split('&');

                                temp   = result[1];
                                temp   = temp.Replace("<p>", "&");
                                temp   = temp.Replace("</p>", "&");
                                result = temp.Split('&');

                                temp = result[1].Replace("</a>", "");
                                temp = temp.Replace("<b>", "");
                                temp = temp.Replace("</b>", "");
                                temp = temp.Replace("<i>", "");
                                temp = temp.Replace("</i>", "");

                                temp   = temp.Replace("<a", "&");
                                temp   = temp.Replace("\">", "&");
                                result = temp.Split('&');

                                temp = "";
                                for (int i = 0; i < tmp.Length; i += 2)
                                {
                                    if ((!tmp[i].Contains("card-info")) && (!tmp[i].Contains("div class")))
                                    {
                                        temp += tmp[i];
                                    }
                                }
                                if (!temp.Equals(""))
                                {
                                    anwer.Answer = temp;
                                    anwer.Url    = "http://wapbaike.baidu.com/item/" + HttpUtility.UrlEncode(keyword);
                                }
                                else
                                {
                                    anwer.Answer = "词条 " + keyword + " 请查看http://wapbaike.baidu.com/item/" + HttpUtility.UrlEncode(keyword);
                                }
                            }
                            else
                            {
                                anwer.Answer = "没有找到这个词条哦~";
                            }
                            break;
                        }
                        }
                    }
                    else
                    {
                        context.Alerts.AddRange(Example());
                    }
                    if (!string.IsNullOrEmpty(anwer.Answer))
                    {
                        if (anwer.Answer.Length + anwer.Url.Length >= 400)
                        {
                            context.Answers.Add(anwer.Answer.Substring(0, 400 - anwer.Url.Length - 6) + "..." + anwer.Url);
                        }
                        else
                        {
                            context.Answers.Add(anwer.Answer + anwer.Url);
                        }
                        // context.Answers.Add(anwer);
                        var newlog = new AutoAnswerMessageLog();
                        newlog.FromUin     = context.SendToId;
                        newlog.ToUin       = context.FromUin;
                        newlog.MessageType = "wiki";
                        newlog.P1          = tmp[1];
                        newlog.Data        = anwer.Answer + anwer.Url;
                        OrmManager.Insert(newlog);
                    }
                }
            }
        }
Пример #30
0
 internal void SetManyToOneEntity()
 {
     ManyToOne.Entity = OrmManager.GetEntity(PropertyInfo.PropertyType);
 }