Example #1
0
        public Result AddAutoUpdateLog(string clientCode, string appName, string currentVersion, string updateVersion, bool isComplete, string errorMessage)
        {
            try
            {
                var ipAdress = MonitoringService.GetIP();
                try
                {
                    BSL.ClientService cs = new BSL.ClientService();
                    var rmsClient        = cs.GetClient(GetClientBy.IPAddress, null, null, ipAdress, true);
                    if (rmsClient != null)
                    {
                        clientCode = rmsClient.ClientCode;
                    }
                }
                catch
                {
                }

                if (string.IsNullOrEmpty(clientCode) && string.IsNullOrEmpty(ipAdress))
                {
                    throw new ArgumentNullException("clientCode && ipAddress");
                }
                if (string.IsNullOrEmpty(appName))
                {
                    throw new ArgumentNullException("appName");
                }

                BSL.AutoUpdateService service = new BSL.AutoUpdateService();
                var location = service.AddAutoUpdateLog(clientCode, ipAdress, appName, currentVersion, updateVersion, isComplete, errorMessage);

                var sr = new Result
                {
                    IsSuccess = true,
                };
                return(sr);
            }
            catch (Exception ex)
            {
                new RMSWebException(this, "0500", "AddAutoUpdateLog failed. " + ex.Message, ex, true);

                var sr = new Result
                {
                    IsSuccess    = false,
                    ErrorMessage = "AddAutoUpdateLog errors. " + ex.Message
                };
                return(sr);
            }
        }
Example #2
0
        public ClientResult GetClient(GetClientBy getClientBy, int?clientID, string clientCode, string ipAddress, bool withDetail, bool activeClient)
        {
            try
            {
                BSL.ClientService cs = new BSL.ClientService();
                var client           = cs.GetClient(getClientBy, clientID, clientCode, ipAddress, activeClient);

                var sr = new ClientResult
                {
                    IsSuccess = true,
                    Client    = client,
                };

                if (client != null && withDetail)
                {
                    using (var db = new MyDbContext())
                    {
                        db.Configuration.ProxyCreationEnabled = false;
                        db.Configuration.LazyLoadingEnabled   = false;

                        RmsMonitoringProfile monitorngProfile = new RmsMonitoringProfile();
                        List <RmsMonitoringProfileDevice> monitoringProfileDevices = new List <RmsMonitoringProfileDevice>();
                        List <RmsDevice> devices = new List <RmsDevice>();

                        sr.MonitoringProfile            = monitorngProfile;
                        sr.ListMonitoringProfileDevices = monitoringProfileDevices;
                        var _client = db.RmsClients.Where(c => c.ClientId == client.ClientId && (!activeClient || (c.Enable == true && c.EffectiveDate <= DateTime.Today && (c.ExpiredDate == null || c.ExpiredDate >= DateTime.Today))))
                                      .Include(
                            i =>
                            i.RmsClientMonitorings.Select(cm => cm.RmsMonitoringProfile)
                            .Select(mp => mp.RmsMonitoringProfileDevices.Select(mpd => mpd.RmsDevice))).FirstOrDefault();

                        if (_client != null)
                        {
                            var rmsClientMonitoring = _client.RmsClientMonitorings.Where(cm => cm.EffectiveDate <= DateTime.Today)
                                                      .OrderByDescending(od => od.EffectiveDate)
                                                      .FirstOrDefault();
                            if (rmsClientMonitoring != null)
                            {
                                monitorngProfile     = rmsClientMonitoring.RmsMonitoringProfile;
                                sr.MonitoringProfile = monitorngProfile;

                                monitoringProfileDevices        = new List <RmsMonitoringProfileDevice>(monitorngProfile.RmsMonitoringProfileDevices);
                                sr.ListMonitoringProfileDevices = monitoringProfileDevices;

                                foreach (var mpd in monitoringProfileDevices)
                                {
                                    if (devices.All(d => d.DeviceId != mpd.RmsDevice.DeviceId))
                                    {
                                        devices.Add(mpd.RmsDevice);
                                    }
                                }
                                sr.ListDevices = new List <RmsDevice>(devices);
                            }
                        }

                        sr.ListDeviceType = db.RmsDeviceTypes.ToList();
                    }
                }
                return(sr);
            }
            catch (Exception ex)
            {
                new RMSWebException(this, "0500", "GetClient failed. " + ex.Message, ex, true);

                var sr = new ClientResult
                {
                    IsSuccess    = false,
                    ErrorMessage = ex.Message
                };
                return(sr);
            }
        }