Exemplo n.º 1
0
        public List <JiraAction> GetActionsForApplication(string application)
        {
            var isValidApp = Applications.Any(a => a.Equals(application, StringComparison.OrdinalIgnoreCase));

            if (!isValidApp)
            {
                return(null);
            }
            return(Actions.Where(i => i.Applications == null ||
                                 i.Applications.Count == 0 ||
                                 i.Applications.Contains(application, StringComparer.OrdinalIgnoreCase)
                                 ).Select(i => i).ToList());
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="applicationPath"></param>
        /// <returns></returns>
        public async Task RegisterInstalledApplication(string applicationPath)
        {
            if (Applications.Any(x => String.Equals(x.InstalledPath, applicationPath)))
            {
                RaiseError("既に登録済みのアプリケーションです。");
                return;
            }

            var application = new InstalledApplication(applicationPath);

            await application.InitializeAsync(_appInfo).ConfigureAwait(false);

            if (!application.IsSupported)
            {
                RaiseError("サポートされていないアプリケーションです。");
                return;
            }

            Applications.Add(application);

            await SaveAsync().ConfigureAwait(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Jednosekundový tik aplikace, zjištuje jméno aplikace na popředí pomocí WinApi funkcí a bud přičítá do již existující aplikace nebo vytváří novou
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void applicationTimer_Tick(object sender, EventArgs e)
        {
            if (firstSend)
            {
                Messenger.Default.Send(new TimeSpan(0, 0, wholeTime));
                firstSend = false;
            }


            string strTitle = getWindowName();

            if (discludedPrograms.Contains(strTitle))
            {
                return;
            }

            if (procrastinationTimer % 60 == 0)
            {
                notification.ShowNotification(new TimeSpan(0, 0, procrastinationTimer).ToString());
            }

            if (strTitle != "EOP" && !timerState)
            {
                Messenger.Default.Send(new SimpleMessage {
                    Type = SimpleMessage.MessageType.ApplicationDeactivated
                });
            }

            if (timerState && !timerStopedByCommand)
            {
                if (Applications.Any(p => p.name == strTitle))
                {
                    var application = Applications.Single(i => i.name == strTitle);
                    application.timeInApp = application.timeInApp.Add(oneSecond);
                    wholeTime++;

                    application.percenTimeInApp = (int)((application.timeInApp.TotalSeconds / wholeTime) * 100);

                    categories[application.Category.name].timeInCategory = categories[application.Category.name].timeInCategory.Add(oneSecond);

                    foreach (KeyValuePair <string, Category> item in categories)
                    {
                        if (item.Value.timeInCategory == item.Value.target && item.Value.target != new TimeSpan(0, 0, 0))
                        {
                            notification.ShowNotificationCategory(item.Value.translatedName);
                        }
                    }

                    recountThePercentage();


                    Messenger.Default.Send(refreshMessage);

                    if (notificationAllowed)
                    {
                        if (application.Category.name != "Work")
                        {
                            procrastinationTimer++;
                        }
                        else
                        {
                            procrastinationTimer = 1;
                        }
                    }
                }
                else
                {
                    if (knownCategories.ContainsKey(strTitle))
                    {
                        Applications.Add(new Application {
                            name = strTitle, timeInApp = new TimeSpan(), Category = categories[knownCategories[strTitle]]
                        });
                        var application = Applications.Single(i => i.name == strTitle);
                        setCategoryIcon(application, categories[knownCategories[strTitle]].name);
                    }
                    else
                    {
                        Applications.Add(new Application {
                            name = strTitle, timeInApp = new TimeSpan(), Category = categories["Other"]
                        });
                        knownCategories.Add(strTitle, "Other");
                        var application = Applications.Single(i => i.name == strTitle);
                        setCategoryIcon(application, "Other");
                    }
                }
            }
        }
Exemplo n.º 4
0
        public async Task <bool> InstallApplicationAsync(string id)
        {
            if (Applications.Any(x => x.Id == id))
            {
                RaiseError("指定されたアプリケーションは既にインストールされています。");
                return(false);
            }

            var target = _appInfo.Applications.FirstOrDefault(x => x.Id == id);

            if (target == null)
            {
                RaiseError("指定された識別子は登録されていません。");
                return(false);
            }

            var appDir        = new DirectoryInfo(Path.Combine(Settings.ApplicationRootDirectoryPath, target.Id));
            var installedPath = Path.Combine(appDir.FullName, target.Id + ".exe");

            if (appDir.Exists)
            {
                // アプリケーションのフォルダが存在していてもいいが、exe があったらアウト
                // (Candy がディレクトリだけ作成して何らかの理由でインストールできずに落ちた場合などを考慮)
                if (File.Exists(installedPath))
                {
                    // TODO: モデルがボタンのテキスト知ってちゃダメでしょ(エラーを識別するコード的なものを渡してビュー側でメッセージを決定した方が良さそう?)
                    RaiseError("指定されたアプリケーションは既にインストールされています。このアプリケーションを Candy で管理するには「インストール済みアプリケーションの追加」を選択してください。");
                    return(false);
                }
            }
            else
            {
                // フォルダがなければ作る
                appDir.Create();
            }

            var client = new HttpClient();

            var urlTemplate = target.InstallUrl ?? _appInfo.DefaultInstallUrl;
            var url         = urlTemplate.Replace("{appName}", target.Id);

            var response = await client.GetAsync(url).ConfigureAwait(false);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    RaiseError("このアプリケーションは Candy でインストールすることができません。");
                    return(false);
                }

                RaiseError(response.StatusCode.ToString());
                return(false);
            }

            var tempFileName = Path.GetTempFileName();

            try
            {
                using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                    using (var zip = File.OpenWrite(tempFileName))
                    {
                        await stream.CopyToAsync(zip).ConfigureAwait(false);
                    }

                ZipFile.ExtractToDirectory(tempFileName, appDir.FullName);

                await RegisterInstalledApplication(installedPath).ConfigureAwait(false);

                return(true);
            }
            finally
            {
                File.Delete(tempFileName);
            }
        }
Exemplo n.º 5
0
        protected override async Task OnGetInternalAsync(SqlConnection connection)
        {
            TeamId = CurrentOrgUser.CurrentTeamId ?? 0;

            SelectedLabel = await connection.FindAsync <Label>(FilterLabelId);

            var appLabels = await new NewItemAppLabels()
            {
                OrgId = OrgId
            }.ExecuteAsync(connection);
            var teamLabels = await new TeamLabels()
            {
                OrgId = OrgId, TeamId = TeamId
            }.ExecuteAsync(connection);

            NewItemLabels = appLabels.Concat(teamLabels);
            Labels        = NewItemLabels.ToLookup(row => row.ApplicationId);

            var labelCounts = await new ItemCountsByLabel()
            {
                OrgId             = OrgId,
                TeamId            = CurrentOrgUser.CurrentTeamId ?? 0,
                AppId             = CurrentOrgUser.EffectiveAppId,
                HasProject        = false,
                HasAssignedUserId = false,
                HasPriority       = false
            }.ExecuteAsync(connection);

            OpenItemCounts = labelCounts.ToDictionary(row => row.LabelId, row => row.Count);

            Applications = await new Applications()
            {
                OrgId = OrgId, AllowNewItems = true, TeamId = TeamId, IsActive = true
            }.ExecuteAsync(connection);
            Teams = await new Teams()
            {
                OrgId = OrgId, IsActive = true
            }.ExecuteAsync(connection);
            TeamInfo = Teams.ToDictionary(row => row.Id); // used to give access to Team.UseApplications for determining whether to show app dropdown in new item form

            if (!Applications.Any() && TeamId != 0)
            {
                SelectedApp = new Application()
                {
                    Name = $"Enter New {CurrentOrgUser.CurrentTeam.Name} work item"
                };
            }

            if (AppId != 0 && SelectedApp == null)
            {
                SelectedApp = await Data.FindAsync <Application>(AppId);
            }

            var workItemLabelMap = SelectedLabels
                                   .Select(grp => new { WorkItemId = grp.Key, LabelId = GetFilteredLabelId(grp) })
                                   .ToDictionary(row => row.WorkItemId, row => row.LabelId);

            var notifyResults = await new LabelSubscriptionUsers()
            {
                OrgId = OrgId
            }.ExecuteAsync(connection);
            var notifyUserLookup = notifyResults.ToLookup(row => row.LabelId);

            LabelNotifyUsers = notifyUserLookup.ToDictionary(row => row.Key, items => string.Join(", ", items.Select(u => u.UserName)));

            AppLabelItems = WorkItems.ToLookup(row => new AppLabelCell(row.ApplicationId, workItemLabelMap[row.Id]));

            var instructions = await new MyLabelInstructions()
            {
                OrgId = OrgId
            }.ExecuteAsync(connection);

            LabelInstructions = instructions.ToDictionary(row => row.LabelId);
        }