Ejemplo n.º 1
0
        private void MoveImagesToOutputDirectory(
            string inputDirectory,
            string outputDirectory,
            ref int filesCount,
            ref int errorsCount)
        {
            ICollection <string> files = this.systemContext.GetFiles(inputDirectory, "*.jpg", SearchOption.TopDirectoryOnly);
            int count = files.Count;

            filesCount += count;
            int num = 0;

            foreach (string file in (IEnumerable <string>)files)
            {
                try
                {
                    this.ProcessFile(file, outputDirectory);
                }
                catch (Exception ex)
                {
                    this.OnMessageSent(new MessageSentEventArgs(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Warning_FailedToProcessFile, (object)file, (object)ex.Message), MessageType.Warning));
                    ++errorsCount;
                }
                this.OnProgressChanged(new ProgressChangedEventArgs(MessagingBase.CalculatePercentage(++num, count), this.currentTotalPercentage));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes all queues and exchanges created or used by this Router.
        /// </summary>
        public void RemoveRouting(Func <string, bool> filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            lock (_lockObject)
            {
                MessagingBase.InternalResetCaches();
                _shortTermConnection.WithChannel(channel => {
                    foreach (var queue in queues.Where(filter))
                    {
                        channel.QueueDelete(queue);
                    }

                    foreach (var exchange in exchanges.Where(filter))
                    {
                        channel.ExchangeDelete(exchange);
                    }
                });

                queues.Clear();
                exchanges.Clear();
            }
        }
Ejemplo n.º 3
0
        public void Should_get_full_name_of_single_interface_from_contract_name_method()
        {
            var instance = new SuperMetadata();
            var result   = MessagingBase.ContractTypeName(instance);

            Assert.That(result, Is.EqualTo("Example.Types.IMetadataFile"));
        }
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static grpc::ServerServiceDefinition BindService(MessagingBase serviceImpl)
 {
     return(grpc::ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_TalkAndListen, serviceImpl.TalkAndListen)
            .AddMethod(__Method_Subscribe, serviceImpl.Subscribe)
            .AddMethod(__Method_Unsubscribe, serviceImpl.Unsubscribe)
            .AddMethod(__Method_Publish, serviceImpl.Publish).Build());
 }
Ejemplo n.º 5
0
        public void MergeDirectories(
            IList <string> inputDirectories,
            string outputDirectory,
            string fileNamePattern,
            bool deleteSourceDirectories)
        {
            if (inputDirectories == null)
            {
                throw new ArgumentException(Resources.Error_InvalidDirectoriesList, nameof(inputDirectories));
            }
            if (string.IsNullOrWhiteSpace(outputDirectory))
            {
                throw new ArgumentException(Resources.Error_InvalidOutputDirectory, outputDirectory);
            }
            this.EnsureDirectoryExists(outputDirectory);
            this.currentTotalPercentage = 0;
            this.firstFile = (string)null;
            this.directorySorterSummary = (IDictionary <string, object>)null;
            int processedDirectoriesCount = 0;
            int filesCount         = 0;
            int deletedDirectories = 0;
            int errorsCount        = 0;
            int count = inputDirectories.Count;

            this.OnProgressChanged(new ProgressChangedEventArgs(0, 0));
            if (inputDirectories.IndexOf(outputDirectory) > 0 && inputDirectories.Remove(outputDirectory))
            {
                inputDirectories.Insert(0, outputDirectory);
            }
            for (int index = 0; index < count; ++index)
            {
                string inputDirectory = inputDirectories[index];
                if (this.systemContext.DirectoryExists(inputDirectory))
                {
                    this.OnMessageSent(new MessageSentEventArgs(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Info_ProcessingDirectory, (object)inputDirectory), MessageType.Information));
                    this.MoveImagesToOutputDirectory(inputDirectory, outputDirectory, ref filesCount, ref errorsCount);
                    ++processedDirectoriesCount;
                }
                this.currentTotalPercentage = MessagingBase.CalculatePercentage(index + 1, count + 1);
                this.OnProgressChanged(new ProgressChangedEventArgs(0, this.currentTotalPercentage));
            }
            if (processedDirectoriesCount > 0)
            {
                this.SortOutputDirectory(outputDirectory, fileNamePattern);
            }
            if (deleteSourceDirectories)
            {
                this.OnMessageSent(new MessageSentEventArgs(Resources.Info_CleaningSourceDirectories, MessageType.Information));
                inputDirectories.Remove(outputDirectory);
                this.CleanSourceDirectories((IEnumerable <string>)inputDirectories, ref deletedDirectories, ref errorsCount);
            }
            this.OnProgressChanged(new ProgressChangedEventArgs(100, 100));
            this.OnCompleted(new CompletedEventArgs(this.PrepareSummary(filesCount, processedDirectoriesCount, deletedDirectories, errorsCount), outputDirectory, this.firstFile));
        }
Ejemplo n.º 6
0
        public void SortDirectory(string directory, string fileNamePattern)
        {
            if (string.IsNullOrWhiteSpace(directory))
            {
                throw new ArgumentException(Resources.Error_InvalidInputDirectory, nameof(directory));
            }
            this.OnMessageSent(new MessageSentEventArgs(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Info_SortingDirectory, (object)directory), MessageType.Information));
            fileNamePattern = fileNamePattern == null ? string.Empty : fileNamePattern.Trim();
            IOrderedEnumerable <string> source1 = this.systemContext.GetFiles(directory, "*.jpg", SearchOption.TopDirectoryOnly).OrderBy <string, DateTime>((Func <string, DateTime>)(file => this.systemContext.GetFileCreationTime(file)));
            int    num1           = source1.Count <string>();
            string fileNameFormat = DirectorySorter.ResolveFileNameFormat(fileNamePattern, num1, ".jpg");
            string firstImage     = (string)null;
            int    counter        = 1;
            int    num2           = 0;
            int    errors         = 0;

            foreach (string source2 in (IEnumerable <string>)source1)
            {
                try
                {
                    string targetFileName = this.DetermineTargetFileName(fileNameFormat, ref counter, directory);
                    this.OnMessageSent(new MessageSentEventArgs(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Info_MovingFile, (object)source2, (object)targetFileName), MessageType.Verbose));
                    this.systemContext.MoveFile(source2, targetFileName);
                    if (num2 == 0)
                    {
                        firstImage = targetFileName;
                    }
                }
                catch (Exception ex)
                {
                    this.OnMessageSent(new MessageSentEventArgs(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Warning_FailedToProcessFile, (object)source2, (object)ex.Message), MessageType.Warning));
                    ++errors;
                }
                this.OnProgressChanged(new ProgressChangedEventArgs(MessagingBase.CalculatePercentage(++num2, num1), 0));
                ++counter;
            }
            this.OnProgressChanged(new ProgressChangedEventArgs(100, 100));
            this.OnCompleted(new CompletedEventArgs(DirectorySorter.PrepareSummary(num1, counter, errors), directory, firstImage));
        }
Ejemplo n.º 7
0
        private IList <string> DistributeImagesToSubDirectories(
            string directory,
            string outputDirectory,
            bool rotateImages,
            out int filesCount,
            out int errorsCount,
            out int rotatedImagesCount)
        {
            errorsCount        = 0;
            rotatedImagesCount = 0;
            ICollection <string> files          = this.systemContext.GetFiles(directory, "*.jpg", SearchOption.TopDirectoryOnly);
            IList <string>       subDirectories = (IList <string>) new List <string>();

            filesCount = files.Count;
            int num = 0;

            foreach (string file in (IEnumerable <string>)files)
            {
                try
                {
                    bool imageRotated;
                    this.ProcessFile(file, rotateImages, outputDirectory, subDirectories, out imageRotated);
                    if (imageRotated)
                    {
                        ++rotatedImagesCount;
                    }
                }
                catch (Exception ex)
                {
                    this.OnMessageSent(new MessageSentEventArgs(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Warning_FailedToProcessFile, (object)file, (object)ex.Message), MessageType.Warning));
                    ++errorsCount;
                }
                this.OnProgressChanged(new ProgressChangedEventArgs(MessagingBase.CalculatePercentage(++num, filesCount), 0));
            }
            this.OnProgressChanged(new ProgressChangedEventArgs(100, 0));
            return(subDirectories);
        }
Ejemplo n.º 8
0
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static grpc::ServerServiceDefinition BindService(MessagingBase serviceImpl)
 {
     return(grpc::ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_SendMessage, serviceImpl.SendMessage).Build());
 }
Ejemplo n.º 9
0
 /// <summary>Register service method with a service binder with or without implementation. Useful when customizing the  service binding logic.
 /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
 /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static void BindService(grpc.ServiceBinderBase serviceBinder, MessagingBase serviceImpl)
 {
     serviceBinder.AddMethod(__Method_CreateStreaming, serviceImpl == null ? null : new grpc.DuplexStreamingServerMethod <RequestMessage, ResponseMessage>(serviceImpl.CreateStreaming));
 }
Ejemplo n.º 10
0
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static grpc.ServerServiceDefinition BindService(MessagingBase serviceImpl)
 {
     return(grpc.ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_CreateStreaming, serviceImpl.CreateStreaming).Build());
 }
Ejemplo n.º 11
0
        public void Should_get_full_name_of_single_interface_from_contract_name_using_concrete_type()
        {
            var result = MessagingBase.ContractTypeName(typeof(SuperMetadata));

            Assert.That(result, Is.EqualTo("Example.Types.IMetadataFile"));
        }