Ejemplo n.º 1
0
 public override object GetProperty(HP.HPTRIM.SDK.TrimObject tmo, HP.HPTRIM.SDK.Database database, IMainObjectRequest request)
 {
     return(new TrimStringProperty()
     {
         Value = string.Format("test - {0}", DateTime.Now)
     });
 }
Ejemplo n.º 2
0
 public void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (!_isDisposed)
         {
             if (null != _trimDatabase)
             {
                 if (_trimDatabase is SDK.Database)
                 {
                     try
                     {
                         _trimDatabase.Dispose();
                         _trimDatabase = null;
                     }
                     catch
                     {
                         throw;
                     }
                 }
                 else
                 {
                     throw new Exception(string.Format("Attempting to dispose: {0}.", _trimDatabase.GetType().Name));
                 }
             }
             _isDisposed = true;
         }
     }
 }
Ejemplo n.º 3
0
        public override object GetProperty(HP.HPTRIM.SDK.TrimObject tmo, HP.HPTRIM.SDK.Database database, IMainObjectRequest request)
        {
            HP.HPTRIM.SDK.Record   record          = tmo as HP.HPTRIM.SDK.Record;
            HP.HPTRIM.SDK.Location closestLocation = null;

            double lastDistanceTo = 0;

            if (record != null)
            {
                if (!string.IsNullOrEmpty(record.GpsLocation))
                {
                    GeoCoordinate coord;
                    if (tryGetCoordinate(record.GpsLocation, out coord))
                    {
                        HP.HPTRIM.SDK.TrimMainObjectSearch search = new HP.HPTRIM.SDK.TrimMainObjectSearch(database, HP.HPTRIM.SDK.BaseObjectTypes.Location);
                        search.SetSearchString($"locGps:within 5 kilometres of record {record.Uri} and type:ProjectTeam");


                        foreach (HP.HPTRIM.SDK.Location location in search)
                        {
                            GeoCoordinate locationCoord;
                            if (tryGetCoordinate(location.GpsLocation, out locationCoord))
                            {
                                if (closestLocation == null)
                                {
                                    closestLocation = location;
                                    lastDistanceTo  = locationCoord.GetDistanceTo(coord);
                                }
                                else if (locationCoord.GetDistanceTo(coord) < lastDistanceTo)
                                {
                                    closestLocation = location;
                                    lastDistanceTo  = locationCoord.GetDistanceTo(coord);
                                }
                            }
                        }
                    }
                }
            }
            if (closestLocation != null)
            {
                return(closestLocation.ToRefModel(request) as LocationRef);
            }

            return(null);
        }
Ejemplo n.º 4
0
        private void setDatabase(string identity, string wgName, int wgPort, string dbid, string alt_wgName, int alt_wgPort, bool isSingleHop, string remoteIp)
        {
            _trimDatabase = new Database()
            {
                Id = dbid,
                WorkgroupServerName = wgName,
                WorkgroupServerPort = wgPort,
                IsSingleHopClient   = isSingleHop
            };

            if (!string.IsNullOrWhiteSpace(identity))
            {
                _trimDatabase.TrustedUser = identity;


                if (TrimApplication.ServiceType == ServiceTypes.WebService)
                {
                    TrimUserOptionSet webclientOption = new TrimUserOptionSet(_trimDatabase, UserOptionSetIds.WebClient);
                    string            timeZone        = webclientOption.GetPropertyString(PropertyIds.WebClientUserOptionsTimezone);

                    if (!string.IsNullOrEmpty(timeZone))
                    {
                        try
                        {
                            _trimDatabase.SetTimezoneString(timeZone);
                        }
                        catch
                        {
                            // if an invalid time zone is set we do not want an exception as that would stop the user fixing the time-zone

                            //  _log.WarnFormat("Invalid timezone ({0}) set by {1}", timeZone, identity);
                        }
                    }
                }

                // this allows the users IP address to be logged in the WGS log
                if (!string.IsNullOrEmpty(remoteIp))
                {
                    _trimDatabase.ClientIPAddress = remoteIp;
                }
            }
            if (!string.IsNullOrEmpty(alt_wgName))
            {
                _trimDatabase.AlternateWorkgroupServerName = alt_wgName;
                _trimDatabase.AlternateWorkgroupServerPort = alt_wgPort;
            }

            if (_trimDatabase.IsValid)
            {
                //Now that all the properties have been established, attempt to connect to the database
                _trimDatabase.Connect();

                if (!_trimDatabase.IsConnected)
                {
                    throw new DatabaseConnectException("Database failed to connect. " + _trimDatabase.ErrorMessage);
                }
            }
            else
            {
                throw new DatabaseConnectException("Unable to connect to database. " + _trimDatabase.ErrorMessage);
            }
        }
Ejemplo n.º 5
0
 public override object GetProperty(HP.HPTRIM.SDK.TrimObject tmo, HP.HPTRIM.SDK.Database database, IMainObjectRequest request)
 {
     return(RegisterFileService.getCommandDefs(tmo as HP.HPTRIM.SDK.Record));
 }