async Task reload()
        {
            _db         = A0DbContext.Create();
            tbComp.Text = VerHelper.CurVerStr(A0DbContext.SolutionCfg);

            try
            {
                await _db.TxMoneySrcs.LoadAsync();

                await _db.BalAmtHists.LoadAsync();

                await _db.TxCoreV2.LoadAsync(); //full history is here: await _db.Vw_TxCore.LoadAsync(); - is it worth it/useful

                var groupByMnySrc = _db.TxCoreV2.Local.GroupBy(c => new { c.TxMoneySrcId }).Select(g => new { g.Key.TxMoneySrcId, Count = g.Count(), LastTx = g.Max(r => r.TxDate) }).ToList();

                //var usedMnySrcList = _db.TxCoreV2.Local.Select(r => r.TxMoneySrcId).Distinct().ToList();        //lbMnySrc_Flas.ItemsSource = _db.TxMoneySrcs.Local.Where(r => usedMnySrcList.Contains(r.Id)).OrderBy(r => r.Fla);
                lbMnySrc_Flas.ItemsSource = _db.TxMoneySrcs.Local.
                                            Join(groupByMnySrc, s => s.Id, c => c.TxMoneySrcId, (s, c) => new { s, c }).
                                            Select(r => new Tms(r.s.Id, r.s.Fla, r.s.Name,
                                                                r.s.IniBalance,
                                                                r.c.LastTx,
                                                                $"{r.s.Notes}\r\nCount: \t {r.c.Count}\r\nLast: \t {r.c.LastTx:yyy-MM-dd}"
                                                                ));

                lbMnySrc_Flas.Focus();
            }
            catch (Exception ex) { ex.Log(); }
        }
        void chart1_MouseDown(object s, MouseEventArgs e)
        {
            var htr = chart1.HitTest(e.X, e.Y);

            if (htr.ChartElementType == ChartElementType.DataPoint)
            {
                using (var db = A0DbContext.Create())
                {
                    var st  = DateTime.FromOADate(htr.Series.Points[htr.PointIndex].XValue);
                    var txn = db.TxCoreV2.Where(r => r.TxDate == st).ToList();
                    if (txn == null)
                    {
                        MessageBox.Show(this, "Not good: \r\n\tNo txs for this date found.");
                    }
                    else
                    {
                        //db.Laps.Load();
                        var dlg = new TxnDetailsVw
                        {
                            ChartRef   = chart1,
                            PointIndex = htr.PointIndex,
                            HTR        = htr,
                            Txns       = txn
                        };
                        dlg.Show(); // MessageBox.Show(this, "DataPoint.Dialog popup is not ready\r\n\nSelected Element is: " + result.ChartElementType.ToString());
                    }
                }
            }
            //else if (result.ChartElementType != ChartElementType.Nothing)
            //{
            //	MessageBox.Show(this, "Selected Element is: " + result.ChartElementType.ToString());
            //}
        }
示例#3
0
        static TxMoneySrc getCreateTxMoneySrc(A0DbContext db, out string acntDir, string acntId, string filename)
        {
            var ad          = acntDir = PreSet.GetAcntFolder((acntId ?? "AcntUnknown").Replace(PreSet.AcntIdTAg, "").Trim());
            var txMoneySrcs = db.TxMoneySrcs.FirstOrDefault(r => string.Compare(ad, r.Fla, true) == 0);

            if (txMoneySrcs == null)
            {
                txMoneySrcs = db.TxMoneySrcs.Add(new TxMoneySrc {
                    CreatedAt = _batchTimeNow, Fla = acntDir, Name = acntDir, Notes = $"Auto created from '{filename}'"
                });
                db.SaveChanges();
                new System.Speech.Synthesis.SpeechSynthesizer().Speak($"New account {acntDir} created from the file {filename}.");
            }

            if (txMoneySrcs == null)
            {
                //todo:        new System.Speech.Synthesis.SpeechSynthesizer().SpeakAsync($"Unable to establich source account. Exiting");
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                else
                {
                    throw new NullReferenceException($"Unable to establich source account. Exiting");
                }
            }

            return(txMoneySrcs);
        }
示例#4
0
        void getAddAuditId(string pathRoot, A0DbContext db)
        {
            try
            {
                #region https://www.andrewcbancroft.com/2017/03/27/solving-spatial-types-and-functions-are-not-available-with-entity-framework/
                SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

                //SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
                //To avoid hard - coding the assembly name you can use
                SqlProviderServices.SqlServerTypesAssemblyName = typeof(SqlGeography).Assembly.FullName; // – Samuel Jack Oct 17 '17 at 10:24
                #endregion

                Debug.WriteLine(db.AuditHists.Count());
                _ah = db.AuditHists.FirstOrDefault(r => r.AuditTimeID == _AuditTimeID);
                if (_ah != null)
                {
                    return;
                }

                _ah = db.AuditHists.Add(new AuditHist
                {
                    AuditTimeID = _AuditTimeID,
                    PathRoot    = pathRoot,
                    TotalFound  = 0,
                    TotalAdded  = 0,
                    TotalHashed = 0,
                });
            }
            catch (Exception ex) { ex.Log(); ErrorMsg = ex.Message; throw; }
        }
示例#5
0
        private static async Task getUpdateSaveMediaDuration(A0DbContext _db, string file, DnLd dr)
        {
            var approximationBySize = (dr.CastFileLength ?? (dr.CastFileLength = new FileInfo(file).Length)) / 1000000;

            if (dr.DurationMin == null ||
                dr.DurationMin.Value < approximationBySize * 0.3 ||
                dr.DurationMin.Value > approximationBySize * 3.0 ||
                dr.DurationMin.Value == ConstHelper.Unknown4004Duration)
            {
                dr.DurationMin = await GetMediaDurationInMinUsingMediaElement(file);

                if (dr.DurationMin == null ||
                    dr.DurationMin.Value < approximationBySize * 0.3 ||
                    dr.DurationMin.Value > approximationBySize * 3.0 ||
                    dr.DurationMin.Value == ConstHelper.Unknown4004Duration)
                {
                    dr.DurationMin = approximationBySize;
                }

                if (_db != null)
                {
                    _db.TrySaveReport();
                }
            }

            Debug.Write($"Final: {dr.DurationMin,5:N1}, approx: {approximationBySize,5:N1}, {dr.CastTitle}\n");
        }
示例#6
0
        async Task <long> smartHashFile_SlowByHash(A0DbContext db, Stopwatch sw, SHA256 ha, long ttl, long prg, FileInfo fi)
        {
            {
                var hash = await GetFileHashAsync(fi, ha); // var  hash1 = GetMd5Hash(ha, "      string source = Hello World!   ");

                _TotalHashed++;
                prg += fi.Length;
                var bps = prg / sw.Elapsed.TotalSeconds;
                var rmg = (ttl - prg) / bps;
                InfoMsg = $"F?: {100.0 * prg / ttl,7:N1} %   {.000001 * bps,5:N1} mb/s   {rmg,5:N0} s ==> {DateTime.Now.AddSeconds(rmg):MM-dd HH:mm:ss}   ";

                var exg = db.FileDetails.FirstOrDefault(r => string.Compare(r.FileHash, hash) == 0);
                if (exg != null)
                {
                    exg.LastSeen = _ah.AuditTimeID;
                    if (string.Compare(exg.FileName, fi.Name, true) != 0 || string.Compare(exg.FilePath, Path.GetFullPath(fi.FullName), true) != 0)
                    {
                        exg.Note += "Dupe!! ";
                    }
                }
                else
                {
                    addNewFD(db, fi, hash, $"<Never tried method: {fi.FullName}>\r\n");
                }
            }

            return(prg);
        }
示例#7
0
        async Task F8_()
        {
            Bpr.BeepClk(); IsReady = false; await Task.Delay(9);

            using (var db = new A0DbContext())
            {
                db.FileDetails.RemoveRange(db.FileDetails);
                SaveRpt += Environment.NewLine + db.GetDbChangesReport();
            }
            IsReady = true;
        }
示例#8
0
        public bool LaunchIfDownloadRequiredMvvm(A0DbContext db, DnLd dl, DataGrid dg)
        {
            Debug.WriteLine("?:>{0}  \t{1}", dl.Feed.Name, dl.CastTitle);

            if (!IsDownloadRequiredWrpr(dl))
            {
                return(false);
            }

            StartDownload(dl, dg);
            return(true);
        }
示例#9
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            A0DbContext db = A0DbContext.Create();

            //var lq = _db.Machines.Include(m => m.Feeds).ToList();
            //var blog1 = _db.Machines.Where(m => m.Id == " V AIO1").Include(m => m.Feeds).FirstOrDefault();			// Load one blogs and its related posts     - http://msdn.microsoft.com/en-ca/data/jj574232.aspx

            //_db.Machines.Where(m => m.Id == "v aio1").Load();//ok: ignore case SQL style.	+	((CollectionViewSource)(this.FindResource("machineViewSource"))).Source = _db.Machines.Local; //!!! ==> only case-sensitive matches


            db.Feeds.Where(r => /*string.Compare(r.HostMachineId, Environment.MachineName, true) == 0 &&*/ r.IsActive && !r.IsDeleted).Load(); ((CollectionViewSource)(this.FindResource("feedViewSource"))).Source = db.Feeds.Local;
        }
        async Task findDupesInDbAndDeleteThemFromFS_SUSPENDED(string mainFolder, int mainRootLen, string dupeFolder, int dupeRootLen, long minSz)
        {
            InfoMsg = "F2: ...";
            synth.SpeakAsync($"F2: Removing dupes from the specified dupe folder {dupeFolder}");
            synth.Speak("F2 suspended for now.");
            return;//  throw new Exception("SUSPENDED: ");

            _TtlBytesDeleted = _TotalAdded = _TotalRenamed = _TotalDeleted = _TotalUpdated = _TotalHashed = 0;
            using (var db = new A0DbContext())
            {
                try
                {
                    var sw = Stopwatch.StartNew();

                    getAddAuditId(dupeFolder.Substring(mainRootLen < dupeFolder.Length ? mainRootLen : 0), db);

                    using (var ha = SHA256Managed.Create()) //_md5 = MD5.Create(),		//  3.5/4.5 faster than SHA256/SHA512			//_sh5 = SHA512Managed.Create(),				//  128 char len					//   64 char len. 3/4 ~ SHA256/SHA512
                    {
                        var delCandidates = FileIO.getFileInfosAsync(dupeFolder).Result.ToList().Where(r => r.Length > minSz).OrderByDescending(r => r.Length);
                        _ah.TotalFound    = delCandidates.Count();
                        TtlLen            = delCandidates.Select(r => r.Length).Sum();
                        PrgLen            = 0L;
                        var idx           = 0L;

                        foreach (var delCandidate in delCandidates.OrderByDescending(r => r.Length))
                        //Parallel.ForEach(delCandidates,
                        //delCandidates.ToList().ForEach(
                        //  async delCandidate =>
                        {
                            PrgLen = await makeSureItIsDupeNadSafeDelete(delCandidate, mainFolder, mainRootLen, dupeFolder, dupeRootLen, db, sw, ha, TtlLen, PrgLen); //

                            Interlocked.Increment(ref idx);
                            lock (_thisLock) { if ((idx) % _dbPackLen == 0)
                                               {
                                                   SaveRpt += Environment.NewLine + db.TrySaveReport($"saved; ttl {idx}");
                                               }
                            }
                        }
                        //);
                    }

                    SaveRpt += Environment.NewLine + db.GetDbChangesReport(5);
                    SaveRpt += Environment.NewLine + db.TrySaveReport("r/s saved");
                }
                catch (Exception ex) { ex.Log(); ErrorMsg = ex.Message; throw; }
                finally
                {
                    updateNewAuditHistRow(_ah.AuditTimeID, "UnDuping from " + dupeFolder);
                }
            }

            synth.Speak("F2 Done.");
        }
示例#11
0
        private static void collectTotalTime(A0DbContext _db, System.Collections.Generic.IEnumerable <string> walkmanPlayableFiles, out int ttlCasts, out double ttlDurnMin)
        {
            var af = walkmanPlayableFiles.Where(r => !r.EndsWith(MediaHelper.AnonsExt));

            ttlCasts   = af.Count();
            ttlDurnMin = 0.0;
            foreach (var file in af.ToList())   //         foreach (var dir in Directory.GetDirectories(MiscHelper.Dir1Cut))
            {
                var dr = getDnldRow(_db, file); // Path.GetFileName(dir));
                ttlDurnMin += dr == null ? 60 : dr.DurationMin.Value;
            }
        }
示例#12
0
        async void onLoaded(object s, RoutedEventArgs e)
        {
            _db = A0DbContext.Create();
            await Task.Yield();                   // displays window now - not after db loads.

            await _db.Vw_TxCore.LoadAsync();      // TxCoreV2 would show the MoneySrc.Name in Binding

            await _db.Vw_Exp_Hist_vs_Last.LoadAsync();

            dgTxVs.ItemsSource = _db.Vw_Exp_Hist_vs_Last.Local.OrderBy(r => r.Name).ThenBy(r => r.TaxLiq__);
            dgTxVs.Focus();
            Bpr.BeepShort();
        }
示例#13
0
        private static async Task doPostDownloadProcessing(A0DbContext _db, System.Collections.Generic.IEnumerable <string> walkmanPlayableFiles)
        {
            foreach (var file in walkmanPlayableFiles)
            {
                var mp3CutDir = Path.Combine(MiscHelper.Dir1Cut, Path.GetFileNameWithoutExtension(file));
                if (!Directory.Exists(mp3CutDir)) // if audio is uncut yet...
                {
                    await DoPostDownloadProcessing(getDnldRow(_db, file));
                }

                Bpr.BeepOk();
            }
        }
        async Task HashFolder_OLD(string folder, bool isMasterish)
        {
            InfoMsg = "F1: ...";
            //..synth.SpeakAsync($"Hashing the specified  {isMasterish} master folder.");

            _TtlBytesDeleted = _TotalAdded = _TotalRenamed = _TotalDeleted = _TotalUpdated = _TotalHashed = 0;
            using (var db = new A0DbContext())
            {
                try
                {
                    var sw = Stopwatch.StartNew();

                    getAddAuditId(folder, db);

                    using (var ha = SHA256Managed.Create()) //_md5 = MD5.Create(),		//  3.5/4.5 faster than SHA256/SHA512			//_sh5 = SHA512Managed.Create(),				//  128 char len					//   64 char len. 3/4 ~ SHA256/SHA512
                    {
                        var fis = await FileIO.getFileInfosAsync(folder);

                        _ah.TotalFound = fis.Count();
                        TtlLen         = fis.Select(r => r.Length).Sum();
                        PrgLen         = 0L;
                        var idx        = 0L;

                        //..synth.SpeakAsync($"{fis.Length} files found in the specified {isMasterish} master folder.");

#if ___
#if __
                        Parallel.ForEach(fis.ToList(),
#else
                        fis.ToList().ForEach(
#endif
                                         async fi => idx = await doFile(folder, isMasterish, db, sw, ha, idx, fi));
#else
                        foreach (var fi in fis)
                        {
                            idx = await doFile_OLD(folder, isMasterish, db, sw, ha, idx, fi);
                        }
#endif
                    }

                    SaveRpt += Environment.NewLine + db.GetDbChangesReport(5);
                    SaveRpt += Environment.NewLine + db.TrySaveReport("r/s saved");
                }
                catch (Exception ex) { ex.Log(); ErrorMsg = ex.Message; throw; }
                finally { updateNewAuditHistRow(_ah.AuditTimeID, "Ini scan into DB"); }
            }

            synth.Speak("Hashing is done.");
        }
        async Task UpdateDBfromFS(int v)
        {
            await Task.Delay(9);

            InfoMsg = "F7: ...";
            synth.SpeakAsync("F7: Updating DB with deletes from file system.");

            _TtlBytesDeleted = _TotalAdded = _TotalRenamed = _TotalDeleted = _TotalUpdated = _TotalHashed = 0;
            try
            {
                using (var db = new A0DbContext())
                {
                    getAddAuditId("DB <== FS", db);

                    //var oneDrBase = Path.GetFullPath(CurrentFolder).Substring(0, MasterSubBaseLen);

                    //Trace.WriteLine(db.FileDetails.Where(r => string.IsNullOrEmpty(r.Note) || !r.Note.Contains(_nfo)).ToString(), "SQL");
                    //var nonDelLst = db.FileDetails.Where(r => string.IsNullOrEmpty(r.Note) || !r.Note.Contains(_nfo)).ToList();
                    //InfoMsg = $"F7: {db.FileDetails.ToList().Count():N0} total, {nonDelLst.Count():N0} non-deleted rows in db.";
                    //await Task.Delay(9);
                    //TtlLen = nonDelLst.Count();
                    //PrgLen = 0;
                    //foreach (var fd in nonDelLst)
                    //{
                    //  PrgLen++;

                    //  var fdFullPathName = Path.Combine(oneDrBase, fd.FilePath.StartsWith(@"\") ? fd.FilePath.Substring(1) : fd.FilePath);
                    //  if (!File.Exists(fdFullPathName))
                    //  {
                    //    smartUpdateNote(fd, $"{_nfo} {_ah.AuditTimeID:yyyy-MM-dd HH:mm}>\r\n");
                    //    _TotalUpdated++;
                    //  }
                    //}

                    SaveRpt += Environment.NewLine + db.GetDbChangesReport(5);

#if !DEBUG
                    SaveRpt += Environment.NewLine + db.TrySaveReport("r/s saved");
#endif
                }
            }
            catch (Exception ex) { ex.Log(); ErrorMsg = ex.Message; throw; }
            finally
            {
                updateNewAuditHistRow(_ah.AuditTimeID, "F7: DB <== FS " + SaveRpt);
                synth.Speak("F7 Done.");
            }
        }
        //Oct 2017
        async Task delSameNameSizeFromCameraRoll_F12(string folder, bool useSize)
        {
            const int d = -64;
            var       i = 0;

            try
            {
                using (var db = new A0DbContext())
                {
                    var fis = new DirectoryInfo(folder).GetFiles("*.*", SearchOption.AllDirectories);
                    var msg = $"{fis.Length} files {fis.Sum(r => r.Length) / 1e9:N1} gb in {folder}";
                    SaveRpt += Environment.NewLine + msg;
                    Trace.WriteLine($"\r\n**>> {msg}:");
                    foreach (var fi in fis)
                    {
                        var dupe = db.FileDetails.FirstOrDefault(r => r.FileName.Equals(fi.Name, StringComparison.OrdinalIgnoreCase) && (useSize ? r.FileSize == fi.Length : true) && r.FilePath.Equals(fi.DirectoryName, StringComparison.OrdinalIgnoreCase));
                        var mstr = db.FileDetails.FirstOrDefault(r => r.FileName.Equals(fi.Name, StringComparison.OrdinalIgnoreCase) && (useSize ? r.FileSize == fi.Length : true) && !r.FilePath.Equals(fi.DirectoryName, StringComparison.OrdinalIgnoreCase));
                        if (mstr != null && dupe != null)
                        {
                            if (!File.Exists(mstr.FullPath))
                            {
                                smartUpdateNote(dupe, $"<Dupe not deleted: Master is missing on FS: {mstr.FullPath}>\r\n");
                            }
                            else
                            {
                                Trace.WriteLine($"{++i,4}/{fis.Length,-4}   {fi.Length / 1e6,8:N2}\r\n-{fi.DirectoryName,d}{fi.Name,-40}{fi.Length / 1e6,8:N2}\r\n+{mstr.FilePath,d}{mstr.FileName,-40}{mstr.FileSize / 1e6,8:N2}");
#if DEBUG
                                synth.Speak($"Deletion suspended for Debug mode.");
#else
                                File.Delete(dupe.FullPath);
                                smartUpdateNote(dupe, $"<Deleted as Dupe by Name {(useSize ? "and Size" : "only")}. Master: {mstr.FullPath}>\r\n");
#endif
                            }
                        }
                    } // foreach

                    SaveRpt += Environment.NewLine + db.GetDbChangesReport(5);
#if !DEBUG
                    SaveRpt += Environment.NewLine + db.TrySaveReport(" F12 rows saved ");
#endif
                }
            }
            catch (Exception ex) { ex.Log(); ErrorMsg = ex.Message; throw; }

            await Task.Delay(9);
        }
        async Task <long> doFile_OLD(string folder, bool isMasterish, A0DbContext db, Stopwatch sw, SHA256 ha, long idx, FileInfo fi)
        {
            {
                var pl = await smartHashFile_FastByFileInfo_OLD(folder, db, sw, ha, TtlLen, PrgLen, fi, isMasterish);

                lock (_thisLock)
                {
                    PrgLen = pl;
                    Interlocked.Increment(ref idx);
                    if ((idx) % _dbPackLen == 0)
                    {
                        SaveRpt += Environment.NewLine + db.TrySaveReport($"saved; ttl {idx}");
                    }
                }
            }

            return(idx);
        }
示例#18
0
        void addNewFD_SansHash(A0DbContext db, FileInfo fi, string note)
        {
            //nogo: SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory); //jul 2017 - Solving ‘Spatial types and functions are not available’ with Entity Framework
            db.FileDetails.Add(new FileDetail
            {
                AddedByAuditTimeID = _ah.AuditTimeID,
                LastSeen           = _ah.AuditTimeID,
                FilePath           = fi.DirectoryName,
                FileName           = fi.Name,
                FileExtn           = fi.Extension,
                FileCreated        = fi.CreationTime,
                FileSize           = fi.Length,
                //leHash = hash,
                Note      = note,
                CreatedAt = _ah.AuditTimeID,
            });

            _TotalAdded++;
        }
示例#19
0
        public static async Task GenerateAllAndFolderAnons(A0DbContext _db, string path)
        {
            //if (Environment.MachineName == "LN1") return;

            try
            {
                //making sure no files left uncut:
                var walkmanPlayableFiles = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Where(f => MediaHelper.WalkmanPlayableExtDsv.Contains(Path.GetExtension(f).ToLower()) && !f.EndsWith(MediaHelper.AnonsExt));

                //todo: decide what to do with cutting in pieces for the new walkman: await doPostDownloadProcessing(_db, walkmanPlayableFiles);

                collectTotalTime(_db, walkmanPlayableFiles, out var ttlCasts, out var ttlDurnMin);
                AdvertCutter.CreateSummaryAnons(ttlDurnMin, path);

                var needReqson = isAnonGenNeeded(path);
                Debug.Write($"<<<<  {path,-80}: {walkmanPlayableFiles.Count(),4} media files, {ttlDurnMin,4:N0}  min \t {needReqson.reason}");

                if (needReqson.needed)
                {
                    foreach (var file in walkmanPlayableFiles) // add anonses for each cast:
                    {
                        var dr = getDnldRow(_db, file);        // Path.GetFileName(dir)); //
                        if (dr == null)
                        {
                            continue;
                        }

                        await getUpdateSaveMediaDuration(_db, file, dr);

#if !DEBUG
                        AdvertCutter.CreateOverwriteAnons(dr.Feed == null ? "Unknown feed" : dr.Feed.Name, dr.PublishedAt, dr.CastTitle, ttlCasts, ttlDurnMin, dr.DurationMin.Value, file);
#endif

                        ttlDurnMin -= dr.DurationMin.Value;
                        ttlCasts--;
                        Bpr.BeepOk();
                    }
                }
            }
            catch (Exception ex) { ex.Log(); }
            Debug.WriteLine($">>>>");
        }
示例#20
0
        void updateNewAuditHistRow(DateTime auditTimeID, string mode)
        {
            using (var db = new A0DbContext())
            {
                var ah = db.AuditHists.FirstOrDefault(r => r.AuditTimeID == auditTimeID) ?? db.AuditHists.Local.FirstOrDefault(r => r.AuditTimeID == auditTimeID);
                if (ah == null)
                {
                    return;
                }

                ah.TotalAdded   = _TotalAdded;
                ah.TotalHashed  = _TotalHashed;
                ah.FoundRenamed = _TotalRenamed;

                InfoMsg += $"\r\n FINAL:  Found {_ah.TotalFound:N0},  Added {_TotalAdded:N0},  Hashed {_TotalHashed:N0},  Moved {_TotalRenamed:N0},  Updated {_TotalUpdated:N0},  Deleted {_TotalDeleted:N0} ({_TtlBytesDeleted / (1024 * 1024):N0} mb)";

                ah.Note = $"{mode}: {InfoMsg.Substring(8)} \r\n";

                SaveRpt += Environment.NewLine + db.TrySaveReport("r/s saved");
            }
        }
示例#21
0
        async Task <long> addOrUpdateToDb_SansHash(string folder, A0DbContext db, Stopwatch sw, SHA256 ha, long ttlLen, long prgLen, FileInfo exisitingFile, bool isMasterish)
        {
            prgLen = await updateMsgInfo(sw, ttlLen, prgLen, exisitingFile, "F1");

            try
            {
                FileDetail exg = null;
                lock (_thisLock)
                {
                    exg = db.FileDetails.FirstOrDefault(r =>
                                                        r.FileSize == exisitingFile.Length &&
                                                        string.Compare(r.FileName, exisitingFile.Name, true) == 0 &&
                                                        string.Compare(r.FilePath, exisitingFile.DirectoryName, true) == 0
                                                        );
                }
                if (exg != null) // if already in DB and has hash - move on.
                {
                    lock (_thisLock)
                    {
                        if (exg.LastSeen != _ah.AuditTimeID.Date)
                        {
                            exg.LastSeen   = _ah.AuditTimeID.Date;
                            exg.ModifiedAt = _ah.AuditTimeID;
                        }
                    }
                }
                else // not in DB yet by filename + Len - add it:
                {
                    lock (_thisLock)
                    {
                        addNewFD_SansHash(db, exisitingFile, isMasterish ? "<new master file>" : "<new from dupe location>");
                    }
                }
            }
            catch (Exception ex) { ex.Log(); ErrorMsg = ex.Message; throw; }

            return(prgLen);
        }
示例#22
0
 static DnLd getDnldRowFormDB(A0DbContext db, string url)
 {
     lock (thisLock)
     {
         do
         {
             try
             {
                 var dr = db.DnLds.FirstOrDefault(r => r.CastUrl == url);
                 if (dr == null)
                 {
                     dr = db.DnLds.FirstOrDefault(r => r.CastUrl.Contains(Path.GetFileName(url)));
                 }
                 if (dr == null)
                 {
                     throw new Exception("Oops. Another problem to fix.");
                 }
                 return(dr);
             }
             catch (Exception ex) { ex.Log(); }
         } while (true);
     }
 }
示例#23
0
        async void onBalanceToDb(object s, RoutedEventArgs e)
        {
            try
            {
                bBalance.Visibility = Visibility.Collapsed;
                await Task.Delay(9);

                using (var db = A0DbContext.Create())
                {
                    var tmsdb = db.TxMoneySrcs.FirstOrDefault(r => r.Id == _tmsId);
                    if (tmsdb != null)
                    {
                        tmsdb.IniBalance += _balDelta;
                        var rowsSaved = DbSaveMsgBox.CheckAskSave(db);
                        tBalance.Text = $"{rowsSaved} row saved.";
                        await reload();

                        chartuc.RmvSeries(_tmsFla);
                        addSeries(tmsdb.Id, tmsdb.Fla, tmsdb.IniBalance);
                    }
                }
            }
            finally { /*bBalance.Visibility = Visibility.Visible;*/ }
        }
        async Task DeleteAllDupesAutoAndManual_F10()
        {
            await Task.Delay(9);

            InfoMsg = "F10: ...";
            synth.SpeakAsync("F10: Major Deleting all dupes from the main/base folder.");

            //throw new Exception("SUSPENDED: How to tell dupe from not? ");

            _TtlBytesDeleted = _TotalAdded = _TotalRenamed = _TotalDeleted = _TotalUpdated = _TotalHashed = 0;
            try
            {
                using (var db = new A0DbContext())
                {
                    getAddAuditId("Delete all dupes", db);

                    var dupesByHash = db.FileDetails.Where(r => string.IsNullOrEmpty(r.Note) || (!r.Note.Contains(_nfo) && !r.Note.Contains(_ndm))).GroupBy(g => g.FileHash).ToList().Select(r => new { r.Key, Cnt = r.Count(), Sze = r.Max(y => y.FileSize) }).Where(r => r.Cnt > 1).OrderByDescending(r => r.Sze).ToList();
                    var dupesBySize = db.FileDetails.Where(r => string.IsNullOrEmpty(r.Note) || (!r.Note.Contains(_nfo) && !r.Note.Contains(_ndm))).GroupBy(g => g.FileSize).ToList().Select(r => new { r.Key, Cnt = r.Count(), Sze = r.Max(y => y.FileSize) }).Where(r => r.Cnt > 1).OrderByDescending(r => r.Sze).ToList();
                    Trace.Write(/**/ db.FileDetails.Where(r => string.IsNullOrEmpty(r.Note) || (!r.Note.Contains(_nfo) && !r.Note.Contains(_ndm))).GroupBy(g => g.FileSize)./**/ Select(r => new { r.Key, Cnt = r.Count(), Sze = r.Max(y => y.FileSize) }).Where(r => r.Cnt > 1).ToString(), "SQL");

                    await Task.Delay(9);

                    InfoMsg = $"F10: dupesBySize:{dupesBySize.Count:N0}, dupesByHash:{dupesByHash.Count:N0}.";
                    Trace.WriteLine($"        F10: dupesBySize:{dupesBySize.Count:N0}, dupesByHash:{dupesByHash.Count:N0}.");

                    TtlLen = (long)(_ah.TotalFound = dupesBySize.Count());
                    PrgLen = 0;                //here not file size but idx.
                    var abort = false;
                    dupesBySize.ForEach(dbs => //foreach (var r in dupesBySize)
                    {
                        PrgLen++;
                        Trace.WriteLine($"{PrgLen,3} / {dupesBySize.Count})  {dbs.Cnt} matches by size of {dbs.Key:N0}.");
                        if (!abort)
                        {
                            lock (_thisLock) { if ((PrgLen) % 10 == 0)
                                               {
                                                   SaveRpt += Environment.NewLine + db.TrySaveReport($"saved; ttl {PrgLen}");
                                               }
                            }
                        }

                        db.FileDetails.Where(f => f.FileSize == dbs.Key).OrderBy(f => f.FileName.Length).ToList().ForEach(f => Trace.WriteLine($"  {f.FileSize / 1048576,8:N1}mb     {f.FilePath}\\{f.FileName}")); // db.FileDetails.Where(f => string.Compare(f.FileHash, r.Key, true) == 0).OrderBy(f => f.FileName.Length).ToList().ForEach(f => Trace.WriteLine("  {0,8:N1}k     {1}", f.FileSize / 1024, f.FilePath));

                        var ary = db.FileDetails.Where(r => r.FileSize == dbs.Key && (string.IsNullOrEmpty(r.Note) || (!r.Note.Contains(_nfo) && !r.Note.Contains(_ndm)))).OrderBy(f => f.FileName.Length).ToArray();
                        for (var i = 1; i < ary.Length; i++)
                        {
                            if (!abort)
                            {
                                if (!tryRemoveDupe(ary[0], ary[i])) // SUSPENDED: How to tell dupe from not?
                                {
                                    abort = true;
                                    synth.SpeakAsync("Wait: aborting the F10 processing...");
                                }
                            }
                        }
                    });

                    SaveRpt += Environment.NewLine + db.GetDbChangesReport(5);

#if !DEBUG
                    SaveRpt += Environment.NewLine + db.TrySaveReport("r/s saved");
#endif
                }
            }
            catch (Exception ex) { ex.Log(); ErrorMsg = ex.Message; throw; }
            finally
            {
                updateNewAuditHistRow(_ah.AuditTimeID, "F10: UnDuping-AutoAll " + SaveRpt);
                synth.Speak("F10 Done.");
            }
        }
        async Task <long> fastSyncFStoDbSansHashing_File(string folder, bool isMasterish, A0DbContext db, Stopwatch sw, SHA256 ha, long idx, FileInfo fi)
        {
            var pl = await addOrUpdateToDb_SansHash(folder, db, sw, ha, TtlLen, PrgLen, fi, isMasterish);

            lock (_thisLock)
            {
                PrgLen = pl;
                Interlocked.Increment(ref idx);
                if ((idx) % _dbPackLen == 0)
                {
                    SaveRpt += Environment.NewLine + db.TrySaveReport($" {idx:N0}").report;
                }
            }

            return(idx);
        }
示例#26
0
        public static List <TxCoreV2> ReadTxs(A0DbContext db, string file, out string fla_acntDir, out TxMoneySrc txMoneySrc)
        {
            Debug.WriteLine(Path.GetFileName(file), "\n\n");

            var txns = new List <TxCoreV2>();

            txMoneySrc = null;

            try
            {
                if (string.Equals(Path.GetExtension(file), ".csv", StringComparison.OrdinalIgnoreCase)) // PC since 2019
                {
                    var lines = File.ReadAllLines(file);
                    if (lines.Length < 2)
                    {
                        fla_acntDir = $"Is empty file: {file}"; return(txns);
                    }
                    if (!lines[0].Equals(_header))
                    {
                        fla_acntDir = $"Is not a known fin file: {file}"; return(txns);
                    }

                    var acntId = lines[1].Split(new[] { _separtor }, StringSplitOptions.RemoveEmptyEntries)[1].Replace("*", "");
                    txMoneySrc = getCreateTxMoneySrc(db, out fla_acntDir, acntId, Path.GetFileName(file));

                    foreach (var line in lines)
                    {
                        if (line.Equals(_header))
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        var cells = line.Split(new[] { _separtor }, StringSplitOptions.RemoveEmptyEntries);
                        if (cells.Length < 3)
                        {
                            continue;
                        }

                        txns.Add(new TxCoreV2
                        {
                            Id        = --_cntr,
                            CreatedAt = _batchTimeNow,
                            FitId     = line,
                            TxDate    = parseTxnDate(cells[2], cells[3]),
                            TxAmount  = parseTA(cells[4].Replace("\"", "")),
                            TxDetail  = cells[0].Substring(1),
                            //MemoPP = mm + cs + td + si,
                            TxCategoryIdTxt = PreSet.__UnKn,
                            TxMoneySrc      = txMoneySrc,
                            TxMoneySrcId    = txMoneySrc.Id,
                            SrcFile         = Path.GetFileNameWithoutExtension(file),
                            Notes           = $"{file}" // 2021-01
                        });
                    }
                }
                else if (string.Equals(Path.GetExtension(file), ".qif", StringComparison.OrdinalIgnoreCase)) // amazon / chase qif file format
                {
                    var blocks = File.ReadAllText(file).Split(new string[] { "^" }, StringSplitOptions.RemoveEmptyEntries);
                    var acntId = "amzn"; //only for amazon since no other formats available; note: no CC # in qif ==> use for amazon only.
                    txMoneySrc = getCreateTxMoneySrc(db, out fla_acntDir, acntId, Path.GetFileName(file));

                    foreach (var block in blocks)
                    {
                        if (block.Contains("\nD"))
                        {
                            txns.Add(doTxnBlockQif(block, file, txMoneySrc));
                        }
                    }
                }
                else // .ofx .qfx .aso
                {
                    var blocks = File.ReadAllText(file).Split(new string[] { "</STMTTRN>" }, StringSplitOptions.RemoveEmptyEntries);

                    var acntId = blocks[0].Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(r => r.Contains(PreSet.AcntIdTAg));
                    if (acntId?.Length > 20) // Jun2017: elements not always are one per line.
                    {
                        acntId = getElCont(acntId, PreSet.AcntIdTAg);
                    }

                    txMoneySrc = getCreateTxMoneySrc(db, out fla_acntDir, acntId, Path.GetFileName(file));

                    foreach (var block in blocks)
                    {
                        if (block.Contains("<STMTTRN>"))
                        {
                            txns.Add(doTxnBlock(block.Replace("\n", "").Replace("\r", ""), file, txMoneySrc));
                        }
                    }
                }
            }
            catch (Exception ex) { ex.Log(); fla_acntDir = "Exceptioned"; }

            return(txns);
        }
示例#27
0
        async Task <long> makeSureItIsDupeNadSafeDelete(FileInfo delCandidate, string mainFolder, int mainRootLen, string dupeFolder, int dupeRootLen, A0DbContext db, Stopwatch sw, SHA256 ha, long ttlLen, long prgLen)
        {
            prgLen = await updateMsgInfo(sw, ttlLen, prgLen, delCandidate, "F2");

            var superPath = Path.GetFullPath(delCandidate.FullName).Substring(mainRootLen); // only works within OneDrive.
            var oneDrBase = Path.GetFullPath(mainFolder).Substring(0, mainRootLen);


            FileDetail dupeInDb = null;

            lock (_thisLock)
            {
                dupeInDb = db.FileDetails.FirstOrDefault(r =>
                                                         r.FileSize == delCandidate.Length &&
                                                         string.Compare(r.FileName, delCandidate.Name, true) == 0 && (
                                                             string.Compare(r.FilePath, superPath, true) == 0 ||            // for within  OneDrive
                                                             r.FilePath.ToLower().Contains(delCandidate.FullName.ToLower()) // for without OneDrive
                                                             )
                                                         );
                if (dupeInDb != null)
                {
                    if (dupeInDb.LastSeen != _ah.AuditTimeID.Date)
                    {
                        dupeInDb.LastSeen = _ah.AuditTimeID.Date;
                    }
                }
            }

            var hash = await GetFileHashAsync(delCandidate, ha);

            lock (_thisLock)
            {
                _TotalHashed++;

                if (!db.FileDetails.Any(r => string.Compare(r.FileHash, hash) == 0))
                {
                    addNewFD(db, delCandidate, hash, $"<Exisiting file does not exist: {delCandidate.FullName}>\r\n");
                }
                else
                {
                    var dupeCount = db.FileDetails.Count(r => r.FileSize == delCandidate.Length);
                    foreach (var exgByLen in db.FileDetails.Where(r => r.FileSize == delCandidate.Length).ToList()) // db.FileDetails.Where(r => string.Compare(r.FileHash, hash) == 0).ToList().ForEach(exgByHash =>
                    {
                        var dbFullPathName = Path.Combine(oneDrBase, exgByLen.FilePath.StartsWith(@"\") ? exgByLen.FilePath.Substring(1) : exgByLen.FilePath);

                        Trace.WriteLine($"{dupeCount} matches, \n {delCandidate.FullName} - fic\n {dbFullPathName} - db ver\n");

                        if (string.Compare(delCandidate.FullName, dbFullPathName, true) != 0) // only if not the same record in db
                        {
                            if (File.Exists(dbFullPathName))                                  // if found in db file exists at the db specified location - safe to delete the dupe
                            {
                                if (File.Exists(delCandidate.FullName))                       // we could have deleted the dupe already.
                                {
                                    if (string.Compare(exgByLen.FileHash, hash) == 0)
                                    {
                                        safeDeleteFile(dupeInDb, dbFullPathName, delCandidate.FullName, "<Deleted-Auto as Dupe by HASH. Org: {0}", delCandidate.Length);
                                        break;
                                    }
                                    else
                                    {
                                        var nu = new DelPopup();
                                        _newUenWindowF.ShowNewWindow(nu, delCandidate.FullName, dbFullPathName, hash, exgByLen.FileHash, delCandidate.Length, exgByLen.FileSize);
                                        if (nu.OkToDelete == null)
                                        {
                                            OnRequestClose();
                                            break;
                                        }
                                        else if (nu.OkToDelete.Value)
                                        {
                                            safeDeleteFile(dupeInDb, dbFullPathName, delCandidate.FullName, "<Deleted as Dupe by FileLen and Look. Org: {0}", delCandidate.Length);
                                            break;
                                        }
                                    }
                                }
                            }
                            else // if the entry in DB does not exist in FS, update the DB with the current DUPE's values (for full local OneDrive mirror)
                            {
                                smartUpdateNote(exgByLen, $"<Moved from  {exgByLen.FilePath}>\r\n");
                                exgByLen.LastSeen = _ah.AuditTimeID;
                                exgByLen.FileName = delCandidate.Name;
                                exgByLen.FileExtn = delCandidate.Extension;
                                exgByLen.FilePath = superPath;
                                _TotalRenamed++;
                            }
                        }
                    }
                }
            }

            return(prgLen);
        }
示例#28
0
        async Task <long> smartHashFile_FastByFileInfo_OLD(string folder, A0DbContext db, Stopwatch sw, SHA256 ha, long ttlLen, long prgLen, FileInfo fi, bool isMasterish)
        {
            prgLen = await updateMsgInfo(sw, ttlLen, prgLen, fi, "F1");

            try
            {
                FileDetail exg = null;
                lock (_thisLock)
                {
                    exg = db.FileDetails.FirstOrDefault(r =>
                                                        r.FileSize == fi.Length &&
                                                        string.Compare(r.FileName, fi.Name, true) == 0 &&
                                                        string.Compare(r.FilePath, fi.DirectoryName, true) == 0
                                                        );
                }
                if (exg != null) // if already in DB and has hash - move on.
                {
                    lock (_thisLock)
                    {
                        if (exg.LastSeen != _ah.AuditTimeID.Date)
                        {
                            exg.LastSeen = _ah.AuditTimeID.Date;
                        }
                    }

                    if (string.IsNullOrEmpty(exg.FileHash)) // rare, but
                    {
                        var fh = await GetFileHashAsync(fi, ha);

                        lock (_thisLock)
                        {
                            _TotalHashed++;
                            exg.FileHash = fh;
                        }
                    }
                }
                else // not in DB yet by filename - hash + find in DB by hash + find in FS + add-if a dupe | update paths-if moved(not exists in DB specified location):
                {
                    var hash = await GetFileHashAsync(fi, ha);

                    lock (_thisLock)
                    {
                        _TotalHashed++;

                        var exgByHash = db.FileDetails.Local.FirstOrDefault(r => string.Compare(r.FileHash, hash) == 0) ?? db.FileDetails.FirstOrDefault(r => string.Compare(r.FileHash, hash) == 0);
                        if (exgByHash == null)
                        {
                            addNewFD(db, fi, hash, isMasterish ? "<new master file>" : "<new from dupe location>");
                        }
                        else
                        {
                            var sameInDb = Path.Combine(exgByHash.FilePath, exgByHash.FileName);
                            if (File.Exists(sameInDb)) // a match by hash exists in FS: add as copy
                            {
                                addNewFD(db, fi, hash, $"<Copy is at  {exgByHash.FilePath}>\r\n");
                            }
                            else // must've been moved/renamed: update DB with the latest filename.
                            {
                                //if(fi.DirectoryName.ToLower().Contains(exgByHash.FilePath.ToLower()))

                                smartUpdateNote(exgByHash, $"<Moved from  {exgByHash.FilePath}>\r\n");
                                exgByHash.LastSeen = _ah.AuditTimeID;
                                exgByHash.FileName = fi.Name;
                                exgByHash.FileExtn = fi.Extension;
                                exgByHash.FilePath = fi.DirectoryName;
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { ex.Log(); ErrorMsg = ex.Message; throw; }

            return(prgLen);
        }
示例#29
0
        static DnLd getDnldRow(A0DbContext db, string audioFile)
        {
            try
            {
                if (!db.DnLds.Any())
                {
                    db.DnLds.Load();
                }

                var nmeOnly = Path.GetFileNameWithoutExtension(audioFile);
                var cnt     = db.DnLds.Count(r => r.CastFilenameExt.Contains(nmeOnly));
                if (cnt == 1)
                {
                    return(db.DnLds.First(r => r.CastFilenameExt.Contains(nmeOnly)));
                }
                if (cnt > 1)
                {
                    var nameExt = Path.GetFileName(audioFile);

                    cnt = db.DnLds.Count(r => r.CastFilenameExt.Contains(nameExt));
                    if (cnt == 1)
                    {
                        return(db.DnLds.First(r => r.CastFilenameExt.Contains(nameExt)));
                    }
                    if (cnt > 1)
                    {
                        cnt = db.DnLds.Count(r => r.CastTitle == nmeOnly);
                        if (cnt >= 1)
                        {
                            return(db.DnLds.First(r => r.CastTitle == nmeOnly));
                        }
                        //else // if (cnt > 1)
                        //{
                        //	MessageBox.Show($"{cnt} matches in BD for \n\n '{nmeOnly}' \n\n\n\t\t\t\t\tWhy???", "You wanna see this!!!", MessageBoxButton.OK, MessageBoxImage.Question);
                        //}
                    }
                }
                else // == 0
                {
                    if (File.Exists(audioFile))
                    {
                        var dr = new DnLd ///////////////// Not a podcast: found in the folder => add to DB for further reference.
                        {
                            CastSummary       = "Not a podcast: found in the folder.",
                            CastFileLength    = new FileInfo(audioFile).Length,
                            CastFilenameExt   = Path.GetFileName(audioFile),
                            CastTitle         = Path.GetFileNameWithoutExtension(audioFile),
                            CastUrl           = audioFile,
                            DnldStatusId      = "C",
                            ReDownload        = false,
                            FeedId            = 180,
                            Feed              = null,
                            IsDownloading     = false,
                            PublishedAt       = DateTime.Today,
                            ModifiedAt        = DateTime.Now,
                            RowAddedAt        = DateTime.Now,
                            RowAddedByPC      = Environment.MachineName,
                            ErrLog            = "",
                            DurationMin       = ConstHelper.Unknown4004Duration, //? will be refined later?
                            TrgFileSortPrefix = ""
                        };

                        db.DnLds.Add(dr);

                        db.TrySaveReport();
                        return(dr);
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            return(null);
        }