Пример #1
0
        private void SetPWVarsCE_NewDesignFileEvent(Bentley.MstnPlatformNET.AddIn sender, NewDesignFileEventArgs eventArgs)
        {
            if (eventArgs.WhenCode == NewDesignFileEventArgs.When.AfterDesignFileOpen)
            {
                string sFileName = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile().GetFileName();

                BPSUtilities.WriteLog($"Filename is '{sFileName}'");

                int iProjectNo = 0, iDocumentNo = 0;

                PWWrapper.aaApi_Initialize(0);

                if (mcmMain_GetDocumentIdByFilePath(sFileName, 1,
                                                    ref iProjectNo, ref iDocumentNo))
                {
                    BPSUtilities.WriteLog($"IDs: {iProjectNo}, {iDocumentNo}");

                    if (iProjectNo > 0 && iDocumentNo > 0)
                    {
                        UpdatePWEnvVars(iProjectNo, iDocumentNo);
                    }
                    else
                    {
                        BPSUtilities.WriteLog("No integrated session of ProjectWise.");
                    }
                }
                else
                {
                    BPSUtilities.WriteLog("No integrated session of ProjectWise.");
                }

                ListReferences(true);
            }
        }
        public static int GetFolderNo(string sFolderPath)
        {
            if (sFolderPath.ToLower().StartsWith("pw:"))
            {
                int iIndex = sFolderPath.ToLower().IndexOf(@"\documents\");

                if (iIndex == -1)
                {
                    iIndex = sFolderPath.ToLower().IndexOf(@"/documents/");
                }

                if (iIndex > -1)
                {
                    string sPWPath = sFolderPath.Substring(iIndex + @"/documents".Length);

                    int iFolderNo = PWWrapper.ProjectNoFromPath(sPWPath);

                    if (iFolderNo < 1)
                    {
                        iFolderNo = PWWrapper.ProjectNoFromPath(System.IO.Path.GetDirectoryName(sPWPath));

                        if (iFolderNo > 0)
                        {
                            string sFileName = Path.GetFileName(sPWPath);

                            if (PWWrapper.aaApi_SelectDocumentsByNameProp(iFolderNo, sPWPath, null, null, null) < 1)
                            {
                                iFolderNo = 0;
                            }
                        }
                    }

                    return(iFolderNo);
                }
            }

            return(0);
        }
Пример #3
0
        private bool mcmMain_GetDocumentIdByFilePath(string sFileName, int iValidateWithChkl,
                                                     ref int iProjectNo, ref int iDocumentNo)
        {
            bool bRetVal = false;

            Guid[] docGuids  = new Guid[1];
            int    iNumGuids = 0;

            try
            {
                IntPtr pGuid = IntPtr.Zero;

                int iRetVal = PWWrapper.aaApi_GetGuidsFromFileName(ref pGuid, ref iNumGuids, sFileName, iValidateWithChkl);

                if (iNumGuids == 1)
                {
                    Guid docGuid = (Guid)System.Runtime.InteropServices.Marshal.PtrToStructure(pGuid, typeof(Guid));

                    if (1 == PWWrapper.aaApi_GUIDSelectDocument(ref docGuid))
                    {
                        bRetVal = true;

                        iProjectNo =
                            PWWrapper.aaApi_GetDocumentNumericProperty(PWWrapper.DocumentProperty.ProjectID, 0);
                        iDocumentNo =
                            PWWrapper.aaApi_GetDocumentNumericProperty(PWWrapper.DocumentProperty.ID, 0);
                    }
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"Error: {ex.Message}\n{ex.StackTrace}");
            }

            return(bRetVal);
        }
        public static void SaveReport(string unparsed)
        {
            string sReportFile = Path.Combine(Path.GetTempPath(), $"{BPSUtilities.GetARandomString(8, "abcdefghijklmnopqrstuvwxyz")}.rpt");

            try
            {
                Bentley.DgnPlatformNET.ConfigurationManager.WriteActiveConfigurationSummary(sReportFile);
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog("Error: {0}\n{1}", ex.Message, ex.StackTrace);
            }

            if (File.Exists(sReportFile))
            {
                StringBuilder sbDSN = new StringBuilder(1024);

                bool bCheckPW = false;

                if (PWWrapper.aaApi_GetActiveDatasourceName(sbDSN, sbDSN.Capacity))
                {
                    bCheckPW = true;
                }

                DataSet ds = new DataSet();
                ds.Tables.Add(new DataTable("ConfigurationVariables"));

                ds.Tables[0].Columns.Add(new DataColumn("Name", typeof(string)));
                ds.Tables[0].Columns.Add(new DataColumn("Level", typeof(string)));
                ds.Tables[0].Columns.Add(new DataColumn("Value", typeof(string)));
                ds.Tables[0].Columns.Add(new DataColumn("ExpandedValue", typeof(string)));
                ds.Tables[0].Columns.Add(new DataColumn("InvalidPWPaths", typeof(string)));

                SortedList <string, int> slVariableLevels = new SortedList <string, int>()
                {
                    { "Application", (int)Bentley.DgnPlatformNET.ConfigurationVariableLevel.Application },
                    { "Predefined", (int)Bentley.DgnPlatformNET.ConfigurationVariableLevel.Predefined },
                    { "Organization", (int)Bentley.DgnPlatformNET.ConfigurationVariableLevel.Organization },
                    { "WorkSpace", (int)Bentley.DgnPlatformNET.ConfigurationVariableLevel.WorkSpace },
                    { "System Environment", (int)Bentley.DgnPlatformNET.ConfigurationVariableLevel.SystemEnvironment },
                    { "System", (int)Bentley.DgnPlatformNET.ConfigurationVariableLevel.System },
                    { "User", (int)Bentley.DgnPlatformNET.ConfigurationVariableLevel.User },
                    { "WorkSet", (int)Bentley.DgnPlatformNET.ConfigurationVariableLevel.WorkSet },
                    { "Role", (int)Bentley.DgnPlatformNET.ConfigurationVariableLevel.Role }
                };

                using (StreamReader sr = new StreamReader(sReportFile))
                {
                    while (!sr.EndOfStream)
                    {
                        string sLine = sr.ReadLine();

                        if (sLine.StartsWith("%level"))
                        {
                            DataRow dr = ds.Tables[0].NewRow();

                            string[] sSplits = sLine.Split(new string[1] {
                                "  "
                            }, StringSplitOptions.RemoveEmptyEntries);

                            if (sSplits.Length > 1)
                            {
                                dr["Level"] = sSplits[1];

                                string sLine2 = sr.ReadLine();

                                string[] sSplits2 = sLine2.Split(new string[1] {
                                    " = "
                                }, StringSplitOptions.RemoveEmptyEntries);

                                if (sSplits2.Length > 1)
                                {
                                    dr["Name"]  = sSplits2[0].Trim();
                                    dr["Value"] = sSplits2[1].Trim();

                                    string sExpandedValue = string.Empty;

                                    if (slVariableLevels.ContainsKey(sSplits[1]))
                                    {
                                        sExpandedValue = Bentley.DgnPlatformNET.ConfigurationManager.GetVariable(sSplits2[0].Trim(),
                                                                                                                 (Bentley.DgnPlatformNET.ConfigurationVariableLevel)slVariableLevels[sSplits[1]]);
                                    }
                                    else
                                    {
                                        sExpandedValue = Bentley.DgnPlatformNET.ConfigurationManager.GetVariable(sSplits2[0].Trim());
                                    }

                                    dr["ExpandedValue"] = sExpandedValue;

                                    if (sExpandedValue.Contains("pw:") && bCheckPW)
                                    {
                                        string[] sSplits3 = sExpandedValue.Split(";".ToCharArray());

                                        SortedList <string, string> slUniqueValues = new SortedList <string, string>();

                                        foreach (string sSplit in sSplits3)
                                        {
                                            slUniqueValues.AddWithCheck(sSplit, sSplit);
                                        }

                                        StringBuilder sbInvalidPaths = new StringBuilder();

                                        foreach (string de in slUniqueValues.Keys)
                                        {
                                            if (de.ToLower().StartsWith("pw:"))
                                            {
                                                if (GetFolderNo(de.ToString()) < 1)
                                                {
                                                    if (sbInvalidPaths.Length > 0)
                                                    {
                                                        sbInvalidPaths.Append(";");
                                                    }

                                                    sbInvalidPaths.Append(de);
                                                }
                                            }
                                        }

                                        dr["InvalidPWPaths"] = sbInvalidPaths.ToString();
                                    }

                                    ds.Tables[0].Rows.Add(dr);
                                }
                            }
                        }
                    } // for each pair of lines in the file
                }

                if (!string.IsNullOrEmpty(unparsed))
                {
                    if (!unparsed.ToLower().EndsWith(".xlsx"))
                    {
                        unparsed += ".xlsx";
                    }
                }
                else
                {
                    SaveFileDialog dlg = new SaveFileDialog();
                    dlg.Title        = "Select Configuration File Report Output Location";
                    dlg.Filter       = "XLSX Files|*.xlsx|All Files|*.*";
                    dlg.DefaultExt   = ".xlsx";
                    dlg.AddExtension = true;

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        unparsed = dlg.FileName;
                    }
                }

                if (ds.Tables[0].Rows.Count > 0 && !string.IsNullOrEmpty(unparsed))
                {
                    try
                    {
                        XLSXDataSetTools.DataSetToXLSXFast(ds, unparsed);

                        if (File.Exists(unparsed))
                        {
                            MessageBox.Show($"Wrote '{unparsed}'", "SetPWVarsCE");
                        }
                    }
                    catch (Exception ex)
                    {
                        BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}");
                        MessageBox.Show($"Error writing '{unparsed}'", "SetPWVarsCE");
                    }
                }
            }
        }
Пример #5
0
        public static void UpdatePWEnvVars(int lProjectNo, int lDocumentNo)
        {
            if (1 == PWWrapper.aaApi_SelectDocument(lProjectNo, lDocumentNo))
            {
                Bentley.DgnPlatformNET.ConfigurationVariableLevel level = Bentley.DgnPlatformNET.ConfigurationVariableLevel.Application;

                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_VAULTID", $"{lProjectNo}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCID", $"{lDocumentNo}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_ORIGINALNO",
                                                                           $"{PWWrapper.aaApi_GetDocumentNumericProperty(PWWrapper.DocumentProperty.OriginalNumber, 0)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCNAME",
                                                                           $"{PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.Name, 0)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_FILENAME",
                                                                           $"{PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.FileName, 0)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCDESC",
                                                                           $"{PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.Desc, 0)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCVERSION",
                                                                           $"{PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.Version, 0)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCCREATETIME",
                                                                           $"{PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.CreateTime, 0)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCUPDATETIME",
                                                                           $"{PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.UpdateTime, 0)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCFILEUPDATETIME",
                                                                           $"{PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.FileUpdateTime, 0)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCLASTRTLOCKTIME",
                                                                           $"{PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.LastRtLockTime, 0)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCWORKFLOW",
                                                                           $"{PWWrapper.GetWorkflowName(PWWrapper.aaApi_GetDocumentNumericProperty(PWWrapper.DocumentProperty.WorkFlowID, 0))}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCWORKFLOWSTATE",
                                                                           $"{PWWrapper.GetStateName(PWWrapper.aaApi_GetDocumentNumericProperty(PWWrapper.DocumentProperty.StateID, 0))}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_VAULTPATHNAME",
                                                                           $"{PWWrapper.GetProjectNamePath2(lProjectNo)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_FULLFILEPATHNAME",
                                                                           $"{PWWrapper.GetDocumentNamePath(lProjectNo, lDocumentNo)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCGUID",
                                                                           $"{PWWrapper.GetGuidStringFromIds(lProjectNo, lDocumentNo)}", level);
                Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_DOCLINK",
                                                                           $"{PWWrapper.GetDocumentURL(lProjectNo, lDocumentNo)}", level);

                if (1 == PWWrapper.aaApi_SelectProject(lProjectNo))
                {
                    Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_VAULTNAME",
                                                                               $"{PWWrapper.aaApi_GetProjectStringProperty(PWWrapper.ProjectProperty.Name, 0)}", level);
                    Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable("PWVAR_VAULTDESC",
                                                                               $"{PWWrapper.aaApi_GetProjectStringProperty(PWWrapper.ProjectProperty.Desc, 0)}", level);
                }

                System.Collections.Generic.SortedList <string, string> slProps = PWWrapper.GetProjectPropertyValuesInList(lProjectNo);

                foreach (System.Collections.Generic.KeyValuePair <string, string> kvp in slProps)
                {
                    Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable($"PWVAR_PROJPROP_{kvp.Key.ToUpper().Replace(" ", "_")}",
                                                                               kvp.Value, level);
                }

                System.Collections.Generic.SortedList <string, string> slAttrs = PWWrapper.GetAllAttributeColumnValuesInList(lProjectNo, lDocumentNo);

                foreach (System.Collections.Generic.KeyValuePair <string, string> kvp in slAttrs)
                {
                    Bentley.DgnPlatformNET.ConfigurationManager.DefineVariable($"PWVAR_ATTR_{kvp.Key.ToUpper().Replace(" ", "_")}",
                                                                               kvp.Value, level);
                }
            } // document selected
            else
            {
                BPSUtilities.WriteLog("Could not select document.");
            }
        }
        public static void Place(string unparsed)
        {
            if (string.IsNullOrEmpty(unparsed))
            {
                string sFileName = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile().GetFileName();

                BPSUtilities.WriteLog($"Filename is '{sFileName}'");

                int iProjectNo = 0, iDocumentNo = 0;

                PWWrapper.aaApi_Initialize(0);

                if (mcmMain_GetDocumentIdByFilePath(sFileName, 1,
                                                    ref iProjectNo, ref iDocumentNo))
                {
                    BPSUtilities.WriteLog($"IDs: {iProjectNo}, {iDocumentNo}");

                    if (iProjectNo > 0 && iDocumentNo > 0)
                    {
                        int GMAIL_PROJECTWISE_WEB_VIEW_SETTING = -5250;

                        string sWebViewURL = PWWrapper.GetPWStringSetting(GMAIL_PROJECTWISE_WEB_VIEW_SETTING);

                        string sProjectGUIDString  = PWWrapper.GetProjectGuidStringFromId(iProjectNo);
                        string sDocumentGUIDString = PWWrapper.GetGuidStringFromIds(iProjectNo, iDocumentNo);

                        if (!string.IsNullOrEmpty(sWebViewURL))
                        {
                            unparsed = $"{sWebViewURL}?project={sProjectGUIDString}&item={sDocumentGUIDString}";
                        }
                        else
                        {
                            BPSUtilities.WriteLog("No web view link address set.");
                        }
                    }
                    else
                    {
                        BPSUtilities.WriteLog("No integrated session of ProjectWise.");
                    }
                }
                else
                {
                    BPSUtilities.WriteLog("No integrated session of ProjectWise.");
                }

                if (string.IsNullOrEmpty(unparsed))
                {
                    unparsed = "www.bentley.com";
                }

                BPSUtilities.WriteLog($"Make code for this: {unparsed}");

                PlaceQRCode.InstallNewInstance(unparsed);
            }
            else
            {
                BPSUtilities.WriteLog($"Make code for this: {unparsed}");

                PlaceQRCode.InstallNewInstance(unparsed);
            }
        }