예제 #1
0
 private WorkThreadDictionary(Thread thread)
 {
     Contract.Requires <ArgumentNullException>(thread != null);
     g_pValues = new List <object>();
     g_pKeys   = new List <string>();
     ThreadUnit.SetObject(thread, this);
 }
예제 #2
0
 /// <summary>
 /// Изменить параметры линии проиводства
 /// </summary>
 /// <param name="threadUnit">Линия производства с измененными параметрами</param>
 public void ReplaceThreadUnit(ThreadUnit threadUnit)
 {
     for (int i = 0; i < ListThreadUnits.GetItemsCount(); i++)
     {
         if (ListThreadUnits[i].Uid == threadUnit.Uid)
         {
             ListThreadUnits[i] = threadUnit;
             break;
         }
     }
 }
예제 #3
0
        public static WorkThreadDictionary Get(Thread thread)
        {
            Contract.Requires <ArgumentNullException>(thread != null);
            object value = ThreadUnit.GetObject(thread);

            if (value == null || !(value is WorkThreadDictionary))
            {
                return(null);
            }
            return((WorkThreadDictionary)value);
        }
예제 #4
0
        /// <summary>
        /// Найти линию производства по номеру
        /// </summary>
        /// <param name="number">Номер линии производства</param>
        /// <returns>Линия производства</returns>
        public ThreadUnit FindThreadUnitByNumber(int number)
        {
            ThreadUnit res = null;

            foreach (ThreadUnit item in _listProductionThreads)
            {
                if (item.ThreadNumber == number)
                {
                    res = item;
                    break;
                }
            }

            return(res);
        }
예제 #5
0
        /// <summary>
        /// Найти линию производства по ID
        /// </summary>
        /// <param name="uid">ID линии производства</param>
        /// <returns>Линия производства</returns>
        public ThreadUnit FindThreadUnitByUid(int uid)
        {
            ThreadUnit res = null;

            foreach (ThreadUnit item in _listProductionThreads)
            {
                if (item.Uid == uid)
                {
                    res = item;
                    break;
                }
            }

            return(res);
        }
예제 #6
0
        /// <summary>
        /// Найти линию производства по ее наименованию
        /// </summary>
        /// <param name="name">Наименование линии производства</param>
        /// <returns>Линия производства</returns>
        public ThreadUnit FindThreadByName(string name)
        {
            ThreadUnit res = null;

            foreach (ThreadUnit unit in ListThreadUnits)
            {
                if (unit.Name == name)
                {
                    res = unit;
                    break;
                }
            }

            return(res);
        }
예제 #7
0
        /// <summary>
        /// Получить максимальный номер производственной линии
        /// </summary>
        /// <returns></returns>
        public int GetLastThreadNumber()
        {
            int res = 0;

            for (int i = 0; i < ListThreadUnits.GetItemsCount(); i++)
            {
                ThreadUnit thread = ListThreadUnits[i];
                if (thread.Uid > res)
                {
                    res = thread.ThreadNumber;
                }
                Debug.WriteLine(res);
            }

            return(res);
        }
예제 #8
0
        /// <summary>
        /// Обработка события изменения индекса выбранной линии производства
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void threadsList_SelectedValueChanged(object sender, EventArgs e)
        {
            ThreadUnit thread = _configuration.FindThreadByName(threadsList.Text);

            textThreadUid.Text            = thread.Uid.ToString();
            textThreadNumber.Text         = thread.ThreadNumber.ToString();
            textThreadName.Text           = thread.Name;
            textThreadStart.Text          = "[" + thread.StartPos.PosX + ":" + thread.StartPos.PosY + "]";
            textThreadFinish.Text         = "[" + thread.FinishPos.PosX + ":" + thread.FinishPos.PosY + "]";
            textThreadDirection.Text      = thread.Direction == ThreadDirection.Horizontal ? "Горизонтально" : "Вертикально";
            checkThreadStopAtEnds.Checked = thread.StopOnEnds;

            _statusBarMessage = $"Выбрана линия производства: [{thread.Uid}] {thread.Name}";
            statusBar1.Text   = _statusBarMessage;

            // UpdateSignalsList(thread.ThreadNumber);
        }
예제 #9
0
        public object FindElementByUid(int uid, UnitsTypes type)
        {
            object res = null;

            switch (type)
            {
            case UnitsTypes.Thread:
                ThreadUnit t = FindThreadUnitByUid(uid);
                res = t;
                break;

            case UnitsTypes.DataBlock:
                DataBlockUnit d = FindDataBlock(uid);
                res = d;
                break;
            }

            return(res);
        }
예제 #10
0
        /// <summary>
        /// Добавить новую нить
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addThreadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddThread addThread = new AddThread();

            addThread.Mode = FormMode.Add;
            addThread.ShowDialog();
            if (addThread.Result == DialogResult.OK)
            {
                ThreadUnit thread = addThread.Thread;
                _configuration.ListThreadUnits.Add(thread);

                UpdateThreadsList();
                _statusBarMessage = $"Добавлена новая нить [{thread.Name}]";
                statusBar1.Text   = _statusBarMessage;
                _modified         = true;
            }

            addThread.Dispose();
        }
예제 #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            Result = DialogResult.None;

            if (!String.IsNullOrEmpty(textName.Text))
            {
                Result = DialogResult.OK;
                Thread = new ThreadUnit();

                // Обработка введенных пользователем значений и заполнение полей объекта
                Thread.Name         = textName.Text ?? "";
                Thread.Uid          = string.IsNullOrEmpty(textUid.Text) ? 0 : int.Parse(textUid.Text);
                Thread.ThreadNumber = string.IsNullOrEmpty(textNumber.Text) ? 0 : int.Parse(textNumber.Text);
                Thread.PrevThread   = string.IsNullOrEmpty(textPrev.Text) ? 0 : int.Parse(textPrev.Text);
                Thread.NextThread   = string.IsNullOrEmpty(textNext.Text) ? 0 : int.Parse(textNext.Text);
                Thread.StopOnEnds   = checkStopAtEnds.Checked;

                Thread.Direction = comboDirection.SelectedIndex == 0
                    ? ThreadDirection.Horizontal
                    : ThreadDirection.Vertical;

                double startX = string.IsNullOrEmpty(textStartX.Text)
                    ? 0
                    : double.Parse(textStartX.Text.Replace(".", ","));
                double startY = string.IsNullOrEmpty(textStartY.Text)
                    ? 0
                    : double.Parse(textStartY.Text.Replace(".", ","));
                double finishX = string.IsNullOrEmpty(textFinishX.Text)
                    ? 0
                    : double.Parse(textFinishX.Text.Replace(".", ","));
                double finishY = string.IsNullOrEmpty(textFinishY.Text)
                    ? 0
                    : double.Parse(textFinishY.Text.Replace(".", ","));
                Point startPos  = new Point(startX, startY);
                Point finishPos = new Point(finishX, finishY);
                Thread.StartPos  = startPos;
                Thread.FinishPos = finishPos;
            }

            // Close();
        }
예제 #12
0
        /// <summary>
        /// Изменить параметры линии производства
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void editThreadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddThread  addThread = new AddThread();
            ThreadUnit unit      = _configuration.FindThreadByName(threadsList.Text);

            addThread.Mode   = FormMode.Edit;
            addThread.Thread = unit;
            addThread.EditThread();
            if (addThread.Result == DialogResult.OK)
            {
                ThreadUnit thread = addThread.Thread;
                _configuration.ReplaceThreadUnit(thread);

                UpdateThreadsList();
                _statusBarMessage = $"Изменены параметры нити [{thread.Name}]";
                statusBar1.Text   = _statusBarMessage;
                _modified         = true;
            }

            addThread.Dispose();
        }
예제 #13
0
        public virtual async Task <WorkResult <HashFile> > RunAsync(HashFile workunit, IProgress <IWorkProgress <HashFile> > progress = null, CancellationToken token = default(CancellationToken))
        {
            Task       t  = null;
            ThreadUnit tu = new ThreadUnit();

            try
            {
                if (workunit.File == null)
                {
                    return(new WorkResult <HashFile>(WorkResultStatus.Error, "File not found"));
                }
                FileSystemResult <Stream> fs = await workunit.File.OpenReadAsync();

                if (fs.Status != Status.Ok)
                {
                    return(new WorkResult <HashFile>(WorkResultStatus.Error, fs.Error));
                }
                BasicWorkProgress <HashFile> progressdata = new BasicWorkProgress <HashFile>
                {
                    Command = this,
                    Unit    = workunit
                };
                tu.WorkUnit     = workunit;
                tu.FileSize     = workunit.File.Size;
                tu.Buffer       = new byte[2][];
                tu.Buffer[0]    = new byte[BUFFER_SIZE];
                tu.Buffer[1]    = new byte[BUFFER_SIZE];
                tu.BufferNumber = 0;
                t = Task.Factory.StartNew(HashWorker, tu, token, TaskCreationOptions.LongRunning, TaskScheduler.Current);
                long read = 0;
                do
                {
                    try
                    {
                        tu.CurrentSize = await fs.Result.ReadAsync(tu.Buffer[tu.BufferNumber], 0, BUFFER_SIZE, token);

                        read += tu.CurrentSize;
                        if (token.IsCancellationRequested)
                        {
                            token.ThrowIfCancellationRequested();
                        }
                        tu.WorkerAutoResetEvent.Set();
                        if (progress != null)
                        {
                            progressdata.Progress = (double)read * 100 / tu.FileSize;
                            progress.Report(progressdata);
                        }
                        if (tu.Abort)
                        {
                            return(new WorkResult <HashFile>(WorkResultStatus.Error, tu.Error));
                        }
                        tu.MainAutoResetEvent.WaitOne();
                        tu.BufferNumber ^= 1;
                    }
                    catch (OperationCanceledException)
                    {
                        tu.CancelWorker();
                        return(new WorkResult <HashFile>(WorkResultStatus.Canceled, "Operation Canceled"));
                    }
                    catch (Exception e)
                    {
                        tu.CancelWorker();
                        return(new WorkResult <HashFile>(WorkResultStatus.Error, e.Message));
                    }
                } while (tu.CurrentSize != 0);
                if (tu.Abort)
                {
                    return(new WorkResult <HashFile>(WorkResultStatus.Error, tu.Error));
                }
                tu.MainAutoResetEvent.WaitOne();
                return(new WorkResult <HashFile>(tu.WorkUnit));
            }
            catch (Exception e)
            {
                if (t != null)
                {
                    tu.CancelWorker();
                }
                return(new WorkResult <HashFile>(WorkResultStatus.Error, e.Message));
            }
        }
예제 #14
0
        private static void HashWorker(object f)
        {
            ThreadUnit tu     = (ThreadUnit)f;
            IntPtr     handle = Init((int)tu.WorkUnit.Types, tu.FileSize);

            if (handle == IntPtr.Zero)
            {
                tu.WorkerError("Unable to Init Hash (failed Init)");
                return;
            }
            do
            {
                tu.WorkerAutoResetEvent.WaitOne();
                if (tu.Abort)
                {
                    tu.MainAutoResetEvent.Set();
                    return;
                }
                int bufferposition = tu.BufferNumber;
                int size           = tu.CurrentSize;
                tu.MainAutoResetEvent.Set();
                try
                {
                    if (size != 0)
                    {
                        Update(handle, tu.Buffer[bufferposition], size);
                    }
                    else
                    {
                        byte[] returnhash = new byte[16 + 4 + 16 + 20];
                        Finish(handle, returnhash);
                        Dictionary <HashTypes, byte[]> hashes = new Dictionary <HashTypes, byte[]>();
                        int pos = 0;
                        if ((tu.WorkUnit.Types & HashTypes.ED2K) == HashTypes.ED2K)
                        {
                            byte[] buf = new byte[16];
                            Array.Copy(returnhash, pos, buf, 0, 16);
                            hashes.Add(HashTypes.ED2K, buf);
                            pos += 16;
                        }
                        if ((tu.WorkUnit.Types & HashTypes.CRC) == HashTypes.CRC)
                        {
                            byte[] buf = new byte[4];
                            Array.Copy(returnhash, pos, buf, 0, 4);
                            hashes.Add(HashTypes.CRC, buf);
                            pos += 4;
                        }
                        if ((tu.WorkUnit.Types & HashTypes.MD5) == HashTypes.MD5)
                        {
                            byte[] buf = new byte[16];
                            Array.Copy(returnhash, pos, buf, 0, 16);
                            hashes.Add(HashTypes.MD5, buf);
                            pos += 4;
                        }
                        if ((tu.WorkUnit.Types & HashTypes.SHA1) == HashTypes.SHA1)
                        {
                            byte[] buf = new byte[20];
                            Array.Copy(returnhash, pos, buf, 0, 20);
                            hashes.Add(HashTypes.SHA1, buf);
                        }
                        tu.WorkUnit.Result = hashes;
                        tu.MainAutoResetEvent.Set();
                        return;
                    }
                }
                catch (Exception e)
                {
                    tu.WorkerError(e.Message);
                }
            } while (tu.CurrentSize != 0);
        }
예제 #15
0
        public static void HashWorker(object f)
        {
            ThreadUnit tu = (ThreadUnit)f;
            long       ed2kchunks;
            long       lastpart;

            byte[] ED2KHashBuffer = null;
            Dictionary <HashTypes, byte[]> hashes = new Dictionary <HashTypes, byte[]>();
            MD4   md4      = null;
            MD5   md5      = null;
            SHA1  sha1     = null;
            Crc32 crc32    = null;
            long  position = 0;

            if ((tu.WorkUnit.Types & HashTypes.ED2K) == HashTypes.ED2K)
            {
                ed2kchunks = tu.FileSize / ED2K_CHUNK_SIZE;
                lastpart   = tu.FileSize % ED2K_CHUNK_SIZE;
                if (lastpart > 0)
                {
                    ed2kchunks++;
                }
                ED2KHashBuffer = new byte[ed2kchunks << 4];
                md4            = MD4.Create();
            }
            if ((tu.WorkUnit.Types & HashTypes.MD5) == HashTypes.MD5)
            {
                md5 = MD5.Create();
            }
            if ((tu.WorkUnit.Types & HashTypes.SHA1) == HashTypes.SHA1)
            {
                sha1 = SHA1.Create();
            }
            if ((tu.WorkUnit.Types & HashTypes.CRC) == HashTypes.CRC)
            {
                crc32 = new Crc32();
            }
            do
            {
                tu.WorkerAutoResetEvent.WaitOne();
                if (tu.Abort)
                {
                    tu.MainAutoResetEvent.Set();
                    return;
                }

                int  buffernumber = tu.BufferNumber;
                long size         = tu.CurrentSize;
                tu.MainAutoResetEvent.Set();
                try
                {
                    if (size != 0)
                    {
                        long bufferpos   = 0;
                        long current_md4 = position / ED2K_CHUNK_SIZE;
                        long till_md4    = (position + size) / ED2K_CHUNK_SIZE;
                        for (long x = current_md4; x <= till_md4; x++)
                        {
                            long init_size = ED2K_CHUNK_SIZE - (position % ED2K_CHUNK_SIZE);
                            if (init_size > size)
                            {
                                init_size = size;
                            }
                            if (init_size == 0)
                            {
                                break;
                            }
                            if ((tu.WorkUnit.Types & HashTypes.ED2K) == HashTypes.ED2K)
                            {
                                md4.TransformBlock(tu.Buffer[buffernumber], (int)bufferpos, (int)init_size, tu.Buffer[buffernumber], (int)bufferpos);
                            }
                            if ((tu.WorkUnit.Types & HashTypes.CRC) == HashTypes.CRC)
                            {
                                crc32.TransformBlock(tu.Buffer[buffernumber], (int)bufferpos, (int)init_size, tu.Buffer[buffernumber], (int)bufferpos);
                            }
                            if ((tu.WorkUnit.Types & HashTypes.MD5) == HashTypes.MD5)
                            {
                                md4.TransformBlock(tu.Buffer[buffernumber], (int)bufferpos, (int)init_size, tu.Buffer[buffernumber], (int)bufferpos);
                            }
                            if ((tu.WorkUnit.Types & HashTypes.SHA1) == HashTypes.SHA1)
                            {
                                sha1.TransformBlock(tu.Buffer[buffernumber], (int)bufferpos, (int)init_size, tu.Buffer[buffernumber], (int)bufferpos);
                            }
                            bufferpos += init_size;
                            position  += init_size;
                            size      -= init_size;
                            if (((tu.WorkUnit.Types & HashTypes.ED2K) == HashTypes.ED2K) && (position % ED2K_CHUNK_SIZE) == 0)
                            {
                                md4.TransformFinalBlock(tu.Buffer[buffernumber], (int)bufferpos, 0);
                                Array.Copy(md4.Hash, 0, ED2KHashBuffer, x * 16, 16);
                                md4 = MD4.Create();
                            }
                        }
                    }
                    else
                    {
                        if ((tu.WorkUnit.Types & HashTypes.ED2K) == HashTypes.ED2K)
                        {
                            long x = position / ED2K_CHUNK_SIZE;
                            if ((position % ED2K_CHUNK_SIZE) != 0)
                            {
                                md4.TransformFinalBlock(tu.Buffer[buffernumber], 0, 0);
                                Array.Copy(md4.Hash, 0, ED2KHashBuffer, x * 16, 16);
                            }
                            if (position > ED2K_CHUNK_SIZE)
                            {
                                if ((position % ED2K_CHUNK_SIZE) > 0)
                                {
                                    x++;
                                }
                                md4 = MD4.Create();
                                md4.ComputeHash(ED2KHashBuffer, 0, (int)x * 16);
                                hashes[HashTypes.ED2K] = md4.Hash;
                            }
                            else
                            {
                                hashes[HashTypes.ED2K] = new byte[16];
                                Array.Copy(ED2KHashBuffer, 0, hashes[HashTypes.ED2K], 0, 16);
                            }
                        }
                        if ((tu.WorkUnit.Types & HashTypes.CRC) == HashTypes.CRC)
                        {
                            crc32.TransformFinalBlock(tu.Buffer[buffernumber], 0, 0);
                            hashes[HashTypes.CRC] = crc32.Hash;
                        }
                        if ((tu.WorkUnit.Types & HashTypes.MD5) == HashTypes.MD5)
                        {
                            md5.TransformFinalBlock(tu.Buffer[buffernumber], 0, 0);
                            hashes[HashTypes.MD5] = md5.Hash;
                        }
                        if ((tu.WorkUnit.Types & HashTypes.SHA1) == HashTypes.SHA1)
                        {
                            sha1.TransformFinalBlock(tu.Buffer[buffernumber], 0, 0);
                            hashes[HashTypes.SHA1] = sha1.Hash;
                        }
                        tu.WorkUnit.Result = hashes;
                        tu.MainAutoResetEvent.Set();
                        return;
                    }
                }
                catch (Exception e)
                {
                    tu.WorkerError(e.Message);
                }
            } while (tu.CurrentSize != 0);
        }
예제 #16
0
        /// <summary>
        /// Заполнить производственные линии объектами из конфигурационного файла
        /// </summary>
        public void FillProductionThreads()
        {
            // Обходим список нитей и для каждой нити обходим списки объектов,
            // которые могут находиться на нити.

            for (int t = 0; t < ListThreadUnits.GetItemsCount(); t++)
            {
                ThreadUnit       thread           = ListThreadUnits[t];
                ProductionThread productionThread = new ProductionThread();

                // Обходим список объектов Рольганг
                for (int i = 0; i < ListRollgangUnits.GetItemsCount(); i++)
                {
                    RollgangUnit rollgang = ListRollgangUnits[i];
                    if (rollgang.ThreadNumber == thread.ThreadNumber)
                    {
                        productionThread.ListRollgangUnits.Add(rollgang);
                    }
                }

                // Обходим список объектов Метка
                for (int i = 0; i < ListLabelUnits.GetItemsCount(); i++)
                {
                    LabelUnit label = ListLabelUnits[i];
                    if (label.ThreadNumber == thread.ThreadNumber)
                    {
                        productionThread.ListLabelUnits.Add(label);
                    }
                }

                // Обходим список объектов Датчик
                for (int i = 0; i < ListSensorUnits.GetItemsCount(); i++)
                {
                    SensorUnit sensor = ListSensorUnits[i];
                    if (sensor.ThreadNumber == thread.ThreadNumber)
                    {
                        productionThread.ListSensorUnits.Add(sensor);
                    }
                }

                // Обходим список объектов Упор
                for (int i = 0; i < ListStopperUnits.GetItemsCount(); i++)
                {
                    StopperUnit stopper = ListStopperUnits[i];
                    if (stopper.ThreadNumber == thread.ThreadNumber)
                    {
                        productionThread.ListStopperUnits.Add(stopper);
                    }
                }

                // Обходим список объектов АгрегатЛинейногоПеремещения
                for (int i = 0; i < ListLinearDisplacementUnits.GetItemsCount(); i++)
                {
                    LinearDisplacementUnit linear = ListLinearDisplacementUnits[i];
                    if (linear.ThreadNumber == thread.ThreadNumber)
                    {
                        productionThread.ListLinearDisplacementUnits.Add(linear);
                    }
                }

                // Обходим список объектов УдалениеЗастрявших
                for (int i = 0; i < ListDeleterUnits.GetItemsCount(); i++)
                {
                    DeleterUnit deleter = ListDeleterUnits[i];
                    if (deleter.ThreadNumber == thread.ThreadNumber)
                    {
                        productionThread.ListDeleterUnits.Add(deleter);
                    }
                }

                // Обходим список объектов Клеть
                for (int i = 0; i < ListCagesUnits.GetItemsCount(); i++)
                {
                    CageUnit cage = ListCagesUnits[i];
                    if (cage.ThreadNumber == thread.ThreadNumber)
                    {
                        productionThread.ListCagesUnits.Add(cage);
                    }
                }

                // Обходим список объектов ТехУзел
                for (int i = 0; i < ListTechnicalUnits.GetItemsCount(); i++)
                {
                    TechnicalUnit tech = ListTechnicalUnits[i];
                    if (tech.ThreadNumber == thread.ThreadNumber)
                    {
                        productionThread.ListTechnicalUnits.Add(tech);
                    }
                }

                productionThread.Uid          = thread.Uid;
                productionThread.Name         = thread.Name;
                productionThread.ThreadNumber = thread.ThreadNumber;
                productionThread.Direction    = thread.Direction;
                productionThread.StartPos     = thread.StartPos;
                productionThread.FinishPos    = thread.FinishPos;
                productionThread.StopOnEnds   = thread.StopOnEnds;
                productionThread.PrevThread   = thread.PrevThread;
                productionThread.NextThread   = thread.NextThread;

                _listProductionThreads.Add(productionThread);
            }
        }