示例#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()));
                }
            }
        }
示例#2
0
        public ucMain(frmMain f)
        {
            main = f;

            InitializeComponent();

            Synchronizer = new FileSynchronization(ref frmParent.FocasaMonitoredFolders, new string[] { ".jpg", ".jpeg", ".bmp", ".tif", ".tiff", ".png" });

            using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
            {
                LoadFolders();
                LoadItems();
            }
        }
示例#3
0
        public ucMain(frmMain f)
        {
            main = f;

            InitializeComponent();

            Synchronizer = new FileSynchronization(ref frmParent.FocasaMonitoredFolders, new string[] { ".jpg", ".jpeg", ".bmp", ".tif", ".tiff", ".png" });

            using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
            {
                LoadFolders();
                LoadItems();
            }
        }
示例#4
0
 private static int AnalyseFolder(string folder)
 {
     int i = 0;
     string[] files = Directory.GetFiles(folder);
     using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
     {
         foreach (string file in files)
         {
             i += AnalyseFile(file, db);
         }
     }
     string[] dirs = Directory.GetDirectories(folder);
     foreach (String dir in dirs)
         i += AnalyseFolder(dir);
     return i;
 }
示例#5
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()));

                }
            }
        }
示例#6
0
        private void optionsFolderManagement_Click(object sender, EventArgs e)
        {
            frmFolderManagement f   = new frmFolderManagement();
            DialogResult        drs = f.ShowDialog();

            if (drs == System.Windows.Forms.DialogResult.OK)
            {
                bool      needSync  = false;
                DataTable dtChanges = FocasaMonitoredFolders.GetChanges();
                if (dtChanges == null)
                {
                    return;
                }
                DataTable dt = dtChanges.Copy();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
                        {
                            Dictionary <string, string> dic = new Dictionary <string, string>();

                            foreach (DataColumn dc in dt.Columns)
                            {
                                dic.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                            }
                            db.Insert("focasaMonitoredFolders", dic);
                            needSync = true;
                        }
                    }
                }

                if (needSync)
                {
                    Synchronizer = new FileSynchronization(ref FocasaMonitoredFolders, new string[] { ".jpg", ".jpeg", ".tif", ".tiff", ".bmp", ".png" });
                    FileSynchronization.OnSyncStateUpdate += FileSynchronization_OnSyncStateUpdate;
                    Task <int> t = FileSynchronization.Sync(dt);
                    int        i = t.Result;

                    mainDialog = new ucMain(this);
                    flpMain.Controls.Clear();
                    flpMain.Controls.Add(mainDialog);
                }
            }
        }
示例#7
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);
            }
        }
示例#8
0
        private static int AnalyseFolder(string folder)
        {
            int i = 0;

            string[] files = Directory.GetFiles(folder);
            using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
            {
                foreach (string file in files)
                {
                    i += AnalyseFile(file, db);
                }
            }
            string[] dirs = Directory.GetDirectories(folder);
            foreach (String dir in dirs)
            {
                i += AnalyseFolder(dir);
            }
            return(i);
        }
示例#9
0
        private void optionsFolderManagement_Click(object sender, EventArgs e)
        {
            frmFolderManagement f = new frmFolderManagement();
            DialogResult drs = f.ShowDialog();
            if (drs == System.Windows.Forms.DialogResult.OK)
            {
                bool needSync = false;
                DataTable dtChanges = FocasaMonitoredFolders.GetChanges();
                if (dtChanges == null)
                    return;
                DataTable dt = dtChanges.Copy();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        using (Data.SQLiteDatabase db = new Data.SQLiteDatabase(System.AppDomain.CurrentDomain.BaseDirectory, "Focasa.db"))
                        {
                            Dictionary<string, string> dic = new Dictionary<string, string>();

                            foreach (DataColumn dc in dt.Columns)
                            {
                                dic.Add(dc.ColumnName, dr[dc.ColumnName].ToString());
                            }
                            db.Insert("focasaMonitoredFolders", dic);
                            needSync = true;
                        }
                    }
                }

                if (needSync)
                {
                    Synchronizer = new FileSynchronization(ref FocasaMonitoredFolders, new string[]{".jpg",".jpeg",".tif",".tiff",".bmp",".png"});
                    FileSynchronization.OnSyncStateUpdate+=FileSynchronization_OnSyncStateUpdate;
                    Task<int> t = FileSynchronization.Sync(dt);
                    int i = t.Result;

                    mainDialog = new ucMain(this);
                    flpMain.Controls.Clear();
                    flpMain.Controls.Add(mainDialog);
                }
            }
        }
示例#10
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();
            }
        }
示例#11
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();
            }
        }