예제 #1
0
        public void TestNonParameterConstructorByTypeName()
        {
            IObjectBuilder creator = new TypeCreator();
            ITestType      actual  = creator.BuildUp <ITestType>(typeof(TestType).AssemblyQualifiedName);

            Assert.IsInstanceOfType(actual, typeof(ITestType));
        }
예제 #2
0
        public void TestParameterizedConstructor()
        {
            IObjectBuilder creator = new TypeCreator();
            TestType       actual  = creator.BuildUp <TestType>(new object[] { "hello" });

            Assert.IsInstanceOfType(actual, typeof(TestType));
            Assert.AreEqual <string>("hello", actual.Data);
        }
예제 #3
0
        public void TestParameterizedConstructorByTypeName()
        {
            IObjectBuilder creator       = new TypeCreator();
            string         quanlifedName = typeof(TestType).AssemblyQualifiedName;
            ITestType      actual        = creator.BuildUp <ITestType>(quanlifedName, new object[] { "hello" });

            Assert.IsInstanceOfType(actual, typeof(ITestType));
            Assert.AreEqual <string>("hello", actual.Data);
        }
예제 #4
0
        private void AddDeviceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddForm addForm = new AddForm(new DeviceProperty());

            addForm.ShowDialog();
            if (addForm.ConfigObject != null)
            {
                TreeNode tn = this.treeView1.SelectedNode;
                if (tn != null)
                {
                    DeviceProperty property = (DeviceProperty)addForm.ConfigObject;
                    Config.Device  device   = new Config.Device
                    {
                        Caption         = property.Caption,
                        DeviceID        = property.DeviceID,
                        AssemblyFile    = property.AssemblyFile,
                        CommunicateType = property.CommunicateType,
                        DeviceType      = property.DeviceType,
                        Instance        = property.Instance,
                        Remarks         = property.Remarks
                    };

                    try
                    {
                        IObjectBuilder builder = new TypeCreator();
                        IRunDevice     runDev  = builder.BuildUp <IRunDevice>(property.AssemblyFile, property.Instance);

                        runDev.DeviceParameter.DeviceID = property.DeviceID;
                        runDev.DeviceDynamic.DeviceID   = property.DeviceID;
                        runDev.CommunicateType          = property.CommunicateType;
                        if (runDev.CommunicateType == CommunicateType.COM)
                        {
                            runDev.DeviceParameter.COM.Port = ComUtils.PortToInt(property.IoParameter1);
                            runDev.DeviceParameter.COM.Baud = property.IoParameter2;
                        }
                        else if (runDev.CommunicateType == CommunicateType.NET)
                        {
                            runDev.DeviceParameter.NET.RemoteIP   = property.IoParameter1;
                            runDev.DeviceParameter.NET.RemotePort = property.IoParameter2;
                        }
                        runDev.DeviceParameter.DeviceCode   = property.DeviceCode;
                        runDev.DeviceParameter.DeviceAddr   = property.DeviceAddr;
                        runDev.DeviceParameter.DeviceName   = property.DeviceName;
                        runDev.DeviceParameter.NET.WorkMode = property.WorkMode;
                        runDev.Initialize(runDev.DeviceParameter.DeviceID);

                        TreeNode parentNode = GetRootNode(tn);
                        AddDevice(parentNode.Tag.ToString(), device);
                    }
                    catch (Exception ex)
                    {
                        WriteLog(ex.Message);
                    }
                }
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            ConsoleUtil.SetConsoleCtrlHandler(new ConsoleUtil.ControlCtrlDelegate(HandlerRoutine), true);
            bool success = true;

            Console.WriteLine("正在初始化服务程序......");
            IObjectBuilder builder = new TypeCreator();

            _serverFactory = new ServerFactory();
            try
            {
                GlobalConfig gc = GlobalConfigTool.Load();
                foreach (ServerSuperIO.Config.Server serverCfg in gc.Servers)
                {
                    IServer server = _serverFactory.CreateServer(serverCfg.ServerConfig);
                    server.AddDeviceCompleted    += server_AddDeviceCompleted;
                    server.DeleteDeviceCompleted += server_DeleteDeviceCompleted;
                    server.Start();
                    _serverFactory.AddServer(server);

                    foreach (Config.Device devCfg in serverCfg.Devices)
                    {
                        try
                        {
                            IRunDevice runDev = builder.BuildUp <IRunDevice>(devCfg.AssemblyFile, devCfg.Instance);

                            runDev.DeviceParameter.DeviceID = devCfg.DeviceID;
                            runDev.DeviceDynamic.DeviceID   = devCfg.DeviceID;
                            runDev.CommunicateType          = devCfg.CommunicateType;
                            runDev.Initialize(devCfg.DeviceID);

                            if (server.AddDevice(runDev) != devCfg.DeviceID)
                            {
                                Console.WriteLine("增加设备:" + devCfg.DeviceID + " 失败!");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            continue;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                success = false;
                Console.WriteLine(ex.Message);
            }

            if (success)
            {
                Console.WriteLine("初始化服务程序完成");
            }

            while ("exit" == Console.ReadLine())
            {
                _serverFactory.RemoveAllServer();
                break;
            }
        }
예제 #6
0
 public void TypeCreator()
 {
     TypeCreator creator = new TypeCreator();
     var         p       = creator.BuildUp <Production>(new string[] { "Apple" });
 }
예제 #7
0
        public void TestNoneParameterConstructor()
        {
            IObjectBuilder creator = new TypeCreator();

            Assert.IsInstanceOfType(creator.BuildUp <TestType>(), typeof(TestType));
        }