コード例 #1
0
        private static void recomputeYesterday(FileAssetType file_type)
        {
            var label_id = (file_type == FileAssetType.image) ? Settings.Default.LabelPhotoYesterday : Settings.Default.LabelVideoYesterday;

            var yes_start = DateTime.Now.AddDays(-1.0).TrimToDay();
            var yes_end   = DateTime.Now.TrimToDay();


            using (var db = new MyDbContext())
            {
                var actual = (from f in db.Object.Files
                              where f.event_time >= yes_start && f.event_time < yes_end && f.type == (int)file_type
                              select f.file_id).Union(
                    from f in db.Object.PendingFiles
                    where f.event_time >= yes_start && f.event_time < yes_end && f.type == (int)file_type
                    select f.file_id
                    ).ToList();

                var current = (from f in db.Object.LabelFiles
                               where f.label_id == label_id
                               select f).ToList();

                var areCurrentAndActualIdentical = actual.Count == current.Count && actual.TrueForAll(x => current.Where(y => y.file_id == x).Any());

                if (!areCurrentAndActualIdentical)
                {
                    foreach (var cur in current)
                    {
                        db.Object.LabelFiles.Remove(cur);
                    }

                    foreach (var act in actual)
                    {
                        db.Object.LabelFiles.Add(new LabeledFile {
                            file_id = act, label_id = label_id
                        });
                    }

                    var lbRecord = (from lb in db.Object.Labels
                                    where lb.label_id == label_id
                                    select lb).First();
                    lbRecord.seq = SeqNum.GetNextSeq();

                    db.Object.SaveChanges();
                }
            }
        }
コード例 #2
0
        private static void updateLabelSeq(SQLiteConnection db, IEnumerable <Guid> labels)
        {
            using (var cmd = db.CreateCommand())
            {
                cmd.CommandText = "update [labels] set seq = @seq where label_id = @label_id";
                cmd.Prepare();

                foreach (var label in labels)
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(new SQLiteParameter("@seq", SeqNum.GetNextSeq()));
                    cmd.Parameters.Add(new SQLiteParameter("@label_id", label));

                    cmd.ExecuteNonQuery();
                }
            }
        }
コード例 #3
0
        private static void copyToFilesTable(List <FileData> data, SQLiteConnection db)
        {
            using (var cmd = db.CreateCommand())
            {
                cmd.CommandText =
                    "insert into Files (file_id, file_name, file_path, file_size, saved_path, parent_folder, device_id, type, event_time, seq, deleted, thumb_ready, width, height, orientation) " +
                    "select file_id, file_name, file_path, file_size, @saved, @parent, device_id, type, event_time, @seq, deleted, thumb_ready, width, height, orientation from [PendingFiles] " +
                    "where file_id = @fid";
                cmd.Prepare();

                foreach (var file in data)
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(new SQLiteParameter("@saved", file.saved_path));
                    cmd.Parameters.Add(new SQLiteParameter("@parent", file.parent_folder));
                    cmd.Parameters.Add(new SQLiteParameter("@fid", file.file_id));
                    cmd.Parameters.Add(new SQLiteParameter("@seq", SeqNum.GetNextSeq()));
                    cmd.ExecuteNonQuery();
                }
            }
        }
コード例 #4
0
        static void Main()
        {
            if (Environment.GetCommandLineArgs().Contains("--close-all-processes"))
            {
                forceCloseAllProcesses();
                return;
            }

            Boolean bCreatedNew;

            var cultureName = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\BunnyHome", "Culture", "");

            if (!string.IsNullOrEmpty(cultureName))
            {
                var cultureInfo   = new CultureInfo(cultureName);
                var currentThread = Thread.CurrentThread;

                currentThread.CurrentCulture   = cultureInfo;
                currentThread.CurrentUICulture = cultureInfo;
            }

            m_InstanceMutex = new System.Threading.Mutex(false, Application.ProductName + Environment.UserName, out bCreatedNew);

            if (!bCreatedNew)
            {
                invokeAnotherRunningProcess();
                return;
            }

            Application.EnableVisualStyles();
            Application.ApplicationExit += new EventHandler(Application_ApplicationExit);

            AppDomain.CurrentDomain.UnhandledException += NBug.Handler.UnhandledException;
            Application.ThreadException += NBug.Handler.ThreadException;

            Log4netConfigure.InitLog4net();

            log4net.LogManager.GetLogger("main").Warn("==== program started ====");

            if (!Settings.Default.IsUpgraded)
            {
                Settings.Default.Upgrade();
                Settings.Default.IsUpgraded = true;
                Settings.Default.Save();
            }

            if (string.IsNullOrEmpty(Settings.Default.ServerId))
            {
                Settings.Default.ServerId             = generateSameServerIdForSameUserOnSamePC();
                Settings.Default.SingleFolderLocation = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\BunnyHome", "ResourceFolder", "");
                Settings.Default.OrganizeMethod       = (int)OrganizeMethod.YearMonth;
                Settings.Default.LocationType         = (int)LocationType.SingleFolder;
                Settings.Default.Save();

                if (!Directory.Exists(Settings.Default.SingleFolderLocation))
                {
                    Directory.CreateDirectory(Settings.Default.SingleFolderLocation);
                }
            }
            try
            {
                NginxUtility.Instance.PrepareNginxConfig(12888, Settings.Default.SingleFolderLocation);
            }
            catch (Exception err)
            {
                log4net.LogManager.GetLogger("main").Warn("Unable to write nginx config", err);
            }

            if (string.IsNullOrEmpty(Settings.Default.LibraryName))
            {
                Settings.Default.LibraryName = string.Format(Resources.DefLibraryName, Environment.UserName);
                Settings.Default.Save();
            }

            SynchronizationContextHelper.SetMainSyncContext();
            DBInitializer.InitialzeDatabaseSchema();
            SeqNum.InitFromDB();

            if (HomeSharing.Enabled)
            {
                NginxUtility.Instance.Start();
            }

            server = new StationServer();
            server.Start();

            BonjourServiceRegistrator.Instance.Register(false);

            if (!Environment.GetCommandLineArgs().Contains("--minimized"))
            {
                ImportUIPresenter.Instance.StartViewer();
            }

            Application.Run();
        }