예제 #1
0
 public void Clear()
 {
     using (var blobs = new DocumentStorage(Server.MapPath("~/app_data/logs")))
     {
         blobs.Clear<LogEntity>();
     }
 }
예제 #2
0
        public void document_storage_should_add()
        {
            // arrange
            var storage = new DocumentStorage(m_store);
            var bucket = m_strategy.GetEntityBucket<AccountView>();

            // act
            storage.AddEntity(m_accountID, m_account);

            // assert
            m_store.EnumerateContents(bucket).ShouldNotBeEmpty();
        }
예제 #3
0
        public void document_storage_should_update()
        {
            // arrange
            AccountView fetch;
            var storage = new DocumentStorage(m_store);
            storage.AddEntity(m_accountID, m_account);

            // act
            storage.UpdateEntity<AccountView>(m_accountID, a => a.Name = "New Name");
            storage.TryGetEntity(m_accountID, out fetch);

            // assert
            fetch.Name.ShouldEqual("New Name");
        }
예제 #4
0
        public void document_storage_should_get_all_type_items()
        {
            // arrange
            IEnumerable<AccountView> entities;
            var storage = new DocumentStorage(m_store);
            storage.AddEntity(new AccountID(Guid.NewGuid()), new AccountView());
            storage.AddEntity(new AccountID(Guid.NewGuid()), new AccountView());
            storage.AddEntity(new AccountID(Guid.NewGuid()), new AccountView());
            storage.AddEntity(new AccountID(Guid.NewGuid()), new AccountView());
            // act
            storage.TryGetAllEntities(out entities);
            var accountViews = entities as List<AccountView> ?? entities.ToList();

            // assert
            accountViews.ShouldNotBeEmpty();
            accountViews.Count().ShouldEqual(4);
        }
예제 #5
0
        public void DoQuery()
        {
            var foo = new IndexQueryProvider();
            var docStorage = new DocumentStorage(new MemoryStream(), new MemoryStream());

            var results = from term in foo.Terms
                          from location in term.Value
                          where term.Key == "foo" || term.Key == "bar"
                          select location;

            foreach (var result in results.Distinct())
            {
                Console.Out.WriteLine(result.Document);
                var document = docStorage.Get(result.Document);
                var context = docStorage.GetContext(result);
                Console.Out.WriteLine(context);
                Console.Out.WriteLine();
            }
        }
예제 #6
0
        public ActionResult All(string id, int index = 0, int size = 50)
        {
            IEnumerable<LogEntity> logData = null;
            //  ViewBag.Type = "";
            var total = 0;
            using (var blobs = new DocumentStorage(Server.MapPath("~/app_data/logs")))
            {
                if (string.IsNullOrEmpty(id))
                    logData = blobs.All<LogEntity>(out total, index, size);
                else
                {
                    var logType = (LogEntityTypes)Enum.Parse(typeof(LogEntityTypes), id);
                    ViewBag.Type = logType;
                    logData = blobs.Where<LogEntity, DateTime>(l => l.Logged, f => f.LogEntityType == logType, out total, index: index, size: size);
                }
            }
            ViewBag.Total = total;

            return View(logData);
        }
예제 #7
0
        private void Write(string message, LogEntityTypes type, Exception e)
        {
            var basePath = "~/app_data/logs";
            var directory = System.Web.Hosting.HostingEnvironment.MapPath(basePath);
            using (var blobs = new DocumentStorage(directory))
            {
                var entity = new LogEntity()
                {
                    Message =message,
                    LogEntityType = type,
                    Logged = DateTime.UtcNow
                };

                if (e != null)
                {
                    var detailLines = new StringBuilder();
                    detailLines.AppendLine("Source error:" + e.Source);
                    detailLines.Append("Stack Trace:" + e.StackTrace);
                    var innerExp = e.InnerException;
                    if (innerExp != null)
                    {
                        detailLines.AppendLine("Inner exception:" + innerExp.Message);

                        while (innerExp != null)
                        {
                            detailLines.AppendLine("Message:" + innerExp.Source);
                            detailLines.AppendLine("Source error:" + e.Source);
                            detailLines.Append("Stack Trace:" + e.StackTrace);
                            innerExp = innerExp.InnerException;
                        }
                    }
                }

                blobs.Add(entity);
                blobs.SaveChanges();
            }
        }
예제 #8
0
 public void Parse(IDocumentEngine engine, DocumentMeta meta, Document document, DocumentStorage file)
 {
 }
예제 #9
0
 protected override long WriteFile(string saveFileName, DocumentStorage storage, DocumentStorageArea storageArea, Document document, DocumentContent content)
 {
     throw new NotImplementedException();
 }
예제 #10
0
 protected override long SaveDocument(string LocalFilePath, DocumentStorage Storage, DocumentStorageArea StorageArea, Document Document, BindingList <DocumentAttributeValue> attributeValue)
 {
     try
     {
         byte[] data         = null;
         File   fileUploaded = null;
         //Pick up the file in binary stream
         data = Document.Content.Blob;
         //
         ClientContext context = new ClientContext(Storage.MainPath);
         context.Credentials = new NetworkCredential(Storage.AuthenticationKey, Storage.AuthenticationPassword);
         Web  web  = context.Web;
         List docs = web.Lists.GetByTitle(Storage.Name);
         context.ExecuteQuery();
         //
         Folder foolder = docs.RootFolder;
         if (!string.IsNullOrEmpty(StorageArea.Path))
         {
             try
             {
                 if ((foolder = docs.RootFolder.Folders.Where(x => x.Name == StorageArea.Path).FirstOrDefault()) == null)
                 {
                     docs.RootFolder.Folders.Add(StorageArea.Path);
                 }
             }
             catch (Exception)
             {
                 docs.RootFolder.Folders.Add(StorageArea.Path);
             }
         }
         context.ExecuteQuery();
         string fileName = GetIdDocuemnt(Document) + System.IO.Path.GetExtension(Document.Name);
         FileCreationInformation newFile = new FileCreationInformation();
         newFile.Content = data;
         newFile.Url     = fileName;
         try
         {
             IEnumerable <File> resultFiles = context.LoadQuery(foolder.Files.Where(x => x.Name == fileName).Include(x => x.ListItemAllFields));
             context.ExecuteQuery();
             fileUploaded = resultFiles.FirstOrDefault();
         }
         catch { }
         if (fileUploaded != null)
         {
             fileUploaded.CheckOut();
             context.ExecuteQuery();
             FileSaveBinaryInformation newFileInfo = new FileSaveBinaryInformation();
             newFileInfo.Content = data;
             fileUploaded.SaveBinary(newFileInfo);
             fileUploaded.CheckIn("BiblosDS", CheckinType.MajorCheckIn);
             context.ExecuteQuery();
             ListItem listItems = fileUploaded.ListItemAllFields;
             foreach (var item in Document.AttributeValues)
             {
                 listItems[item.Attribute.Name] = item.Value;
             }
             fileUploaded.ListItemAllFields.Update();
         }
         else
         {
             fileUploaded = foolder.Files.Add(newFile);
             ListItem listItems = fileUploaded.ListItemAllFields;
             foreach (var item in Document.AttributeValues)
             {
                 listItems[item.Attribute.Name] = item.Value;
             }
             fileUploaded.ListItemAllFields.Update();
         }
         //Set the file version
         context.ExecuteQuery();
         context.Load(fileUploaded, w => w.MajorVersion);
         context.ExecuteQuery();
         Document.StorageVersion = fileUploaded.MajorVersion;
         return(data.Length);
     }
     catch (Exception ex)
     {
         Logging.WriteLogEvent(LoggingSource.BiblosDS_WCF_Storage, "SaveDocument", ex.ToString(), LoggingOperationType.BiblosDS_InsertDocument, LoggingLevel.BiblosDS_Errors);
         throw;
     }
 }
예제 #11
0
 public IndexWriter(TermStorage termStorage, DocumentStorage documentStorage)
     : this()
 {
     TermStorage = termStorage;
     DocumentStorage = documentStorage;
 }
예제 #12
0
        protected override long SaveDocument(string LocalFilePath, DocumentStorage Storage, DocumentStorageArea StorageArea, Document Document, BindingList <DocumentAttributeValue> attributeValue)
        {
            SPSite site = null;
            SPWeb  web  = null;

            byte[]            data            = null;
            SPFile            fileUploaded    = null;
            string            RootLibraryName = String.Empty;
            SPDocumentLibrary doclib          = null;

            //Pick up the file in binary stream
            data = Document.Content.Blob;

            using (site = new SPSite(Storage.MainPath))
            {
                using (web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;

                    //SPFolder Folder = web.GetFolder(StorageArea.Path);
                    doclib = web.Lists[Storage.Name] as SPDocumentLibrary;
                    if (doclib == null)
                    {
                        web.Lists.Add(Storage.Name, string.Empty, SPListTemplateType.DocumentLibrary);
                    }

                    /// **REMOVE**: 20090818
                    /// viene impostato l'override, altrimenti il documento resterebbe nel transito
                    /// TODO : da sistemare con la gestione delle versioni in sharepoint
                    try
                    {
                        SPFolder foolder = null;
                        if (data != null)
                        {
                            if (!string.IsNullOrEmpty(StorageArea.Path))
                            {
                                try
                                {
                                    if (doclib.RootFolder.SubFolders[StorageArea.Path] == null)
                                    {
                                        doclib.RootFolder.SubFolders.Add(StorageArea.Path);
                                    }
                                }
                                catch (Exception)
                                {
                                    doclib.RootFolder.SubFolders.Add(StorageArea.Path);
                                }
                                foolder = doclib.RootFolder.SubFolders[StorageArea.Path];
                            }
                            else
                            {
                                foolder = doclib.RootFolder;
                            }

                            string fileName = GetIdDocuemnt(Document) + Path.GetExtension(Document.Name);
                            try
                            {
                                fileUploaded = foolder.Files[fileName];
                            }
                            catch { }
                            if (fileUploaded != null)
                            {
                                fileUploaded.CheckOut();
                                fileUploaded.SaveBinary(data);
                                fileUploaded.CheckIn("BiblosDS", SPCheckinType.MajorCheckIn);
                            }
                            else
                            {
                                fileUploaded = foolder.Files.Add(fileName, data, true);
                            }
                            //Set the file version
                            Document.StorageVersion = fileUploaded.MajorVersion;


                            if (ConfigurationManager.AppSettings["ForceSharePointSecurity"] != null && ConfigurationManager.AppSettings["ForceSharePointSecurity"].ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase))
                            {
                                fileUploaded.Item.BreakRoleInheritance(false);
                                try
                                {
                                    for (int i = 0; i < fileUploaded.Item.RoleAssignments.Count; i++)
                                    {
                                        try
                                        {
                                            fileUploaded.Item.RoleAssignments.Remove((SPPrincipal)fileUploaded.Item.RoleAssignments[i].Member);
                                        }
                                        catch (Exception)
                                        {
                                        }
                                        //
                                    }
                                    string SiteGroupsName = ConfigurationManager.AppSettings["SiteGroupsName"] == null ? string.Empty : ConfigurationManager.AppSettings["SiteGroupsName"].ToString();
                                    //foreach (var item in Document.Permissions)
                                    //{
                                    SPRoleDefinitionCollection webroledefinition = web.RoleDefinitions;

                                    SPGroup group = null;
                                    try
                                    {
                                        group = web.SiteGroups[SiteGroupsName];
                                    }
                                    catch (Exception)
                                    {
                                        web.SiteGroups.Add(SiteGroupsName, web.AssociatedOwnerGroup, null, "");
                                        group = web.SiteGroups[SiteGroupsName];
                                    }

                                    //Add user to the group of viewer
                                    //try
                                    //{
                                    //    group.AddUser()
                                    //}
                                    //catch (Exception)
                                    //{

                                    //    throw;
                                    //}
                                    SPRoleAssignment assignment = new SPRoleAssignment(group);
                                    assignment.RoleDefinitionBindings.Add(webroledefinition.GetByType(SPRoleType.Reader));
                                    fileUploaded.Item.RoleAssignments.Add(assignment);
                                    //}
                                }
                                catch (Exception)
                                {
                                }
                                finally
                                {
                                    fileUploaded.Item.BreakRoleInheritance(true);
                                }
                            }

                            //In questo caso forse conviene salvare gli attributi al momento dell'upload del file.
                            //SPListItem MyListItem = fileUploaded.Item;
                            foreach (var item in Document.AttributeValues)
                            {
                                try
                                {
                                    fileUploaded.Item[item.Attribute.Name] = item.Value;
                                }
                                catch (Exception)
                                {
                                    doclib.Fields.Add(item.Attribute.Name, ParseSPFieldType(item.Attribute.AttributeType), item.Attribute.IsRequired);
                                    doclib.Update();
                                }
                            }
                            fileUploaded.Item.SystemUpdate();
                        }
                    }
                    catch (Exception ex)
                    {
                        //Write the log
                        Logging.WriteLogEvent(BiblosDS.Library.Common.Enums.LoggingSource.BiblosDS_Sharepoint,
                                              "SaveDocument",
                                              ex.ToString(),
                                              BiblosDS.Library.Common.Enums.LoggingOperationType.BiblosDS_General,
                                              BiblosDS.Library.Common.Enums.LoggingLevel.BiblosDS_Errors);
                        throw new FileNotUploaded_Exception("File not uploaded" + Environment.NewLine + ex.ToString());
                    }
                    web.AllowUnsafeUpdates = false;
                }
            }
            return(data.Length);
        }
예제 #13
0
 public SaveChanges()
 {
     DocumentStorage.Subscribe(this);
 }
예제 #14
0
 public SingleDocumentIndex(Document document, IAnalyzer analyzer, TermStorage termStorage, DocumentStorage documentStorage)
 {
     TermStorage = termStorage;
     DocumentStorage = documentStorage;
     AddDocument(document, analyzer);
 }
예제 #15
0
        public override bool LoadDocumentType(string typeOf, bool isInitialize = false)
        {
            Logger?.Debug(ScopeType.Engine, $"Load TypeOf: {typeOf}");

            var documentType = GetDocumentType(typeOf);
            var meta         = new DocumentMeta(typeOf, documentType, Provider, Option);

            if (isInitialize && meta.Cache.Lazy)
            {
                return(true);
            }

            var files = new List <DocumentStorage>();

            #region Files
            var directoryInfo = new DirectoryInfo(meta.Directory);
            if (directoryInfo.Exists)
            {
                var extentions     = Option.Extention;
                var directoryFiles = directoryInfo.GetFiles(extentions, SearchOption.TopDirectoryOnly);

                meta.HasData = directoryFiles.Length > 0;

                var parts = new List <int>();
                foreach (var file in directoryFiles)
                {
                    var storage = new DocumentStorage(meta.TypeOf, Provider?.BaseDirectory, file);

                    if (storage.Partition > meta.Partitions.Current)
                    {
                        meta.Partitions.Current = storage.Partition;
                    }

                    if (!parts.Contains(storage.Partition))
                    {
                        parts.Add(storage.Partition);
                    }

                    files.Add(storage);
                }

                parts = parts.OrderBy(p => p).ToList();

                foreach (var part in parts)
                {
                    meta.Partitions.Add(part, 0);
                }

                meta.Partitions.Next = meta.Partitions.Current + 1;
            }
            #endregion

            if (files.Count == 0)
            {
                Logger?.Debug(ScopeType.Engine, "LoadDocumentType files.count = 0");

                return(false);
            }

            Logger?.Debug(ScopeType.Engine, $"TypeOf:{typeOf} number of files : {files.Count}");

            int bufferSize = Option.BufferSize;
            var serializer = new JsonSerializer();
            var parser     = GetDocumentParser(meta.TypeOf, OperationType.Load);

            foreach (DocumentStorage file in files)
            {
                Logger?.Debug(ScopeType.Engine, $"Read TypeOf: {file.TypeOf} - File : {file.Target}");

                try
                {
                    using (FileStream fs = new FileStream(file.Target, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize))
                        using (StreamReader sr = new StreamReader(fs, Encoding.UTF8, true, bufferSize))
                            using (JsonReader reader = new JsonTextReader(sr))
                            {
                                reader.SupportMultipleContent = false;

                                while (reader.Read())
                                {
                                    if (reader.TokenType == JsonToken.StartObject)
                                    {
                                        var document = GetDocumentFromSource(ref meta, serializer.Deserialize <JObject>(reader), file.Partition);

                                        if (Option.SupportDocumentParser && parser != null)
                                        {
                                            parser.Parse(this, meta, document, file);
                                        }

                                        meta.SubmitChanges(document, OperationType.Load);

                                        Cache.Set(document, meta.Cache.Expire);

                                        document.Dispose();
                                    }
                                }
                            }
                }
                catch (Exception ex)
                {
                    Logger?.Fatal($"Exception Read TypeOf: {file.TypeOf} File : {file.Target}", ex);
                }
            }

            Cache.Set(meta, meta.Cache.Expire);
            Cache.Set(new DocumentSequence(typeOf, meta.Sequence));

            documentType.Dispose();
            meta.Dispose();

            return(true);
        }
예제 #16
0
 public SwGeneratorController()
 {
     _storage   = DocumentStorageFactory.Get();
     _generator = DocGeneratorFactory.Get();
 }
예제 #17
0
 public void Destroy()
 {
     DocumentStorage.Unsubscribe(this);
     //if (SUtils.SavedRelationships != null)
     //    SUtils.SavedRelationships = null;
 }
예제 #18
0
 /// <summary>
 /// Restituisce l'elenco di tutte le relazioni storage-archive per lo storage selezionato
 /// </summary>
 /// <param name="Storage">DocumentStorage di cui ottenere le relazioni con gli archives</param>
 /// <returns>BindingList<DocumentArchiveStorage></returns>
 public static BindingList <DocumentArchiveStorage> GetStorageArchiveRelationsFromStorage(DocumentStorage Storage)
 {
     try
     {
         return(DbAdminProvider.GetStorageArchiveRelationsFromStorage(Storage.IdStorage));
     }
     catch (Exception e)
     {
         Logging.WriteLogEvent(BiblosDS.Library.Common.Enums.LoggingSource.BiblosDS_General,
                               "ArchiveStorageService." + System.Reflection.MethodBase.GetCurrentMethod().Name,
                               e.ToString(),
                               BiblosDS.Library.Common.Enums.LoggingOperationType.BiblosDS_General,
                               BiblosDS.Library.Common.Enums.LoggingLevel.BiblosDS_Errors);
         throw e;
     }
 }
예제 #19
0
 public HomeController(ILogger <HomeController> logger)
 {
     _logger          = logger;
     _documentStorage = new DocumentStorage();
     _queue           = new Queue(_documentStorage);
 }