Beispiel #1
0
 /// <summary>
 /// Add a new cancel override.
 /// </summary>
 /// <param name="evtCancel">Specifies the cancel override to add.</param>
 public void AddCancelOverride(CancelEvent evtCancel)
 {
     lock (m_syncObj)
     {
         m_rgCancel.Add(new Tuple <WaitHandle, bool, string>(evtCancel.m_hOriginalCancel, false, evtCancel.Name));
     }
 }
        /// <summary>
        /// Remove a new cancel override.
        /// </summary>
        /// <param name="evtCancel">Specifies the cancel override to remove.</param>
        /// <returns>If removed, <i>true</i> is returned.</returns>
        public bool RemoveCancelOverride(CancelEvent evtCancel)
        {
            int  nIdx    = -1;
            bool bResult = false;

            for (int i = 0; i < m_rgCancel.Count; i++)
            {
                if (m_rgCancel[i].Item1 == evtCancel.m_hOriginalCancel)
                {
                    nIdx = i;
                    break;
                }
            }

            if (nIdx >= 0)
            {
                if (m_rgCancel[nIdx].Item2)
                {
                    m_rgCancel[nIdx].Item1.Dispose();
                }

                m_rgCancel.RemoveAt(nIdx);
                bResult = true;
            }

            setHandles();

            return(bResult);
        }
        /// <summary>
        /// The UnBucketize method converts all Data received into their respective Bucket average values.
        /// </summary>
        /// <param name="strName">Specifies the name to use when writing status information.</param>
        /// <param name="rgrgData">Specifies the data to unbucketize.</param>
        /// <param name="log">Specifies the output log.</param>
        /// <param name="evtCancel">Specifies the CancelEvent used to cancel the unbucketizing process.</param>
        /// <returns>On success, <i>true</i> is returned, otherwise <i>false</i>.</returns>
        public bool UnBucketize(string strName, List <double[]> rgrgData, Log log, CancelEvent evtCancel)
        {
            int       nIdx       = 0;
            int       nItemCount = rgrgData.Count * rgrgData[0].Length;
            Stopwatch sw         = new Stopwatch();

            sw.Start();

            for (int i = 0; i < rgrgData.Count; i++)
            {
                for (int j = 0; j < rgrgData[i].Length; j++)
                {
                    double dfVal    = rgrgData[i][j];
                    double dfNewVal = Translate(dfVal);
                    rgrgData[i][j] = dfNewVal;

                    if (evtCancel != null && evtCancel.WaitOne(0))
                    {
                        return(false);
                    }

                    if (sw.Elapsed.TotalMilliseconds > 1000)
                    {
                        double dfPct = (double)nIdx / (double)nItemCount;
                        log.WriteLine(strName + " at " + dfPct.ToString("P") + "...");
                        sw.Restart();
                    }

                    nIdx++;
                }
            }

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Remove a new cancel override.
        /// </summary>
        /// <param name="evtCancel">Specifies the cancel override to remove.</param>
        /// <returns>If removed, <i>true</i> is returned.</returns>
        public bool RemoveCancelOverride(CancelEvent evtCancel)
        {
            lock (m_syncObj)
            {
                int nIdx = -1;

                for (int i = 0; i < m_rgCancel.Count; i++)
                {
                    if (m_rgCancel[i].Item1 == evtCancel.m_hOriginalCancel)
                    {
                        nIdx = i;
                        break;
                    }
                }

                if (nIdx >= 0)
                {
                    if (m_rgCancel[nIdx].Item2)
                    {
                        m_rgCancel[nIdx].Item1.Dispose();
                    }

                    m_rgCancel.RemoveAt(nIdx);
                    return(true);
                }
            }

            return(false);
        }
Beispiel #5
0
 /// <summary>
 /// Extract a Tar (*.tar) file to a specified output directory.
 /// </summary>
 /// <param name="strFileName">Specifies the name of the .tar file to extract.</param>
 /// <param name="strOutputDir">Specifies the output directory.</param>
 /// <param name="evtCancel">Optionally, specifies the cancel event used to cancel the extraction (default = null).</param>
 /// <param name="log">Optionally, specifies the Log used to output status of the extraction (default = null).</param>
 /// <param name="nExpectedTotal">Optionally, specifies the expected total number of files (default = 0).</param>
 /// <param name="nIdx">Optionally, specifies an item index (default = 0).</param>
 /// <returns>Upon a successful extraction, the number of files extracted offset by the index is returned, or 0 on abort.</returns>
 public static int ExtractTar(string strFileName, string strOutputDir, CancelEvent evtCancel = null, Log log = null, int nExpectedTotal = 0, int nIdx = 0)
 {
     using (FileStream fstrm = File.OpenRead(strFileName))
     {
         return(ExtractTar(fstrm, strOutputDir, evtCancel, log, nExpectedTotal, nIdx));
     }
 }
 /// <summary>
 /// Add a new cancel override.
 /// </summary>
 /// <param name="evtCancel">Specifies the cancel override to add.</param>
 public void AddCancelOverride(CancelEvent evtCancel)
 {
     if (!Contains(evtCancel))
     {
         m_rgCancel.Add(new Tuple <WaitHandle, bool, string>(evtCancel.m_hOriginalCancel, false, evtCancel.Name));
         setHandles();
     }
 }
Beispiel #7
0
        /// <summary>
        /// Check to see if the cancel event has already been added.
        /// </summary>
        /// <param name="evt">Specifies the cancel event to look for.</param>
        /// <returns>Returns <i>true</i> if the cancel event has already been added, <i>false</i> otherwise.</returns>
        public bool Contains(CancelEvent evt)
        {
            foreach (Tuple <WaitHandle, bool, string> item in m_rgCancel)
            {
                if (item.Item1 == evt.m_hOriginalCancel)
                {
                    return(true);
                }
            }

            return(false);
        }
 /// <summary>
 /// Create a new Cancel Event and add another to this ones overrides.
 /// </summary>
 /// <param name="evtCancel">Specifies the Cancel Event to add to the overrides.</param>
 public CancelEvent(CancelEvent evtCancel)
 {
     m_hOriginalCancel = new EventWaitHandle(false, EventResetMode.ManualReset, m_strName);
     m_rgCancel.Add(new Tuple <WaitHandle, bool, string>(evtCancel.m_hOriginalCancel, false, evtCancel.Name));
     setHandles();
 }
 /// <summary>
 /// Check to see if the cancel event has already been added.
 /// </summary>
 /// <param name="evt">Specifies the cancel event to look for.</param>
 /// <returns>Returns <i>true</i> if the cancel event has already been added, <i>false</i> otherwise.</returns>
 public bool Contains(CancelEvent evt)
 {
     return(Contains(evt.m_hOriginalCancel));
 }
        /// <summary>
        /// The Bucketize method adds all values within a SimpleDatum to a new BucketCollection.
        /// </summary>
        /// <param name="strName">Specifies the name to use when writing status information.</param>
        /// <param name="nBucketCount">Specifies the number of Buckets to use.</param>
        /// <param name="sd">Specifies the SimpleDatum containing the data to add.</param>
        /// <param name="log">Specifies the output log.</param>
        /// <param name="evtCancel">Specifies the CancelEvent used to cancel the bucketizing process.</param>
        /// <param name="dfMin">Optionally, specifies a overall minimum to use in the BucketCollection, when missing this is calculated from the SimpleDatum.</param>
        /// <param name="dfMax">Optionally, specifies a overall maximum to use in the BucketCollection, when missing this is calculated from the SimpleDatum.</param>
        /// <returns></returns>
        public static BucketCollection Bucketize(string strName, int nBucketCount, SimpleDatum sd, Log log, CancelEvent evtCancel, double?dfMin = null, double?dfMax = null)
        {
            int       nIdx       = 0;
            int       nChannels  = sd.Channels;
            int       nCount     = sd.ItemCount / nChannels;
            int       nItemCount = sd.ItemCount;
            int       nOffset    = 0;
            Stopwatch sw         = new Stopwatch();

            sw.Start();

            // Calculate the min/max values if not already specified.
            if (!dfMin.HasValue || !dfMax.HasValue)
            {
                dfMin = double.MaxValue;
                dfMax = -double.MaxValue;

                for (int i = 0; i < nChannels; i++)
                {
                    for (int j = 0; j < nCount; j++)
                    {
                        double dfVal = sd.GetDataAtD(nOffset + j);
                        dfMin = Math.Min(dfMin.Value, dfVal);
                        dfMax = Math.Max(dfMax.Value, dfVal);
                        nIdx++;

                        if (sw.Elapsed.TotalMilliseconds > 1000)
                        {
                            if (evtCancel != null && evtCancel.WaitOne(0))
                            {
                                return(null);
                            }

                            double dfPct = (double)nIdx / (double)nItemCount;
                            log.WriteLine("Calculating min/max at " + dfPct.ToString("P") + "...");
                            sw.Restart();
                        }
                    }

                    nOffset += nCount;
                }
            }

            BucketCollection col = new BucketCollection(dfMin.Value, dfMax.Value, nBucketCount);

            nIdx    = 0;
            nOffset = 0;
            for (int i = 0; i < nChannels; i++)
            {
                for (int j = 0; j < nCount; j++)
                {
                    double dfVal = sd.GetDataAtD(nOffset + j);
                    col.Add(dfVal);
                    nIdx++;

                    if (sw.Elapsed.TotalMilliseconds > 1000)
                    {
                        if (evtCancel != null && evtCancel.WaitOne(0))
                        {
                            return(null);
                        }

                        double dfPct = (double)nIdx / (double)nItemCount;
                        log.WriteLine(strName + " at " + dfPct.ToString("P") + "...");
                        sw.Restart();
                    }
                }

                nOffset += nCount;
            }

            return(col);
        }
Beispiel #11
0
        /// <summary>
        /// Extract Tar data from a stream to a specified output directory.
        /// </summary>
        /// <param name="stream">Specifies the stream containing the Tar data to extract.</param>
        /// <param name="strOutputDir">Specifies the output directory.</param>
        /// <param name="evtCancel">Optionally, specifies the cancel event used to cancel the extraction (default = null).</param>
        /// <param name="log">Optionally, specifies the Log used to output status of the extraction (default = null).</param>
        /// <param name="nExpectedTotal">Optionally, specifies the expected total number of files (default = 0).</param>
        /// <param name="nIdx">Optionally, specifies an item index (default = 0).</param>
        /// <returns>Upon a successful extraction, the number of files extracted offset by the index is returned, or 0 on abort.</returns>
        public static int ExtractTar(Stream stream, string strOutputDir, CancelEvent evtCancel = null, Log log = null, int nExpectedTotal = 0, int nIdx = 0)
        {
            byte[]    rgBuffer   = new byte[500];
            bool      bDone      = false;
            int       nFileCount = 0;
            Stopwatch sw         = new Stopwatch();

            sw.Start();

            try
            {
                while (!bDone)
                {
                    stream.Read(rgBuffer, 0, 100);
                    string strName = Encoding.ASCII.GetString(rgBuffer).Trim('\0');

                    if (string.IsNullOrWhiteSpace(strName))
                    {
                        break;
                    }

                    stream.Seek(24, SeekOrigin.Current);
                    stream.Read(rgBuffer, 0, 12);

                    long lSize = Convert.ToInt64(Encoding.UTF8.GetString(rgBuffer, 0, 12).Trim('\0').Trim(), 8);

                    stream.Seek(376L, SeekOrigin.Current);

                    string strOutput = Path.Combine(strOutputDir, strName);
                    string strPath   = Path.GetDirectoryName(strOutput);

                    if (!Directory.Exists(strPath))
                    {
                        Directory.CreateDirectory(strPath);
                    }

                    if (!strName.EndsWith("/") && !strName.EndsWith("\\"))
                    {
                        if (sw.Elapsed.TotalMilliseconds > 1000)
                        {
                            if (log != null)
                            {
                                if (nExpectedTotal > 0)
                                {
                                    log.Progress = (double)(nIdx + nFileCount) / nExpectedTotal;
                                }

                                log.WriteLine("Extracting " + nFileCount.ToString("N0") + " files - '" + strName + "'...");
                            }

                            sw.Restart();
                        }

                        using (FileStream fstrm = File.Open(strOutput, FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            byte[] rgData = new byte[lSize];
                            stream.Read(rgData, 0, rgData.Length);
                            fstrm.Write(rgData, 0, rgData.Length);
                            nFileCount++;
                        }
                    }

                    long lPos    = stream.Position;
                    long lOffset = 512 - (lPos % 512);
                    if (lOffset == 512)
                    {
                        lOffset = 0;
                    }

                    stream.Seek(lOffset, SeekOrigin.Current);

                    if (evtCancel != null)
                    {
                        if (evtCancel.WaitOne(0))
                        {
                            return(0);
                        }
                    }
                }

                if (log != null)
                {
                    log.WriteLine("Extracted a total of " + nFileCount.ToString("N0") + " files.");
                }
            }
            catch (Exception excpt)
            {
                if (log != null)
                {
                    log.WriteError(excpt);
                }
                throw excpt;
            }

            return(nFileCount + nIdx);
        }