public async Task <string> SendCommandAsync(string[] arguments, CancellationToken cancel)
 {
     try
     {
         Running?.Invoke(this, arguments.Where(a => commands.Contains(a.ToLowerInvariant().Trim())).FirstOrDefault() ?? string.Empty);
         return(await _inner.SendCommandAsync(arguments, cancel));
     }
     finally
     {
         StoppedRunning?.Invoke(this, new EventArgs());
     }
 }
예제 #2
0
 public void Run()
 {
     Running?.Invoke(this);
     try
     {
         RunInternal();
     }
     catch (Exception ex)
     {
         Faulted?.Invoke(this, ex);
         return;
     }
     Success?.Invoke(this);
 }
예제 #3
0
 private void timeimage_Tick(object sender, EventArgs e)
 {
     if (Thuan)
     {
         idx++;
         if (idx >= imageList1.Images.Count)
         {
             idx = 0;
         }
     }
     else
     {
         idx--;
         if (idx < 0)
         {
             idx = imageList1.Images.Count - 1;
         }
     }
     picImage.Image = imageList1.Images[idx];
     //Kich hoat su kien co ten Running
     Running?.Invoke(this, Thuan, this.Speed);
 }
예제 #4
0
        private async Task LoadImages()
        {
            Running?.Invoke(this, EventArgs.Empty);

            // Set fast access to file properties
            var queryOptions = new QueryOptions(CommonFileQuery.OrderByName,
                                                new List <string> {
                ".jpg", ".jpeg", ".png", ".bmp"
            });

            queryOptions.SetThumbnailPrefetch(ThumbnailMode.SingleItem, Constants.ThumbnailSize,
                                              ThumbnailOptions.ReturnOnlyIfCached);
            queryOptions.SetPropertyPrefetch(
                PropertyPrefetchOptions.BasicProperties | PropertyPrefetchOptions.ImageProperties, null);

            using (var db = new Context())
            {
                // Old images in database
                var oldImages    = db.Images.Include(image => image.Tags);
                var oldImagesSet = oldImages.ToHashSet();

                // Load all images from folders
                var newImages = new List <Image>();
                var folders   = db.Folders.ToList();
                foreach (var folder in folders)
                {
                    var storageFolder =
                        await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(folder.Token);

                    var storageFiles = await storageFolder.CreateFileQueryWithOptions(queryOptions).GetFilesAsync();

                    // TODO: query.ContentsChanged += OnContentsChanged;
                    foreach (var storageFile in storageFiles)
                    {
                        var basicProperties = await storageFile.GetBasicPropertiesAsync();

                        var imageProperties = await storageFile.Properties.GetImagePropertiesAsync();

                        var newImage = new Image
                        {
                            Name         = Path.GetFileNameWithoutExtension(storageFile.Name),
                            FileType     = storageFile.FileType,
                            Path         = storageFile.Path,
                            Size         = basicProperties.Size,
                            DateModified = basicProperties.DateModified,
                            Height       = imageProperties.Height,
                            Width        = imageProperties.Width,
                            DateTaken    = imageProperties.DateTaken,
                            Latitude     = imageProperties.Latitude,
                            Longitude    = imageProperties.Longitude
                        };

                        var newImageBase = newImage.ToImageBase();
                        if (oldImagesSet.Contains(newImageBase))
                        {
                            oldImagesSet.Remove(newImageBase);
                            continue;
                        }

                        newImage.Id = Guid.NewGuid();

                        // Save Thumbnail to LocalFolder
                        using (var thumbnail =
                                   await storageFile.GetThumbnailAsync(ThumbnailMode.SingleItem, Constants.ThumbnailSize))
                        {
                            var saveFile =
                                await ApplicationData.Current.LocalFolder.CreateFileAsync(newImage.Id.ToString(),
                                                                                          CreationCollisionOption.ReplaceExisting);

                            using (var destFileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
                            {
                                var     inputBuffer = new Buffer(2048);
                                IBuffer buf;
                                while ((buf = await thumbnail.ReadAsync(inputBuffer, inputBuffer.Capacity,
                                                                        InputStreamOptions.None)).Length > 0)
                                {
                                    await destFileStream.WriteAsync(buf);
                                }
                            }
                        }

                        // Save location information
                        if (newImage.Latitude != null && newImage.Longitude != null)
                        {
                            var location = new BasicGeoposition
                            {
                                Latitude  = (double)newImage.Latitude,
                                Longitude = (double)newImage.Longitude
                            };
                            var result = await MapLocationFinder.FindLocationsAtAsync(new Geopoint(location));

                            if (result.Status == MapLocationFinderStatus.Success)
                            {
                                newImage.Region   = result.Locations[0].Address.Region;
                                newImage.District = result.Locations[0].Address.District;
                                newImage.Town     = result.Locations[0].Address.Town;
                            }
                        }

                        newImages.Add(newImage);
                    }
                }

                var hasOldImages = oldImagesSet.Any();
                var hasNewImages = newImages.Any();

                // Delete unexisted images in database
                if (hasOldImages)
                {
                    try
                    {
                        var unexistedImages = oldImages.AsEnumerable().Intersect(oldImagesSet.ToList()).ToList();
                        // Delete cascade
                        foreach (var image in unexistedImages)
                        {
                            var tags = image.Tags;
                            foreach (var tag in tags)
                            {
                                db.Tags.Remove(tag);
                            }
                        }

                        db.Images.RemoveRange(unexistedImages);
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                        throw;
                    }
                }

                // Add new images to database
                // ReSharper disable once InvertIf
                if (hasNewImages)
                {
                    var addImages = newImages.Select(image => image.ToImageBase());
                    db.Images.AddRange(addImages);
                    db.SaveChanges();
                }

                if (hasOldImages || hasNewImages)
                {
                    ContentChanged?.Invoke(this, EventArgs.Empty);
                }
            }

            Completed?.Invoke(this, EventArgs.Empty);
        }
예제 #5
0
 protected virtual void OnRunning(EventArgs <IJob> e)
 {
     Running?.Invoke(this, e);
 }
예제 #6
0
        public static void Initialize()
        {
            string[] args = Environment.GetCommandLineArgs();


            //  프레임워크 초기화
            {
                SpinWorker.Initialize();


                _stopRunningEvent = new EventWaitHandle(false, EventResetMode.ManualReset);
                _releaseEvent     = new EventWaitHandle(false, EventResetMode.ManualReset);
                Logger.Info(LogMask.Aegis, "Aegis Framework({0})", AegisVersion.ToString(3));
            }



            AegisTask.Run(() =>
            {
                //  컨텐츠 초기화 (UI 모드)
                if (Environment.UserInteractive)
                {
                    AegisTask.SafeAction(() =>
                    {
                        if (Initialized == null ||
                            Initialized.Invoke(args) == true)
                        {
                            Running?.Invoke();
                        }
                    });

                    AegisTask.SafeAction(() => { Finalizing?.Invoke(CloseReason.Close); });
                }
                //  컨텐츠 초기화 (서비스 모드)
                else
                {
                    ServiceMain.Instance.EventStart = () =>
                    {
                        AegisTask.SafeAction(() =>
                        {
                            if (Initialized == null ||
                                Initialized?.Invoke(System.Environment.GetCommandLineArgs()) == true)
                            {
                                //  Running이 설정된 경우에는 Running이 반환되기를 대기하고, 반환된 후 종료처리 진행
                                if (Running != null)
                                {
                                    (new Thread(() =>
                                    {
                                        AegisTask.SafeAction(() => { Running.Invoke(); });
                                        ServiceMain.Instance.Stop();
                                    })).Start();
                                }
                            }
                        });
                    };
                    ServiceMain.Instance.EventStop = () =>
                    {
                        AegisTask.SafeAction(() => { Finalizing?.Invoke(CloseReason.ServiceStop); });
                    };
                    ServiceMain.Instance.EventShutDown = () =>
                    {
                        AegisTask.SafeAction(() => { Finalizing?.Invoke(CloseReason.ShutDown); });
                    };
                    ServiceMain.Instance.Run();
                }


                _stopRunningEvent.Set();
            });


            AegisTask.Run(() =>
            {
                WaitForRunning();


                //  프레임워크 종료
                Calculate.IntervalTimer.DisposeAll();
                NamedThread.DisposeAll();
                NamedObjectManager.Clear();
                SpinWorker.Release();


                Logger.Info(LogMask.Aegis, "Aegis Framework finalized.");
                Logger.RemoveAll();


                AegisTask.SafeAction(() => { Finalized?.Invoke(); });
                Initialized = null;
                Finalizing  = null;
                Finalized   = null;
                Running     = null;

                _releaseEvent.Set();
            });
        }
예제 #7
0
 private void OnRunning()
 {
     Running?.Invoke(this, EventArgs.Empty);
 }
예제 #8
0
파일: ActionBase.cs 프로젝트: H-Core/H.Core
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 protected void OnRunning(ICommand value)
 {
     Running?.Invoke(this, value);
 }