private bool CheckMultipleInstances()
        {
            TimeSpan cacheDuration = TimeSpan.FromMinutes(2);

            lock (_dbCheckSync)
            {
                if (!_multipleInstanceDetected.HasValue || Math.Abs(Environment.TickCount - _lastDbCheck) > cacheDuration.TotalMilliseconds)
                {
                    _lastDbCheck = Environment.TickCount;

                    using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                    {
                        var broker = context.GetBroker <IServiceLockEntityBroker>();

                        var criteria = new ServiceLockSelectCriteria();
                        criteria.ServiceLockTypeEnum.EqualTo(ServiceLockTypeEnum.ImportFiles);
                        criteria.Enabled.EqualTo(true);

                        var list = broker.Find(criteria);

                        _multipleInstanceDetected = list.Count > 1;
                    }
                }
            }

            return(_multipleInstanceDetected.Value);
        }
 /// <summary>
 /// Finds all <see cref="ServiceLock"/> of the specified <see cref="ServiceLockTypeEnum"/>
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static IList <ServiceLock> FindServicesOfType(ServiceLockTypeEnum type)
 {
     using (var readCtx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
     {
         var broker   = readCtx.GetBroker <IServiceLockEntityBroker>();
         var criteria = new ServiceLockSelectCriteria();
         criteria.ServiceLockTypeEnum.EqualTo(type);
         return(broker.Find(criteria));
     }
 }
Exemple #3
0
 /// <summary>
 /// Finds all <see cref="ServiceLock"/> of the specified <see cref="ServiceLockTypeEnum"/>
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static IList <ServiceLock> FindServicesOfType(ServiceLockTypeEnum type)
 {
     using (var context = new ServerExecutionContext())
     {
         var broker   = context.ReadContext.GetBroker <IServiceLockEntityBroker>();
         var criteria = new ServiceLockSelectCriteria();
         criteria.ServiceLockTypeEnum.EqualTo(type);
         return(broker.Find(criteria));
     }
 }
Exemple #4
0
        /// <summary>
        /// Get an Online and Writeable <see cref="ServiceLock"/> related incoming directory.
        /// </summary>
        /// <param name="partition">The ServerPartion</param>
        /// <param name="folder">The absolute path of the output folder</param>
        /// <returns>true on a found writeable path, false on failure or no writeable path</returns>
        public bool GetWriteableIncomingFolder(ServerPartition partition, out string folder)
        {
            using (ServerExecutionContext context = new ServerExecutionContext())
            {
                IServiceLockEntityBroker  broker   = context.ReadContext.GetBroker <IServiceLockEntityBroker>();
                ServiceLockSelectCriteria criteria = new ServiceLockSelectCriteria();
                criteria.ServiceLockTypeEnum.EqualTo(ServiceLockTypeEnum.ImportFiles);

                IList <ServiceLock> rows = broker.Find(criteria);
                foreach (ServiceLock serviceLock in rows)
                {
                    if (!serviceLock.Enabled)
                    {
                        continue;
                    }

                    string reason;
                    if (!CheckFilesystemOnline(serviceLock.FilesystemKey, out reason))
                    {
                        continue;
                    }

                    if (!CheckFilesystemWriteable(serviceLock.FilesystemKey, out reason))
                    {
                        continue;
                    }

                    String incomingFolder = String.Format("{0}_{1}", partition.PartitionFolder, ImportDirectorySuffix);
                    folder = serviceLock.Filesystem.GetAbsolutePath(incomingFolder);
                    return(true);
                }

                folder = string.Empty;
                return(false);
            }
        }
        /// <summary>
        /// Load the devices for the partition based on the filters specified in the filter panel.
        /// </summary>
        /// <remarks>
        /// This method only reloads and binds the list bind to the internal grid.
        /// </remarks>
        public void LoadServiceLocks()
        {
            var criteria = new ServiceLockSelectCriteria();

            var controller = new ServiceLockConfigurationController();

            if (TypeDropDownList.SelectedValue != SR.All)
            {
                criteria.ServiceLockTypeEnum.EqualTo(ServiceLockTypeEnum.GetEnum(TypeDropDownList.SelectedValue));
            }

            if (StatusFilter.SelectedIndex != 0)
            {
                if (StatusFilter.SelectedIndex == 1)
                {
                    criteria.Enabled.EqualTo(true);
                }
                else
                {
                    criteria.Enabled.EqualTo(false);
                }
            }

            if (FileSystemFilter.SelectedIndex != -1)
            {
                var fsController   = new FileSystemsConfigurationController();
                var fileSystemKeys = new List <ServerEntityKey>();
                foreach (ListItem fileSystem in FileSystemFilter.Items)
                {
                    if (fileSystem.Selected)
                    {
                        fileSystemKeys.Add(new ServerEntityKey("FileSystem", fileSystem.Value));
                    }
                }

                IList <Filesystem> fs = fsController.GetFileSystems(fileSystemKeys);

                if (fs != null)
                {
                    var entityKeys = new List <ServerEntityKey>();
                    foreach (Filesystem f in fs)
                    {
                        entityKeys.Add(f.Key);
                    }
                    criteria.FilesystemKey.In(entityKeys);
                }
            }

            if (PartitionFilter.SelectedIndex != -1)
            {
                var partitionKeys = new List <ServerEntityKey>();
                foreach (ListItem partition in PartitionFilter.Items)
                {
                    if (partition.Selected)
                    {
                        partitionKeys.Add(new ServerEntityKey("ServerPartition", partition.Value));
                    }
                }

                criteria.ServerPartitionKey.In(partitionKeys);
            }

            IList <ServiceLock> services = controller.GetServiceLocks(criteria);

            List <ServiceLock> sortedServices =
                CollectionUtils.Sort(services, delegate(ServiceLock a, ServiceLock b)
            {
                if (a == null)
                {
                    if (b == null)
                    {
                        // If both null, they're equal.
                        return(0);
                    }
                    // If x is null and y is not null, y
                    // is greater.
                    return(-1);
                }
                // If a is not null...
                if (b == null)
                {
                    // ...and b is null, x is greater.
                    return(1);
                }
                // just compare
                if (a.Filesystem == null || b.Filesystem == null)
                {
                    return(String.Compare(a.ServiceLockTypeEnum.Description, b.ServiceLockTypeEnum.Description, StringComparison.Ordinal));
                }

                int retVal = String.Compare(a.Filesystem.Description, b.Filesystem.Description, StringComparison.Ordinal);
                if (retVal == 0)
                {
                    return(String.Compare(a.ServiceLockTypeEnum.Description, b.ServiceLockTypeEnum.Description, StringComparison.Ordinal));
                }
                return(retVal);
            });


            var items = new ServiceLockCollection
            {
                sortedServices
            };

            ServiceLockGridViewControl.ServiceLocks = items;

            ServiceLockGridViewControl.RefreshCurrentPage();
        }
 /// <summary>
 /// Retrieve list of services.
 /// </summary>
 /// <param name="criteria"/>
 /// <returns>List of <see cref="ServiceLock"/> matches <paramref name="criteria"/></returns>
 public IList <ServiceLock> GetServiceLocks(ServiceLockSelectCriteria criteria)
 {
     return(_adapter.GetServiceLocks(criteria));
 }