Ejemplo n.º 1
0
        /// <summary>
        /// The check file locked.
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <param name="lockedException">
        /// The locked exception.
        /// </param>
        /// <param name="anyExceptionReturnsTrue">
        /// The any exception returns true.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private static bool CheckFileLocked(
            string path,
            ref Exception lockedException,
            bool anyExceptionReturnsTrue = false)
        {
            if (FileExists(path))
            {
                try
                {
                    var fileAttributes = File.GetAttributes(path);
                    var flag           = (fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
                    try
                    {
                        if (flag)
                        {
                            File.SetAttributes(path, FileAttributes.Normal);
                        }

                        File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None).Dispose();
                    }
                    finally
                    {
                        if (flag)
                        {
                            File.SetAttributes(path, fileAttributes);
                        }
                    }
                }
                catch (IOException exception)
                {
                    if ((lockedException == null) || (lockedException.Message != exception.Message))
                    {
                        FomsLogger.WriteLog(
                            LogType.Local,
                            string.Format("[{0}] {1}", exception.Message, path),
                            "[FileLocked] ",
                            LogErrorType.None);
                    }

                    lockedException = exception;
                    return(true);
                }
                catch (Exception exception2)
                {
                    if (!anyExceptionReturnsTrue)
                    {
                        throw;
                    }

                    FomsLogger.WriteError(exception2, null);
                    lockedException = exception2;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The do raise global event.
        /// </summary>
        /// <param name="runningEventData">
        /// The running event data.
        /// </param>
        private static void DoRaiseGlobalEvent(RunningEventData runningEventData)
        {
            bool flag;

            do
            {
                flag = false;
                try
                {
                    // GlobalEventAction(runningEventData);
                }
                catch (Exception exception)
                {
                    FomsLogger.WriteError(exception, null);
                }

                try
                {
                    lock (runningEvents)
                    {
                        // if (runningEventData.TakeNextPending() && GlobalEventAction(runningEventData.globalEvent, null))
                        // {
                        // if (runningEventData.separateThread != null)
                        // {
                        // flag = true;
                        // }
                        // else
                        // {
                        // bool forceSeparateThread = true;
                        {
                            // RaiseGlobalEventStart(runningEventData, forceSeparateThread);
                            // }
                            // }

                            // else
                            runningEvents.Remove(runningEventData.globalEvent);
                        }
                    }
                }
                catch (Exception exception2)
                {
                    FomsLogger.WriteError(exception2, null);
                }
            }while (flag);
        }