コード例 #1
0
ファイル: Stif.cs プロジェクト: yitaom2/ravendb
        public void GetDummyDoc()
        {
            using (var store = GetDocumentStore(new Options
            {
                ModifyDocumentStore = s =>
                {
                    s.Conventions.SaveEnumsAsIntegers = true;
                }
            }))
            {
                new MyDocIndex().Execute(store);

                using (IDocumentSession documentSession = store.OpenSession())
                {
                    documentSession.Store(new MyDoc {
                        Id = new Guid(0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0).ToString(), Message = "some dummy message"
                    });
                    documentSession.SaveChanges();
                }

                using (IDocumentSession documentSession = store.OpenSession())
                {
                    MyDoc docFetched = documentSession.Load <MyDoc>(new Guid(0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0).ToString()); //returns an object
                    Debug.WriteLine(string.Format("found {0}", docFetched.Id));

                    Assert.NotNull(docFetched);

                    List <MyDoc> docs = documentSession.Query <MyDoc>().Customize(x => x.WaitForNonStaleResults()).ToList(); //returns an empty list
                    Debug.WriteLine(string.Format("found {0} docs", docs.Count));

                    Assert.Equal(1, docs.Count);
                }
            }
        }
コード例 #2
0
        public void GetDummyDoc()
        {
            using (var documentStore = new EmbeddableDocumentStore {
                RunInMemory = true
            })
            {
                documentStore.Conventions.SaveEnumsAsIntegers        = true;
                documentStore.Conventions.DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites;
                documentStore.Initialize();
                new MyDocIndex().Execute(documentStore);

                using (IDocumentSession documentSession = documentStore.OpenSession())
                {
                    documentSession.Store(new MyDoc {
                        Id = new Guid(0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0), Message = "some dummy message"
                    });
                    documentSession.SaveChanges();
                }

                using (IDocumentSession documentSession = documentStore.OpenSession())
                {
                    MyDoc docFetched = documentSession.Load <MyDoc>(new Guid(0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0));                    //returns an object
                    Debug.WriteLine(string.Format("found {0}", docFetched.Id));

                    Assert.NotNull(docFetched);

                    List <MyDoc> docs = documentSession.Query <MyDoc>().ToList();                   //returns an empty list
                    Debug.WriteLine(string.Format("found {0} docs", docs.Count));

                    Assert.Equal(1, docs.Count);
                }
            }
        }
コード例 #3
0
 protected object RenderShareDoc(MyDoc myDoc, Dictionary <long, isPin> dicPin, List <User> users, MyDocPerm myDocPerm, bool isQcn, List <MyDoc> folders, List <UserRecent> userrecents = null)
 {
     return(new
     {
         ID = myDoc.ID,
         Path = GlobalConfig.StgSrcPath(myDoc.Path),
         Size = Utils.SizeConvert(myDoc.Size),
         Name = myDoc.Name,
         Created = CUtils.DateTimeToLong(myDoc.Created),
         CreateBy = (users.FirstOrDefault(t => t.ID == myDoc.CreatedBy) ?? new User()).Name ?? "",
         Updated = userrecents == null?CUtils.DateTimeToLong(myDoc.Updated) : CUtils.DateTimeToLong(userrecents.FirstOrDefault(t => t.IDDoc == myDoc.ID).Created),
                       UpdateBy = (users.FirstOrDefault(t => t.ID == myDoc.UpdatedBy) ?? new User()).Name ?? "",
                       IsFolder = myDoc.IsFolder,
                       Icon = GlobalConfig.StgSrcPath((myDoc.Extension ?? "").Replace(".", "") + ".png"),
                       IsView = myDocPerm.IsView(myDoc),
                       IsUpdate = myDocPerm.IsUpdate(myDoc),
                       IsDelete = myDocPerm.IsDelete(myDoc),
                       IsCreate = myDocPerm.IsCreate(myDoc),
                       IsCopy = myDocPerm.IsCopy(myDoc),
                       IsDownload = myDocPerm.IsDownload(myDoc),
                       IsMove = myDocPerm.IsMove(myDoc),
                       IsShare = myDocPerm.IsShare(myDoc),
                       IsNote = myDocPerm.IsNote(myDoc),
                       IsPassword = !string.IsNullOrEmpty(myDoc.Password),
                       IsSetPassword = CUser.ID == myDoc.CreatedBy,
                       IsChangePassword = CUser.ID == myDoc.CreatedBy,
                       TypeExtension = CUtils.GetTypebyExtension(myDoc.Extension),
                       Parent = myDoc.Parent,
                       IsPin = (int)dicPin[myDoc.ID],
                       PasswordParentId = GetPasswordParent(folders, myDoc)
     });
 }
コード例 #4
0
        private void AddDocument(MyDoc docType)
        {
            if (SearchDocument(docType.ToString(), dockManager.Layout) == null)
            {
                /*Get Corresponding  View*/
                string userString = EnumHelper.StringValueOf(docType, ReturnType.CLASS);
                Type   userClass  = Type.GetType(userString);

                /*Init VIew*/
                UserControl user =
                    Activator.CreateInstance(userClass) as UserControl;

                /*Add View*/
                LayoutDocument doc = new LayoutDocument();
                doc.Content   = user;
                doc.ContentId = docType.ToString();
                doc.Title     = EnumHelper.StringValueOf(docType);

                var firstDocumentPane = dockManager.Layout.Descendents().OfType <LayoutDocumentPane>().FirstOrDefault();
                firstDocumentPane.Children.Add(doc);
            }

            var nowButton = SearchToggleButton(docType.ToString());

            if (nowButton != null)
            {
                nowButton.IsChecked = true;
            }
        }
コード例 #5
0
        private void CloseDocument(MyDoc docType)
        {
            var searched = SearchDocument(docType.ToString(), dockManager.Layout);

            if (searched != null)
            {
                searched.Close();
            }
        }
コード例 #6
0
        private long GetPasswordParent(List <MyDoc> myDocs, MyDoc myDoc)
        {
            var parent = myDocs.FirstOrDefault(t => t.ID == myDoc.Parent);

            if (Utils.IsEmpty(parent) || parent.ID == 0)
            {
                return(0);
            }

            return(!string.IsNullOrEmpty(parent.Password)
                ? parent.ID
                : GetPasswordParent(myDocs, parent));
        }
コード例 #7
0
        private void btn_Word_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFilDlg = new SaveFileDialog();

            saveFilDlg.FileName   = this.txt_DATA_NAME.Text;
            saveFilDlg.DefaultExt = "*.rtf";
            saveFilDlg.Filter     = "RTF 文档(*.rtf)|*.rtf|Word 文档 (*.doc)|*.doc";

            if (saveFilDlg.ShowDialog() == DialogResult.OK && saveFilDlg.FileName.Length > 0)
            {
                try
                {
                    if (saveFilDlg.FileName.Contains(".rtf"))
                    {
                        this.rtb_DATA.SaveFile(saveFilDlg.FileName);
                    }
                    if (saveFilDlg.FileName.Contains(".doc"))
                    {
                        ApplicationClass MyWord = new ApplicationClass();
                        Document         MyDoc;
                        Object           Nothing = System.Reflection.Missing.Value;
                        MyDoc = MyWord.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                        MyWord.Selection.Text = this.rtb_DATA.Text;
                        //MyDoc.Paragraphs.Last.Range.Text = this.rtb_DATA.Text;
                        object MyFileName = saveFilDlg.FileName;
                        //将WordDoc文档对象的内容保存为DOC文档
                        MyDoc.SaveAs(ref MyFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                        //关闭WordDoc文档对象
                        MyDoc.Close(ref Nothing, ref Nothing, ref Nothing);
                        //关闭WordApp组件对象
                        MyWord.Quit(ref Nothing, ref Nothing, ref Nothing);
                    }
                    MessageBoxEx.Show("WORD文件保存成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception Err)
                {
                    MessageBoxEx.Show("WORD文件保存失败!" + Err.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #8
0
        protected Dictionary <long, isPin> GetDicPinDocs(List <MyDoc> mydocs, MyDoc mydoc = null)
        {
            var items = new List <MyDoc>();

            if (Utils.IsNotEmpty(mydocs))
            {
                items.AddRange(mydocs);
            }
            if (Utils.IsNotEmpty(mydoc))
            {
                items.Add(mydoc);
            }

            var dicResult     = new Dictionary <long, isPin>();
            var userFavorites = items.Count > 0 ? Repository.UserFavoriteRepository.GetList(CUser.IDChannel, CUser.ID, FavoriteType.Myfile, items.Select(x => x.ID).ToArray()) : new List <UserFavorite>();

            foreach (var item in items)
            {
                dicResult[item.ID] = userFavorites.Any(x => x.IDDoc == item.ID) ? isPin.Co : isPin.Khong;
            }
            return(dicResult);
        }
        public async Task select_to_anonymous_type()
        {
            StoreOptions(opts =>
            {
                opts.Serializer(new JilSerializer());
            });

            var myDoc = new MyDoc
            {
                Name   = "foo",
                Number = 16
            };

            theSession.Store(myDoc);
            await theSession.SaveChangesAsync();



            var custom = await theSession.Query <MyDoc>().Where(x => x.Id == myDoc.Id)
                         .Select(x => new { Name = x.Name, Number = x.Number }).SingleAsync();

            custom.Number.ShouldBe(myDoc.Number);
        }
コード例 #10
0
 protected Dictionary <long, isPin> GetDicPinDoc(MyDoc mydoc)
 {
     return(GetDicPinDocs(null, mydoc));
 }