public TagService()
        {
            MediaContext context = new MediaContext();

            this.uow           = new UnitOfWork(context);
            this.tagRepository = new Repository <Tag>(context);
        }
        public async Task <bool> UpdateDepartment(DepartmentViewModel entity)
        {
            var result = false;

            using (var mediaContext = new MediaContext())
            {
                using (var transaction = mediaContext.Database.BeginTransaction())
                {
                    try
                    {
                        var department = await mediaContext.Departments.FirstOrDefaultAsync(x => x.Id == entity.Id);

                        department.LibraryId = entity.LibraryId;
                        department.Name      = entity.Name;

                        mediaContext.Departments.Add(department);
                        await mediaContext.SaveChangesAsync();

                        result = true;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            return(result);
        }
示例#3
0
        public async Task<bool> AddMedia(StorageFile media)
        {
            try
            {
                Media newMedia = new Media();

                if ((bool)localSettings.Values["EnableOxford"])
                {
                    AnalysisResult analysisResult = await DoVision(media);
                    Emotion[] emotions = await DoFeel(media);
                    newMedia = ExtractFeatures(analysisResult, emotions);
                }

                newMedia.IsMerged = false;
                newMedia.MediaName = media.Name;
                localSettings.Values["LastImageName"] = media.Name;
                newMedia.CaptureDate = media.DateCreated.DateTime;
                using (var db = new MediaContext())
                {
                    db.Medias.Add(newMedia);
                    db.SaveChanges();
                }
                MediaList.Add(newMedia);
            }
            catch (Exception)
            {

            }
            return true;
        }
示例#4
0
        /// <summary>
        /// Returns whether the specified PixelShader major/minor version is
        /// supported by this version of WPF, and whether Effects using the
        /// specified major/minor version can run on the GPU.
        /// </summary>
        public static bool IsPixelShaderVersionSupported(short majorVersionRequested, short minorVersionRequested)
        {
            bool isSupported = false;

            //
            // For now, we only support PS 2.0 and 3.0.  Can only return true if this is
            // the version asked for.
            //
            if (majorVersionRequested == 2 && minorVersionRequested == 0 ||
                majorVersionRequested == 3 && minorVersionRequested == 0)
            {
                // Now actually check.

                MediaContext mediaContext = MediaContext.CurrentMediaContext;
                byte         majorVersion = (byte)((mediaContext.PixelShaderVersion >> 8) & 0xFF);
                byte         minorVersion = (byte)((mediaContext.PixelShaderVersion >> 0) & 0xFF);

                // We assume here that a higher version does in fact support the
                // version we're requiring.
                if (majorVersion >= majorVersionRequested)
                {
                    isSupported = true;
                }
                else if (majorVersion == majorVersionRequested && minorVersion >= minorVersionRequested)
                {
                    isSupported = true;
                }
            }

            return(isSupported);
        }
        public async Task <int> AddMaterialType(MaterialTypeViewModel entity)
        {
            var result = 0;

            using (var mediaContext = new MediaContext())
            {
                using (var transaction = mediaContext.Database.BeginTransaction())
                {
                    try
                    {
                        var materialType = new MaterialType
                        {
                            Name = entity.Name
                        };
                        mediaContext.MaterialTypes.Add(materialType);
                        await mediaContext.SaveChangesAsync();

                        result = materialType.Id;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            return(result);
        }
示例#6
0
 public User GetUserById(Guid userId)
 {
     using (var mediaContext = new MediaContext())
     {
         return(mediaContext.Users.Where(x => !x.IsDeleted).FirstOrDefault());
     }
 }
        public async Task <int> AddDepartment(DepartmentViewModel entity)
        {
            var result = 0;

            using (var mediaContext = new MediaContext())
            {
                using (var transaction = mediaContext.Database.BeginTransaction())
                {
                    try
                    {
                        var department = new Department
                        {
                            Name      = entity.Name,
                            LibraryId = entity.LibraryId
                        };
                        mediaContext.Departments.Add(department);
                        await mediaContext.SaveChangesAsync();

                        result = department.Id;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            return(result);
        }
        public bool DeleteUser(User user)
        {
            var result = false;

            using (var mediaContext = new MediaContext())
            {
                using (var transaction = mediaContext.Database.BeginTransaction())
                {
                    try
                    {
                        user.IsDeleted = true;
                        mediaContext.Users.Add(user);
                        mediaContext.SaveChanges();
                        result = true;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            return(result);
        }
        /// <summary>
        /// Calling this will make sure that the render request
        /// is registered with the MediaContext.
        /// </summary>
        private void RegisterForAsyncRenderForCyclicBrush()
        {
            DUCE.IResource resource = this as DUCE.IResource;

            if (resource != null)
            {
                if ((Dispatcher != null) && !_isAsyncRenderRegistered)
                {
                    MediaContext mediaContext = MediaContext.From(Dispatcher);

                    //
                    // Only register for a deferred render if this visual brush
                    // is actually on the channel.
                    //
                    if (!resource.GetHandle(mediaContext.Channel).IsNull)
                    {
                        // Add this handler to this event means that the handler will be
                        // called on the next UIThread render for this Dispatcher.
                        ICyclicBrush cyclicBrush = this as ICyclicBrush;
                        mediaContext.ResourcesUpdated += new MediaContext.ResourcesUpdatedHandler(cyclicBrush.RenderForCyclicBrush);
                        _isAsyncRenderRegistered       = true;
                    }
                }
            }
        }
示例#10
0
        public async Task <bool> DeleteLibrary(int id)
        {
            var result = false;

            using (var mediaContext = new MediaContext())
            {
                using (var transaction = mediaContext.Database.BeginTransaction())
                {
                    try
                    {
                        var library = await mediaContext.Libraries.FirstOrDefaultAsync(x => x.Id == id);

                        library.IsDeleted = true;
                        mediaContext.Libraries.Add(library);
                        await mediaContext.SaveChangesAsync();

                        result = true;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            return(result);
        }
示例#11
0
        //+---------------------------------------------------------------------
        //
        //  Internal Methods
        //
        //----------------------------------------------------------------------

        #region Internal Methods

        /// <summary>
        /// Sets the owner MediaContext and creates the notification window.
        /// </summary>
        internal MediaContextNotificationWindow(MediaContext ownerMediaContext)
        {
            // Remember the pointer to the owner MediaContext that we'll forward the broadcasts to.
            _ownerMediaContext = ownerMediaContext;

            // Create a top-level, invisible window so we can get the WM_DWMCOMPOSITIONCHANGED
            // and other DWM notifications that are broadcasted to top-level windows only.
            HwndWrapper hwndNotification;

            hwndNotification = new HwndWrapper(0, NativeMethods.WS_POPUP, 0, 0, 0, 0, 0, "MediaContextNotificationWindow", IntPtr.Zero, null);

            _hwndNotificationHook = new HwndWrapperHook(MessageFilter);

            _hwndNotification = new SecurityCriticalDataClass <HwndWrapper>(hwndNotification);
            _hwndNotification.Value.AddHook(_hwndNotificationHook);

            _isDisposed = false;

            //
            // On Vista, we need to know when the Magnifier goes on and off
            // in order to switch to and from software rendering because the
            // Vista Magnifier cannot magnify D3D content. To receive the
            // window message informing us of this, we must tell the DWM
            // we are MIL content.
            //
            // The Win7 Magnifier can magnify D3D content so it's not an
            // issue there. In fact, Win7 doesn't even send the WM.
            //
            // If the DWM is not running, this call will result in NoOp.
            //

            ChangeWindowMessageFilter(s_dwmRedirectionEnvironmentChanged, 1 /* MSGFLT_ADD */);
            MS.Internal.HRESULT.Check(MilContent_AttachToHwnd(_hwndNotification.Value.Handle));
        }
        public override void Dispose()
        {
            try
            {
                VerifyAccess();

                if (!IsDisposed)
                {
                    if (_hostVisual != null && _connected)
                    {
                        RootVisual = null;

                        //
                        // Unregister this CompositionTarget from the MediaSystem.
                        //
                        // we need to properly unregister in a disconnected state
                        MediaContext.UnregisterICompositionTarget(Dispatcher, this);
                    }
                }
            }
            finally
            {
                base.Dispose();
            }
        }
示例#13
0
        public async Task <bool> UpdateCategory(CategoryViewModel entity)
        {
            var result = false;

            using (var mediaContext = new MediaContext())
            {
                using (var transaction = mediaContext.Database.BeginTransaction())
                {
                    try
                    {
                        var category = new Category
                        {
                            Name             = entity.Name,
                            ParentCategoryId = entity.ParentCategoryId,
                            MaterialTypeId   = entity.MaterialTypeId,
                            Id = entity.Id.Value
                        };
                        mediaContext.Categories.Add(category);
                        await mediaContext.SaveChangesAsync();

                        result = true;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            return(result);
        }
示例#14
0
 public void RemoveCategory(Category categoryToRemove)
 {
     using (var ctx = new MediaContext()) {
         ctx.Categories.Remove(categoryToRemove);
         ctx.SaveChanges();
     }
 }
示例#15
0
 public void RemoveSubject(Subject subjectToRemove)
 {
     using (var ctx = new MediaContext()) {
         ctx.Subjects.Remove(subjectToRemove);
         ctx.SaveChanges();
     }
 }
示例#16
0
 public User GetByUserIdPassword(string userName, string password)
 {
     using (var mediaContext = new MediaContext())
     {
         return(mediaContext.Users.Where(x => !x.IsDeleted && x.Username == userName && x.Password == password).FirstOrDefault());
     }
 }
示例#17
0
        public async Task <int> AddLibrary(LibraryViewModel entity)
        {
            var result = 0;

            using (var mediaContext = new MediaContext())
            {
                using (var transaction = mediaContext.Database.BeginTransaction())
                {
                    try
                    {
                        var library = new Library
                        {
                            Name = entity.Name
                        };
                        mediaContext.Libraries.Add(library);
                        await mediaContext.SaveChangesAsync();

                        result = library.Id;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            return(result);
        }
        public async Task <bool> RemoveMaterialType(int id)
        {
            var result = false;

            using (var mediaContext = new MediaContext())
            {
                using (var transaction = mediaContext.Database.BeginTransaction())
                {
                    try
                    {
                        var materialType = await mediaContext.MaterialTypes.FirstOrDefaultAsync(x => x.Id == id);

                        materialType.IsDeleted = true;
                        mediaContext.MaterialTypes.Add(materialType);
                        await mediaContext.SaveChangesAsync();

                        result = true;
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }
            }
            return(result);
        }
示例#19
0
 // posts a layout update
 private void NeedsRecalc()
 {
     if (!_layoutRequestPosted && !_isUpdating)
     {
         MediaContext.From(Dispatcher).BeginInvokeOnRender(_updateCallback, this);
         _layoutRequestPosted = true;
     }
 }
        private readonly IGridFSBucket _gridFS;    //файловое хранилище

        public CategoryPhotoRepository(MediaContext db)
        {
            Log.Instance.LogAsInfo($"{nameof(CategoryPhotoRepository)}.{nameof(CategoryPhotoRepository)}: Constructor is stratring.");
            _database = db.Database;
            _gridFS   = db.GridFsBucket;
            CreateProductIdIndex().GetAwaiter().GetResult();
            Log.Instance.LogAsInfo($"{nameof(CategoryPhotoRepository)}.{nameof(CategoryPhotoRepository)}: Constructor is ended.");
        }
示例#21
0
 public Category AddCategory(Category newCategory)
 {
     using (var ctx = new MediaContext()) {
         var result = ctx.Categories.Add(newCategory);
         ctx.SaveChanges();
         return(result);
     }
 }
示例#22
0
 public Subject AddSubject(Subject newSubject)
 {
     using (var ctx = new MediaContext()) {
         var result = ctx.Subjects.Add(newSubject);
         ctx.SaveChanges();
         return(result);
     }
 }
示例#23
0
 private void NeedsRecalc()
 {
     if (!this._layoutRequestPosted && !this._isUpdating)
     {
         this._layoutRequestPosted = true;
         MediaContext.From(base.Dispatcher).BeginInvokeOnRender(this._updateCallback, this);
     }
 }
        public MenuService()
        {
            MediaContext context = new MediaContext();

            this.uow                = new UnitOfWork(context);
            this.menuRepository     = new Repository <Menu>(context);
            this.menuItemRepository = new Repository <MenuItem>(context);
        }
示例#25
0
 public IEnumerable <ISubject> GetSubjects()
 {
     using (var ctx = new MediaContext()) {
         foreach (var subject in ctx.Subjects)
         {
             yield return(subject);
         }
     }
 }
示例#26
0
 public IEnumerable <ICategory> GetCategories()
 {
     using (var ctx = new MediaContext()) {
         foreach (var category in ctx.Categories)
         {
             yield return(category);
         }
     }
 }
 public void AddMediaContainer(MediaContainer containerToAdd)
 {
     using (var ctx = new MediaContext())
     {
         ctx.Containers.Add(containerToAdd);
         OnContainersAdded(new MediaContainer[] { containerToAdd });
         ctx.SaveChanges();
     }
 }
示例#28
0
 private void UnsubscribeFromCommittingBatch()
 {
     if (_isWaitingForPresent)
     {
         MediaContext mediaContext = MediaContext.From(Dispatcher);
         mediaContext.CommittingBatch -= _sendPresentDelegate;
         _isWaitingForPresent = false;
     }
 }
 public IEnumerable <IMediaContainer> GetMediaContainers()
 {
     using (var ctx = new MediaContext()) {
         foreach (var container in ctx.Containers)
         {
             yield return(container);
         }
     }
 }
示例#30
0
        public async void Test_UnitOfWork_CommitAsync()
        {
            using var ctx = new MediaContext(Options);
            var unitOfWork = new UnitOfWork(ctx);
            var actual     = await unitOfWork.CommitAsync();

            Assert.NotNull(unitOfWork.Media);
            Assert.Equal(0, actual);
        }
示例#31
0
 public void SetContext(MediaContext MediaContext)
 {
     db = MediaContext;
 }