Beispiel #1
0
        public IPagedList <Album> GetAlbums(ILoadOptions options)
        {
            IPagedList <Album> result = new PagedList <Album>();

            if (options == null)
            {
                return(result);
            }

            if (options.MaxResults <= 0)
            {
                return(result);
            }

            ISession session = SessionFactory.GetSession();

            try
            {
                DetachedCriteria countCriteria = GetAlbumsImpl(options);
                DetachedCriteria listCriteria  = GetAlbumsImpl(options);

                countCriteria.SetProjection(Projections.RowCount());
                countCriteria.ClearOrders();

                listCriteria.
                SetFirstResult(options.FirstResult).
                SetMaxResults(options.MaxResults);

                IMultiCriteria multiCriteria = session.CreateMultiCriteria();
                multiCriteria.Add(countCriteria);
                multiCriteria.Add(listCriteria);


                IList queryResult = multiCriteria.List();

                result.TotalItems = (int)((IList)queryResult[0])[0];

                IList recordsList = (IList)queryResult[1];

                EntityConverter entityConverter = new EntityConverter();

                foreach (var e in recordsList)
                {
                    AlbumEntity dataEntity     = e as AlbumEntity;
                    Album       businessEntity = entityConverter.FromDataEntity(dataEntity, AlbumConvertOptions.Small);
                    result.Add(businessEntity);
                }
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }
            finally
            {
                session.Close();
            }

            return(result);
        }
        public HttpResponseMessage SaveFile(EditDocumentRequest postedData)
        {
            try
            {
                string htmlContent  = postedData.getContent(); // Initialize with HTML markup of the edited document
                string guid         = postedData.GetGuid();
                string password     = postedData.getPassword();
                string saveFilePath = Path.Combine(globalConfiguration.GetEditorConfiguration().GetFilesDirectory(), guid);
                string tempFilename = Path.GetFileNameWithoutExtension(saveFilePath) + "_tmp";
                string tempPath     = Path.Combine(Path.GetDirectoryName(saveFilePath), tempFilename + Path.GetExtension(saveFilePath));

                ILoadOptions loadOptions = GetLoadOptions(guid);
                if (loadOptions != null)
                {
                    loadOptions.Password = password;
                }

                // Instantiate Editor object by loading the input file
                using (GroupDocs.Editor.Editor editor = new GroupDocs.Editor.Editor(guid, delegate { return(loadOptions); }))
                {
                    EditableDocument htmlContentDoc = EditableDocument.FromMarkup(htmlContent, null);
                    dynamic          saveOptions    = GetSaveOptions(guid);

                    if (!(saveOptions is TextSaveOptions))
                    {
                        saveOptions.Password = password;
                    }

                    if (saveOptions is WordProcessingSaveOptions)
                    {
                        saveOptions.EnablePagination = true;
                    }

                    using (FileStream outputStream = File.Create(tempPath))
                    {
                        editor.Save(htmlContentDoc, outputStream, saveOptions);
                    }
                }

                if (File.Exists(saveFilePath))
                {
                    File.Delete(saveFilePath);
                }

                File.Move(tempPath, saveFilePath);

                LoadDocumentEntity loadDocumentEntity = LoadDocument(saveFilePath, password);

                // return document description
                return(Request.CreateResponse(HttpStatusCode.OK, loadDocumentEntity));
            }
            catch (Exception ex)
            {
                // set exception message
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, postedData.getPassword())));
            }
        }
        public virtual IEnumerable <TInterface> Get(Expression filterExpression = null,
                                                    ILoadOptions loadOptions    = null)
        //bool includeParameters = true,
        //BuildMode buildMode = BuildMode.Single)
        {
            throw new NotImplementedException();
            //var values =
            //    ExecuteMultiple<TModel>(QueryBuilder.BuildSelectQuery(filterExpression, true, includeParameters),
            //        buildMode);

            //return values;
        }
        private static ILoadOptions GetLoadOptions(string guid)
        {
            string       extension = Path.GetExtension(guid).Replace(".", "").ToLowerInvariant();
            ILoadOptions options   = null;

            foreach (var item in typeof(WordProcessingFormats).GetFields())
            {
                if (item.Name.ToLowerInvariant().Equals("auto"))
                {
                    continue;
                }

                if (item.Name.ToLowerInvariant().Equals(extension))
                {
                    options = new WordProcessingLoadOptions();
                    break;
                }
            }

            foreach (var item in typeof(PresentationFormats).GetFields())
            {
                if (item.Name.ToLowerInvariant().Equals("auto"))
                {
                    continue;
                }

                if (item.Name.ToLowerInvariant().Equals(extension))
                {
                    options = new PresentationLoadOptions();
                    break;
                }
            }

            foreach (var item in typeof(SpreadsheetFormats).GetFields())
            {
                if (item.Name.ToLowerInvariant().Equals("auto"))
                {
                    continue;
                }

                if (item.Name.ToLowerInvariant().Equals(extension))
                {
                    options = new SpreadsheetLoadOptions();
                    break;
                }
            }

            return(options);
        }
Beispiel #5
0
        private DetachedCriteria GetArtistsImpl(ILoadOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            if (options.MaxResults <= 0)
            {
                return(null);
            }

            string fieldName   = options.FilterField.FieldName;
            string filterValue = options.FilterValue;

            DetachedCriteria criteria = DetachedCriteria.For <ArtistEntity>();

            if (!options.IncludeWaste)
            {
                criteria.Add(Restrictions.Eq("IsWaste", false));
            }

            if (fieldName != "Tag")
            {
                criteria.
                Add(Restrictions.InsensitiveLike(fieldName, filterValue, MatchMode.Anywhere)).
                AddOrder(new Order(fieldName, true));
            }
            else
            {
                DetachedCriteria tagsCriteria = DetachedCriteria.For <ArtistEntity>().CreateCriteria("Tags").
                                                Add(Restrictions.InsensitiveLike("Name", filterValue, MatchMode.Anywhere)).
                                                SetProjection(Property.ForName("ID"));

                criteria.Add(
                    Subqueries.PropertyIn("ID", tagsCriteria)).AddOrder(new Order("ID", true));
            }

            return(criteria);
        }
Beispiel #6
0
        private DetachedCriteria GetGenresImpl(ILoadOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            if (options.MaxResults <= 0)
            {
                return(null);
            }

            string fieldName   = options.FilterField.FieldName;
            string filterValue = options.FilterValue;

            DetachedCriteria criteria = DetachedCriteria.For <GenreEntity>();

            criteria.
            Add(Restrictions.InsensitiveLike(fieldName, filterValue, MatchMode.Anywhere)).
            AddOrder(new Order(fieldName, true));

            return(criteria);
        }
Beispiel #7
0
        public IPagedList <Genre> GetGenres(ILoadOptions options)
        {
            DataProvider provider = new DataProvider();

            return(provider.GetGenres(options));
        }
Beispiel #8
0
        public IPagedList <Album> GetAlbums(ILoadOptions options)
        {
            DataProvider provider = new DataProvider();

            return(provider.GetAlbums(options));
        }
Beispiel #9
0
        public IPagedList <TaggedObject> GetTaggedObjects(ILoadOptions loadOptions)
        {
            /*
             * This method uses sophisticated stored procedure which performs actual pagination and
             * filtering logic against special database view.
             *
             * First record of result set is stub one and returns total number of items matching filtering
             * rules.
             */

            var result = new PagedList <TaggedObject>();

            ISession session = SessionFactory.GetSession();

            try
            {
                var    specialOptions   = loadOptions as TagLoadOptions;
                string entityTypeFilter = String.Empty;
                string entityNameFilter = String.Empty;
                if (specialOptions != null)
                {
                    if (!specialOptions.ExcludeAlbums && !specialOptions.ExcludeArtists)
                    {
                        entityTypeFilter = String.Format("{0},{1}", (int)TaggedObjectType.Artist, (int)TaggedObjectType.Album);
                    }
                    else if (!specialOptions.ExcludeAlbums)
                    {
                        entityTypeFilter = String.Format("{0}", (int)TaggedObjectType.Album);
                    }
                    else if (!specialOptions.ExcludeArtists)
                    {
                        entityTypeFilter = String.Format("{0}", (int)TaggedObjectType.Artist);
                    }

                    entityNameFilter = specialOptions.EntityName == null ? String.Empty : specialOptions.EntityName;
                }

                var query = session.GetNamedQuery("GetTaggedObjects");
                query.SetParameter("tagIDs", loadOptions.FilterValue);
                query.SetParameter("entityTypes", entityTypeFilter);
                query.SetParameter("ioffset", loadOptions.FirstResult);
                query.SetParameter("ilimit", loadOptions.MaxResults);
                query.SetParameter("entityName", entityNameFilter);
                var dataEntities = query.SetResultTransformer(new TaggedObjectResultTransformer()).List <TaggedObjectEntity>();

                //get stub entity generated by sp, which stores total items count needed for pagination
                var stubCounterEntity = dataEntities.Where(e => e.ObjectType == -1).First();
                dataEntities.Remove(stubCounterEntity);

                EntityConverter converter = new EntityConverter();

                foreach (var de in dataEntities)
                {
                    var tag = converter.FromDataEntity(de);
                    result.Add(tag);
                }

                result.TotalItems = stubCounterEntity.ID;
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
            }
            finally
            {
                session.Close();
            }

            return(result);
        }
Beispiel #10
0
        private DetachedCriteria GetListeningsImpl(ILoadOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            if (options.MaxResults <= 0)
            {
                return(null);
            }

            string fieldName   = options.FilterField.FieldName;
            string filterValue = options.FilterValue;

            DetachedCriteria criteria = DetachedCriteria.For <ListeningEntity>();

            switch (fieldName)
            {
            /*
             *             fields.Add(new Field("Album", "Album"));
             * fields.Add(new Field("Date", "Date", FieldTypeEnum.DateInterval));*/
            case "ListenRating":
            {
                int intFilterValue = -1;
                Int32.TryParse(filterValue, out intFilterValue);

                criteria.
                Add(Restrictions.Eq(fieldName, intFilterValue));
            }
            break;

            case "Album":
            {
                DetachedCriteria tagsCriteria = DetachedCriteria.For <ListeningEntity>().CreateCriteria("Album").
                                                Add(Restrictions.InsensitiveLike("Name", filterValue, MatchMode.Anywhere)).
                                                SetProjection(Property.ForName("ID"));

                criteria.Add(Subqueries.PropertyIn("ID", tagsCriteria));
            }
            break;

            case "Date":
            {
                DateInterval interval = DateInterval.Parse(filterValue);

                if (interval != null)
                {
                    criteria.
                    Add(Restrictions.Ge("Date", interval.StartDate)).
                    Add(Restrictions.Le("Date", interval.EndDate));
                }
            }
            break;

            default:
            {
                criteria.Add(Restrictions.InsensitiveLike(fieldName, filterValue, MatchMode.Anywhere));
            }
            break;
            }

            criteria.AddOrder(new Order("Date", false));

            return(criteria);
        }
        private LoadDocumentEntity LoadDocument(string guid, string password)
        {
            LoadDocumentEntity loadDocumentEntity = new LoadDocumentEntity();

            loadDocumentEntity.SetGuid(guid);
            ILoadOptions loadOptions = GetLoadOptions(guid);

            if (loadOptions != null)
            {
                loadOptions.Password = password;
            }

            // Instantiate Editor object by loading the input file
            using (GroupDocs.Editor.Editor editor = new GroupDocs.Editor.Editor(guid, delegate { return(loadOptions); }))
            {
                IDocumentInfo documentInfo = editor.GetDocumentInfo(password);

                dynamic editOptions = GetEditOptions(guid);
                if (editOptions is WordProcessingEditOptions)
                {
                    editOptions.EnablePagination = true;

                    // Open input document for edit — obtain an intermediate document, that can be edited
                    EditableDocument      beforeEdit = editor.Edit(editOptions);
                    string                allEmbeddedInsideString = beforeEdit.GetEmbeddedHtml();
                    PageDescriptionEntity page = new PageDescriptionEntity();
                    page.SetData(allEmbeddedInsideString);
                    loadDocumentEntity.SetPages(page);
                    beforeEdit.Dispose();
                }
                else if (editOptions is SpreadsheetEditOptions)
                {
                    for (var i = 0; i < documentInfo.PageCount; i++)
                    {
                        // Let's create an intermediate EditableDocument from the i tab
                        SpreadsheetEditOptions sheetEditOptions = new SpreadsheetEditOptions();
                        sheetEditOptions.WorksheetIndex = i; // index is 0-based
                        EditableDocument tabBeforeEdit = editor.Edit(sheetEditOptions);

                        // Get document as a single base64-encoded string, where all resources (images, fonts, etc)
                        // are embedded inside this string along with main textual content
                        string allEmbeddedInsideString = tabBeforeEdit.GetEmbeddedHtml();
                        PageDescriptionEntity page     = new PageDescriptionEntity();
                        page.SetData(allEmbeddedInsideString);
                        page.number = i + 1;
                        loadDocumentEntity.SetPages(page);
                        tabBeforeEdit.Dispose();
                    }
                }
                else if (editOptions is PresentationEditOptions)
                {
                    for (var i = 0; i < documentInfo.PageCount; i++)
                    {
                        // Create editing options
                        PresentationEditOptions presentationEditOptions = new PresentationEditOptions();
                        // Specify slide index from original document.
                        editOptions.SlideNumber = i; // Because index is 0-based, it is 1st slide
                        EditableDocument slideBeforeEdit = editor.Edit(presentationEditOptions);

                        // Get document as a single base64-encoded string, where all resources (images, fonts, etc)
                        // are embedded inside this string along with main textual content
                        string allEmbeddedInsideString = slideBeforeEdit.GetEmbeddedHtml();
                        PageDescriptionEntity page     = new PageDescriptionEntity();
                        page.SetData(allEmbeddedInsideString);
                        page.number = i + 1;
                        loadDocumentEntity.SetPages(page);
                        slideBeforeEdit.Dispose();
                    }
                }
            }

            return(loadDocumentEntity);
        }
Beispiel #12
0
        public IPagedList <TaggedObject> GetTaggedObjects(ILoadOptions loadOptions)
        {
            var provider = new DataProvider();

            return(provider.GetTaggedObjects(loadOptions));
        }
Beispiel #13
0
        public IPagedList <Listening> GetListenings(ILoadOptions loadOptions)
        {
            DataProvider provider = new DataProvider();

            return(provider.GetListenings(loadOptions));
        }