コード例 #1
0
        /// <summary>
        /// 実行ファイルのパスからアプリケーションを登録する
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="isFromDropped"></param>
        public void AddListFromPath(string filePath, bool isFromDropped = true)
        {
            string[] parsed = filePath.Split('\\');
            string   name   = parsed.Last().Replace(".exe", "");

            if (mainWindow.AppDatas.Any(a => a.ProcessName == name))
            {
                if (!isFromDropped)
                {
                    MessageBox.Show("既に登録されています");
                }
            }
            else
            {
                Mouse.OverrideCursor = Cursors.Wait;
                AppDataObject appData = new AppDataObject(mainWindow, name)
                {
                    DisplayedName = name
                };
                IconGetter.SetIconToNewAppData(filePath, appData);
                appData.SaveFileDatas();
                AddFileListWindow(appData);
                lock (mainWindow.AppDatas)
                {
                    mainWindow.AppDatas.Add(appData);
                }

                mainWindow.SaveAndLoader.SaveCsvData();
            }
            UpdateListView();
            Mouse.OverrideCursor = null;
        }
コード例 #2
0
        /// <summary>
        /// 右クリックメニュー>ファイル拡張子を設定 をクリック時
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem_ClickSetFileExtension(object sender, RoutedEventArgs e)
        {
            AppDataObject appData       = (AppDataObject)mainWindow.listView.SelectedItem;
            var           fileExtension = new FileExtensionSettingWindow(appData);

            fileExtension.ShowDialog();
        }
コード例 #3
0
        /// <summary>
        /// アプリデータを保存
        /// </summary>
        /// <param name="path">保存先パス</param>
        public void SaveCsvData(string path = "")
        {
            try
            {
                string filePath = Settings.CurrentDir + "/data/appData.csv";

                using (var sw = new StreamWriter(filePath, false, Encoding.UTF8))
                {
                    sw.WriteLine($"アプリケーション名,今日の起動時間,累積起動時間,最終起動日時," +
                                 $"toggle連携フラグ,連携プロジェクト名,連携タグ名, ファイル拡張子");
                    foreach (AppDataObject appData in mainWindow.AppDatas)
                    {
                        sw.WriteLine($"{appData.ProcessName}," +
                                     $"{AppDataObject.ConvertTimeSpanToSavingFormattedString(appData.TodaysTime)}," +
                                     $"{AppDataObject.ConvertTimeSpanToSavingFormattedString(appData.TotalTime)}," +
                                     $"{appData.GetLastLaunchedTimeText}," +
                                     $"{appData.IsLinkedToToggl.ToString()}," +
                                     $"{appData.LinkedProjectName}," +
                                     $"{appData.LinkedTag}," +
                                     $"{appData.GetFileExtensionText()}");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }

            mainWindow.AppDatas.ToList().ForEach(a => a.SaveFileDatas());
        }
コード例 #4
0
        /// <summary>
        /// 右クリックメニュー>表示アプリ名を変更 をクリック時
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem_ClickChangeDesplayedName(object sender, RoutedEventArgs e)
        {
            AppDataObject appData = (AppDataObject)mainWindow.listView.SelectedItem;
            var           appNameSettingWindow = new AppNameSettingWindow(mainWindow, appData);

            appNameSettingWindow.ShowDialog();
        }
コード例 #5
0
 public FileExtensionSettingWindow(AppDataObject appData)
 {
     this.AppData = appData;
     InitializeComponent();
     TextBox.Text = appData.GetFileExtensionText();
     OKButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent,
                         new RoutedEventHandler(OnClicked));
 }
コード例 #6
0
 /// <summary>
 /// アプリケーションのデータを削除
 /// </summary>
 /// <param name="appData"></param>
 public void RemoveAppData(AppDataObject appData)
 {
     appData.RemoveAllFileData();
     lock (AppDatas)
     {
         AppDatas.Remove(appData);
     }
     ListViewSetter.UpdateListView();
     SaveAndLoader.SaveCsvData();
     IconGetter.RemoveIconImage(appData.ProcessName);
 }
コード例 #7
0
        public AppNameSettingWindow(MainWindow mainWindow, AppDataObject data)
        {
            InitializeComponent();
            this.mainWindow   = mainWindow;
            appData           = data;
            AppNameInput.Text = appData.DisplayedName;

            OKButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent,
                                new RoutedEventHandler(OnClickedOK));

            cancelButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent,
                                    new RoutedEventHandler(OnClickedCancel));
        }
コード例 #8
0
        public FileViewWindow(AppDataObject data)
        {
            InitializeComponent();
            this.Title   = data.DisplayedName + "のファイル別作業時間一覧";
            this.AppData = data;

            fileListView.ItemsSource = AppData.Files;

            DeleteAllButton.AddHandler(System.Windows.Controls.Primitives.ButtonBase.ClickEvent,
                                       new RoutedEventHandler(Button_ClickAllDelete));

            CreateMenu();

            Closing += Window_Closing;
        }
コード例 #9
0
        /// <summary>
        /// 右クリックメニュー>表示内容をコピー をクリック時
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem_ClickCopy(object sender, RoutedEventArgs e)
        {
            string text = "";

            foreach (var item in mainWindow.listView.SelectedItems)
            {
                AppDataObject data = (AppDataObject)item;
                text += $"{data.DisplayedName}の起動時間 今日:{data.GetTodaysTimeText} 累積:{data.GetTotalTimeText}\n";
            }

            if (text != "")
            {
                Clipboard.SetDataObject(text);
            }
        }
コード例 #10
0
        /// <summary>
        /// アプリデータを読み込み
        /// </summary>
        /// <param name="path">保存先パス</param>
        public void LoadData()
        {
            try
            {
                string filePath = Settings.CurrentDir + "/data/appData.csv";
                using (StreamReader reader = new StreamReader(filePath, Encoding.UTF8))
                {
                    reader.ReadLine();
                    while (!reader.EndOfStream)
                    {
                        string        line       = reader.ReadLine();
                        string[]      parsedLine = line.Split(',');
                        AppDataObject data       = new AppDataObject(mainWindow, parsedLine[0]);
                        data.DisplayedName = parsedLine[0];
                        data.TodaysTime    = AppDataObject.ConvertStringToTimeSpan(parsedLine[1]);
                        data.TotalTime     = AppDataObject.ConvertStringToTimeSpan(parsedLine[2]);

                        //structなので元データはnullでよい
                        data.SetLastRunningTime(parsedLine[3]);

                        //nullの場合はfalse
                        bool isLinkedToToggl;
                        bool.TryParse(parsedLine[4], out isLinkedToToggl);
                        data.IsLinkedToToggl = isLinkedToToggl;

                        //nullでよい
                        data.LinkedProjectName = parsedLine[5];
                        data.LinkedTag         = parsedLine[6];

                        if (!string.IsNullOrEmpty(parsedLine[7]))
                        {
                            data.SetFileExtensions(parsedLine[7]);
                        }

                        mainWindow.AppDatas.Add(data);
                    }
                }
            }
            catch (Exception ex)
            {
                //データが存在しない場合など
                ErrorLogger.Log(ex);
            }

            mainWindow.AppDatas.ToList().ForEach(a => a.LoadFileDatas());
        }
コード例 #11
0
        public void okButton_OnClicked(object sender, RoutedEventArgs e)
        {
            var sumTime = new TimeSpan(0, 0, 0);
            var appData = fileViewWindow.AppData;

            for (int i = appData.Files.Count - 1; i >= 0; i--)
            {
                if (fileViewWindow.fileListView.SelectedItems.Contains(appData.Files[i]))
                {
                    sumTime += appData.Files[i].TotalTime;
                    appData.RemoveFileDataFromList(appData.Files[i]);
                }
            }

            var fileData = AppDataObject.CreateFileDate(TextBox.Text, sumTime);

            fileViewWindow.AppData.AddFileDataToList(fileData);

            Close();
        }
コード例 #12
0
        /// <summary>
        /// TimeEntryを追加
        /// </summary>
        /// <param name="appData"></param>
        public void SetTimeEntry(AppDataObject appData)
        {
            int       duration = (int)(appData.LastRunningTime - appData.LaunchedTime).TotalSeconds;
            TimeEntry te       = new TimeEntry()
            {
                IsBillable  = true,
                CreatedWith = "TogglAPI.Net",
                Description = appData.DisplayedName,
                Duration    = duration,
                Start       = appData.LaunchedTime.ToIsoDateStr(),
                Stop        = appData.LastRunningTime.ToIsoDateStr(),

                WorkspaceId = defaultWorkspaceID
            };

            if (ProjectIDs.ContainsKey(appData.LinkedProjectName))
            {
                te.ProjectId = ProjectIDs[appData.LinkedProjectName];
            }

            if (!string.IsNullOrEmpty(appData.LinkedTag))
            {
                te.TagNames = new List <string>()
                {
                    appData.LinkedTag
                };
            }

            try
            {
                if (te != null)
                {
                    timeEntryService.Add(te);
                    Console.WriteLine($"sended:{te}");
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }
コード例 #13
0
        /// <summary>
        /// ファイルパスからアイコンを読み込み、保存
        /// </summary>
        /// <param name="path"></param>
        public static void SetIconToNewAppData(string path, AppDataObject appData)
        {
            try
            {
                var img         = Icon.ExtractAssociatedIcon(@path).ToBitmap();
                var imageSource = img.ToImageSource();
                appData.IconImageSource = imageSource;

                var savePath = Settings.IconFileDirFullDirPath + $"{appData.ProcessName}.png";
                SaveIconImage(imageSource, savePath);
            }
            catch (FileNotFoundException ex)
            {
                var defaultIconImagePath = Settings.IconFileDirFullDirPath + $"defaultIcon.png";
                ErrorLogger.Log(ex);
                LoadIconImage(defaultIconImagePath);
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }
コード例 #14
0
        public void CountOnlyActiveApp()
        {
            string        processName = "";
            StringBuilder sb          = new StringBuilder(65535);

            GetWindowText(GetForegroundWindow(), sb, 65535);
            IntPtr hWnd = GetForegroundWindow();
            int    processid;

            try
            {
                GetWindowThreadProcessId(hWnd, out processid);
                if (0 != processid)
                {
                    Process p = Process.GetProcessById(processid);
                    if (Properties.Settings.Default.IsCountingNotMinimized)
                    {
                        if (p.MainWindowHandle != IntPtr.Zero && !IsIconic(p.MainWindowHandle))
                        {
                            processName = p.ProcessName.ToString();
                        }
                    }
                    else
                    {
                        processName = p.ProcessName.ToString();
                    }
                    AppDataObject data = mainWindow.AppDatas.ToList().Find(a => a.ProcessName == processName);
                    if (data != null)
                    {
                        data.AccumulateTimes();
                    }
                }
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }
コード例 #15
0
        /// <summary>
        /// リストビューにアイテムを追加する
        /// </summary>
        /// <param name="data"></param>
        private void AddFileListWindow(AppDataObject data)
        {
            FileViewWindow fileListWindow = new FileViewWindow(data);

            mainWindow.FileViewWindows.Add(fileListWindow);
        }