Exemplo n.º 1
0
        private static void ScanSystem <T>(T algorithm, string path) where T : HashAlgorithm
        {
            HashContainer hashContainer = new HashContainer();

            while (true)
            {
                CheckSumCreator.WriteFileWithCheckSum <T>(algorithm, path);
                hashContainer.oldFilesWithHash = CheckSumComparer.ReadFileWithCheckSum(path);

                Thread.Sleep(waitTime);

                CheckSumCreator.WriteFileWithCheckSum <T>(algorithm, path);
                hashContainer.newFilesWithHash = CheckSumComparer.ReadFileWithCheckSum(path);

                Console.WriteLine("Files were processed by {0} hash: ", algorithm.GetType().Name);
                ICollection <KeyValuePair <string, bool> > comparisonResult = CheckSumComparer.CompareFilesCheckSum(hashContainer.oldFilesWithHash, hashContainer.newFilesWithHash);
                Console.WriteLine("\n\n");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// <para>Returns the cache container</para>
        /// </summary>
        /// <param name="containerType">
        /// <para>Container type. Recommend using a CacheContainer.</para>
        /// </param>
        private ContainerTemplate GetContainer(Enum containerType)
        {
            ContainerTemplate container;
            string            containerName = containerType.ToString();

            if (MCacheContainer.TryGetValue(containerName, out container))
            {
                return(container);
            }
            var containerTypeAttr = containerType.GetType()
                                    .GetFields(BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public)
                                    .Where(fldAt => fldAt.Name.Equals(containerName))
                                    .Select(fld => fld.GetCustomAttributes(typeof(Attributes.CacheContainer), true)
                                            .FirstOrDefault())
                                    .Select(ct => (ct as Attributes.CacheContainer))
                                    .FirstOrDefault();

            lock (MCacheContainer)
            {
                Enums.CacheType?type      = null;
                string          storage   = "";
                bool            audit     = false;
                bool            keepCache = false;

                if (containerTypeAttr != null)
                {
                    type      = containerTypeAttr.CacheType;
                    storage   = containerTypeAttr.StoragePath;
                    audit     = containerTypeAttr.Audit;
                    keepCache = containerTypeAttr.KeepCache;
                }
                else
                {
                    type = (Enums.CacheType)containerType;
                }

                switch (type.Value)
                {
                case Enums.CacheType.Hash:
                    container = new HashContainer();
                    break;

                case Enums.CacheType.SortedHash:
                    container = new SortedHashContainer();
                    break;

                case Enums.CacheType.FileSystemMultipleFiles:
                    container = new FileContainer(storage, containerName, keepCache);
                    break;

                case Enums.CacheType.FileSystemMdbFile:
                    container = new MdbContainer(storage, containerName, keepCache, audit);
                    break;

                //case CacheType.AppFabric:
                //    container = new AppFabricContainer(containerName);
                //    break;
                default:
                    container = new HashContainer();
                    break;
                }

                if (containerTypeAttr != null)
                {
                    container.UseContainerTime       = true;
                    container.SlideExpiration        = TimeSpan.FromMinutes(containerTypeAttr.SlideExpiration);
                    container.AbsoluteExpirationTime = TimeSpan.FromMinutes(containerTypeAttr.AbsoluteExpirationTime);
                }

                try
                {
                    if (!MCacheContainer.ContainsKey(containerName))
                    {
                        MCacheContainer.Add(containerName, container);
                    }
                }
                catch (Exception ex)
                {
                    Service.Statistics.Add(ex.GetAllMessagesMtn());
                }
            }

            return(container);
        }