Пример #1
0
        /// <summary>
        /// Copy recorded item in list
        /// </summary>
        /// <param name="recordId"></param>
        /// <returns></returns>
        public static bool CopyItem(long recordId, bool source)
        {
            ClipboardRecord item = null;

            if (source)
            {
                item = ClipboardRecordsL.Single(i => i.RowId == recordId);
            }
            else
            {
                item = ClipboardRecordHistoryL.Single(i => i.RowId == recordId);
            }

            if (item != null)
            {
                if (item.ContentType == ContentType.Text)
                {
                    System.Windows.Clipboard.SetText(item.ContentText);
                }
                else if (item.ContentType == ContentType.Image)
                {
                    BitmapSource bitmapSource = new BitmapImage(new Uri(item.ContentImage));

                    System.Windows.Clipboard.SetImage(bitmapSource);
                }
            }

            return(true);
        }
Пример #2
0
        public static void GetHistory(string sessionKey)
        {
            var thread = new Thread(() =>
            {
                if (ClipboardRecordHistoryL.Count > 0)
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                    {
                        ClipboardRecordHistoryL.Clear();
                    }));
                }

                using (var conn = new SQLiteConnection(Connection.ConnString))
                {
                    conn.Open();

                    using (var comm = new SQLiteCommand(conn))
                    {
                        comm.CommandText = "SELECT rowid, * FROM clipboard WHERE session_key=?";
                        comm.Parameters.AddWithValue("@0", sessionKey);

                        using (var reader = comm.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                int i = 1;

                                while (reader.Read())
                                {
                                    var item = new ClipboardRecord()
                                    {
                                        RowId              = Convert.ToInt64(reader["rowid"].ToString()),
                                        OrderNumber        = i++,
                                        DateTime           = reader["date_time"].ToString(),
                                        Size               = reader["size"].ToString(),
                                        ContentType        = (ContentType)Enum.Parse(typeof(ContentType), reader["content_type"].ToString()),
                                        ContentText        = reader["content_text"].ToString(),
                                        ContentTextPreview = reader["content_text"].ToString().Length >= 150 ? reader["content_text"].ToString().Substring(0, 150) + "..." : reader["content_text"].ToString()
                                    };

                                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                                    {
                                        ClipboardRecordHistoryL.Add(item);
                                    }));
                                }
                            }
                        }
                    }

                    conn.Close();
                }
            })
            {
                IsBackground = true
            };

            thread.Start();
        }
Пример #3
0
        /// <summary>
        /// Save as item an file
        /// </summary>
        /// <param name="recordId"></param>
        /// <returns></returns>
        public static bool SaveAsItem(long recordId, bool source)
        {
            ClipboardRecord item = null;

            if (source)
            {
                item = ClipboardRecordsL.Single(i => i.RowId == recordId);
            }
            else
            {
                item = ClipboardRecordHistoryL.Single(i => i.RowId == recordId);
            }

            if (item != null)
            {
                if (item.ContentType == ContentType.Text)
                {
                    SaveFileDialog opfiledialog = new SaveFileDialog
                    {
                        FileName     = $"Copied Text {recordId}.txt",
                        DefaultExt   = ".txt",
                        Filter       = "TXT Files (*.txt)|*.txt|JSON Files (*.json)|*.json",
                        AddExtension = true,
                        Title        = "Metni tekrar katdedeceğiniz konumu seçin"
                    };
                    bool?result = opfiledialog.ShowDialog();

                    if (result == true)
                    {
                        File.WriteAllText(opfiledialog.FileName, item.ContentText);
                    }
                }
                else if (item.ContentType == ContentType.Image)
                {
                    SaveFileDialog opfiledialog = new SaveFileDialog
                    {
                        FileName     = $"Copied Image {recordId}",
                        DefaultExt   = ".jpg",
                        Filter       = "JPG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png",
                        AddExtension = true,
                        Title        = "Görseli tekrar katdedeceğiniz konumu seçin"
                    };
                    bool?result = opfiledialog.ShowDialog();

                    if (result == true)
                    {
                        BitmapImageExtensions.SaveBitmapSource2File(new BitmapImage(new Uri(item.ContentImage)), opfiledialog.FileName);
                    }
                }
            }

            return(true);
        }
Пример #4
0
        /// <summary>
        /// When clipboard image changed
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="bitmapsource">return value</param>
        public static void ClipboardImageChanged(object sender, BitmapSource bitmapsource)
        {
            if (bitmapsource == null)
            {
                return;
            }

            if (action == "Mouse L. Click" && ViewModel.ClipboardManager.Clipboard.MouseRLImage)
            {
                string img = CreateSaveLocation();

                var thread = new Thread(async() =>
                {
                    await Task.Factory.StartNew(() =>
                    {
                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                        {
                            using (var fileStream = new FileStream(img, FileMode.Create))
                            {
                                BitmapEncoder encoder = new PngBitmapEncoder();
                                encoder.Frames.Add(BitmapFrame.Create(bitmapsource));
                                encoder.Save(fileStream);
                            }
                        }));
                    }).ContinueWith((T) =>
                    {
                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                        {
                            var item = new ClipboardRecord()
                            {
                                OrderNumber            = ClipboardRecordsL.Count + 1,
                                DateTime               = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                                Size                   = (new FileInfo(img).Length / 1024).ToString(),
                                ContentImageResolution = bitmapsource.Width + " x " + bitmapsource.Height,
                                Action                 = action ?? "Unknown Action",
                                ContentType            = ContentType.Image,
                                ContentImage           = img,
                                ContentTextPreview     = img
                            };

                            item.RowId = SaveContent(item);
                            ClipboardRecordsL.Add(item);
                        }));
                    });
                })
                {
                    IsBackground = true
                };
                thread.Start();
            }
        }
Пример #5
0
        public static long SaveContent(ClipboardRecord cliprec)
        {
            long row = 0;

            var thread = new Thread(() =>
            {
                using (SQLiteConnection conn = new SQLiteConnection(Connection.ConnString))
                {
                    conn.Open();

                    using (SQLiteCommand comm = new SQLiteCommand(conn))
                    {
                        comm.CommandText = "INSERT INTO clipboard (date_time, size, content_type, content_text, content_image_path, resolution, session_key) values(?,?,?,?,?,?,?)";
                        comm.Parameters.AddWithValue("@0", cliprec.DateTime);
                        comm.Parameters.AddWithValue("@1", cliprec.Size);
                        comm.Parameters.AddWithValue("@2", cliprec.ContentType.ToString());
                        comm.Parameters.AddWithValue("@3", cliprec.ContentText);
                        comm.Parameters.AddWithValue("@4", cliprec.ContentImage);
                        comm.Parameters.AddWithValue("@5", cliprec.ContentImageResolution);
                        comm.Parameters.AddWithValue("@6", SessionKey);

                        var rows = comm.ExecuteNonQuery();
                        row      = conn.LastInsertRowId;
                    }

                    conn.Close();
                }
            })
            {
                IsBackground = true
            };

            thread.Start();

            return(row);
        }
Пример #6
0
        /// <summary>
        /// When clipboard text changed
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="text">return value</param>
        public static void ClipboardTextChanged(object sender, string text)
        {
            var clippedText = text.Trim();

            if (string.IsNullOrWhiteSpace(clippedText))
            {
                return;
            }

            if (action == "CTRL + C" && clippedText != _tempstringC && ViewModel.ClipboardManager.Clipboard.KeyC)
            {
                var thread = new Thread(() =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                    {
                        var item = new ClipboardRecord()
                        {
                            OrderNumber        = ClipboardRecordsL.Count + 1,
                            DateTime           = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                            Size               = Encoding.Unicode.GetByteCount(clippedText).ToString(),
                            Action             = action ?? "Unknown Action",
                            ContentType        = ContentType.Text,
                            ContentText        = clippedText,
                            ContentTextPreview = clippedText.Length >= 150
                                ? clippedText.Substring(0, 150) + "..."
                                : clippedText
                        };

                        item.RowId = SaveContent(item);
                        ClipboardRecordsL.Add(item);
                    }));
                })
                {
                    IsBackground = true
                };
                thread.Start();

                _tempstringC = clippedText;
            }

            else if (action == "CTRL + X" && clippedText != _tempstringX && ViewModel.ClipboardManager.Clipboard.KeyC)
            {
                var thread = new Thread(() =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                    {
                        var item = new ClipboardRecord()
                        {
                            OrderNumber        = ClipboardRecordsL.Count + 1,
                            DateTime           = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                            Size               = Encoding.Unicode.GetByteCount(clippedText).ToString(),
                            Action             = action ?? "Unknown Action",
                            ContentType        = ContentType.Text,
                            ContentText        = clippedText,
                            ContentTextPreview = clippedText.Length >= 150
                                ? clippedText.Substring(0, 150) + "..."
                                : clippedText
                        };

                        item.RowId = SaveContent(item);
                        ClipboardRecordsL.Add(item);
                    }));
                })
                {
                    IsBackground = true
                };
                thread.Start();

                _tempstringC = clippedText;
            }

            else if (action == "Mouse L. Click" && ViewModel.ClipboardManager.Clipboard.MouseRLText)
            {
                var thread = new Thread(() =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                    {
                        var item = new ClipboardRecord()
                        {
                            OrderNumber        = ClipboardRecordsL.Count + 1,
                            DateTime           = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                            Size               = Encoding.Unicode.GetByteCount(clippedText).ToString(),
                            Action             = action ?? "Unknown Action",
                            ContentType        = ContentType.Text,
                            ContentText        = clippedText,
                            ContentTextPreview = clippedText.Length >= 150
                                ? clippedText.Substring(0, 150) + "..."
                                : clippedText
                        };

                        item.RowId = SaveContent(item);
                        ClipboardRecordsL.Add(item);
                    }));
                })
                {
                    IsBackground = true
                };
                thread.Start();

                _tempstringC = clippedText;
                _tempstringX = clippedText;
                _tempstringV = clippedText;
            }
        }
Пример #7
0
        /// <summary>
        /// Keyboard key down event
        /// </summary>
        private static async void keyboardHook_KeyDown(KeyboardHook.VKeys key)
        {
            if (key == KeyboardHook.VKeys.LCONTROL)
            {
                LCTRL = true;
            }

            if (ViewModel.ClipboardManager.Clipboard.KeyX && LCTRL && key == KeyboardHook.VKeys.KEY_X)
            {
                action = "CTRL + X";

                string stringX =
                    ClipboardHelper.GetContentFromClipboardWithRetry(Helpers.ContentType
                                                                     .Text) as string;

                if (!(stringX != _tempstringX & stringX != null))
                {
                    return;
                }
                await Task.Factory.StartNew(() =>
                {
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                    {
                        var item = new ClipboardRecord()
                        {
                            OrderNumber        = ClipboardRecordsL.Count + 1,
                            DateTime           = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                            Size               = Encoding.Unicode.GetByteCount(stringX).ToString(),
                            Action             = action ?? "Unknown Action",
                            ContentType        = ContentType.Text,
                            ContentText        = stringX,
                            ContentTextPreview = stringX.Length >= 150 ? stringX.Substring(0, 150) + "..." : stringX
                        };

                        item.RowId = SaveContent(item);
                        ClipboardRecordsL.Add(item);
                    }));
                });

                _tempstringX = stringX;
            }

            else if (ViewModel.ClipboardManager.Clipboard.KeyC && LCTRL && key == KeyboardHook.VKeys.KEY_C)
            {
                action = "CTRL + C";
            }

            else if (ViewModel.ClipboardManager.Clipboard.KeyV && LCTRL && key == KeyboardHook.VKeys.KEY_V)
            {
                action = "CTRL + V";

                string stringV =
                    ClipboardHelper.GetContentFromClipboardWithRetry(Helpers.ContentType
                                                                     .Text) as string;

                if (stringV != _tempstringV & stringV != null)
                {
                    Debug.WriteLine(action);
                    await Task.Factory.StartNew(() =>
                    {
                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                        {
                            var item = new ClipboardRecord()
                            {
                                OrderNumber        = ClipboardRecordsL.Count + 1,
                                DateTime           = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                                Size               = Encoding.Unicode.GetByteCount(stringV).ToString(),
                                Action             = action ?? "Unknown Action",
                                ContentType        = ContentType.Text,
                                ContentText        = stringV,
                                ContentTextPreview = stringV.Length >= 150 ? stringV.Substring(0, 150) + "..." : stringV
                            };

                            item.RowId = SaveContent(item);
                            ClipboardRecordsL.Add(item);
                        }));
                    });

                    _tempstringV = stringV;
                }
            }

            else if (ViewModel.ClipboardManager.Clipboard.KeyLShift && LCTRL && key == KeyboardHook.VKeys.LSHIFT)
            {
                if (ClipboardRecordsL.Any())
                {
                    var midlist = ClipboardRecordsL.Where(w => w.ContentType == ContentType.Text);

                    if (midlist.Any())
                    {
                        int    outputc = 0;
                        string output  = string.Empty;
                        foreach (var item in midlist)
                        {
                            if (item.ContentText.Length > 0)
                            {
                                output += item.ContentText + Environment.NewLine;
                                outputc++;
                            }
                        }
                        System.Windows.Clipboard.SetText(output);

                        MessageBox.Show(outputc + " Adet içerik liste halinede panoya kopyalandı.");
                    }
                    else
                    {
                        MessageBox.Show("Listelenecek türden veri bulunamadı.");
                    }
                }
                else
                {
                    MessageBox.Show("Listede hiç öğe yok.");
                }
            }
        }