Beispiel #1
0
        static async Task Main(string[] args)
        {
            /*
             * 1.修改文件内容的名称
             *  遍历所有文件,使用正则表达式查找匹配的内容做替换(YourWebApiName替换为{你的项目名称})
             *  修改包括:YourWebApiName命名空间,
             * 2.修改文件名称
             *  修改包括:.csproj,
             * 2.修改文件夹名称
             *  修改包括:
             *  YourWebApiName.ApiServices,YourWebApiName.IRepository,YourWebApiName.IServices
             *  YourWebApiName.Repository,YourWebApiName.Services,YourWebApiName.Models
             *  可选修改(不修改就可以直接删掉,建议修改要不然很多都可以删掉):
             */

            var AppSettings = await "Configurations/appsettings.json".ReadJson <AppSettings>();

            var dirOperator = new DirectoryOperator(
                new Regex("git"),
                new Regex("git|documents|AutoUpdateServer|common|database"),
                AppSettings.FileReplaceModels,
                AppSettings.ContentReplaceModels);

            dirOperator.DirectoryHandler(AppSettings.SourceDir);
            Console.WriteLine("Over");
            Console.ReadKey();
        }
Beispiel #2
0
        // =============================================================================================================
        // private method (プライベートメソッド)
        // =============================================================================================================
        #region "private method"

        /// ------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// ■Open (Open log file. 1 log file per date)
        /// </summary>
        /// <exception>
        /// </exception>
        /// <remarks>
        /// If file is not opening, m_LogFile is null -> open new log file
        /// Other hand,
        /// if current date same m_FileOpenningDate, do nothing.
        /// if current date different with m_FileOpenningDate, close opening log file and new log file should be created
        /// </remarks>
        /// <history>
        /// Ver.01.00.00.000  2013-04-11  (TSDV)hung.trinhhong  Create
        /// Ver.01.01.00.000  2013-06-07  (TSDV)hung.trinhhong  Update  Change specification
        /// </history>
        /// ------------------------------------------------------------------------------------------------------------
        private void Open()
        {
            //Get current datetime
            string currentDate = DateTime.Now.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
            string filePath    = m_SavePath + @"\" + currentDate + @"\" + m_FileName;

            // file is not opening
            if (m_LogFile == null)
            {
                m_LogFile = new TextFileAccessor();

                try
                {
                    // Confirm destination subfolder
                    string subfolderPath = m_SavePath + @"\" + currentDate;
                    if (!DirectoryOperator.Exists(subfolderPath))
                    {
                        // Create folder(m_savePath)/subfolder if not exist
                        DirectoryOperator.CreateDirectory(subfolderPath);
                    }

                    m_LogFile.Open(filePath, FileAccessMode.WriteMode);

                    m_LogFile.AutoFlush = true;

                    m_FileOpenningDate = DateTime.Now;
                }
                catch
                {
                    if (m_ExceptionHandling == ExceptionHandling.Throw)
                    {
                        throw;
                    }
                    else
                    {
                        // skip exception
                    }
                }
            }
            else
            {
                // Compare current datetime with datetime of openning log file (1 log file per day)
                string dateOfOpenningFile = m_FileOpenningDate.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                if (dateOfOpenningFile.CompareTo(currentDate) == 0)
                {
                    // do nothing
                }
                else
                {
                    // Firstly, close log openning log file
                    Close();
                    m_LogFile = null;

                    // Open log file recursive
                    this.Open();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Displays the root View.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
        {
            IExtendedWindowManager windowManager       = new ExtendedWindowManager();
            ILastFMClientFactory   lastFMClientFactory = new LastFMClientFactory();
            IScrobblerFactory      scrobblerFactory    = new ScrobblerFactory();
            ILocalFileFactory      localFileFactory    = new LocalFileFactory();
            IFileOperator          fileOperator        = new FileOperator();
            IDirectoryOperator     directoryOperator   = new DirectoryOperator();
            ISerializer <User>     userSerializer      = new DCSerializer <User>();
            MainViewModel          mainVM = new MainViewModel(windowManager, lastFMClientFactory, scrobblerFactory, localFileFactory, fileOperator, directoryOperator, userSerializer);

            windowManager.ShowWindow(new SystemTrayViewModel(windowManager, mainVM));
        }
Beispiel #4
0
        // =============================================================================================================
        // public method (パブリックメソッド)
        // =============================================================================================================
        #region "public method"

        /// ------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// ■DeleteBackupOverFile (Delete log files and retain specified number of log files)
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// Ver.01.00.00.000  2013-04-11  (TSDV)hung.trinhhong  Create
        /// Ver.01.01.00.000  2013-06-07  (TSDV)hung.trinhhong  Update Specification change
        /// Ver.01.01.00.001  2013-06-11  (TSDV)hung.trinhhong  Update Bug when create system semaphore
        /// Ver.01.01.00.002  2013-06-12  (TSDV)hung.trinhhong  Update Confirm rule for naming semaphore
        /// </history>
        /// ------------------------------------------------------------------------------------------------------------
        public void DeleteBackupOverFile()
        {
            // Create semaphore for delete
            string semaphoreForDeleteString = "SemaphoreForDelete";

            try
            {
                // Try to reference to exist system semaphore
                m_SemaphoreForDelete = Semaphore.OpenExisting(semaphoreForDeleteString);
            }
            catch
            {
                // Create new semaphore
                m_SemaphoreForDelete = CreateSemaphore(semaphoreForDeleteString);
            }

            try
            {
                m_SemaphoreForDelete.WaitOne();

                // Get subfolder list in m_savePath
                string[] allSubFolders = DirectoryOperator.GetDirectories(m_SavePath);
                if (allSubFolders.Length > m_KeepDays)
                {
                    int numberDeleteFolders = allSubFolders.Length - m_KeepDays;
                    for (int topIndex = 0; topIndex < numberDeleteFolders; topIndex++)
                    {
                        DirectoryOperator.Delete(allSubFolders[topIndex], true);
                    }
                }
            }
            catch
            {
                if (m_ExceptionHandling == ExceptionHandling.Throw)
                {
                    throw;
                }
                else
                {
                    // skip exception
                }
            }
            finally
            {
                m_SemaphoreForDelete.Release();
            }
        }
        /// <summary>
        /// Displays the root View.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
        {
            IExtendedWindowManager windowManager     = new ExtendedWindowManager();
            ILastFMClient          client            = new LastFMClient(APIKEY, APISECRET);
            IScrobblerFactory      scrobblerFactory  = new ScrobblerFactory();
            ILocalFileFactory      localFileFactory  = new LocalFileFactory();
            IFileOperator          fileOperator      = new FileOperator();
            IDirectoryOperator     directoryOperator = new DirectoryOperator();
            ISerializer            userSerializer    = new DCSerializer();
            ILogger         logger         = new Logger("log.txt");
            IGitHubClient   gitHubClient   = new GitHubClient(new ProductHeaderValue("Last.fm-Scrubbler-WPF"));
            IProcessManager processManager = new ProcessManager();
            MainViewModel   mainVM         = new MainViewModel(windowManager, client, scrobblerFactory, localFileFactory, fileOperator,
                                                               directoryOperator, userSerializer, logger, gitHubClient, processManager);

            windowManager.ShowWindow(new SystemTrayViewModel(windowManager, mainVM));
        }
Beispiel #6
0
        /// <summary>
        /// Displays the root View.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
        {
            IExtendedWindowManager windowManager     = new ExtendedWindowManager();
            ILastFMClient          client            = new LastFMClient(APIKEY, APISECRET);
            IScrobblerFactory      scrobblerFactory  = new ScrobblerFactory();
            ILocalFileFactory      localFileFactory  = new LocalFileFactory();
            IFileOperator          fileOperator      = new FileOperator();
            IDirectoryOperator     directoryOperator = new DirectoryOperator();
            ISerializer            userSerializer    = new DCSerializer();
            ILogger                logger            = new Logger("log.txt");
            IGitHubClient          gitHubClient      = new GitHubClient(new ProductHeaderValue("Last.fm-Scrubbler-WPF"));
            IProcessManager        processManager    = new ProcessManager();
            IDiscogsDataBaseClient discogsClient     = new DiscogsClient.DiscogsClient(new TokenAuthenticationInformation("vcrTuxlCPCANcLDUDcbGSYBxbODkeyywIUtYAMxg"));

            MainViewModel mainVM = new MainViewModel(windowManager, client, scrobblerFactory, localFileFactory, fileOperator,
                                                     directoryOperator, userSerializer, logger, gitHubClient, processManager, discogsClient);

            windowManager.ShowWindow(new SystemTrayViewModel(windowManager, mainVM));
        }
Beispiel #7
0
        /// <summary>
        /// delete unrelated hbv cached files
        /// </summary>
        private void CleanUnUsedHbvCache()
        {
            var rootInfo = new DirectoryInfo(Constant.CacheDir);
            var dirList  = rootInfo.EnumerateDirectories();

            foreach (DirectoryInfo dir in dirList)
            {
                var target = new DirectoryOperator(dir.FullName);
                var found  = false;
                foreach (var file  in this._appData.RecentFiles)
                {
                    if (file.CacheDir == target.Name)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    target.Delete();
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// メタファイルをパース
        /// </summary>
        /// <returns>true:パース成功、false:それ以外</returns>
        internal bool ParseMeta()
        {
            bool result = false;

            this.Index       = 0;
            this._rootDir    = "";
            this._contentDir = "";
            this._pages.Clear();
            this.Toc.Clear();
            try {
                var model = JsonConvert.DeserializeObject <MetaModel>(File.ReadAllText(this.MetaFile));
                this._rootDir    = new FileOperator(this.MetaFile).FileDir + @"\";
                this._contentDir = this._rootDir + this.ConvertWinPath(model.ContentDir) + @"\";
                this.Title       = model.Title;
                //if (0 < model.Cover?.Length) {
                //    this._pages.Add(this.ConvertWinPath(model.Cover));
                //}
                var contentDir = new DirectoryOperator(this._contentDir);
                contentDir.ParseChildren(false);
                foreach (var content in contentDir.Children)
                {
                    this._pages.Add(content.Name);
                }

                foreach (var content in model.TableOfContents)
                {
                    var toc = new TocModelEx(content);
                    if (0 < toc.Link?.Length)
                    {
                        if (this._pages.Contains(toc.Link))
                        {
                            toc.Index = this._pages.IndexOf(toc.Link);
                        }
                        toc.Link = this.ConvertWinPath(toc.Link);
                    }
                    if (0 < toc.Level && 0 < toc.Content?.Length)
                    {
                        var padding = " ";
                        if (2 == toc.Level)
                        {
                            padding = "  ";
                        }
                        else if (3 == toc.Level)
                        {
                            padding = "    ";
                        }
                        else if (4 == toc.Level)
                        {
                            padding = "      ";
                        }

                        toc.Content = padding + toc.Content;
                        if (0 < toc.Link.Length)
                        {
                            toc.FileIndex = string.Format("[{0:000}]  ", toc.Index + 1);
                        }
                        this.Toc.Add(toc);
                    }
                }
                result = true;
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }

            return(result);
        }
Beispiel #9
0
        /// <summary>
        /// 初期処理
        /// </summary>
        private void Initialize()
        {
            // delete cache icon
            var dirUtil = new DirectoryOperator(Constant.IconCache);

            dirUtil.Create();
            dirUtil.ParseChildren(false, new List <string>()
            {
                "tmp"
            });
            foreach (var child in dirUtil.Children)
            {
                ((FileOperator)child).Delete();
            }

            // set window position
            this._settings = AppRepository.Init(Constant.SettingFile);
            if (0 <= this._settings.Pos.X && (this._settings.Pos.X + this.Width) < SystemParameters.VirtualScreenWidth)
            {
                this.Left = this._settings.Pos.X;
            }
            if (0 <= this._settings.Pos.Y && (this._settings.Pos.Y + this.Height) < SystemParameters.VirtualScreenHeight)
            {
                this.Top = this._settings.Pos.Y;
            }

            // show title
            var fullname = typeof(App).Assembly.Location;
            var info     = System.Diagnostics.FileVersionInfo.GetVersionInfo(fullname);

            this._appTitle = $"MyQuickLauncher({info.ProductMajorPart}.{info.ProductMinorPart}.{info.ProductPrivatePart})";
            this.UpdateTitle();

            // setup grid items
            this._items = _items = ItemRepository.Init(Constant.AppDataFile);
            var index = 0;

            this._itemViews = new ItemView[Constant.ItemCount];
            for (int row = 0; row < this.cContainer.RowDefinitions.Count - 1; row++)
            {
                for (int col = 0; col < this.cContainer.ColumnDefinitions.Count; col++)
                {
                    var model = this._items.ItemList[this._settings.Page][index];
                    //model.PageNo = 1;
                    //model.Index = index;
                    if (!System.IO.File.Exists(model.Icon))
                    {
                        model.Icon = Constant.NoItemIcon;
                    }
                    var item = new ItemView(this, model, this._keybinding[index]);
                    this._itemViews[index] = item;
                    index++;
                    item.VerticalAlignment = VerticalAlignment.Bottom;
                    Grid.SetRow(item, row);
                    Grid.SetColumn(item, col);
                    item.ItemClick        += ItemClick;
                    item.ItemAdded        += ItemAdded;
                    item.ItemUpdated      += ItemUpdated;
                    item.ItemRemoved      += ItemRemoved;
                    item.ItemDir          += ItemDir;
                    item.VerticalAlignment = VerticalAlignment.Top;
                    this.cContainer.Children.Add(item);
                }
            }

            // register hot key
            this._hotkey.Register(ModifierKeys.None, Key.ImeNonConvert, (_, __) => {
                if (!this.ShowInTaskbar)
                {
                    NotifyMenuShow_Click(null, null);
                }
                else
                {
                    if (this.WindowState == WindowState.Minimized)
                    {
                        this.WindowState = WindowState.Normal;
                    }
                    this.Activate();
                }
            }
                                  );
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            OpenXMLParser     parser            = new OpenXMLParser();
            DirectoryOperator directoryOperator = new DirectoryOperator();

            IList <string> filePaths = new List <string>();
            IList <string> reportNameAndApprovalList = new List <string>();

            Console.WriteLine(@"Enter the path to your Docx Folder. Make sure to escape with '\\'.");
            Console.WriteLine(@"Example: C:\\Users\\foo\\Desktop\\DocxFolder");
            string folderPath = Console.ReadLine();

            Console.WriteLine(@"Enter the path to your text file + textfile name. Make sure to escape with '\\'.");
            string textFilePath = Console.ReadLine();

            try
            {
                filePaths = directoryOperator.GetListOfAllPaths(folderPath.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (!(filePaths.Count > 0))
            {
                Console.WriteLine("No files found in {0}.", folderPath);
                Console.ReadLine();
            }

            else
            {
                Console.WriteLine("Processing...");
                foreach (string filePath in filePaths)
                {
                    try
                    {
                        reportNameAndApprovalList.Add(parser.GetReportAndApproverInfo(filePath));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                try
                {
                    System.IO.File.WriteAllLines(textFilePath, reportNameAndApprovalList);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                Console.WriteLine("{0} files written to {1}", (parser.CountOfApprovals + parser.CountOfNonApprovals).ToString(), textFilePath);
                Console.WriteLine("# of Approvals: {0}", parser.CountOfApprovals.ToString());
                Console.WriteLine("# of NonApprovals: {0}", parser.CountOfNonApprovals.ToString());
                Console.WriteLine("Done.");
                Console.ReadLine();
            }
        }
Beispiel #11
0
 public void CreateDirTest()
 {
     DirectoryOperator.CreateDir(dataPath + "/Temp");
     Debug.Log("create dir!");
 }
Beispiel #12
0
 public void DeleteDirTest()
 {
     DirectoryOperator.DeleteDir(dataPath + "/Temp");
     Debug.Log("delete dir!");
 }