// IVsPersistSolutionProps::QuerySaveSolutionProps public int QuerySaveSolutionProps([In] IVsHierarchy pHierarchy, [Out] VSQUERYSAVESLNPROPS[] pqsspSave) { // This function is called by the IDE to determine if something needs to be saved in the solution. // If the package returns that it has dirty properties, the shell will callback on SaveSolutionProps // We will write solution properties only for the solution // A provider may consider writing in the solution project-binding-properties for each controlled project // that could help it locating the projects in the store during operations like OpenFromSourceControl if (!SccService.IsProjectControlled(null)) { pqsspSave[0] = VSQUERYSAVESLNPROPS.QSP_HasNoProps; } else { if (SolutionHasDirtyProps) { pqsspSave[0] = VSQUERYSAVESLNPROPS.QSP_HasDirtyProps; } else { pqsspSave[0] = VSQUERYSAVESLNPROPS.QSP_HasNoDirtyProps; } } return(VSConstants.S_OK); }
/// <summary> /// 初始化系统/页面基本信息 /// </summary> public void LoadBaseData() { LangType = Tools.CookieHelper.GetCookie("LangType"); LoginUserID = Tools.CookieHelper.GetCookie("LoginUserID"); if (LangType.IsNullOrEmpty() && LoginUserID.IsNotNullOrEmpty()) { var userLanguage = SccService.GetUserLanguageByUserId(LoginUserID); if (userLanguage != null) { LangType = userLanguage.LanguageID; } } //当前系统中的识别号 SysID = ConfigurationManager.AppSettings["SysID"]; FunctionID = "Home"; PageID = "Login"; //菜单编号(在SBA数据库中生成的ID) SysCode = ConfigurationManager.AppSettings["SysCode"]; FunctionCode = ConfigurationManager.AppSettings["SysCode"]; //调试 Debug = Tools.DataTypeConvertHelper.ToBoolean(ConfigurationManager.AppSettings["Debug"]); }
/// <summary> /// 权限验证 /// </summary> /// <param name="action"></param> private void Authorize(string action) { if (this.JsonProcessor.ContainsKey(action) || this.ImageProcessor.ContainsKey(action) || this.FileDownloadProcessor.ContainsKey(action) ) { System.Reflection.MethodInfo methodInfo = this.JsonProcessor.ContainsKey(action) ? this.JsonProcessor[action].Method : this.ImageProcessor.ContainsKey(action) ? this.ImageProcessor[action].Method : this.FileDownloadProcessor[action].Method; var attr = methodInfo.GetCustomAttributes(false).OfType <AuthorizeAttribute>().FirstOrDefault(); if (attr != null) { if (SccService.Authorized() && SccService.IsInRole(attr.Role, this.FunctionCode)) { //通过权限检查 } else { this.ReturnJson(JsonConvert.SerializeObject(new AjaxResult { Message = Commons.Language.GetText("UnAuthorized", "CN:你无权访问!~EN:UnAuthorized", SccService.CurrentLanguageType), IsSuccess = false })); } } } }
/// <summary> /// 初始化 FunctionID, FunctionCode /// </summary> private void LoadFunctionId() { if (this.FunctionCode.IsNullOrEmpty()) { var sccFunAttr = this.GetType() .GetCustomAttributes(typeof(SccFunctionAttribute), true) .OfType <SccFunctionAttribute>() .FirstOrDefault(); if (sccFunAttr == null) { var getFunctionIdFromRequestPath = SccService.GetFunctionId(this.Request.Path); if (getFunctionIdFromRequestPath.IsNullOrEmpty()) { throw new Exception(this.GetType().Name + " Class not defined SccFunction Attribute, Please check."); } this.FunctionID = getFunctionIdFromRequestPath; this.FunctionCode = getFunctionIdFromRequestPath; } else { this.FunctionID = sccFunAttr.WebConfigAppKey; this.FunctionCode = ConfigurationManager.AppSettings[this.FunctionID]; } } }
protected override void Dispose(bool disposing) { logger.Trace("Entering Dispose() of: {0}", this.ToString()); SccService.Dispose(); base.Dispose(disposing); }
// IVsPersistSolutionProps::SaveUserOptions public int SaveUserOptions([In] IVsSolutionPersistence pPersistence) { // This function gets called by the shell when the SUO file is saved. // The provider calls the shell back to let it know which options keys it will use in the suo file. // The shell will create a stream for the section of interest, and will call back the provider on // IVsPersistSolutionProps.WriteUserOptions() to save specific options under the specified key. int pfResult = 0; SccService.AnyItemsUnderSourceControl(out pfResult); if (pfResult > 0) { pPersistence.SavePackageUserOpts(this, _strSolutionUserOptionsKey); } return(VSConstants.S_OK); }
/// <summary> /// 尝试登录 /// </summary> protected void TryLogin() { string txtUserName = this.Request["user"]; string txtPassword = this.Request["password"]; string txtDomain = this.Request["domain"]; string txtLanguageType = this.Request["language"]; SavePostForm(txtUserName, txtDomain, txtLanguageType); if (txtUserName.IsNullOrEmpty()) { this.FlashMessage = Language.GetText("Common.s_NotValidUserID", "CN:请输入一个有效的用户ID!~EN:Sorry,the userid or password is not right!", txtLanguageType); return; } if (txtPassword.IsNullOrEmpty()) { this.FlashMessage = Language.GetText("Common.s_PleaseTypePassword", "CN:请输入一个有效的密码!~EN:Please input a valid password!", txtLanguageType); return; } txtDomain = txtDomain.IsNullOrEmpty() ? SccService.GetDomain(txtUserName) : txtDomain; txtUserName = SccService.GetBaseUserId(txtUserName); if (!SccService.CheckPassword(txtUserName, txtDomain, txtPassword, txtLanguageType)) { this.FlashMessage = Language.GetText("Common.s_InvalidUserIdOrPassword", "CN:用户名或密码不正确!~EN:User Name Or Password invalid!", txtLanguageType); return; } if (SccService.CheckUserHasAnyRightBySCC(txtUserName)) { SccService.SaveAuthCookie(txtUserName, txtDomain, txtLanguageType); Response.Redirect("Index.aspx"); } else { this.FlashMessage = Language.GetText("Common.s_UserHasNoRightAccess", "CN:您无权访问,请联系管理员设置权限!~EN:You are not authorized to access, please contact the administrator set permissions!", txtLanguageType); } }
/// <summary> /// 验证Processor相应的Action的权限 /// </summary> /// <param name="action"></param> private void Authorize(string action) { var attr = this.Processor[action].Method .GetCustomAttributes(false) .OfType <AuthorizeAttribute>() .FirstOrDefault(); if (attr != null) { if (!SccService.IsInRole(attr.Role, this.FunctionCode)) { //没有通过权限检查则跳转 throw new System.Web.HttpException(403, "没有权限,访问禁止"); } } }
internal void CheckLazyLoadStatus() { if (Preferences.LocalSettings.GetBool("LazyLoadStatus", false)) { // if lazy laoding, update status of the selected files that haven't had // their status loaded IList <string> files = SccService.SelectedFiles; IList <string> llfiles = new List <string>(files.Count); foreach (string file in files) { SourceControlStatus status = SccService.GetFileStatus(file); if (status.Test(SourceControlStatus.scsUnknown)) { llfiles.Add(file); } } CurrentScm.UpdateFiles(llfiles, true); Glyphs.RefreshFilesAndGlyphs(llfiles); } }
/// <summary> /// 从配置文件中载入基本数据和初始化基本参数,并检验是否有权限访问 /// </summary> /// <param name="functionID">web config 中功能Key</param> /// <param name="pageID"></param> /// <param name="functionName"></param> private void LoadBaseData() { //当前系统中的识别号 this.SysID = ConfigurationManager.AppSettings["SysID"]; this.SysCode = ConfigurationManager.AppSettings["SysCode"]; if (String.IsNullOrEmpty(SysCode)) { this.SysCode = SysID; } //菜单编号(在SBA数据库中生成的ID) this.LoadFunctionId(); this.PageID = this.GetType().BaseType.Name; this.Debug = Tools.DataTypeConvertHelper.ToBoolean(ConfigurationManager.AppSettings["Debug"]); this.FunctionName = Commons.Language.GetText(this.FunctionID + ".Name", this.FunctionID); this.LanguageSourceType = Tools.ConfigHelper.GetConfigString("LanguageSourceType").ToUpper(); //获取加密参数 this.EncryptionParas = new Dictionary <string, string>(); String paras = Tools.DataTypeConvertHelper.ToString(Request["paras"]); if (!String.IsNullOrEmpty(paras)) { paras = Tools.DESEncrypt.Decrypt(paras); this.EncryptionParas = Tools.DataTypeConvertHelper.StringToDictionary(paras, '&', '='); } //验证是否有查看权限,查看为最基本权限 if (SccService.Authorized() && SccService.IsInRole(SccService.Roles.View, this.FunctionCode)) { //通过权限检查 this.LangType = SccService.CurrentLanguageType; this.LoginUserID = SccService.CurrentUserId; } else { // throw new System.Web.HttpException(403, "没有权限,访问禁止"); } }
protected void Page_Load(object sender, EventArgs e) { StartTime = DateTime.Now; using (var t = new Log4WebStandard.Tracker("Page_Load")) { // 验证权限 if (!SccService.Authorized()) { throw new System.Web.HttpException(401, "Auth Failed"); } LoadBaseData(); SetLangAttribute(); GetMenu(); lblLoginerName.Text = SccService.CurrentUserInfo.UserInfo.displayname; if (!String.IsNullOrEmpty(this.CompanyCode)) { var company = SccService.GetCompany(this.CompanyCode); if (company != null) { lblComapnyName.Text = this.LangType.EqualWithTrim("CN") ? company.Company_Name_CN.SafeTrim() : company.Company_Name_EN.SafeTrim(); } else { lblComapnyName.Text = this.CompanyCode; } CompanyGroup.Visible = true; } } TimeSpan BlackRunTime = DateTime.Now.Subtract(StartTime); }
//IList<SelectedFile> SelectedFiles { get; set; } /// <summary> /// Returns a list of source controllable files in the selection (recursive) /// </summary> internal IList <string> GetSelectedFilesInControlledProjectsInt( out IList <string> selectedFilesFolders, out IList <VSITEMSELECTION> selectedNodes, out Hashtable SelectedHierarchies, out bool isSolutionSelected) { IDictionary <string, object> sccFiles = new Dictionary <string, object>(); IDictionary <string, object> sccFilesFolders = new Dictionary <string, object>(); //SelectedFiles = new List<SelectedFile>(); selectedNodes = GetSelectedNodes(); isSolutionSelected = false; SelectedHierarchies = GetSelectedHierarchies(ref selectedNodes, out isSolutionSelected); if (isSolutionSelected) { // Replace the selection with the root items of all controlled projects selectedNodes.Clear(); SelectedHierarchies.Clear(); Hashtable hashControllable = GetLoadedControllableProjectsEnum(); foreach (IVsHierarchy pHier in hashControllable.Keys) { if (SccService.IsProjectControlled(pHier)) { VSITEMSELECTION vsItemSelection; SelectedHierarchies[pHier] = true; vsItemSelection.pHier = pHier; vsItemSelection.itemid = VSConstants.VSITEMID_ROOT; selectedNodes.Add(vsItemSelection); } } // Add the solution file to the list if (SccService.IsProjectControlled(null)) { IVsHierarchy solHier = (IVsHierarchy)GetService(typeof(SVsSolution)); SelectedHierarchies[solHier] = true; VSITEMSELECTION vsItemSelection; vsItemSelection.pHier = solHier; vsItemSelection.itemid = VSConstants.VSITEMID_ROOT; selectedNodes.Add(vsItemSelection); } } SccService.IsaControlledProjectSelected = false; // now look in the rest of selection and accumulate scc files foreach (VSITEMSELECTION vsItemSel in selectedNodes) { if (vsItemSel.itemid == VSConstants.VSITEMID_ROOT) { SccService.IsaControlledProjectSelected |= SccService.IsProjectControlled(vsItemSel.pHier); } IVsSccProject2 pscp2 = vsItemSel.pHier as IVsSccProject2; if (pscp2 == null) { string solutionFileName = GetSolutionFileName(); // solution case sccFiles[solutionFileName] = null; string solutionFolder = Path.GetDirectoryName(solutionFileName); solutionFolder = string.Format("{0}\\...", solutionFolder); sccFilesFolders[solutionFolder] = true; } else { // if this is a project, add the projects directory to the list of selected folders string path = string.Empty; IVsProject pscp = pscp2 as IVsProject; if (pscp != null) { bool addSubFiles = false; if (isSolutionSelected == false) { //only add subpaths if the folder is not selected pscp.GetMkDocument(vsItemSel.itemid, out path); if ((path != null) && (vsItemSel.itemid == VSConstants.VSITEMID_ROOT)) { // if it's a project path = Path.GetDirectoryName(path); path = string.Format("{0}\\...", path); sccFilesFolders[path] = null; } else if ((path != null) && path.EndsWith("\\")) { // if it's a folder path = string.Format("{0}...", path); sccFilesFolders[path] = null; } else { addSubFiles = true; } } IList <string> nodefilesrec = GetProjectFiles(pscp2, vsItemSel.itemid); foreach (string file in nodefilesrec) { sccFiles[file] = null; if (addSubFiles) { sccFilesFolders[file] = null; } } } } } selectedFilesFolders = sccFilesFolders.Keys.ToList(); return(sccFiles.Keys.ToList()); }
// Used to open a connection to a Perforce depot public void OpenConnection(string Port, string User, string Workspace) { #if DB_DEBUG P4VsOutputWindow.AppendMessage(string.Format("Opening connection, CurrentScm scm ID:{0}", CurrentScm != null?CurrentScm.__Id:-1)); #endif P4ScmProvider scm = new P4ScmProvider(SccService); scm.LoadingSolution = !string.IsNullOrEmpty(SccService.LoadingControlledSolutionLocation); #if DB_DEBUG P4VsOutputWindow.AppendMessage(string.Format("Opening connection, new scm ID:{0}", scm.__Id)); #endif bool noUi = InCommandLineMode() || (Port != null) && (User != null) && (Workspace != null); // trigger the connection dialog scm.Connection.Connect(Port, User, Workspace, noUi, null); if (scm.Connected) { #if DB_DEBUG P4VsOutputWindow.AppendMessage(string.Format("Opening connection user clicked OK, new scm ID:{0}", scm.__Id)); #endif if (SccService.ScmProvider != null) { BroadcastNewConnection(null); SccService.Dispose(); SccService.ScmProvider = null; } SccService.ScmProvider = scm; createActiveChangelists(SccService); if (string.IsNullOrEmpty(SccService.ScmProvider.SolutionFile)) { string solutionFile = GetSolutionFileName(); if (string.IsNullOrEmpty(solutionFile) == false) { SccService.ScmProvider.SolutionFile = GetSolutionFileName(); if (Preferences.LocalSettings.GetBool("TagSolutionProjectFiles", false)) { // Need to tag sln file if tagging is enabled, so mark dirty props so // it'll get tagged SolutionHasDirtyProps = true; } } if (!SccService.IsProjectControlled(null)) { SccService.OnAfterOpenSolution(null, 0); } } Cursor oldCursor = Cursor.Current; try { Cursor.Current = Cursors.WaitCursor; // now refresh the selected nodes' glyphs if (Preferences.LocalSettings.GetBool("LazyLoadStatus", false) == false) { Glyphs.RefreshNodesGlyphs(null, null); } } finally { Cursor.Current = oldCursor; } BroadcastNewConnection(SccService.ScmProvider); MRUList recentConnections = (MRUList)Preferences.LocalSettings["RecentConnections"]; currentConnectionDropDownComboChoice = recentConnections[0].ToString(); SuppressConnection = true; LastConnectionInfo = new ConnectionData(); LastConnectionInfo.ServerPort = SccService.ScmProvider.Connection.Port; LastConnectionInfo.UserName = SccService.ScmProvider.Connection.User; LastConnectionInfo.Workspace = SccService.ScmProvider.Connection.Workspace; #if _DBB_DEBUG // How to set a setting for the ide (Generally from tool/options dialog) // The category and page values are listed on MSDN at: // http://msdn.microsoft.com/en-us/library/ms165643(v=vs.100).aspx // The category and pages no longer follow the layout in the options dialog, // they seem to still follow the old layout fro VS 2003. There's a general // discussion on MSDN about properties here: // http://msdn.microsoft.com/en-us/library/ms165641(v=vs.100).aspx // and: // http://msdn.microsoft.com/en-us/library/awdwz11a(v=vs.100).aspx // The Property object is documented here: // http://msdn.microsoft.com/en-us/library/envdte.property(v=vs.100).aspx // The Properties interface is documented here: // http://msdn.microsoft.com/en-us/library/envdte.properties(v=vs.100).aspx try { EnvDTE.DTE dte2; dte2 = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); EnvDTE.Properties generalPnS = dte2.DTE.Properties["Environment", "ProjectsAndSolution"]; EnvDTE.Property prop2 = generalPnS.Item("ProjectsLocation"); string val = prop2.Value as string; //dynamic v2 = val + "\\temp"; prop2.Value = val; val = prop2.Value as string; } catch (Exception ex) { string msg = ex.Message; MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error); } #endif // How to set a setting for the ide (Generally from tool/options dialog) // The category and page values are listed on MSDN at: // http://msdn.microsoft.com/en-us/library/ms165643(v=vs.100).aspx // The category and pages no longer follow the layout in the options dialog, // they seem to still follow the old layout fro VS 2003. There's a general // discussion on MSDN about properties here: // http://msdn.microsoft.com/en-us/library/ms165641(v=vs.100).aspx // and: // http://msdn.microsoft.com/en-us/library/awdwz11a(v=vs.100).aspx // The Property object is documented here: // http://msdn.microsoft.com/en-us/library/envdte.property(v=vs.100).aspx // The Properties interface is documented here: // http://msdn.microsoft.com/en-us/library/envdte.properties(v=vs.100).aspx if (Preferences.LocalSettings.GetBool("SetProjectFileLocation", true) && !string.IsNullOrEmpty(scm.Connection.WorkspaceRoot)) { try { EnvDTE.Property prop = null; EnvDTE.DTE dte2; dte2 = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); EnvDTE.Properties generalPnS = dte2.get_Properties("Environment", "ProjectsAndSolution"); foreach (EnvDTE.Property temp in generalPnS) { prop = temp; if (prop.Name == "ProjectsLocation") { if (Directory.Exists(scm.Connection.WorkspaceRoot)) { prop.Value = scm.Connection.WorkspaceRoot.Replace("/", "\\"); } } } } catch (Exception ex) { string msg = ex.Message; MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } #if DB_DEBUG P4VsOutputWindow.AppendMessage(string.Format("Leaving open connection, CurrentScm scm ID:{0}", CurrentScm != null ? CurrentScm.__Id : -1)); #endif }
public void CheckoutResource(IList <string> sel) { IList <VSITEMSELECTION> nodes = SccService.SelectedNodes; IList <string> lockedFiles = new List <string>(); IList <string> lockUsers = new List <string>(); IList <string> staleFiles = new List <string>(); IList <string> checkoutFiles = new List <string>(); for (int idx = 0; idx < sel.Count; idx++) { string file = sel[idx]; bool isWildcard = file.EndsWith("...") || file.EndsWith("*"); if (isWildcard == false) { P4.FileMetaData fmd = null; if (string.IsNullOrEmpty(file) == false) { fmd = SccService.ScmProvider.Fetch(file); } if (fmd != null && fmd.HeadType.Modifiers.HasFlag(P4.FileTypeModifier.ExclusiveOpen) && fmd.OtherOpen > 0) { // Show the error for exclusive open file and continue // without adding file to list of files to checkout P4ErrorDlg.Show(Resources.P4VsProvider_ExclusiveOpenError, false, false); continue; } if ((fmd == null) || (fmd.HeadAction == P4.FileAction.Delete)) { sel.RemoveAt(idx--); continue; } if (fmd.OtherLock) { lockedFiles.Add(fmd.LocalPath.Path); string otherlocks = string.Empty; foreach (string otherLock in fmd.OtherLockUserClients) { if (string.IsNullOrEmpty(otherlocks) == false) { otherlocks += ","; } otherlocks += otherLock; } lockUsers.Add(otherlocks); } if (fmd.IsStale) { staleFiles.Add(fmd.LocalPath.Path); } } else { IList <P4.FileMetaData> fmdList = SccService.ScmProvider.GetFileMetaData(null, file); foreach (P4.FileMetaData fmd in fmdList) { if (fmd.OtherLock) { lockedFiles.Add(fmd.LocalPath.Path); string otherlocks = string.Empty; foreach (string otherLock in fmd.OtherLockUserClients) { if (string.IsNullOrEmpty(otherlocks) == false) { otherlocks += ","; } otherlocks += otherLock; } lockUsers.Add(otherlocks); } if (fmd.IsStale) { staleFiles.Add(fmd.LocalPath.Path); } } } checkoutFiles.Add(file); } if ((lockedFiles != null) && (lockedFiles.Count > 0)) { string lockWarning = Resources.WarningStyle_Locked_Prompt; if (FileListWarningDlg.Show(lockedFiles, lockUsers, FileListWarningDlg.WarningStyle.Locked) == DialogResult.Cancel) { return; } } if ((staleFiles != null) && (staleFiles.Count > 0)) { DialogResult answer = FileListWarningDlg.Show(staleFiles, null, FileListWarningDlg.WarningStyle.GetLatest); if (answer == DialogResult.Cancel) { return; } if (answer == DialogResult.OK) { if (!SccService.SyncFiles(null, staleFiles)) { return; } } } if (checkoutFiles.Count < 1) { return; } P4.Changelist getDesc = SccService.ScmProvider.GetChangelist(-1); if (getDesc == null) { return; } string newChangeDescription = getDesc.Description; if (newChangeDescription == Resources.DefaultChangeListDescription) { newChangeDescription = Resources.P4VsProvider_CheckoutFilesDefaultChangelistDescription; } IList <P4.Changelist> changes = SccService.ScmProvider.GetAvailibleChangelists(-1); int changeListId = -1; string prompt = Resources.P4VsProvider_CheckoutFilePrompt; if (sel.Count >= 2) { prompt = Resources.P4VsProvider_CheckoutFilesPrompt; } changeListId = SelectChangelistDlg2.ShowChooseChangelistYesNo(prompt, checkoutFiles, changes, ref newChangeDescription); if (changeListId < -1) { // user hit cancel return; } if (string.IsNullOrEmpty(newChangeDescription)) { newChangeDescription = Resources.P4VsProvider_CheckoutFilesDefaultChangelistDescription; } SelectChangelistDlg.CurrentChangeList = SccService.CheckoutFiles(sel, changeListId, newChangeDescription); // now refresh the selected nodes' glyphs Glyphs.RefreshNodesGlyphs(nodes, sel); }