Ejemplo n.º 1
0
        static void Main()
        {
            #region Check for Existing Running Instances
            const string appName = "Archival Tool";
            bool         createdNew;

            var mutex = new Mutex(true, appName, out createdNew);

            if (!createdNew)
            {
                return;
            }
            #endregion

            // Configure logging
            XmlConfigurator.Configure();

            // Configure application settings
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Configure archival metadata
            ArchiveMetadata.Initialize();

            // Begin running core form app
            using (new TrayIcon())
            {
                Application.Run();
            }
        }
Ejemplo n.º 2
0
            public SortWorker(ConcurrentQueue <FileInfo> queue) : base()
            {
                DoWork += async delegate
                {
                    while (!queue.IsEmpty)
                    {
                        try
                        {
                            if (queue.TryDequeue(out var file))
                            {
                                if (file.IsReadOnly)
                                {
                                    file.Attributes = FileAttributes.Normal;
                                }

                                var folder = ArchiveMetadata.GetArchiveDirectory(file);

                                for (int i = 0; i < Settings.Default.FileMoveAttempts; i++)
                                {
                                    try
                                    {
                                        string
                                            newFullName = $"{folder.FullName}{Path.DirectorySeparatorChar}{Path.GetFileNameWithoutExtension(ArchiveMetadata.RemoveAddendums(file.Name))}";
                                        if (File.Exists($"{newFullName}{file.Extension}"))
                                        {
                                            int iterator = 0;
                                            while (File.Exists($"{newFullName} ({iterator}){file.Extension}"))
                                            {
                                                iterator++;
                                            }
                                            newFullName = $"{newFullName} ({iterator})";
                                        }
                                        file.MoveTo($"{newFullName}{file.Extension}");
                                    }
                                    catch (IOException)
                                    {
                                        await Task.Delay(Settings.Default.ThreadWaitTime);

                                        continue;
                                    }
                                    break;
                                }
                                log.Info($"Sorted File: {file.FullName}");
                            }
                            else
                            {
                                await Task.Delay(Settings.Default.ThreadWaitTime);
                            }
                        }
                        catch (IOException ex) { log.Info("IOException moving file", ex); }
                        catch (Exception ex) { log.Error("Exception moving file", ex); }
                    }
                };
            }