예제 #1
0
        void Load()
        {
            string filePath = ConfigService.Instance.LocalDataPath;

            if (!System.IO.Path.GetDirectoryName(filePath).IsExistDirectory())
            {
                System.IO.Path.GetDirectoryName(filePath).CreateDir();
            }

            if (!File.Exists(filePath))
            {
                return;
            }

            string result = File.ReadAllText(filePath);

            var loadResult = result.SerializeDeJson <List <NotePadItem> >();

            if (loadResult == null)
            {
                return;
            }

            foreach (var item in loadResult)
            {
                this.Collection.Add(NotePadItemNotifyClass.CreateFrom(item));
            }
        }
        public static NotePadItemNotifyClass CreateFrom(NotePadItem model)
        {
            NotePadItemNotifyClass vm = new NotePadItemNotifyClass();

            vm.CopyFromObj(model);

            return(vm);
        }
예제 #3
0
        public void RelayMethod(object obj)
        {
            string command = obj.ToString();

            //  Do:应用
            if (command == "Init")
            {
                ClipBoardRegisterService.Instance.ClipBoardChanged += () =>
                {
                    if (!System.Windows.Clipboard.ContainsText())
                    {
                        return;
                    }

                    string text = string.Empty;

                    try
                    {
                        // HTodo  :复制的文件路径
                        text = System.Windows.Clipboard.GetText();
                    }
                    catch
                    {
                    }


                    if (string.IsNullOrEmpty(text))
                    {
                        return;
                    }

                    if (this.Collection.Count > 0)
                    {
                        NotePadItemNotifyClass last = this.Collection.First();

                        if (last.Content != text)
                        {
                            NotePadItemNotifyClass f = new NotePadItemNotifyClass();
                            f.Content = text;
                            f.Date    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                            this.Collection.Insert(0, f);
                        }
                    }
                    else
                    {
                        NotePadItemNotifyClass f = new NotePadItemNotifyClass();
                        f.Content = text;
                        f.Date    = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        this.Collection.Insert(0, f);
                    }
                };

                this.Load();

                //  ToDo:定时保存
                System.Timers.Timer time = new System.Timers.Timer();

                time.Interval = 10000;

                time.Elapsed += (l, k) =>
                {
                    this.Save();
                };
                time.Start();
            }

            else if (command == "ButtonCommand_Save")
            {
                this.Save();
            }
        }