コード例 #1
0
ファイル: AccessManager.cs プロジェクト: Cycapb/Vault
        public async Task RevokeCreateAccess(VaultUser vaultUser, string vaultId)
        {
            var vault = await _userVaultRepository.GetItemAsync(vaultId);

            var userToDel = vault?.AllowCreate?.SingleOrDefault(x => x.Id == vaultUser.Id);

            if (userToDel != null)
            {
                vault.AllowCreate.Remove(userToDel);
                await _userVaultRepository.UpdateAsync(vault);
            }
        }
コード例 #2
0
        public async Task <ActionResult> DeleteUser(string id, string vaultId)
        {
            var userToDel = new VaultUser()
            {
                Id = id
            };
            await _accessManager.RevokeReadAccess(userToDel, vaultId);

            await _accessManager.RevokeCreateAccess(userToDel, vaultId);

            return(RedirectToAction("EditUsers", new { id = vaultId }));
        }
コード例 #3
0
        int IComparer.Compare(Object x, Object y)
        {
            if (!(x is VaultUser) || !(y is VaultUser))
            {
                throw new InvalidCastException("One of objects supplied is not of the valid type.");
            }

            VaultUser item1 = (VaultUser)x;
            VaultUser item2 = (VaultUser)y;

            return(item1.Name.CompareTo(item2.Name));
        }
コード例 #4
0
ファイル: AccessManager.cs プロジェクト: Cycapb/Vault
        public async Task GrantCreateAccess(VaultUser vaultUser, string vaultId)
        {
            var vault = await _userVaultRepository.GetItemAsync(vaultId);

            if (vault.AllowCreate == null)
            {
                vault.AllowCreate = new List <VaultUser> {
                    vaultUser
                };
            }
            else
            {
                if (!vault.AllowCreate.Any(x => x.Id == vaultUser.Id))
                {
                    vault.AllowCreate.Add(vaultUser);
                }
            }
            await _userVaultRepository.UpdateAsync(vault);
        }
コード例 #5
0
        public async Task <ActionResult> AddUsers(UserToAddModel user)
        {
            var vaultUser = new VaultUser()
            {
                Id       = user.UserId,
                UserName = (await UserManager.FindByIdAsync(user.UserId)).UserName
            };

            if (user.AccessRight == "Read")
            {
                await _accessManager.GrantReadAccess(vaultUser, user.VaultId);
            }
            if (user.AccessRight == "Create")
            {
                await _accessManager.GrantCreateAccess(vaultUser, user.VaultId);
            }
            await _accessManager.ValidateUserAccessRights(user.VaultId, user.UserId);

            return(RedirectToAction("EditUsers", new { id = user.VaultId }));
        }
コード例 #6
0
        //Outlook.Explorer thisExplorer;
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //thisExplorer = Application.ActiveExplorer();
            //thisExplorer.FolderSwitch +=
            //new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_FolderSwitchEventHandler(ThisApplication_SelectionChange);
            //thisExplorer.SelectionChange +=
            //new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_SelectionChangeEventHandler(ThisApplication_SelectionChange);

            //TODO: throw error when not connected to exchange server
            //var CurrentUserEmailAddr = this.Application.ActiveExplorer().Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress;

            var CurrentUserEmailAddr = "*****@*****.**";

            this.Application.NewMail += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail);

            string folderName = "QISMsgVault";

            Outlook.MAPIFolder inbox = (Outlook.MAPIFolder)
                                       this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            // TODO: if folder dones't exist, create it.
            try
            {
                this.Application.ActiveExplorer().CurrentFolder            = inbox.Parent.Folders[folderName];
                this.Application.ActiveExplorer().CurrentFolder.WebViewURL = "http://localhost/MsgVaultWeb/Default.htm";
                this.Application.ActiveExplorer().CurrentFolder.WebViewOn  = true;
                // this.Application.ActiveExplorer().CurrentFolder.Display();
            }
            catch
            {
                MessageBox.Show("There is no folder named " + folderName +
                                ".", "Find Folder Name");
            }

            //Outlook.MAPIFolder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            Outlook.MailItem moveMail = null;
            Outlook.Items    items    = (Outlook.Items)inbox.Items;

            MsgVaultSvc.MsgVaultServiceClient client = new MsgVaultSvc.MsgVaultServiceClient();
            VaultUser currentUser = client.GetUserByEmail(CurrentUserEmailAddr);

            if (currentUser != null)
            {
                //MessageBox.Show("User exist!");
                if (!currentUser.initialized) //not initialized, import all emails
                {
                    int i = 0;
                    foreach (Object eMail in items)
                    {
                        //export email to temp folder
                        // i++;
                        //MessageBox.Show("processing no. " + i.ToString());
                        if (eMail is Outlook.MailItem)
                        {
                            i++;
                            List <string> atts = new List <string>();
                            try
                            {
                                moveMail = eMail as Outlook.MailItem;
                                foreach (Attachment attachment in moveMail.Attachments)
                                {
                                    string retrive_type = attachment.FileName.ToString();
                                    // if (System.IO.Path.GetExtension(attachment.FileName) == ".txt")
                                    //var attachmentData = attachment.PropertyAccessor.GetProperty(PR_ATTACH_DATA_BIN);
                                    atts.Add(retrive_type);
                                }
                                MongoMail msg = new MongoMail()
                                {
                                    Subject            = moveMail.Subject,
                                    Categories         = moveMail.Categories,
                                    CreationTime       = moveMail.CreationTime,
                                    ReceivedTime       = moveMail.ReceivedTime,
                                    CC                 = moveMail.CC,
                                    SenderEmailAddress = moveMail.SenderName,//moveMail.SenderEmailAddress,
                                    Body               = moveMail.Body,
                                    To                 = moveMail.To,
                                    EntryID            = moveMail.EntryID,
                                    Attachments        = atts.ToArray()
                                };

                                client.UploadEmail(msg); //TODO: need to consider InsertBatch in MongoDB for better performance

                                //if (GetUserProperty((Outlook.MailItem)eMail) == null)
                                //{
                                //    SetUserProperty((Outlook.MailItem)eMail, "3001440");
                                //    ((Outlook.MailItem)eMail).Save();
                                //}

                                //this line cause out of memory issue
                                // moveMail.SaveAs("C:\\temp\\" + moveMail.Subject + ".msg", Outlook.OlSaveAsType.olMSG); //cause out of memory error
                            }
                            catch (System.Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                        //if (i > 200)
                        //{
                        //    //MessageBox.Show("Imported !");
                        //    break;
                        //}
                    }
                    currentUser.initialized = true;
                    client.UpdateUser(currentUser);
                }
            }
            else
            {
                //please create the user first
                //MessageBox.Show("User doesn't exist!");
                VaultUser usr = new VaultUser()
                {
                    emailAddress = CurrentUserEmailAddr,
                    initialized  = false,
                    CreationTime = DateTime.Now,
                    LastUpdated  = DateTime.Now
                };
                client.CreateUser(usr);
            }
        }