当前位置: 首页>>代码示例>>C#>>正文


C# UPnPStateVariable.AddAssociation方法代码示例

本文整理汇总了C#中OpenSource.UPnP.UPnPStateVariable.AddAssociation方法的典型用法代码示例。如果您正苦于以下问题:C# UPnPStateVariable.AddAssociation方法的具体用法?C# UPnPStateVariable.AddAssociation怎么用?C# UPnPStateVariable.AddAssociation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenSource.UPnP.UPnPStateVariable的用法示例。


在下文中一共展示了UPnPStateVariable.AddAssociation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddMethod

        /// <summary>
        /// Add a method to expose in this service
        /// </summary>
        /// <param name="MethodName">The name of the method to expose</param>
        public void AddMethod(String MethodName)
        {
            string retname = "_ReturnValue";
            UPnPStateVariable[] ESV;
            bool DontCreate = false;
            ESV = this.GetStateVariables();
            UPnPStateVariable sv;
            MethodInfo minfo = ServiceInstance.GetType().GetMethod(MethodName);
            if (minfo == null)
            {
                throw (new Exception(MethodName + " does not exist in " + ServiceInstance.GetType().ToString()));
            }

            // Create Generic State Variables
            DontCreate = false;
            if (minfo.ReturnType.FullName != "System.Void")
            {
                if (minfo.GetCustomAttributes(true).Length > 0)
                {
                    foreach (Attribute a in minfo.GetCustomAttributes(true))
                    {
                        if (a.GetType() == typeof(OpenSource.UPnP.ReturnArgumentAttribute))
                        {
                            retname = ((ReturnArgumentAttribute)a).Name;
                            break;
                        }
                    }
                }

                // There is a return value
                sv = new UPnPStateVariable("A_ARG_TYPE_" + MethodName + "_RetType", minfo.ReturnType, false);
                sv.AddAssociation(MethodName, retname);

                foreach (UPnPStateVariable _ESV in ESV)
                {
                    foreach (UPnPStateVariable.AssociationNode AESV in _ESV.GetAssociations())
                    {
                        if ((AESV.ActionName == MethodName) && (AESV.ArgName == retname))
                        {
                            // Don't create state variable
                            DontCreate = true;
                        }
                    }
                }

                if (DontCreate == false) this.AddStateVariable(sv);
            }

            ParameterInfo[] pinfo = minfo.GetParameters();
            for (int x = 0; x < pinfo.Length; ++x)
            {
                sv = new UPnPStateVariable("A_ARG_TYPE_" + MethodName + "_" + pinfo[x].Name, pinfo[x].ParameterType, false);
                sv.AddAssociation(MethodName, pinfo[x].Name);
                DontCreate = false;
                foreach (UPnPStateVariable _ESV in ESV)
                {
                    foreach (UPnPStateVariable.AssociationNode AESV in _ESV.GetAssociations())
                    {
                        if ((AESV.ActionName == MethodName) && (AESV.ArgName == pinfo[x].Name))
                        {
                            // Don't create state variable
                            DontCreate = true;
                        }
                    }
                }
                if (DontCreate == false) this.AddStateVariable(sv);
            }
            UPnPAction NewAction = new UPnPAction();
            NewAction.Name = MethodName;
            NewAction.ParentService = this;
            NewAction.MethodPointer = minfo;
            UPnPArgument ARG;

            if (minfo.ReturnType.FullName != "System.Void")
            {
                ARG = new UPnPArgument(retname, "");
                ARG.DataType = UPnPStateVariable.ConvertToUPnPType(minfo.ReturnType);
                ARG.Direction = "out";
                ARG.IsReturnValue = true;
                ARG.ParentAction = NewAction;
                ARG.StateVarName = this.GetStateVariableObject(MethodName, retname).Name;
                NewAction.AddArgument(ARG);
            }
            foreach (ParameterInfo p in pinfo)
            {
                ARG = new UPnPArgument(p.Name, "");
                ARG.DataType = UPnPStateVariable.ConvertToUPnPType(p.ParameterType);

                ARG.Direction = p.Attributes == ParameterAttributes.Out ? "out" : "in";

                ARG.IsReturnValue = false;
                ARG.ParentAction = NewAction;
                ARG.StateVarName = this.GetStateVariableObject(MethodName, p.Name).Name;
                NewAction.AddArgument(ARG);
            }
            this.AddAction(NewAction);
//.........这里部分代码省略.........
开发者ID:rvodden,项目名称:upnp-developertools-old,代码行数:101,代码来源:UPnPService.cs

示例2: MainForm

        public MainForm(string[] args)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            foreach (string parm in args)
            {
                if (parm.ToUpper().StartsWith("/CACHE:"))
                {
                    DText p = new DText();
                    p.ATTRMARK = ":";
                    p[0] = parm;
                    try
                    {
                        CacheTime = int.Parse(p[2]);
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (parm.ToUpper() == "/DEBUG")
                {
                    OpenSource.Utilities.EventLogger.Enabled = true;
                    OpenSource.Utilities.EventLogger.ShowAll = true;
                    OpenSource.Utilities.InstanceTracker.Display();
                }
                else if (parm.ToUpper().StartsWith("/PORT:"))
                {
                    DText p = new DText();
                    p.ATTRMARK = ":";
                    p[0] = parm;
                    try
                    {
                        PortNum = int.Parse(p[2]);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            upnpLightDevice = UPnPDevice.CreateRootDevice(CacheTime, 1, "web\\");
            upnpLightDevice.Icon = iconImageList.Images[0];
            upnpLightDevice.HasPresentation = true;
            upnpLightDevice.PresentationURL = "/";
            upnpLightDevice.FriendlyName = this.Text + " (" + System.Windows.Forms.SystemInformation.ComputerName + ")";
            upnpLightDevice.Manufacturer = "OpenSource";
            upnpLightDevice.ManufacturerURL = "http://opentools.homeip.net";
            upnpLightDevice.ModelName = "Network Light Bulb";
            upnpLightDevice.ModelDescription = "Software Emulated Light Bulb";
            upnpLightDevice.ModelURL = new Uri("http://opentools.homeip.net");
            upnpLightDevice.ModelNumber = "XPC-L1";
            upnpLightDevice.StandardDeviceType = "DimmableLight";
            upnpLightDevice.UniqueDeviceName = System.Guid.NewGuid().ToString();

            // Switch Power
            upnpLightService = new UPnPService(1, "SwitchPower.0001", "SwitchPower", true, this);
            upnpLightService.AddMethod("SetTarget");
            upnpLightService.AddMethod("GetTarget");
            upnpLightService.AddMethod("GetStatus");

            UPnPStateVariable upnpStatusVar = new UPnPStateVariable("Status", typeof(bool), true);
            upnpStatusVar.AddAssociation("GetStatus", "ResultStatus");
            upnpStatusVar.Value = false;
            upnpLightService.AddStateVariable(upnpStatusVar);
            UPnPStateVariable upnpTargetVar = new UPnPStateVariable("Target", typeof(bool), false);
            upnpTargetVar.AddAssociation("SetTarget", "newTargetValue");
            upnpTargetVar.AddAssociation("GetTarget", "newTargetValue");
            upnpTargetVar.Value = false;
            upnpLightService.AddStateVariable(upnpTargetVar);

            // Dimmable device
            upnpDimmerService = new UPnPService(1, "Dimming.0001", "Dimming", true, this);
            upnpDimmerService.AddMethod("SetLoadLevelTarget");
            upnpDimmerService.AddMethod("GetLoadLevelTarget");
            upnpDimmerService.AddMethod("GetLoadLevelStatus");
            upnpDimmerService.AddMethod("GetMinLevel");

            UPnPStateVariable upnpLevelTargetVar = new UPnPStateVariable("LoadLevelTarget", typeof(byte), false);
            upnpLevelTargetVar.AddAssociation("SetLoadLevelTarget", "NewLoadLevelTarget");
            upnpLevelTargetVar.AddAssociation("GetLoadLevelTarget", "NewLoadLevelTarget");
            upnpLevelTargetVar.Value = (byte)100;
            upnpLevelTargetVar.SetRange((byte)0, (byte)100, null);
            upnpDimmerService.AddStateVariable(upnpLevelTargetVar);
            UPnPStateVariable upnpLevelStatusVar = new UPnPStateVariable("LoadLevelStatus", typeof(byte), true);
            upnpLevelStatusVar.AddAssociation("GetLoadLevelStatus", "RetLoadLevelStatus");
            upnpLevelStatusVar.Value = (byte)100;
            upnpLevelStatusVar.SetRange((byte)0, (byte)100, null);
            upnpDimmerService.AddStateVariable(upnpLevelStatusVar);
            UPnPStateVariable upnpMinLevelVar = new UPnPStateVariable("MinLevel", typeof(byte), false);
            upnpMinLevelVar.AddAssociation("GetMinLevel", "MinLevel");
            upnpMinLevelVar.Value = (byte)0;
            upnpDimmerService.AddStateVariable(upnpMinLevelVar);

            // Add Services
            upnpLightDevice.AddService(upnpLightService);
            upnpLightDevice.AddService(upnpDimmerService);
        }
开发者ID:amadare,项目名称:DeveloperToolsForUPnP,代码行数:100,代码来源:MainForm.cs


注:本文中的OpenSource.UPnP.UPnPStateVariable.AddAssociation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。