Esempio n. 1
0
 protected BsonValue GetPropertyByName(string name)
 {
     lock (_readWriteLock)
     {
         InternalDocument.TryGetValue(name, out BsonValue value);
         return(value);
     }
 }
Esempio n. 2
0
 /// <summary>Saves resulting PDF document to disk.</summary>
 /// <param name="filename">Output file.</param>
 public void Save(string filename = "bingo.pdf")
 {
     try
     {
         InternalDocument.Save(filename);
     }
     catch (Exception e)
     {
         Console.Error.WriteLine($"Cannot save to {filename}.");
         Console.Error.WriteLine(e.ToString());
     }
 }
Esempio n. 3
0
        public Response <InternalDocumentModel> Create(InternalDocumentCreateModel createModel)
        {
            try
            {
                using (var unitOfwork = new UnitOfWork())
                {
                    var user = unitOfwork.GetRepository <User>().GetById(createModel.CreatedByUserId);
                    if (user == null)
                    {
                        return(new Response <InternalDocumentModel>(0, "", null));
                    }

                    InternalDocument entity = new InternalDocument
                    {
                        SecretLevel       = createModel.SecretLevel,
                        ResponsibleUserId = createModel.ResponsibleUserId,
                        Summary           = createModel.Summary,
                        WrittenByUserId   = createModel.WrittenByUserId,
                        Name                 = createModel.Name,
                        CategoryId           = createModel.CategoryId,
                        CreatedByUserId      = createModel.CreatedByUserId,
                        CreatedOnDate        = DateTime.Now,
                        LastModifiedOnDate   = DateTime.Now,
                        DepartmentId         = user.DepartmentId,
                        IsDelete             = false,
                        LastModifiedByUserId = createModel.CreatedByUserId,
                        DocumentStatusId     = createModel.DocumentStatusId,
                        DirectoryId          = createModel.DirectoryId,
                        InternalDocumentId   = 1,
                        ProjectId            = createModel.ProjectId,
                        AttachedFileUrl      = createModel.AttachedFileUrl
                    };
                    var last = unitOfwork.GetRepository <InternalDocument>().GetAll().OrderByDescending(d => d.InternalDocumentId).FirstOrDefault();
                    if (last != null)
                    {
                        entity.InternalDocumentId = last.InternalDocumentId + 1;
                    }
                    unitOfwork.GetRepository <InternalDocument>().Add(entity);
                    if (unitOfwork.Save() >= 1)
                    {
                        return(GetById(entity.InternalDocumentId));
                    }
                    return(new Response <InternalDocumentModel>(0, "Lưu thông tin không thành công", null));
                }
            }
            catch (Exception ex)
            {
                return(new Response <InternalDocumentModel>(-1, ex.ToString(), null));
            }
        }
 protected override void ReadValue(PsdReader reader, object userData, out PsdDocument value)
 {
     if (this.IsDocument(reader) == true)
     {
         using (Stream stream = new RangeStream(reader.Stream, reader.Position, this.Length))
         {
             PsdDocument document = new InternalDocument();
             document.Read(stream, reader.Resolver, reader.Uri);
             value = document;
         }
     }
     else
     {
         value = null;
     }
 }
Esempio n. 5
0
        //async creation
        private async Task <InternalDocument> _add_async(Document document)
        {
            bool  bool_has_dict = false;
            long  l_doc_pos = _Globals.storage_virtual_length, l_tag_pos = 0;
            int   i = 0, i_tag_data_len = 0;
            ulong u_hash = 0;

            //ulong uhash_col = 0;

            //tags
            if (document != null)
            {
                //Type _type = document.GetType();
                //FieldInfo[] fields = _type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

                byte[] temp_bytes;

                /*FieldInfo fieldInfo;
                 * for (i = 0; i < fields.Length; i++) //go thru all fields
                 * {
                 *  fieldInfo = fields[i];
                 *  string dict_name = fieldInfo.Name;
                 *  if (dict_name == "dict") { bool_has_dict = true; break; } //if not appropriate dictionary inside
                 * }/**/

                //if it's not a true Document class - exit
                //if (bool_has_dict == false) { return null; }

                InternalDocument _doc = new InternalDocument();
                l_tag_pos         = _doc.doc_header_length; //set first tag_pos
                _doc.doc_created  = DateTime.Now.Ticks;
                _doc.doc_changed  = DateTime.Now.Ticks;
                _doc.doc_id       = _Globals.storage_document_id;
                _doc.doc_position = _Globals.storage_virtual_length;
                foreach (KeyValuePair <string, object> _kv in document) // document_dictionary)//document.dict) //go thru all fields
                {
                    if (_kv.Key.Length < _Globals.storage_tag_max_len)  //get info if field's name not more than it's possible max value
                    {
                        if (_kv.Key.Length > 0)
                        {
                            if (_kv.Key.Length > _Globals.storage_tag_max_len)
                            {
                                _doc = null; break;
                            }

                            u_hash = _Globals._hash.CreateHash64bit(Encoding.ASCII.GetBytes(_kv.Key));
                            _doc.tag_hash.Add(u_hash, _kv.Key); //get/set tags
                            _doc.lst_tag_hash.Add(u_hash);

                            _doc.tag_data_pos.Add(l_tag_pos); //add tag_pos NOTE pos = tag_hash + tag_data

                            _doc.tag_data_type.Add(_Globals._datatypeserializer.returnTypeAndRawByteArray(_kv.Value, out temp_bytes));

                            i_tag_data_len = temp_bytes.Length;
                            _doc.tag_data_len.Add(i_tag_data_len);
                            _doc.tag_data.Add(temp_bytes);           //data byte array
                            _doc._tag_data_length += i_tag_data_len; //sum of all data length

                            l_tag_pos += (8 + i_tag_data_len);
                        }
                    }
                }//foreach
                //increase virtual file length
                _Globals.lst_docs_to_save.Add(_doc);
                //_Globals.lst_docs_to_save_BYTES.Add(_doc.get_data_bytes());
                _Globals.storage_virtual_length += _doc.getlength();
                //increase document id
                _Globals.storage_document_id++;
                //result
                return(await Task.FromResult(_doc));
            }
            return(null);
        }