private static void UpdateFilesystemKey(Model.ServiceLock item)
        {
            IPersistentStore store = PersistentStoreRegistry.GetDefaultStore();

            using (IUpdateContext ctx = store.OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                ServiceLockUpdateColumns columns = new ServiceLockUpdateColumns();
                columns.FilesystemKey = item.FilesystemKey;

                IServiceLockEntityBroker broker = ctx.GetBroker <IServiceLockEntityBroker>();
                broker.Update(item.Key, columns);
                ctx.Commit();
            }
        }
示例#2
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);
            }
        }
示例#3
0
        /// <summary>
        /// Updates the 'State' of the filesystem associated with the 'FilesystemDelete' <see cref="ServiceLock"/> item
        /// </summary>
        /// <param name="item"></param>
        /// <param name="fs"></param>
        private static void UpdateState(Model.ServiceLock item, ServerFilesystemInfo fs)
        {
            FilesystemState state = null;

            if (item.State != null && item.State.DocumentElement != null)
            {
                //load from datatabase
                state = XmlUtils.Deserialize <FilesystemState>(item.State.DocumentElement);
            }

            if (state == null)
            {
                state = new FilesystemState();
            }

            if (fs.AboveHighWatermark)
            {
                // we don't want to generate alert if the filesystem is offline or not accessible.
                if (fs.Online && (fs.Readable || fs.Writeable))
                {
                    TimeSpan ALERT_INTERVAL = TimeSpan.FromMinutes(ServiceLockSettings.Default.HighWatermarkAlertInterval);

                    if (state.AboveHighWatermarkTimestamp == null)
                    {
                        state.AboveHighWatermarkTimestamp = Platform.Time;
                    }

                    TimeSpan elapse = (state.LastHighWatermarkAlertTimestamp != null) ? Platform.Time - state.LastHighWatermarkAlertTimestamp.Value : Platform.Time - state.AboveHighWatermarkTimestamp.Value;

                    if (elapse.Duration() >= ALERT_INTERVAL)
                    {
                        ServerPlatform.Alert(AlertCategory.System, AlertLevel.Warning, "Filesystem",
                                             AlertTypeCodes.LowResources, null, TimeSpan.Zero,
                                             SR.AlertFilesystemAboveHW,
                                             fs.Filesystem.Description,
                                             TimeSpanFormatter.Format(Platform.Time - state.AboveHighWatermarkTimestamp.Value, true));


                        state.LastHighWatermarkAlertTimestamp = Platform.Time;
                    }
                }
                else
                {
                    state.AboveHighWatermarkTimestamp     = null;
                    state.LastHighWatermarkAlertTimestamp = null;
                }
            }
            else
            {
                state.AboveHighWatermarkTimestamp     = null;
                state.LastHighWatermarkAlertTimestamp = null;
            }


            XmlDocument stateXml = new XmlDocument();

            stateXml.AppendChild(stateXml.ImportNode(XmlUtils.Serialize(state), true));

            IPersistentStore store = PersistentStoreRegistry.GetDefaultStore();

            using (IUpdateContext ctx = store.OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                ServiceLockUpdateColumns columns = new ServiceLockUpdateColumns();
                columns.State = stateXml;

                IServiceLockEntityBroker broker = ctx.GetBroker <IServiceLockEntityBroker>();
                broker.Update(item.GetKey(), columns);
                ctx.Commit();
            }
        }