コード例 #1
0
            internal BaseWorkerGroup(InternalController controller, int numWorkers)
            {
                this.numWorkers = numWorkers;
                this.schedulers = new Scheduler[numWorkers];

                if (controller.Configuration.UseBroadcastWakeup)
                {
                    this.useBroadcastWakeup = true;
                    this.wakeUpEvent        = new EventCount();
                }
                else
                {
                    this.useBroadcastWakeup = false;
                }

                for (int i = 0; i < numWorkers; ++i)
                {
                    switch (System.Environment.OSVersion.Platform)
                    {
                    case PlatformID.Win32NT:
                        this.schedulers[i] = new PinnedScheduler(string.Format("Naiad worker {0}", i), i, controller);
                        break;

                    default:
                        this.schedulers[i] = new Scheduler(string.Format("Naiad worker {0}", i), i, controller);
                        break;
                    }
                }
            }
コード例 #2
0
        void SaveToFileBody(string FileName)
        {
            try
            {
                XmlTextWriter textWritter = new XmlTextWriter(FileName, Encoding.UTF8);
                textWritter.WriteStartDocument();
                textWritter.WriteStartElement("Setup");
                textWritter.WriteEndElement();
                textWritter.Close();
            }
            catch
            {
                MessageBox.Show("Не удалось создать XML-файл!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            XmlDocument document = new XmlDocument();

            try
            {
                document.Load(FileName);
            }
            catch
            {
                MessageBox.Show("Не удалось создать XML-файл!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            #region Digits
            XmlNode element = document.CreateElement("Digits");
            document.DocumentElement.AppendChild(element);              // указываем родителя

            XmlAttribute attribute = document.CreateAttribute("Count"); // создаём атрибут
            attribute.Value = digitPlates.Count.ToString();
            element.Attributes.Append(attribute);                       // добавляем атрибут
            #endregion

            #region DigitN
            for (int i = 0; i < digitPlates.Count; i++)
            {
                element = document.CreateElement("Digit" + (i + 1).ToString());
                document.DocumentElement.AppendChild(element);

                attribute       = document.CreateAttribute("Type");     // создаём атрибут
                attribute.Value = digitPlates[i].DigitType.ToString();
                element.Attributes.Append(attribute);                   // добавляем атрибут

                attribute       = document.CreateAttribute("Invert");   // создаём атрибут
                attribute.Value = digitPlates[i].Invert.ToString();
                element.Attributes.Append(attribute);                   // добавляем атрибут

                attribute       = document.CreateAttribute("Addr");     // создаём атрибут
                attribute.Value = "0x" + digitPlates[i].StartAddr.ToString("X4");
                element.Attributes.Append(attribute);                   // добавляем атрибут

                attribute       = document.CreateAttribute("EventPos"); // создаём атрибут
                attribute.Value = "0x" + digitPlates[i].EventStructAddr.ToString("X4");
                element.Attributes.Append(attribute);                   // добавляем атрибут

                attribute       = document.CreateAttribute("Title");    // создаём атрибут
                attribute.Value = digitPlates[i].Titl.ToString();
                element.Attributes.Append(attribute);                   // добавляем атрибут

                attribute       = document.CreateAttribute("UseMask");  // создаём атрибут
                attribute.Value = digitPlates[i].UseMask.ToString();
                element.Attributes.Append(attribute);                   // добавляем атрибут

                for (int i2 = 0; i2 < 16; i2++)
                {
                    attribute       = document.CreateAttribute("Line" + (i2).ToString()); // создаём атрибут
                    attribute.Value = digitPlates[i].DigitNames[i2];
                    element.Attributes.Append(attribute);                                 // добавляем атрибут
                }
            }
            #endregion

            #region MeasureParams
            element = document.CreateElement("MeasureParams");
            document.DocumentElement.AppendChild(element);       // указываем родителя

            attribute       = document.CreateAttribute("Count"); // создаём атрибут
            attribute.Value = MeasureParams.Count.ToString();
            element.Attributes.Append(attribute);                // добавляем атрибут
            #endregion

            #region MeasureParamN
            for (int i = 0; i < measureParams.Count; i++)
            {
                element = document.CreateElement("MeasureParam" + (i + 1).ToString());
                document.DocumentElement.AppendChild(element);

                attribute       = document.CreateAttribute("Name");   // создаём атрибут
                attribute.Value = measureParams[i].ParameterName;
                element.Attributes.Append(attribute);                 // добавляем атрибут

                attribute       = document.CreateAttribute("Addr");   // создаём атрибут
                attribute.Value = "0x" + measureParams[i].Addr.ToString("X4");
                element.Attributes.Append(attribute);                 // добавляем атрибут

                attribute       = document.CreateAttribute("Format"); // создаём атрибут
                attribute.Value = measureParams[i].Format.ToString();
                element.Attributes.Append(attribute);                 // добавляем атрибут
            }
            #endregion

            #region EventCodes
            element = document.CreateElement("EventCodes");
            document.DocumentElement.AppendChild(element);       // указываем родителя

            attribute       = document.CreateAttribute("Count"); // создаём атрибут
            attribute.Value = EventCodes.Count.ToString();
            element.Attributes.Append(attribute);                // добавляем атрибут
            #endregion

            #region EvenCodeN
            ICollection keys       = eventCodes.Keys;
            int         eventindex = 0;
            foreach (string s in keys)
            {
                element = document.CreateElement("EventCode" + (++eventindex).ToString());
                document.DocumentElement.AppendChild(element);

                attribute       = document.CreateAttribute("Code"); // создаём атрибут
                attribute.Value = s;
                element.Attributes.Append(attribute);               // добавляем атрибут

                attribute       = document.CreateAttribute("Name"); // создаём атрибут
                attribute.Value = eventCodes[s].ToString();
                element.Attributes.Append(attribute);               // добавляем атрибут
            }
            #endregion

            #region OtherParams
            element = document.CreateElement("OtherParams");
            document.DocumentElement.AppendChild(element);                   // указываем родителя

            attribute       = document.CreateAttribute("StartMeasureAddr");  // создаём атрибут
            attribute.Value = "0x" + StartMeasureAddr.ToString("X4");
            element.Attributes.Append(attribute);                            // добавляем атрибут

            attribute       = document.CreateAttribute("EventCodeAddr");     // создаём атрибут
            attribute.Value = "0x" + EventCodeAddr.ToString("X4");
            element.Attributes.Append(attribute);                            // добавляем атрибут

            attribute       = document.CreateAttribute("EventTimeAddr");     // создаём атрибут
            attribute.Value = "0x" + EventTimeAddr.ToString("X4");
            element.Attributes.Append(attribute);                            // добавляем атрибут

            attribute       = document.CreateAttribute("EventBlockCount");   // создаём атрибут
            attribute.Value = "0x" + EventBlockCount.ToString("X4");
            element.Attributes.Append(attribute);                            // добавляем атрибут

            attribute       = document.CreateAttribute("LoadEventAddr");     // создаём атрибут
            attribute.Value = "0x" + LoadEventAddr.ToString("X4");
            element.Attributes.Append(attribute);                            // добавляем атрибут

            attribute       = document.CreateAttribute("LoadEventDataAddr"); // создаём атрибут
            attribute.Value = "0x" + LoadEventDataAddr.ToString("X4");
            element.Attributes.Append(attribute);                            // добавляем атрибут

            attribute       = document.CreateAttribute("EventCount");        // создаём атрибут
            attribute.Value = EventCount.ToString();
            element.Attributes.Append(attribute);                            // добавляем атрибут

            if (EnaDigits)
            {
                attribute       = document.CreateAttribute("EnaDigits"); // создаём атрибут
                attribute.Value = "1";
                element.Attributes.Append(attribute);                    // добавляем атрибут
            }

            if (EnaDirectAccess)
            {
                attribute       = document.CreateAttribute("EnaDirectAccess"); // создаём атрибут
                attribute.Value = "1";
                element.Attributes.Append(attribute);                          // добавляем атрибут
            }

            if (EnaFloatDirectAccess)
            {
                attribute       = document.CreateAttribute("EnaFloatDirectAccess"); // создаём атрибут
                attribute.Value = "1";
                element.Attributes.Append(attribute);                               // добавляем атрибут
            }

            if (EnaScope)
            {
                attribute       = document.CreateAttribute("EnaScope"); // создаём атрибут
                attribute.Value = "1";
                element.Attributes.Append(attribute);                   // добавляем атрибут
            }

            if (EnaLoadSyms)
            {
                attribute       = document.CreateAttribute("EnaLoadSyms"); // создаём атрибут
                attribute.Value = "1";
                element.Attributes.Append(attribute);                      // добавляем атрибут
            }

            if (EnaEventLog)
            {
                attribute       = document.CreateAttribute("EnaEventLog"); // создаём атрибут
                attribute.Value = "1";
                element.Attributes.Append(attribute);                      // добавляем атрибут
            }

            if (EnaJog)
            {
                attribute       = document.CreateAttribute("EnaJog"); // создаём атрибут
                attribute.Value = "1";
                element.Attributes.Append(attribute);                 // добавляем атрибут
            }

            if (EnaAngle)
            {
                attribute       = document.CreateAttribute("EnaAngle"); // создаём атрибут
                attribute.Value = "1";
                element.Attributes.Append(attribute);                   // добавляем атрибут
            }

            if (EnaForceDig)
            {
                attribute       = document.CreateAttribute("EnaForceDig"); // создаём атрибут
                attribute.Value = "1";
                element.Attributes.Append(attribute);                      // добавляем атрибут
            }


            #endregion

            #region Warnings
            element = document.CreateElement("Warnings");
            document.DocumentElement.AppendChild(element);       // указываем родителя

            attribute       = document.CreateAttribute("Count"); // создаём атрибут
            attribute.Value = warningParams.Count.ToString();
            element.Attributes.Append(attribute);                // добавляем атрибут
            #endregion

            #region WarningN
            for (int i = 0; i < warningParams.Count; i++)
            {
                element = document.CreateElement("Warning" + (i + 1).ToString());
                document.DocumentElement.AppendChild(element);


                attribute       = document.CreateAttribute("Addr"); // создаём атрибут
                attribute.Value = "0x" + warningParams[i].EventPosAddr.ToString("X4");
                element.Attributes.Append(attribute);               // добавляем атрибут


                attribute       = document.CreateAttribute("Title"); // создаём атрибут
                attribute.Value = warningParams[i].Titl.ToString();
                element.Attributes.Append(attribute);                // добавляем атрибут


                for (int i2 = 0; i2 < 16; i2++)
                {
                    attribute       = document.CreateAttribute("Line" + (i2).ToString()); // создаём атрибут
                    attribute.Value = warningParams[i].Names[i2];
                    element.Attributes.Append(attribute);                                 // добавляем атрибут
                }
            }
            #endregion

            #region Alarms
            element = document.CreateElement("Alarms");
            document.DocumentElement.AppendChild(element);       // указываем родителя

            attribute       = document.CreateAttribute("Count"); // создаём атрибут
            attribute.Value = alarmParams.Count.ToString();
            element.Attributes.Append(attribute);                // добавляем атрибут
            #endregion

            #region AlarmN
            for (int i = 0; i < alarmParams.Count; i++)
            {
                element = document.CreateElement("Alarm" + (i + 1).ToString());
                document.DocumentElement.AppendChild(element);


                attribute       = document.CreateAttribute("Addr"); // создаём атрибут
                attribute.Value = "0x" + alarmParams[i].EventPosAddr.ToString("X4");
                element.Attributes.Append(attribute);               // добавляем атрибут


                attribute       = document.CreateAttribute("Title"); // создаём атрибут
                attribute.Value = alarmParams[i].Titl.ToString();
                element.Attributes.Append(attribute);                // добавляем атрибут


                for (int i2 = 0; i2 < 16; i2++)
                {
                    attribute       = document.CreateAttribute("Line" + (i2).ToString()); // создаём атрибут
                    attribute.Value = alarmParams[i].Names[i2];
                    element.Attributes.Append(attribute);                                 // добавляем атрибут
                }
            }
            #endregion

            #region Readys
            element = document.CreateElement("Readys");
            document.DocumentElement.AppendChild(element);       // указываем родителя

            attribute       = document.CreateAttribute("Count"); // создаём атрибут
            attribute.Value = readyParams.Count.ToString();
            element.Attributes.Append(attribute);                // добавляем атрибут
            #endregion

            #region ReadyN
            for (int i = 0; i < readyParams.Count; i++)
            {
                element = document.CreateElement("Ready" + (i + 1).ToString());
                document.DocumentElement.AppendChild(element);


                attribute       = document.CreateAttribute("Addr"); // создаём атрибут
                attribute.Value = "0x" + readyParams[i].EventPosAddr.ToString("X4");
                element.Attributes.Append(attribute);               // добавляем атрибут


                attribute       = document.CreateAttribute("Title"); // создаём атрибут
                attribute.Value = readyParams[i].Titl.ToString();
                element.Attributes.Append(attribute);                // добавляем атрибут


                for (int i2 = 0; i2 < 16; i2++)
                {
                    attribute       = document.CreateAttribute("Line" + (i2).ToString()); // создаём атрибут
                    attribute.Value = readyParams[i].Names[i2];
                    element.Attributes.Append(attribute);                                 // добавляем атрибут
                }
            }
            #endregion

            timeConfig.AppendTimeXMLNode(document);

            try
            {
                document.Save(FileName);
            }
            catch
            {
                MessageBox.Show("Не удалось создать XML-файл!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
コード例 #3
0
ファイル: Networking.cs プロジェクト: omidm/naiad
        //TOCHECK: config is passed in but inside the method we use this.Controller.Configuration a lot
        internal TcpNetworkChannel(int id, InternalController controller, Configuration config)
        {
            this.id = id;
            this.Controller = controller;

            this.localProcessID = this.Controller.Configuration.ProcessID;

            this.graphmailboxes = new List<List<List<UntypedMailbox>>>();

            this.connections = new List<ConnectionState>();

            this.sendConnectionCountdown = new CountdownEvent(1);
            this.recvConnectionCountdown = new CountdownEvent(1);

            this.shutdownRecvCountdown = new CountdownEvent(1);
            this.shutdownSendCountdown = new CountdownEvent(1);

            this.startupRecvCountdown = new CountdownEvent(1);

            this.startCommunicatingEvent = new ManualResetEvent(false);

            if (controller.Configuration.UseNetworkBroadcastWakeup)
            {
                this.useBroadcastWakeup = true;
                this.wakeUpEvent = new EventCount();
            }
            else
            {
                this.useBroadcastWakeup = false;
                this.wakeUpEvent = null;
            }

            this.broadcastSequenceNumber = 1;

            // UDP broadcast setup.
            if (this.Controller.Configuration.Broadcast == Configuration.BroadcastProtocol.UdpOnly
            || this.Controller.Configuration.Broadcast == Configuration.BroadcastProtocol.TcpUdp)
            {

                this.udpClient = new UdpClient(new IPEndPoint(this.Controller.Configuration.Endpoints[this.Controller.Configuration.ProcessID].Address, this.Controller.Configuration.BroadcastAddress.Port));
                
                IPEndPoint multicastGroupEndpoint = this.Controller.Configuration.BroadcastAddress;
                byte[] addrbytes = multicastGroupEndpoint.Address.GetAddressBytes();

                Logging.Progress("Configuring UDP broadcast channel using address {0}", multicastGroupEndpoint);

                if (this.Controller.Configuration.ProcessID != 0)
                {
                    if ((addrbytes[0] & 0xF0) == 224)
                    {
                        //Console.WriteLine("Multicast!");
                        this.udpClient.JoinMulticastGroup(multicastGroupEndpoint.Address);
                    }
                    else
                    {
                        //Console.WriteLine("Broadcast?");
                    }
                    Thread udpclientThread = new Thread(() => this.UdpReceiveThread(multicastGroupEndpoint));
                    udpclientThread.IsBackground = true;
                    udpclientThread.Start();
                }
                else
                {
                    if ((addrbytes[0] & 0xF0) == 224)
                    {
                        //Console.WriteLine("Multicast!");
                        this.udpClient.Connect(multicastGroupEndpoint);
                    }
                    else
                    {
                        //Console.WriteLine("Broadcast?");
                        this.udpClient.Connect(multicastGroupEndpoint);
                        this.udpClient.EnableBroadcast = true;
                    }
                }
            }
 
            this.sendPageSize = this.Controller.Configuration.SendPageSize;

            for (int i = 0; i < this.Controller.Configuration.Endpoints.Length; ++i)
                if (i != this.Controller.Configuration.ProcessID)
                    this.AddEndPointOutgoing(i, this.Controller.Configuration.Endpoints[i]);

            this.MAX_SEND_SIZE = 32 * this.sendPageSize;

            this.globalPool = new BoundedBufferPool2<byte>(this.sendPageSize, this.Controller.Configuration.SendPageCount);
        }
コード例 #4
0
 public void Setup()
 {
     _sut = new EventCount();
 }
コード例 #5
0
 protected override void Arrange()
 {
     Sut = new EventCount();
 }