private object GetAPIInfo(TagServer tagServer)
        {
            var urlRoot = "http://" + Request.RequestUri.Host + ":" + Request.RequestUri.Port + "/api/";

            return(new
            {
                SampleUrls = new
                {
                    BasicQueries = new Dictionary <string, string>
                    {
                        { urlRoot + "Tags/c%23", "c# questions (have to escape \"c#\" -> \"c%23\"), defaults to QueryType.ViewCount, pageSize = 50, skip = 0" },
                        { urlRoot + "Tags/c%23?Type=LastActivityDate&PageSize=25", "25 Most Recent c# questions" },
                        { urlRoot + "Tags/c%23?Type=Score&PageSize=1&Skip=71993", "Lowest scoring c# question" },
                        { urlRoot + "Tags/.net?Type=AnswerCount&PageSize=1", "The .NET question with the most answers" }
                    }.ToArray(),
                    AdvancedQueries = new Dictionary <string, string>
                    {
                        { urlRoot + "Query/.net?operator=AND&otherTag=jquery", "AND, i.e. 'C# AND jQuery'" },
                        { urlRoot + "Query/.net?operator=OR&otherTag=jquery", "OR, i.e. 'C# OR jQuery'" },
                        { urlRoot + "Query/.net?operator=OR-NOT&otherTag=jquery", "OR NOT, i.e. 'C# OR NOT jQuery'" },
                        { urlRoot + "Query/.net?operator=OR-NOT&otherTag=jquery&useLinq=true", "OR NOT, i.e. 'C# OR NOT jQuery' BUT using LINQ" },
                    }.ToArray(),
                    AdvancedQueryParameters = new Dictionary <string, string>
                    {
                        { "OtherTag", "i.e. 'c# AND jQuery' (&otherTag=jquery)" },
                        { "Type", "Can be " + String.Join(", ", Enum.GetNames(typeof(QueryType))) },
                        { "Operator", "Can be 'AND', 'AND-NOT', 'OR', 'OR-NOT', 'NOT'" },
                        { "PageSize", "1 to 50" },
                        { "Skip", "0 to 'as many as you want!!'" },
                        { "UseLinq", "i.e. '&UseLinq=true' (will be slower than the default mode)" },
                        { "UseLeppieExclusions", "See " + urlRoot + "/Wildcards/LeppieExpandedTags for the full list" },
                        { "DebugMode", "i.e. '&DebugMode=true'" }
                    },
                    //RelatedTagQueries = new Dictionary<string, string>
                    //{
                    //}.ToArray(),
                    Questions = new Dictionary <string, string>
                    {
                        { urlRoot + "Questions/472906", "Get an individual question (by Id)" },
                    }.ToArray(),
                    Wildcards = new Dictionary <string, string>
                    {
                        { urlRoot + "/Wildcards/?wildcards=*c%23*,*java*", "Show all the Tags that matches the given wildcards (comma seperated list, starts-with, end-with or contains only)" },
                        { urlRoot + "/Wildcards/?wildcards=*c%23,c%23*,.net", "Show all the Tags that matches the given wildcards (comma seperated list, starts-with, end-with or contains only)" },
                        { urlRoot + "/Wildcards/?useLeppieWildcards=true",
                          "Show all the Tags that matches the exclusion list from Leppie (see " +
                          urlRoot + "Wildcards/LeppieExpandedTags and " + urlRoot + "Wildcards/LeppieWildcards for the full list)" },
                    }.ToArray(),
                },
                SetupMessages = Logger.Messages,
                Top50Tags = tagServer.AllTags
                            .Take(50),
                Bottom50Tags = tagServer.AllTags
                               .OrderBy(t => t.Value)
                               .Take(50)
            });
        }
示例#2
0
 private void OnValidate()
 {
     if (tagDetect == null)
     {
         tagDetect = GetComponent <TagDetection>();
     }
     if (server == null)
     {
         server = GetComponent <TagServer>();
     }
 }
示例#3
0
    void Awake()
    {
        instance = this;

        // Initialization of the server network
        ServerNetwork.port = portNumber;
        if (serverNet == null)
        {
            serverNet = GetComponent <ServerNetwork>();
        }
        if (serverNet == null)
        {
            serverNet = (ServerNetwork)gameObject.AddComponent(typeof(ServerNetwork));
            Debug.Log("ServerNetwork component added.");
        }

        //serverNet.EnableLogging("rpcLog.txt");
    }
示例#4
0
        public static ServerSuperIO.OPC.Client.Config.OPCClientConfig GetOPCClientConfig()
        {
            OPCClientConfigService dbConfig = null;
            OPCServerConfigService dbServer = null;
            OPCGroupConfigService  dbGroup  = null;
            TagConfigService       dbTag    = null;

            try
            {
                dbConfig = OPCClientConfigService.Instance;
                dbServer = OPCServerConfigService.Instance;
                dbGroup  = OPCGroupConfigService.Instance;
                dbTag    = TagConfigService.Instance;

                ServerSuperIO.OPC.Client.Config.OPCClientConfig config = new ServerSuperIO.OPC.Client.Config.OPCClientConfig();

                Business.Model.OPCClientConfig configModel = dbConfig.GetOPCClientConfig();

                config.StartOpcClientService = configModel.StartOpcClientService;
                config.OPCClientPersistence  = configModel.OPCClientPersistence;
                config.OPCClientReadInterval = configModel.OPCClientReadInterval;
                config.OPCClientReadMode     = (OPCClientReadMode)Enum.Parse(typeof(OPCClientReadMode), configModel.OPCClientReadMode);

                IList <Business.Model.OPCServerConfig> serverModels = dbServer.GetAllOPCServerConfig();
                foreach (Business.Model.OPCServerConfig mServer in serverModels)
                {
                    TagServer tagServer = new TagServer();
                    tagServer.ServerID   = mServer.Id;
                    tagServer.ServerName = mServer.ServerName;
                    tagServer.RemoteIP   = mServer.RemoteIP;
                    config.TagServers.Add(tagServer);

                    IList <Business.Model.OPCGroupConfig> groupModels = dbGroup.GetOPCGroupConfigOfServer(tagServer.ServerID);
                    foreach (Business.Model.OPCGroupConfig mGroup in groupModels)
                    {
                        TagGroup tagGroup = new TagGroup();
                        tagGroup.GroupID    = mGroup.Id;
                        tagGroup.GroupName  = mGroup.GroupName;
                        tagGroup.DeadBand   = mGroup.DeadBand;
                        tagGroup.IsActive   = mGroup.IsActive;
                        tagGroup.TimeBias   = mGroup.TimeBias;
                        tagGroup.UpdateRate = mGroup.UpdateRate;
                        tagServer.TagGroups.Add(tagGroup);

                        IList <Business.Model.TagConfig> tagModels = dbTag.GetTagConfigOfDevice(tagGroup.GroupID);
                        foreach (Business.Model.TagConfig mTag in tagModels)
                        {
                            TagItem tag = new TagItem();
                            tag.TagID     = mTag.Id;
                            tag.TagName   = mTag.TagName;
                            tag.TagType   = mTag.TagDataType;
                            tag.TagRemark = mTag.Note;

                            tagGroup.TagItems.Add(tag);
                        }
                    }
                }

                return(config);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (dbConfig != null)
                {
                    dbConfig.Dispose();
                }
                if (dbServer != null)
                {
                    dbConfig.Dispose();
                }
                if (dbGroup != null)
                {
                    dbGroup.Dispose();
                }
                if (dbTag != null)
                {
                    dbTag.Dispose();
                }
            }
        }
示例#5
0
        public static void SaveOPCClientConfig(ServerSuperIO.OPC.Client.Config.OPCClientConfig config)
        {
            OPCClientConfigService dbConfig = null;
            OPCServerConfigService dbServer = null;
            OPCGroupConfigService  dbGroup  = null;
            TagConfigService       dbTag    = null;

            try
            {
                dbConfig = OPCClientConfigService.Instance;
                dbServer = OPCServerConfigService.Instance;
                dbGroup  = OPCGroupConfigService.Instance;
                dbTag    = TagConfigService.Instance;

                Business.Model.OPCClientConfig configModel = dbConfig.GetOPCClientConfig();
                if (configModel == null)
                {
                    return;
                }

                configModel.StartOpcClientService = config.StartOpcClientService;
                configModel.OPCClientPersistence  = config.OPCClientPersistence;
                configModel.OPCClientReadMode     = config.OPCClientReadMode.ToString();
                configModel.OPCClientReadInterval = config.OPCClientReadInterval;
                dbConfig.UpdateOPCClientConfig(configModel);

                #region 更新
                foreach (TagServer tagServer in config.TagServers)
                {
                    OPCServerConfig mServer = dbServer.Repository.Queryable.Where <OPCServerConfig>(t => t.Id == tagServer.ServerID).FirstOrDefault();
                    if (mServer == null)
                    {
                        mServer            = new OPCServerConfig();
                        mServer.Id         = tagServer.ServerID;
                        mServer.ServerName = tagServer.ServerName;
                        mServer.RemoteIP   = tagServer.RemoteIP;
                        dbServer.AddOPCServerConfig(mServer);
                    }
                    else
                    {
                        mServer.ServerName = tagServer.ServerName;
                        mServer.RemoteIP   = tagServer.RemoteIP;
                        dbServer.UpdateOPCServerConfig(mServer);
                    }

                    foreach (TagGroup tagGroup in tagServer.TagGroups)
                    {
                        OPCGroupConfig mGroup = dbGroup.Repository.Queryable.Where <OPCGroupConfig>(t => t.Id == tagGroup.GroupID).FirstOrDefault();
                        if (mGroup == null)
                        {
                            mGroup            = new OPCGroupConfig();
                            mGroup.Id         = tagGroup.GroupID;
                            mGroup.ServerId   = tagServer.ServerID;
                            mGroup.GroupName  = tagGroup.GroupName;
                            mGroup.DeadBand   = tagGroup.DeadBand;
                            mGroup.IsActive   = tagGroup.IsActive;
                            mGroup.TimeBias   = tagGroup.TimeBias;
                            mGroup.UpdateRate = tagGroup.UpdateRate;
                            dbGroup.AddOPCGroupConfig(mGroup);
                        }
                        else
                        {
                            mGroup.GroupName  = tagGroup.GroupName;
                            mGroup.DeadBand   = tagGroup.DeadBand;
                            mGroup.IsActive   = tagGroup.IsActive;
                            mGroup.TimeBias   = tagGroup.TimeBias;
                            mGroup.UpdateRate = tagGroup.UpdateRate;
                            dbGroup.UpdateOPCGroupConfig(mGroup);
                        }

                        foreach (TagItem tagItem in tagGroup.TagItems)
                        {
                            TagConfig mTag = dbTag.Repository.Queryable.Where <TagConfig>(t => t.Id == tagItem.TagID).FirstOrDefault();
                            if (mTag == null)
                            {
                                mTag    = new TagConfig();
                                mTag.Id = tagItem.TagID;
                                mTag.DeviceOrGroupId = tagGroup.GroupID;
                                mTag.TagName         = tagItem.TagName;
                                mTag.TagDataType     = tagItem.TagType;
                                mTag.TagNote         = "";
                                mTag.SourceType      = "opc";
                                mTag.DefaultValue    = 0.0d;
                                mTag.UpLimitValue2   = 0.0d;
                                mTag.UpLimitValue1   = 0.0d;
                                mTag.DownLimitValue1 = 0.0d;
                                mTag.DownLimitValue2 = 0.0d;
                                mTag.MaxValue        = 0.0d;
                                mTag.MinValue        = 0.0d;
                                mTag.Note            = "";
                                mTag.SlaveId         = 0;
                                mTag.Function        = 0x03;
                                mTag.Address         = 1;
                                mTag.Quantity        = 1;
                                mTag.Mode            = "RTU";
                                dbTag.AddTagConfig(mTag);
                            }
                            else
                            {
                                mTag.TagName     = tagItem.TagName;
                                mTag.TagDataType = tagItem.TagType;
                                dbTag.UpdateTagConfig(mTag);
                            }
                        }
                    }
                }
                #endregion

                #region  除
                IList <OPCServerConfig> serverList = dbServer.GetAllOPCServerConfig();
                foreach (OPCServerConfig osc in serverList)
                {
                    TagServer tagServer = config.TagServers.FirstOrDefault(s => s.ServerID == osc.Id);
                    if (tagServer == null)
                    {
                        dbServer.DeleteOPCServerConfig(osc.Id);

                        IList <OPCGroupConfig> groupList = dbGroup.GetAllOPCGroupConfig();
                        foreach (OPCGroupConfig ogc in groupList)
                        {
                            dbGroup.DeleteOPCGroupConfig(ogc.Id);

                            dbTag.DeleteTagConfigOfDevice(ogc.Id);
                        }
                    }
                    else
                    {
                        IList <OPCGroupConfig> groupList = dbGroup.GetOPCGroupConfigOfServer(osc.Id);
                        foreach (OPCGroupConfig ogc in groupList)
                        {
                            TagGroup tagGroup = tagServer.TagGroups.FirstOrDefault(g => g.GroupID == ogc.Id);
                            if (tagGroup == null)
                            {
                                dbGroup.DeleteOPCGroupConfig(ogc.Id);

                                dbTag.DeleteTagConfigOfDevice(ogc.Id);
                            }
                            else
                            {
                                IList <TagConfig> tagList = dbTag.GetTagConfigOfDevice(ogc.Id);
                                foreach (TagConfig tc in tagList)
                                {
                                    TagItem tagItem = tagGroup.TagItems.FirstOrDefault(t => t.TagID == tc.Id);
                                    if (tagItem == null)
                                    {
                                        dbTag.DeleteTagConfig(tc.Id);
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
            }
            catch
            {
                throw;
            }
            finally
            {
                if (dbConfig != null)
                {
                    dbConfig.Dispose();
                }
                if (dbServer != null)
                {
                    dbConfig.Dispose();
                }
                if (dbGroup != null)
                {
                    dbGroup.Dispose();
                }
                if (dbTag != null)
                {
                    dbTag.Dispose();
                }
            }
        }
示例#6
0
 private void Start()
 {
     tagServer     = GetComponent <TagServer>();
     serverNetwork = GetComponent <ServerNetwork>();
 }