Наследование: ComponentDialog
Пример #1
0
        /*
         * public static string FixTag( string tagText, TagCasing casingFormat, out List<char> rejectedChars)
         * {
         *  var result = FilterChars(tagText, out rejectedChars);
         *  result = ChangeToSnakeCasing(result);
         *  return result;
         * }
         */
        public static void FixAllTagsInFiles(ImageFiles imageFiles)//, TagCasing casingFormat = TagCasing.SnakeCase)
        {
            var cancel        = false;
            var cancelContext = new CancelDialogDataContext();
            var cancelDialog  = new CancelDialog();

            cancelContext.CurrentValue  = 0;
            cancelContext.MaxValue      = imageFiles.Count;
            cancelContext.PerformAction = () =>
            {
                foreach (var filePath in imageFiles)
                {
                    if (cancel)
                    {
                        break;
                    }
                    var cleaned = ImageFileUtil.GetImageTags(filePath);
                    ImageFileUtil.ApplyTagsToImage(filePath, cleaned);
                    cancelContext.CurrentValue++;
                }
            };
            cancelContext.OnCancel = (s, e) => { cancel = true; cancelDialog.Close(); };
            cancelContext.OnClosed = (s, e) => { cancel = true; cancelDialog.Close(); };
            cancelDialog.SetContext(cancelContext);
            cancelDialog.ShowDialog();
        }
Пример #2
0
        async void onCancelButtonClicked(object source, ButtonClickArgs args)
        {
            app_id   = args.id_val;
            app_temp = ((FrameworkElement)source).DataContext as AppointmentDetails;
            CancelDialog dialog = new CancelDialog();

            dialog.ButtonClicked += this.onYesButtonClicked;
            await dialog.ShowAsync();
        }
Пример #3
0
 /// <summary>
 /// Show the cancel dialog to let the user cancel the long download
 /// </summary>
 /// <param name="localLock">The lock to ensure no stale updates</param>
 /// <param name="cancelToken">The download token to cancel</param>
 public async void ShowCancelDialog(long localLock, CancellationTokenSource cancelToken, string trackName)
 {
     if (!App.isInBackgroundMode && localLock == App.playbackService.GlobalLock)
     {
         await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             CancelDialog.SetCancelToken(cancelToken);
             CancelDialog.SetTrackName(trackName);
             CancelDialog.Visibility = Visibility.Visible;
         });
     }
 }
 async void Cancel()
 {
     if (PermitInfo.PermitStatus == 2)
     {
         CancelDialog cancelDialogObj = new CancelDialog(this);
         cancelDialogObj.ShowDialog();
     }
     else
     {
         MessageBox.Show("The permit has been Cancelled already.");
     }
 }
Пример #5
0
        /// <summary>
        /// Used when freeing memory
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            if (App.isInBackgroundMode)
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    this.KeyDown       -= Page_KeyUp;
                    currentNavSelection = null;
                    loadingLocks.Clear();

                    // direct elements
                    UserName.PointerReleased         -= UserElement_PointerReleased;
                    UserPicContainer.PointerReleased -= UserElement_PointerReleased;
                    BlankUser.PointerReleased        -= UserElement_PointerReleased;
                    Hamburger.Click -= Hamburger_Click;
                    Back.Click      -= Back_Click;
                    HamburgerOptions.SelectionChanged -= HamburgerOptions_SelectionChanged;
                    SettingsItem.Click -= SettingsItem_Click;

                    CancelDialog.Unload();
                    PlaybackMenu.UserControl_Unloaded(null, null);
                    PlaybackMenu.Unloaded -= PlaybackMenu.UserControl_Unloaded;

                    // dependant pages
                    await Task.Run(() =>
                    {
                        if (browsePage != null)
                        {
                            browsePage.Page_Unloaded(null, null);
                        }
                        if (profilePage != null)
                        {
                            profilePage.Page_Unloaded(null, null);
                        }
                        if (yourMusicPage != null)
                        {
                            yourMusicPage.Page_Unloaded(null, null);
                        }
                        if (searchPage != null)
                        {
                            searchPage.Page_Unloaded(null, null);
                        }
                        if (settingsPage != null)
                        {
                            settingsPage.Page_Unloaded(null, null);
                        }
                    });
                    if (browsePage != null)
                    {
                        browsePage.Unloaded -= browsePage.Page_Unloaded;
                    }
                    if (profilePage != null)
                    {
                        profilePage.Unloaded -= profilePage.Page_Unloaded;
                    }
                    if (yourMusicPage != null)
                    {
                        yourMusicPage.Unloaded -= yourMusicPage.Page_Unloaded;
                    }
                    if (searchPage != null)
                    {
                        searchPage.Unloaded -= searchPage.Page_Unloaded;
                    }
                    if (settingsPage != null)
                    {
                        settingsPage.Unloaded -= settingsPage.Page_Unloaded;
                    }

                    // announcements
                    Announcements.Content         = null;
                    PreviousAnnouncement.Click   -= PreviousAnnouncement_Click;
                    NextAnnouncement.Click       -= NextAnnouncement_Click;
                    CloseAnnouncements.Click     -= CloseAnnouncements_Click;
                    AnnouncementsContainer.KeyUp -= AnnouncementsContainer_KeyUp;
                });
            }
        }
Пример #6
0
        }                                                                                            //, "jpeg", "gif", "png", };

        public static List <string> GetImageFilenames(string sourcePath = null, TagQueryCriteria tagQueryCriteria = null)
        {
            sourcePath = sourcePath ?? PersistanceUtil.RetreiveSetting(Setting.SourceDirectory);
            if (!Directory.Exists(sourcePath))
            {
                sourcePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            }
            tagQueryCriteria = tagQueryCriteria ?? new TagQueryCriteria();

            var result = new List <string>();
            var query  = tagQueryCriteria.GetQueryClause(sourcePath, out bool randomize);

            var windowsSearchConnection = @"Provider=Search.CollatorDSO.1;Extended Properties=""Application=Windows""";

            using (OleDbConnection connection = new OleDbConnection(windowsSearchConnection))
            {
                connection.Open();
                var command = new OleDbCommand(query, connection);
                try
                {
                    using (var r = command.ExecuteReader())
                    {
                        var cont     = true;
                        var context  = new CancelDialogDataContext();
                        var dialogue = new CancelDialog(context);
                        context.OnCancel = (n, m) => cont = false;
                        context.OnClosed = (n, m) => context.OnCancel(n, null);

                        dialogue.Show();
                        while (cont)
                        {
                            try
                            {
                                cont = r.Read();
                                var filepath = $"{r[0]}";

                                if (IsJpg(filepath))
                                {
                                    result.Add(filepath);
                                }
                            }
                            catch (Exception e) { Debug.WriteLine(e); }
                            finally { dialogue.Close(); }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                    var dialogue = new CancelDialog();
                    var context  = new CancelDialogDataContext();
                    int i;
                    var files = Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories);
                    context.MaxValue      = files.Length;
                    context.PerformAction = () =>
                    {
                        for (i = 0; i < files.Length; i++)
                        {
                            var fileName = files[i];
                            if (IsJpg(fileName) && MatchesCriteria(fileName, tagQueryCriteria))
                            {
                                result.Add(fileName);
                            }

                            context.CurrentValue++;
                        }
                    };
                    context.OnCancel = (n, m) => { i = files.Length; dialogue.Close(); };
                    context.OnClosed = (n, m) => context.OnCancel(n, null);

                    dialogue.SetContext(context);
                    dialogue.ShowDialog();
                }
                finally
                {
                    connection.Close();
                }
            }
            if (randomize)
            {
                result.Shuffle();
            }

            return(result);
        }
Пример #7
0
        public static System.Collections.Async.IAsyncEnumerable <Dictionary <string, List <TagSuggestion> > > RequestBatchAnalysis(IEnumerable <string> imageFilePaths, bool skipAutoTagged = true)
        {
            return(new AsyncEnumerable <Dictionary <string, List <TagSuggestion> > >(async yield =>
            {
                var result = new Dictionary <string, List <TagSuggestion> >();
                if (IsPerformingBatchOperation)
                {
                    MessageBox.Show("only one batch operation may be performed at a time!");
                    yield.Break();
                }

                IsPerformingBatchOperation = true;
                var tokenSource = new CancellationTokenSource();
                var token = tokenSource.Token;
                var cancelContext = new CancelDialogDataContext()
                {
                    MaxValue = imageFilePaths.Count(),
                    OnCancel = (s, e) => { tokenSource.Cancel(); },
                    OnClosed = (s, e) => { tokenSource.Cancel(); }
                };
                CancelDialog cancelWindow = null;
                await App.Current.Dispatcher.InvokeAsync(() =>
                {
                    cancelWindow = new CancelDialog(cancelContext);
                    cancelWindow.Show();
                });
                var splitPaths = new List <List <string> >();
                splitPaths.Add(new List <string>());
                long maxfilesize = 9000000;//9mb
                long splitSize = 0;
                foreach (var imageFilePath in imageFilePaths)
                {
                    var i = splitPaths.Count - 1;
                    var thisFileSize = new FileInfo(imageFilePath).Length;
                    if (thisFileSize > maxfilesize)
                    {
                        continue;
                    }
                    if ((splitPaths[i].Count >= 8) || (splitSize + thisFileSize > maxfilesize))
                    {
                        splitPaths.Add(new List <string>());
                        splitSize = 0;
                        i++;
                    }

                    if (skipAutoTagged && ImageFileUtil.GetImageTags(imageFilePath).Any(t => t.TagName.ToLower().Contains("auto") && t.TagName.ToLower().Contains("tagged")))
                    {
                        App.Current.Dispatcher.Invoke(() => cancelContext.CurrentValue++);
                        continue;
                    }
                    splitSize += thisFileSize;
                    splitPaths[i].Add(imageFilePath);
                }
                foreach (var paths in splitPaths)
                {
                    try
                    {
                        result = VisionAPISuggestions.VisionApi.RequestBatchVisionAnalysis(paths);

                        var input = paths.Select((path) => new ClarifaiFileImage(File.ReadAllBytes(path), path));
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }
                        var res = await clarifaiClient.WorkflowPredict("workflow", input).ExecuteAsync();
                        if (res.IsSuccessful)
                        {
                            foreach (var workflow in res.Get().WorkflowResults)
                            {
                                var imageFilePath = workflow.Input.ID;
                                var suggestions = ParsePredictions(imageFilePath, workflow.Predictions);
                                if (result.ContainsKey(imageFilePath))
                                {
                                    result[imageFilePath].AddRange(suggestions);
                                }
                                else
                                {
                                    result.Add(imageFilePath, suggestions);
                                }
                            }
                        }
                        else
                        {
                            Debug.WriteLine("batch clarifai analysis was unsuccessful");
                        }
                        foreach (var path in paths)
                        {
                            if (result.ContainsKey(path))
                            {
                                result[path].Add(new TagSuggestion(new ImageTag("autoTagged"), 1, "general"));
                            }
                            else
                            {
                                result.Add(path, new List <TagSuggestion>(new TagSuggestion[] { new TagSuggestion(new ImageTag("autoTagged"), 1, "general") }));
                            }

                            result[path].AddRange(ImageFileUtil.GetImageTags(path).Select(tag => new TagSuggestion(tag, 1, "preexisting")));
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("error thrown in batch conversion\n\n" + e);
                    }
                    finally
                    {
                        await yield.ReturnAsync(result);
                    }
                    Thread.Sleep(1000);//can only make a call every 1 sec
                    App.Current.Dispatcher.Invoke(() => cancelContext.CurrentValue += paths.Count);
                }
                App.Current.Dispatcher.Invoke(() => cancelWindow.Close());
                IsPerformingBatchOperation = false;
            }));
        }