/*--------------------------------------------------------------------------------------------*/ private void StoreExportResults() { using (ISession sess = vSessProv.OpenSession()) { using (ITransaction tx = sess.BeginTransaction()) { foreach (FabResponse <FabBatchResult> fr in vThreadResults) { var b = new Batch(); b.Job = sess.Load <Job>(vJob.Id); b.Timestamp = fr.Timestamp; b.DataLen = fr.DataLen; b.DbMs = fr.DbMs; b.TotalMs = fr.TotalMs; sess.Save(b); foreach (FabBatchResult br in fr.Data) { if (br.Error != null) { continue; } var e = new Data.Domain.Export(); e.Batch = b; e.FabricId = br.ResultId; SetItemTypeId(sess, e, (int)br.BatchId); sess.Save(e); } } //end "results" loop tx.Commit(); } } }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ private void CheckBatch(Batch pBatch, ParallelLoopState pState, long pIndex) { string msg = "BatchId " + pBatch.Id; if (pBatch.ExportList.Count == 0) { ++vCheckCount; CommIo.Print(msg + "Empty."); return; } Data.Domain.Export e = pBatch.ExportList[0]; //CommIo.Print(" - First Export Id="+e.Id+", ArtifactId="+e.Artifact.Id+ // ", FabricId="+e.FabricId); var f = new FabricClient(); f.AppDataProvSession.RefreshTokenIfNecessary(); f.UseDataProviderPerson = true; if (!f.AppDataProvSession.IsAuthenticated) { throw new Exception("Could not authenticate."); } FabResponse <FabClass> fr = f.Services.Traversal.GetRootStep.ClassId(e.FabricId).Get(); msg += " \t(" + (++vCheckCount) + " \tof " + vTotalCount + "): \t"; if (fr == null) { lock ( vFailList ) { vFailList.Add(pBatch); } CommIo.Print(msg + "Failed. FabResponse was null."); return; } FabClass c = fr.FirstDataItem(); if (c == null) { lock ( vFailList ) { vFailList.Add(pBatch); } CommIo.Print(msg + "Failed. FabClass was null."); return; } CommIo.Print(msg + "ArtifactId=" + c.ArtifactId + "."); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public override void Start() { var sp = new SessionProvider(); using (ISession sess = sp.OpenSession()) { Artifact a = sess.QueryOver <Artifact>() .Where(x => x.Id == vArtifactId) .SingleOrDefault(); Data.Domain.Export e = sess.QueryOver <Data.Domain.Export>() .Where(x => x.Artifact.Id == vArtifactId) .Fetch(x => x.Batch).Eager .SingleOrDefault(); CommIo.Print("Artifact.Id: " + a.Id); CommIo.Print("Artifact.Name: " + a.Name); CommIo.Print("Artifact.Note: " + a.Note); CommIo.Print("Artifact.Disamb: " + a.Disamb); CommIo.Print("Artifact.SynsetId: " + (a.Synset == null ? "NULL" : a.Synset.Id + "")); CommIo.Print("Artifact.WordId: " + (a.Word == null ? "NULL" : a.Word.Id + "")); CommIo.Print(""); if (e == null) { CommIo.Print("Export: NULL"); } else { CommIo.Print("Export.Id: " + e.Id); CommIo.Print("Export.FabricId: " + e.FabricId); CommIo.Print(""); CommIo.Print("Batch.Id: " + e.Batch.Id); CommIo.Print("Batch.DbMs: " + e.Batch.DbMs); CommIo.Print("Batch.TotalMs: " + e.Batch.TotalMs); //CommIo.Print("Batch.Size: "+e.Batch.Size); //CommIo.Print("Batch.Count: "+e.Batch.Count); //CommIo.Print("Batch.Threads: "+e.Batch.Threads); } } }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public override void Start() { try { CommIo.Print("Authenticating Fabric DataProvider..."); var f = new FabricClient(); f.AppDataProvSession.RefreshTokenIfNecessary(); f.UseDataProviderPerson = true; if (!f.AppDataProvSession.IsAuthenticated) { throw new Exception("DataProvider is not authenticated."); } CommIo.Print("DataProvider authenticated."); } catch (Exception e) { CommIo.Print("Authentication exception: " + e); return; } var sp = new SessionProvider(); using (ISession sess = sp.OpenSession()) { if (vJobId == -1) { Job j = sess.QueryOver <Job>() .OrderBy(x => x.Id).Desc .Take(1) .SingleOrDefault(); vJobId = j.Id; } CommIo.Print("Loading Job " + vJobId); IList <Batch> batchList = sess.QueryOver <Batch>() .Where(x => x.Job.Id == vJobId) .List(); var failList = new List <Batch>(); int i = 0; foreach (Batch b in batchList) { CommIo.Print("Confirming Batch " + b.Id + " (" + (++i) + " of " + batchList.Count + ")"); Data.Domain.Export e = b.ExportList[0]; CommIo.Print(" - First Export Id=" + e.Id + ", ArtifactId=" + e.Artifact.Id + ", FabricId=" + e.FabricId); var f = new FabricClient(); f.AppDataProvSession.RefreshTokenIfNecessary(); f.UseDataProviderPerson = true; if (!f.AppDataProvSession.IsAuthenticated) { throw new Exception("Could not authenticate."); } FabResponse <FabClass> fr = f.Services.Traversal.GetRootStep.ClassId(e.FabricId).Get(); if (fr == null) { failList.Add(b); CommIo.Print(" - FabResponse was null."); continue; } FabClass c = fr.FirstDataItem(); if (c == null) { failList.Add(b); CommIo.Print(" - FabClass was null."); continue; } CommIo.Print(" - Found class: " + c.ArtifactId); } CommIo.Print(""); CommIo.Print("Failures: " + failList.Count); foreach (Batch b in failList) { CommIo.Print(" - Batch " + b.Id); } } }
/*--------------------------------------------------------------------------------------------*/ protected override void SetItemTypeId(ISession pSess, Data.Domain.Export pExport, int pBatchId) { pExport.Factor = pSess.Load <Factor>(pBatchId); pExport.Artifact = null; }
/*--------------------------------------------------------------------------------------------*/ protected abstract void SetItemTypeId(ISession pSess, Data.Domain.Export pExport, int pBatchId);