Ejemplo n.º 1
0
        private void LoadFolders(string folder)
        {
            using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
            {
                frmParent.FocasaMonitoredFolders = db.GetDataTable("SELECT * FROM focasaMonitoredFolders");
            }

            foreach (DataRow drow in frmParent.FocasaMonitoredFolders.Rows)
            {
                if (drow.RowState != DataRowState.Deleted)
                {
                    if (folder != null && folder == drow["path"].ToString())
                    {
                        continue;
                    }

                    string[] pathParts = drow["path"].ToString().Split('\\');
                    TreeNode parent    = null;
                    foreach (string pathPart in pathParts)
                    {
                        TreeNode[] foundNodes;
                        if (parent == null)
                        {
                            foundNodes = tvFolders.Nodes.Find(pathPart, false);
                        }
                        else
                        {
                            foundNodes = parent.Nodes.Find(pathPart, false);
                        }

                        if (foundNodes.Length == 1)
                        {
                            parent = foundNodes[0];
                        }
                        else if (foundNodes.Length == 0)
                        {
                            TreeNode node = new TreeNode(pathPart);
                            if (parent == null)
                            {
                                tvFolders.Nodes.Add(node);
                            }
                            else
                            {
                                parent.Nodes.Add(node);
                            }
                            parent = node;
                        }
                        else
                        {
                            throw new Exception("Too many nodes found");
                        }
                    }
                    foreach (TreeNode n in tvFolders.Nodes)
                    {
                        n.Expand();
                    }
                    //TreeNode node = new TreeNode(Path.GetFileName(drow["path"].ToString()));
                }
            }
        }
Ejemplo n.º 2
0
        private void LoadFolders(string folder)
        {
            using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
            {
                frmParent.FocasaMonitoredFolders = db.GetDataTable("SELECT * FROM focasaMonitoredFolders");
            }

            foreach (DataRow drow in frmParent.FocasaMonitoredFolders.Rows)
            {
                if (drow.RowState != DataRowState.Deleted)
                {
                    if (folder != null && folder == drow["path"].ToString()) continue;

                    string[] pathParts = drow["path"].ToString().Split('\\');
                    TreeNode parent = null;
                    foreach (string pathPart in pathParts)
                    {
                        TreeNode[] foundNodes;
                        if (parent == null)
                            foundNodes = tvFolders.Nodes.Find(pathPart, false);
                        else
                            foundNodes = parent.Nodes.Find(pathPart, false);

                        if (foundNodes.Length == 1)
                            parent = foundNodes[0];
                        else if (foundNodes.Length == 0)
                        {
                            TreeNode node = new TreeNode(pathPart);
                            if (parent == null)
                                tvFolders.Nodes.Add(node);
                            else
                                parent.Nodes.Add(node);
                            parent = node;

                        }
                        else
                            throw new Exception("Too many nodes found");
                    }
                    foreach (TreeNode n in tvFolders.Nodes)
                    {
                        n.Expand();
                    }
                    //TreeNode node = new TreeNode(Path.GetFileName(drow["path"].ToString()));

                }
            }
        }
Ejemplo n.º 3
0
        private static int AnalyseFile(string file, Data.SQLiteDatabase db)
        {
            if (allowedFileExtensions.Contains <string>(Path.GetExtension(file)))
            {
                Image  image = Image.FromFile(file);
                Image  thumb = image.GetThumbnailImage(120, 120, () => false, IntPtr.Zero);
                Bitmap bmp   = new Bitmap(thumb);

                //System.IO.MemoryStream ms = new System.IO.MemoryStream();
                //bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                //byte[] byteImage = ms.ToArray();
                //string SigBase64= Convert.ToBase64String(byteImage); //Get Base64

                string SigBase64 = ImageToBase64(bmp, System.Drawing.Imaging.ImageFormat.Jpeg);

                if (db.GetDataTable("SELECT * FROM focasaItems WHERE path='" + Path.GetDirectoryName(file) + "' AND name='" + Path.GetFileName(file) + "'").Rows.Count == 0)
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    dic.Add("guid", Guid.NewGuid().ToString());
                    dic.Add("path", Path.GetDirectoryName(file));
                    dic.Add("name", Path.GetFileName(file));
                    dic.Add("thumbnail", SigBase64);
                    dic.Add("exif", "");
                    dic.Add("importedon", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    dic.Add("lastmodified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                    bool result = db.Insert("focasaItems", dic);
                    if (!result)
                    {
                        throw new Exception("Could not insert analyzed file " + file + " in db " + db.ConnectionString);
                    }
                }


                RaiseSyncStateUpdate(Path.GetFileName(file), Path.GetFileName(Path.GetDirectoryName(file)), bmp);
                return(1);
            }
            else
            {
                //ignore
                return(0);
            }
        }
Ejemplo n.º 4
0
        private void LoadItems()
        {
            using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
            {
                frmParent.FocasaItems = db.GetDataTable("SELECT * FROM focasaItems");
            }

            DataView view = new DataView(frmParent.FocasaItems);

            view.Sort = "path asc";
            DataTable distinctValues = view.ToTable(true, "path");
            string    currentFolder  = null;

            foreach (DataRow drow in distinctValues.Rows)
            {
                if (drow.RowState != DataRowState.Deleted)
                {
                    ucFolderRepresentation ucFolder = null;
                    if (currentFolder == null || currentFolder != drow["path"].ToString())
                    {
                        ucFolder = new ucFolderRepresentation(main, drow["path"].ToString());
                        flpPictures.Controls.Add(ucFolder);
                        currentFolder = drow["path"].ToString();
                    }

                    DataRow[] items = frmParent.FocasaItems.Select("path='" + drow["path"].ToString() + "'");
                    foreach (DataRow item in items)
                    {
                        ucPictureRepresentation ucPicture = new ucPictureRepresentation(main, item["path"].ToString(), item["name"].ToString(), Base64ToImage(item["thumbnail"].ToString()), item["exif"].ToString());
                        ucFolder.Images.Controls.Add(ucPicture);
                    }
                }
            }

            foreach (TreeNode n in tvFolders.Nodes)
            {
                n.Expand();
            }
        }
Ejemplo n.º 5
0
        private void LoadItems()
        {
            using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
            {
                frmParent.FocasaItems = db.GetDataTable("SELECT * FROM focasaItems");
            }

            DataView view = new DataView(frmParent.FocasaItems);
            view.Sort = "path asc";
            DataTable distinctValues = view.ToTable(true, "path");
            string currentFolder = null;

            foreach (DataRow drow in distinctValues.Rows)
            {
                if (drow.RowState != DataRowState.Deleted)
                {
                    ucFolderRepresentation ucFolder = null;
                    if (currentFolder == null || currentFolder != drow["path"].ToString())
                    {
                        ucFolder = new ucFolderRepresentation(main, drow["path"].ToString());
                        flpPictures.Controls.Add(ucFolder);
                        currentFolder = drow["path"].ToString();
                    }

                    DataRow[] items = frmParent.FocasaItems.Select("path='" + drow["path"].ToString() + "'");
                    foreach (DataRow item in items)
                    {
                        ucPictureRepresentation ucPicture = new ucPictureRepresentation(main, item["path"].ToString(), item["name"].ToString(), Base64ToImage(item["thumbnail"].ToString()), item["exif"].ToString());
                        ucFolder.Images.Controls.Add(ucPicture);
                    }

                }
            }

            foreach (TreeNode n in tvFolders.Nodes)
            {
                n.Expand();
            }
        }