/// <summary>
        /// 查询 iBMC 服务器分页。
        /// </summary>
        /// <param name="queryDeviceParam">查询参数</param>
        /// <returns>分页对象</returns>
        public QueryPageResult <HWDevice> QueryHWPage(DeviceParam queryDeviceParam)
        {
            StringBuilder sb = new StringBuilder(ConstMgr.HWESightHost.URL_DEVICEPAGE);

            sb.Append("?servertype=").Append(queryDeviceParam.ServerType);
            if (queryDeviceParam.StartPage > 0)
            {
                sb.Append("&start=").Append(queryDeviceParam.StartPage);
            }
            if (queryDeviceParam.PageSize > 0)
            {
                sb.Append("&size=").Append(queryDeviceParam.PageSize);
            }
            if (string.IsNullOrEmpty(queryDeviceParam.PageOrder))
            {
                sb.Append("&orderby=").Append(queryDeviceParam.PageOrder);
            }
            if (string.IsNullOrEmpty(queryDeviceParam.PageOrder))
            {
                sb.Append("&desc=").Append(queryDeviceParam.OrderDesc);
            }
            JObject jResult = HCGet(sb.ToString());

            CheckAndThrowDviException(jResult);
            QueryPageResult <HWDevice> pageResult = jResult.ToObject <QueryPageResult <HWDevice> >();

            if (pageResult.Code != 0)
            {
                LogUtil.HWLogger.API.ErrorFormat("openid:" + this.OpenID);
                throw new ESSessionExpceion(pageResult.Code.ToString(), this, "Query device list error:" + pageResult.Description);
            }
            return(pageResult);
        }
Example #2
0
        private static int ReadInputData(ref DeviceParam device, out byte[] databuffer, bool throwOnFail)
        {
            databuffer = new byte[BIUSB.MAX_INPUTS];
            var result = BIUSB.ReadInputData(ref device, databuffer, 0);

            if (throwOnFail)
            {
                var lastError = Marshal.GetLastWin32Error();
                //check to see if a Win32 error was returned as a result of
                //the previous calls
                if (lastError != 0)
                {
                    //a Win32 API error occured, so throw it as a wrapped exception
                    Exception e = new Win32Exception(lastError);
                    throw new OperationFailedException(e.Message, e);
                }
                switch (result)
                {
                case BIUSB.DEV_TIMEOUT:
                    throw new TimeoutException("Device did not respond within 1 second.");

                case BIUSB.DEV_FAILED:
                    throw new OperationFailedException("Failure reading from device.");
                }
            }
            return(result);
        }
Example #3
0
 public void Remove(DeviceParam value)
 {
     GmsecPINVOKE.DeviceParamList_Remove(swigCPtr, DeviceParam.getCPtr(value));
     if (GmsecPINVOKE.SWIGPendingException.Pending)
     {
         throw GmsecPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #4
0
 public void Insert(int index, DeviceParam value)
 {
     GmsecPINVOKE.DeviceParamList_Insert(swigCPtr, index, DeviceParam.getCPtr(value));
     if (GmsecPINVOKE.SWIGPendingException.Pending)
     {
         throw GmsecPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #5
0
        public int LastIndexOf(DeviceParam value)
        {
            int ret = GmsecPINVOKE.DeviceParamList_LastIndexOf(swigCPtr, DeviceParam.getCPtr(value));

            if (GmsecPINVOKE.SWIGPendingException.Pending)
            {
                throw GmsecPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #6
0
        public bool Contains(DeviceParam value)
        {
            bool ret = GmsecPINVOKE.DeviceParamList_Contains(swigCPtr, DeviceParam.getCPtr(value));

            if (GmsecPINVOKE.SWIGPendingException.Pending)
            {
                throw GmsecPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #7
0
        public static DeviceParamList Repeat(DeviceParam value, int count)
        {
            global::System.IntPtr cPtr = GmsecPINVOKE.DeviceParamList_Repeat(DeviceParam.getCPtr(value), count);
            DeviceParamList       ret  = (cPtr == global::System.IntPtr.Zero) ? null : new DeviceParamList(cPtr, true);

            if (GmsecPINVOKE.SWIGPendingException.Pending)
            {
                throw GmsecPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #8
0
        private DeviceParam getitem(int index)
        {
            global::System.IntPtr cPtr = GmsecPINVOKE.DeviceParamList_getitem(swigCPtr, index);
            DeviceParam           ret  = (cPtr == global::System.IntPtr.Zero) ? null : new DeviceParam(cPtr, false);

            if (GmsecPINVOKE.SWIGPendingException.Pending)
            {
                throw GmsecPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #9
0
        /// <summary>
        /// Gets the server list.
        /// </summary>
        /// <param name="queryDeviceParam">The query device parameter.</param>
        /// <returns>QueryPageResult&lt;HWDevice&gt;.</returns>
        public QueryPageResult <HWDevice> GetServerList(DeviceParam queryDeviceParam)
        {
            var    result = new QueryPageResult <HWDevice>();
            string url    = string.Empty;

            try
            {
                StringBuilder sb = new StringBuilder("rest/openapi/server/device");
                sb.Append("?servertype=").Append(queryDeviceParam.ServerType);
                if (queryDeviceParam.StartPage > 0)
                {
                    sb.Append("&start=").Append(queryDeviceParam.StartPage);
                }
                if (queryDeviceParam.PageSize > 0)
                {
                    sb.Append("&size=").Append(queryDeviceParam.PageSize);
                }
                if (string.IsNullOrEmpty(queryDeviceParam.PageOrder))
                {
                    sb.Append("&orderby=").Append(queryDeviceParam.PageOrder);
                }
                if (string.IsNullOrEmpty(queryDeviceParam.PageOrder))
                {
                    sb.Append("&desc=").Append(queryDeviceParam.OrderDesc);
                }
                url = this.GetFullUrl(sb.ToString());

                //logger.Api.Info($"GetServerList start.Url:{url}");

                this.CheckAndReLogin();
                this.TrustCertificate();

                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Add("openid", this.OpenId);
                var res       = httpClient.GetAsync(url).Result;
                var resultStr = res.Content.ReadAsStringAsync().Result;
                logger.Api.Debug($"GetServerList success.Url:{url} \r\nresult:{resultStr}");
                resultStr = resultStr.Replace("\"data\":\"null\"", "\"data\":[]");
                result    = JsonUtil.DeserializeObject <QueryPageResult <HWDevice> >(resultStr);
                if (result.Code != 0)
                {
                    throw new ESSessionExpceion(result.Code.ToString(), this, resultStr);
                }
            }
            catch (Exception ex)
            {
                result.Code        = -1;
                result.Description = ex.Message;
                logger.Api.Error($"GetServerList Error.Url:{url} : ", ex);
                throw;
            }
            return(result);
        }
Example #10
0
        public void QueryHWPageTest()
        {
            _esSession.Open();
            DeviceParam queryDeviceParam = new DeviceParam();

            queryDeviceParam.ServerType = ConstMgr.HWDevice.SERVER_TYPE_BLADE;
            queryDeviceParam.StartPage  = 1;
            queryDeviceParam.PageSize   = 100;
            queryDeviceParam.PageOrder  = "ipAddress";
            queryDeviceParam.OrderDesc  = true;
            QueryPageResult <HWDevice> hwDevicePageResult = _esSession.QueryHWPage(queryDeviceParam);

            LogUtil.HWLogger.DEFAULT.Info(hwDevicePageResult);
            Assert.IsNotNull(hwDevicePageResult);
        }
Example #11
0
        public void TestOpenId()
        {
            ESightEngine.Instance.SaveNewESSession(_hwESightHost.HostIP, _hwESightHost.HostPort, _hwESightHost.LoginAccount, _hwESightHost.LoginPwd);
            IESSession  iSession         = ESightEngine.Instance.FindAndOpenESSession(_hwESightHost.HostIP);
            DeviceParam queryDeviceParam = new DeviceParam();

            queryDeviceParam.ServerType = ConstMgr.HWDevice.SERVER_TYPE_BLADE;
            queryDeviceParam.StartPage  = 1;
            queryDeviceParam.PageSize   = 100;
            queryDeviceParam.PageOrder  = "ipAddress";
            queryDeviceParam.OrderDesc  = true;
            QueryPageResult <HWDevice> hwDevicePageResult = iSession.QueryHWPage(queryDeviceParam);

            LogUtil.HWLogger.DEFAULT.Info(hwDevicePageResult);
            Assert.IsTrue(!string.IsNullOrEmpty(iSession.OpenID));
        }
Example #12
0
        /// <summary>
        /// 查询昆仑列表
        /// </summary>
        /// <param name="startPage">The start page.</param>
        /// <returns>机架列表</returns>
        public ApiServerList <KunLunServer> QueryKunLunServer(int startPage)
        {
            var result           = new ApiServerList <KunLunServer>();
            var queryDeviceParam = new DeviceParam()
            {
                PageSize = 100, StartPage = startPage, ServerType = "kunlun"
            };
            var reqResult = this.GetServerList(queryDeviceParam);

            reqResult.Data.ForEach(x =>
            {
                KunLunServer kunlunServer = new KunLunServer(x);
                result.Data.Add(kunlunServer);
            });
            result.TotalSize = reqResult.TotalSize;
            result.TotalPage = reqResult.TotalPage;
            return(result);
        }
Example #13
0
        /// <summary>
        /// 查询机架列表
        /// </summary>
        /// <param name="startPage">The start page.</param>
        /// <returns>机架列表</returns>
        public ApiServerList <RackServer> QueryRackServer(int startPage)
        {
            var result           = new ApiServerList <RackServer>();
            var queryDeviceParam = new DeviceParam()
            {
                PageSize = 100, StartPage = startPage, ServerType = "rack"
            };
            var reqResult = this.GetServerList(queryDeviceParam);

            reqResult.Data.ForEach(x =>
            {
                RackServer rackServer = new RackServer(x);
                result.Data.Add(rackServer);
            });
            result.TotalSize = reqResult.TotalSize;
            result.TotalPage = reqResult.TotalPage;
            return(result);
        }
Example #14
0
        public void QueryHWPageJsonTest()
        {
            _esSession.Open();
            DeviceParam queryDeviceParam = new DeviceParam();

            queryDeviceParam.ServerType = ConstMgr.HWDevice.SERVER_TYPE_BLADE;
            queryDeviceParam.StartPage  = 1;
            queryDeviceParam.PageSize   = 100;
            queryDeviceParam.PageOrder  = "ipAddress";
            queryDeviceParam.OrderDesc  = true;
            WebOneESightParam <DeviceParam> webQueryParam = new WebOneESightParam <DeviceParam>();

            webQueryParam.ESightIP = "127.0.0.1";
            webQueryParam.Param    = queryDeviceParam;
            LogUtil.HWLogger.API.Info("queryDeviceParam:" + JsonUtil.SerializeObject(webQueryParam));

            QueryPageResult <HWDevice> hwDevicePageResult = _esSession.QueryHWPage(queryDeviceParam);

            LogUtil.HWLogger.API.Info("hwDevicePageResult:" + JsonUtil.SerializeObject(hwDevicePageResult));
            Assert.IsNotNull(hwDevicePageResult);
        }
Example #15
0
        /// <summary>
        /// 查询高密列表
        /// </summary>
        /// <param name="startPage">The start page.</param>
        /// <returns>高密列表</returns>
        public ApiServerList <HighdensityServer> QueryHighDesentyServer(int startPage)
        {
            var result           = new ApiServerList <HighdensityServer>();
            var queryDeviceParam = new DeviceParam()
            {
                PageSize = 100, StartPage = startPage, ServerType = "highdensity"
            };
            var reqResult = this.GetServerList(queryDeviceParam);

            reqResult.Data.ForEach(x =>
            {
                var highDesentyServer = new HighdensityServer(x);
                x.ChildBlades.ForEach(m =>
                {
                    var childHighdensity = new ChildHighdensity(m, this.ESight.HostIP);
                    highDesentyServer.ChildHighdensitys.Add(childHighdensity);
                });
                result.Data.Add(highDesentyServer);
            });
            result.TotalSize = reqResult.TotalSize;
            result.TotalPage = reqResult.TotalPage;
            return(result);
        }
Example #16
0
        /// <summary>
        /// 查询刀片列表
        /// </summary>
        /// <param name="startPage">The start page.</param>
        /// <returns>刀片列表</returns>
        public ApiServerList <BladeServer> QueryBladeServer(int startPage)
        {
            var result           = new ApiServerList <BladeServer>();
            var queryDeviceParam = new DeviceParam()
            {
                PageSize = 100, StartPage = startPage, ServerType = "blade"
            };
            var reqResult = this.GetServerList(queryDeviceParam);

            reqResult.Data.ForEach(x =>
            {
                BladeServer bladeServer = new BladeServer(x);
                x.ChildBlades.ForEach(m =>
                {
                    ChildBlade childBlade = new ChildBlade(m, this.ESight.HostIP);
                    bladeServer.ChildBlades.Add(childBlade);
                });
                result.Data.Add(bladeServer);
            });
            result.TotalSize = reqResult.TotalSize;
            result.TotalPage = reqResult.TotalPage;
            return(result);
        }
Example #17
0
 /// <summary>Copy-constructor that can be used to make a deep-copy of another %DeviceParam object.</summary>
 ///
 /// <param name="other">The %DeviceParam object to copy</param>
 public DeviceParam(DeviceParam other)
 {
 }
Example #18
0
    static int Main(string[] args)
    {
        if (args.Length < 1)
        {
            Console.WriteLine("usage device_message.exe mw-id=<middleware ID>");
            return(-1);
        }

        Config config = new Config(args);

        InitializeLogging(config);

        //o Enable Message validation.  This parameter is "false" by default.
        config.AddValue("GMSEC-MSG-CONTENT-VALIDATE", "true");

        // TODO: Once available, replace this statement with usage of
        // ConnectionManager::getAPIVersion (See RTC 4798)
        Log.Info(Connection.GetAPIVersion());

        try
        {
            ConnectionManager connManager = new ConnectionManager(config);

            Log.Info("Opening the connection to the middleware server");
            connManager.Initialize();

            Log.Info(connManager.GetLibraryVersion());

            //o Create all of the GMSEC Message header Fields which will
            // be used by all GMSEC Messages
            //
            // Note: Since these Fields contain variable values which are
            // based on the context in which they are used, they cannot be
            // automatically populated using MistMessage.
            List <Field> definedFields = new List <Field>();

            StringField missionField = new StringField("MISSION-ID", "MISSION");
            // Note: SAT-ID-PHYSICAL is an optional header Field, according
            // to the GMSEC ISD.
            StringField satIdField     = new StringField("SAT-ID-PHYSICAL", "SPACECRAFT");
            StringField facilityField  = new StringField("FACILITY", "GMSEC Lab");
            StringField componentField = new StringField("COMPONENT", "device_message");

            definedFields.Add(missionField);
            definedFields.Add(satIdField);
            definedFields.Add(facilityField);
            definedFields.Add(componentField);

            //o Use setStandardFields to define a set of header fields for
            // all messages which are created or published on the
            // ConnectionManager using the following functions:
            // createLogMessage, publishLog, createHeartbeatMessage,
            // startHeartbeatService, createResourceMessage,
            // publishResourceMessage, or startResourceMessageService
            connManager.SetStandardFields(definedFields);

            I32Field    paramVal = new I32Field("DEVICE.1.PARAM.1.VALUE", 79);
            DeviceParam param    = new DeviceParam("DEV parameter 1", "parameter 1 timestamp", paramVal);

            Device device1 = new Device("device 1", Device.DeviceStatus.RED);
            device1.SetGroup("group");
            device1.SetRole("role");
            device1.SetModel("model");
            device1.SetSerial("1138");
            device1.SetVersion("1.4.5.2.3.4.5");
            I16Field devInfo = new I16Field("info", 5);
            device1.SetInfo(devInfo);
            I16Field devNum = new I16Field("num", 5);
            device1.SetNumber(devNum);
            device1.AddParam(param);

            //o Construct an DEV Message and add the Device values to it
            using (GMSEC.API.MIST.MESSAGE.DeviceMessage devMessage = new GMSEC.API.MIST.MESSAGE.DeviceMessage(DEV_MESSAGE_SUBJECT, connManager.GetSpecification()))
            {
                devMessage.AddDevice(device1);

                connManager.AddStandardFields(devMessage);

                connManager.Publish(devMessage);

                Log.Info("Published DEV message:\n" + devMessage.ToXML());
            }

            connManager.Cleanup();
        }
        catch (GMSEC_Exception e)
        {
            Log.Error(e.ToString());
            return(-1);
        }

        return(0);
    }
Example #19
0
 /// <summary>Assign a DeviceParam object to the list held by the %Device.</summary>
 ///
 /// <param name="param">The DeviceParam object to add to the %Device</param>
 public void AddParam(DeviceParam param)
 {
 }