private Task<Tuple<bool, Exception>> exportTSV(IStoreDataManager pMan, StatDataSet oSet, String filename,
     CancellationToken cancellationToken, IProgress<int> progress)
 {
     return Task.Run<Tuple<bool, Exception>>(() =>
     {
         bool bRet = false;
         Exception err = null;
         try
         {
             var xx = pMan.GetDataSetIndexes(oSet);
             if (xx == null)
             {
                 return new Tuple<bool, Exception>(bRet, err);
             }
             var indexes = xx.Item1;
             if (indexes == null)
             {
                 return new Tuple<bool, Exception>(bRet, err);
             }
             int nMaxIndex = indexes.Max() + 1;
             int nm1 = nMaxIndex - 1;
             double dTotal = (double)nMaxIndex;
             StringBuilder sb = new StringBuilder();
             int nCur = 0;
             var varsCol = oSet.Variables.ToArray();
             int nVars = varsCol.Length;
             for (int i = 0; i < nVars; ++i)
             {
                 if (i > 0)
                 {
                     sb.Append("\t");
                 }
                 sb.Append(varsCol[i].Name);
             }// i
             sb.Append("\n");
             if (progress != null)
             {
                 int f = (int)((nCur++ / dTotal) * 100.0 + 0.5);
                 progress.Report(f);
             }
             for (int irow = 0; irow < nMaxIndex; ++irow)
             {
                 if (cancellationToken.IsCancellationRequested)
                 {
                     break;
                 }
                 String[] vals = new String[nVars];
                 for (int i = 0; i < nVars; ++i)
                 {
                     vals[i] = "N/A";
                 }// i
                 if (indexes.Contains(irow))
                 {
                     var yy = pMan.GetDataSetIndivValues(oSet, irow);
                     if ((yy != null) && (yy.Item1 != null) && (yy.Item2 == null))
                     {
                         var xvals = yy.Item1;
                         for (int j = 0; j < nVars; ++j)
                         {
                             int ind = varsCol[j].Id;
                             var qq = from x in xvals where x.VariableId == ind select x;
                             if (qq.Count() > 0)
                             {
                                 var z = StatHelpers.ConvertValue(qq.First().DataStringValue);
                                 if (!String.IsNullOrEmpty(z))
                                 {
                                     vals[j] = z;
                                 }
                             }// ok
                         }// j
                     }// ok
                 }
                 for (int i = 0; i < nVars; ++i)
                 {
                     if (i > 0)
                     {
                         sb.Append("\t");
                     }
                     sb.Append(vals[i]);
                 }// i
                 if (irow < nm1)
                 {
                     sb.Append("\n");
                 }
                 if (progress != null)
                 {
                     int f = (int)((nCur++ / dTotal) * 100.0 + 0.5);
                     progress.Report(f);
                 }
             }// irow
             String s = sb.ToString();
             String ss = s.Replace(",", ".");
             FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);
             StreamWriter writer = new StreamWriter(fs);
             writer.Write(ss);
             writer.Close();
             bRet = true;
         }// try
         catch (Exception ex)
         {
             err = ex;
         }
         return new Tuple<bool, Exception>(bRet, err);
     }, cancellationToken);
 }
 private Task importPhotosAsync(IStoreDataManager pMan, String[] filenames,
     CancellationToken cancellationToken,
     IProgress<int> progress)
 {
     return Task.Run(() =>
     {
         try
         {
             for (int i = 0; i < filenames.Length; ++i)
             {
                 if (cancellationToken.IsCancellationRequested)
                 {
                     break;
                 }
                 String filename = filenames[i];
                 if (!String.IsNullOrEmpty(filename))
                 {
                     var xx = PhotosModelView.GetJPEGBytes(filename);
                     byte[] data = xx.Item1;
                     String name = xx.Item2;
                     Exception err = xx.Item3;
                     if ((data != null) && (data.Length > 1) && (err == null) && (!String.IsNullOrEmpty(name)))
                     {
                         PhotoDesc oPhoto = new PhotoDesc();
                         oPhoto.DataBytes = data;
                         oPhoto.Name = name;
                         var yy = pMan.MaintainsPhoto(oPhoto);
                         if ((yy.Item1 == null) || (yy.Item2 != null))
                         {
                             break;
                         }
                     }// data
                 }
                 if (progress != null)
                 {
                     progress.Report(i);
                 }
             }// i
         }
         catch (Exception /*ex */)
         {
         }
     }, cancellationToken);
 }//importPhotosAsync
 }// CommitChanges
 #endregion // Methods
 #region Helpers
 private Tuple<int, DisplayItemsArray> refreshPhotosAsync(IStoreDataManager pMan)
 {
     DisplayItemsArray oRet = null;
     int nRet = 0;
     String s = this.SearchString;
     var xx = pMan.SearchPhotosCount(s);
     if ((xx != null) && (xx.Item2 == null))
     {
         nRet = xx.Item1;
     }
     var yy = pMan.SearchPhotos(s, this.Skip, this.Taken);
     if ((yy != null) && (yy.Item2 == null))
     {
         var col = yy.Item1;
         oRet = new DisplayItemsArray();
         foreach (var v in col)
         {
             DisplayItems vv = new DisplayItems();
             vv.Tag = v;
             vv.Add(new DisplayItem(v.DataBytes));
             vv.Add(new DisplayItem(v.Name));
             oRet.Add(vv);
         }// v
     }
     return new Tuple<int, DisplayItemsArray>(nRet, oRet);
 }// refreshPhotosAsync