Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        /// <param name="userCode"></param>
        public static void Protect(ref T target, ProtectedSection <T> userCode)
        {
            T lockedObject = Enter(ref target);

            try
            {
                userCode(lockedObject);
            }
            finally
            {
                Leave(ref target, lockedObject);
            }
        }
Exemple #2
0
        public void Close()
        {
            var alignmentGroups = _lines.OfType <Aligned>().GroupBy(l => l.AlignmentId);

            foreach (var alignmentGroup in alignmentGroups)
            {
                Aligned.Expand(alignmentGroup);
            }

            var protectedSections = _lines.OfType <ProtectedSection>();

            foreach (var protectedSection in protectedSections)
            {
                ProtectedSection.Expand(protectedSection, _fileSystem, Filename);
            }

            _isClosed = true;
        }
Exemple #3
0
            public static void Expand(ProtectedSection protectedSection, IFileSystem fileSystem, string outputPath)
            {
                var humanGeneratedCode = fileSystem.File.Exists(outputPath)
                    ? fileSystem.File.ReadAllLines(outputPath)
                                         .SkipWhile(line => line.Trim() != protectedSection.MarkBegin)
                                         .Skip(1)
                                         .TakeWhile(line => line.Trim() != protectedSection.MarkEnd)
                                         .ToList()
                    : new List <string>();

                var maxLeftIndent = humanGeneratedCode.Count > 0
                    ? humanGeneratedCode.Min(line => line.Length - line.TrimStart().Length)
                    : 0;

                var indent = string.Format(System.Globalization.CultureInfo.InvariantCulture, $"{{0,{maxLeftIndent}}}", "");

                protectedSection.ExpandedValue = string.Join(Environment.NewLine,
                                                             indent + protectedSection.MarkBegin,
                                                             string.Join(Environment.NewLine, humanGeneratedCode),
                                                             indent + protectedSection.MarkEnd);
            }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userCode"></param>
        public void Locked(ProtectedSection <T> userCode)
        {
            //lock (_Lock)
            //{
            //    // check if disposed
            //    if (_Disposed)
            //        throw new InvalidOperationException(
            //            String.Format("Guarded<{0}>.Locked: Object disposed!", typeof(T).Name));
            //    userCode(_Target);
            //}
            T lockedObject = Enter();

            try
            {
                userCode(lockedObject);
            }
            finally
            {
                Leave(lockedObject);
            }
        }