예제 #1
0
/*-----------------------------------------------------------------------------*/
        ///<summary>Prior to using any mdl..._setFunction
        ///function we must be certain the current MDL descriptor is
        ///belongs to our add-in. This is essential because the
        ///mdl...setFunction functions save the function pointer in the
        ///MDL descriptor. This is guaranteed to be true if called from
        ///directly or indirectly from AddInMain.Run or from a key-in.
        ///</summary>
/*-----------------------------------------------------------------------------*/
        private static void VerifyMdlDescriptor()
        {
            System.IntPtr myMdlDesc   = BVSchemaChecker.MyAddin.GetMdlDescriptor();
            System.IntPtr currMdlDesc = BVSchemaChecker.mdlSystem_getCurrMdlDesc();

            System.Diagnostics.Debug.Assert(myMdlDesc == currMdlDesc);
        }
예제 #2
0
/*-----------------------------------------------------------------------------*/
        /// <summary>
        /// a command to allow the user to turn off and on the write to file hook.
        /// added per request to avoid potential conflict with some existing process.
        /// </summary>
        /// <param name="unparsed">on or off will do nothing for any other unparsed.
        /// if no value then it will prompt the user to use on or off.</param>
/*-----------------------------------------------------------------------------*/
        public static void ToggleWriteHook(string unparsed)
        {
            if (unparsed.Length == 0)
            {
                BVSchemaChecker.ComApp.MessageCenter.AddMessage("Requires On or Off", "To toggle the write to file filter use BVSchemaChecker Toggle On or Off", BCOM.MsdMessageCenterPriority.Info, true);
                return;
            }
            if (unparsed.ToUpper().Equals("ON"))
            {
                BVSchemaChecker.TurnOnWriteHook(true);
            }
            else if (unparsed.ToUpper().Equals("OFF"))
            {
                BVSchemaChecker.TurnOnWriteHook(false);
            }
        }
예제 #3
0
/*-----------------------------------------------------------------------------*/
        /// <summary>
        /// The command to process the active file.  It will attempt to create a session
        /// and open the connection to the active model.
        /// If the connection cannot be opened it will error out.
        /// The findEmbeded method to look at the file for embedded schemas
        /// </summary>
        /// <param name="unparsed">not used.</param>
/*-----------------------------------------------------------------------------*/
        public static void BVSchemaCheckerCommand(System.String unparsed)
        {
            string        errMessage = "ERROR";
            List <string> schemaList = new List <string>();

            //set to silent mode
            m_silentMode = false;
            if (1 == BVSchemaChecker.mdlSystem_startedAsAutomationServer() && ((null != unparsed) && unparsed == "FROM_HOOK"))
            {
                return;
            }
            //if an unparsed string is sent in then set silent to true
            if (1 != BVSchemaChecker.mdlSystem_startedAsAutomationServer() && ((null != unparsed) && (unparsed.Length > 0)))
            {
                m_silentMode = true;
            }
            //see if it is an imodel if so then don't check.
            if (1 == BVSchemaChecker.IsIModel(BVSchemaChecker.ComApp.ActiveModelReference.MdlModelRefP()))
            {
                BVSchemaChecker.ComApp.MessageCenter.AddMessage("this is an i-model", "i-models are not processed", BCOM.MsdMessageCenterPriority.Info, false);
                return;
            }
            //if there are references then we process special.
            if (BVSchemaChecker.ComApp.ActiveModelReference.Attachments.Count > 0)
            {//if the references are imodels then notify the users.
                if (BVSchemaChecker.HasIModelReference(BVSchemaChecker.ComApp.ActiveModelReference))
                {
                    BVSchemaChecker.ComApp.MessageCenter.AddMessage("Has IModel Attached",
                                                                    "This file has an imodel in the attachment set",
                                                                    BCOM.MsdMessageCenterPriority.Info, false);
                }

                BCOM.DesignFile workFile = BVSchemaChecker.ComApp.OpenDesignFileForProgram(
                    BVSchemaChecker.ComApp.ActiveDesignFile.FullName, true);
                //create a model in the file that has no references
                //proces the new model.  this will avoid using the references as part
                //of the ec repository.
                //delete the model after the processing.
                try
                {
                    BCOM.ModelReference workModel = workFile.Models.Add(
                        workFile.DefaultModelReference,
                        "working", "working",
                        BCOM.MsdModelType.Normal, true);

                    int iAttachmentCount = workModel.Attachments.Count;
                    for (int i = iAttachmentCount; i > 0; --i)
                    {
                        BCOM.Attachment oAtt = workModel.Attachments[i];
                        workModel.Attachments.Remove(oAtt);
                    }

                    BVSchemaChecker.ProcessModel(workModel);
                    workFile.Models.Delete(workModel);
                }
                catch (Exception e)
                {
                    Console.WriteLine("unable to wrtie to file");
                }
                workFile.Close();
                return;
            }

            //if I am a simple file with normal dgn references
            ECSR.RepositoryConnection connection = null;
            CSVReporter.CreateReport(string.Format("SC_{0}.csv", DateTime.Now.ToString("yyyy-dd-MM")));
            if (m_debugMode)
            {
                BVSchemaChecker.ComApp.MessageCenter.AddMessage("created csv file",
                                                                string.Format("created report file at {0}", CSVReporter.FileName),
                                                                BCOM.MsdMessageCenterPriority.Info, m_debugMode);
            }

            if (m_usesSelector)
            {
                m_selectorForm.SetMessage("Processing File " + BVSchemaChecker.ComApp.ActiveDesignFile.Name);
            }

            try
            {
                ECSS.ECSession ecSession = ECSS.SessionManager.CreateSession(true);
                connection = BVSchemaChecker.OpenConnectionToActiveModel(ecSession);

                if (BVSchemaChecker.FindEmbededSchemas(connection, schemaList))
                {
                    BVSchemaChecker.ComApp.MessageCenter.AddMessage("Found schema in this file. \n Please contact the Bentley Execution team with the Schema list provided on the following dialog box. \n Select Ok to get a list of the schema you will need to provide",
                                                                    "Found Schema",
                                                                    BCOM.MsdMessageCenterPriority.Error,
                                                                    m_silentMode);
                    BVSchemaChecker.iSchemaFoundCount++;
                    //show the list...
                    if (m_silentMode)
                    {
                        SchemaListForm sform = new SchemaListForm();
                        sform.SetSchemaNames(schemaList);
                        sform.ShowDialog();
                    }
                }
                else
                {
                    BVSchemaChecker.ComApp.MessageCenter.AddMessage("no schema in the file",
                                                                    "nothing found",
                                                                    BCOM.MsdMessageCenterPriority.Info,
                                                                    (unparsed != "FROM_HOOK"));
                }
            }
            catch (Exception e)
            {
                BVSchemaChecker.ComApp.MessageCenter.AddMessage(e.Message, e.Message,
                                                                BCOM.MsdMessageCenterPriority.Error,
                                                                !BVSchemaChecker.bUseLogFile);
                errMessage = e.Message;
            }
            finally
            {
                if (null == connection)
                {
                    CSVReporter.writeLine(BVSchemaChecker.strCurrentProjectName,
                                          BVSchemaChecker.ComApp.ActiveDesignFile.Name,
                                          BVSchemaChecker.ComApp.ActiveModelReference.Name,
                                          errMessage, false);
                }
                else
                {
                    BVSchemaChecker.CloseConnection(connection);
                }

                CSVReporter.close();
            }
        }
예제 #4
0
        /// <summary>
        /// The command to process an entire PW tree.
        /// </summary>
        /// <param name="unparsed">The arguments that are used to control the command.
        /// -m:ALL to process all the models - by default only the default model will be processed.
        /// -p:projectID - the id of the PW folder to  process.
        /// if not present then a dialog to select will be shown.
        /// -d:TRUE to provide logging information for debugging
        /// </param>
        public static void BVSchemaCheckerTraverseRepository(System.String unparsed)
        {
            m_silentMode = true; //this will be turned off in the parser...
            string[] parsed = null;
            LogWriter.CreateLog(string.Format("SC_{0}.log", DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")));

            BVSchemaChecker.s_runningTraverse = true;

            //break up the unparsed string
            ParseKeyin(parsed, unparsed);

            if (m_debugMode)
            {
                LogWriter.writeLine("in debug mode", true);
            }

            //go through the init logic.
            if (PWAPI.dmscli.aaApi_Initialize(0))
            {
                int           status = -1;
                StringBuilder sbName = new StringBuilder(512);
                string        sbDataSource; // = new StringBuilder(512);
                string        sbPass;       // = new StringBuilder(512);
                string        sbSchema;     // = new StringBuilder(512);
                IntPtr        hSession = IntPtr.Zero;
                LogWriter.writeLine("logging into ProjectWise", false);
                if (!PWAPI.dmscli.aaApi_GetCurrentSession(ref hSession) || (hSession == IntPtr.Zero))
                {
                    status = PWAPI.dmawin.aaApi_LoginDlg(PWAPI.dmawin.DataSourceType.Unknown,
                                                         sbName, 512, "", "", "");
                }
                else
                {
                    LogWriter.writeLine("Already logged into ProjectWise", true);
                }

                if (status == 1)
                {
                    LogWriter.writeLine("successfully logged into ProjectWise", true);
                }
            }
            else
            {
                return;
            }

            BVSchemaChecker.iSchemaFoundCount = 0; //initialize the count
            BVSchemaChecker.bUseLogFile       = true;


            if (m_iProjectID == 0)
            {
                m_iProjectID = PWAPI.dmawin.aaApi_SelectProjectDlg(0, "Select Project",
                                                                   m_iProjectID);
            }
            LogWriter.writeLine("selected project", false);

            BVSchemaChecker.BVSchemaCheckerTraverseProject(m_iProjectID);

            BVSchemaChecker.ComApp.MessageCenter.AddMessage(
                string.Format("Found {0} schema in the Selection",
                              BVSchemaChecker.iSchemaFoundCount), "Schema Found",
                BCOM.MsdMessageCenterPriority.Info, m_silentMode);
            if (m_usesSelector)
            {
                m_selectorForm.SetMessage(
                    string.Format("Found {0} schema in the Selection",
                                  BVSchemaChecker.iSchemaFoundCount));
            }

            LogWriter.writeLine(string.Format("Process Ended at {0}",
                                              DateTime.Now.ToString()), false);

            LogWriter.writeLine(string.Format("Processed {0} files and found {1} errors",
                                              BVSchemaChecker.iFileCount,
                                              BVSchemaChecker.iSchemaFoundCount),
                                true);

            LogWriter.close();

            BVSchemaChecker.s_runningTraverse = false;
        }
/*-----------------------------------------------------------------------------*/
        /// <summary>
        /// processes a dgn model to see if it has embedded schema
        /// </summary>
        /// <param name="oModel">the model to check</param>
        /// <returns>true that the model was processed and does not have a schema.</returns>
/*-----------------------------------------------------------------------------*/
        public static bool ProcessModel(BCOM.ModelReference oModel)
        {
            List <string> schemaList   = new List <string>();
            bool          m_debugMode  = false;
            bool          m_silentMode = false;
            string        errMessage   = "ERROR";
            bool          bStatus      = true;

            ECSR.RepositoryConnection connection = null;
            CSVReporter.CreateReport(string.Format("SC_{0}.csv", DateTime.Now.ToString("yyyy-dd-MM")));
            if (m_debugMode)
            {
                BVSchemaChecker.ComApp.MessageCenter.AddMessage("created csv file",
                                                                string.Format("created report file at {0}", CSVReporter.FileName),
                                                                BCOM.MsdMessageCenterPriority.Info, m_debugMode);
            }
            try
            {
                ECSS.ECSession ecSession = ECSS.SessionManager.CreateSession(true);
                connection = BVSchemaChecker.OpenConnectionToModel(oModel, ecSession);

                if (BVSchemaChecker.FindEmbededSchemas(connection, schemaList))
                {
                    BVSchemaChecker.ComApp.MessageCenter.AddMessage("found schema in the file",
                                                                    "found Schema",
                                                                    BCOM.MsdMessageCenterPriority.Error,
                                                                    m_silentMode);
                    BVSchemaChecker.iSchemaFoundCount++;
                    SchemaListForm sform = new SchemaListForm();
                    sform.SetSchemaNames(schemaList);
                    sform.ShowDialog();
                    bStatus = false;
                }
                else
                {
                    BVSchemaChecker.ComApp.MessageCenter.AddMessage("no schema in the file",
                                                                    "nothing found",
                                                                    BCOM.MsdMessageCenterPriority.Info,
                                                                    m_silentMode);
                }
            }
            catch (Exception e)
            {
                BVSchemaChecker.ComApp.MessageCenter.AddMessage(e.Message, e.Message,
                                                                BCOM.MsdMessageCenterPriority.Error,
                                                                !BVSchemaChecker.bUseLogFile);
                errMessage = e.Message;
                bStatus    = false;
            }
            finally
            {
                if (null == connection)
                {
                    CSVReporter.writeLine(BVSchemaChecker.strCurrentProjectName,
                                          BVSchemaChecker.ComApp.ActiveDesignFile.Name,
                                          BVSchemaChecker.ComApp.ActiveModelReference.Name,
                                          errMessage, false);
                }
                else
                {
                    BVSchemaChecker.CloseConnection(connection);
                }

                CSVReporter.close();
            }
            return(bStatus);
        }
/*-----------------------------------------------------------------------------*/
        /// <summary>Private constructor required for all AddIn classes derived from
        /// Bentley.MicroStation.AddIn.
        /// </summary>
        /// <param name="mdlDesc">a pointer to the mdl app behind the addin</param>
/*-----------------------------------------------------------------------------*/
        private BVSchemaChecker(System.IntPtr mdlDesc)
            : base(mdlDesc)
        {
            s_addin = this;
        }