示例#1
0
文件: CmdClose.cs 项目: EAWCS1/SUITT
        protected override void handleClick(  )
        {
            DialogResult dr = MessageBox.Show("Are you sure you want to Close the current Transaction?",
                "Close Transaction Confirmation", MessageBoxButtons.OKCancel,
                MessageBoxIcon.Question);

            if(DialogResult.OK.Equals(dr))
            {
                // use default path, and prompt if this was a new document.

                this.ext.TransactionManager.Close();

                // Get the path and filename of the Normal template
                // currently being used in this application

                this.ext.TransactionManager.disableDocEvents();

                try
                {
                    Logger.Write("save current, open new");
                    SystemDefaults defaults = new SystemDefaults();

                    //this.app.NewDocument(false, this.app.Templates.get_Item(0));
                    this.app.NewDocument(false, defaults.get_Default("tm.temp"));
                }
                finally
                {
                    Logger.Write("enable open/close events");
                    this.ext.TransactionManager.enableDocEvents();
                }
            }

            Logger.DeactivateLogger();
        }
示例#2
0
文件: Logger.cs 项目: EAWCS1/SUITT
        public static void CreateLogFile()
        {
            // Open log file for writing
            if (_LogFile == null && IsActive)
            {
                String logFileName = "";
                try
                {
                    // Get the system defaults
                    SystemDefaults sd = new SystemDefaults();
                    string logDirectoryPath = sd.get_Default(LOG_DIRECTORY_KEY)
                        + System.IO.Path.DirectorySeparatorChar;

                    // Create the log filename, based on the current time and the windows temp path
                    logFileName = logDirectoryPath + "isdut_" + Environment.UserName + "_" + DateTime.Now.ToString("s").Replace(":", "-") + ".log";

                    // Create the log file
                    _LogFile = System.IO.File.CreateText(logFileName);
                }
                catch (Exception ex)
                {
                    // Display the error message in a message box to the user
                    System.Windows.Forms.MessageBox.Show(ex.ToString());
                    System.Windows.Forms.MessageBox.Show("Could not initiate log file.  Tried to create text file at '" + logFileName + "'");
                }
            }
        }
示例#3
0
        public void Start()
        {
            try
            {
                //Debug.WriteLine("\t-> 1");

                util.Logger.Write(this.Name + " starting up.", util.Logger.LogLevel.Info);
                util.Logger.Write(this.Name + " version number: " + GetType().Assembly.GetName().Version.ToString());
                util.Logger.LoggingLevel = util.Logger.LogLevel.Debug;

                this._defaults = new util.SystemDefaults();

                //Added to avoid passing isdut.mxd as a command-line argument.
                //this._app.NewDocument(false, this._defaults.get_Default("tm.temp"));

                // event init

                //this.doc_close = new IDocumentEvents_CloseDocumentEventHandler(StoreTransactionToMap);
                //this.new_doc = new IDocumentEvents_NewDocumentEventHandler(LoadTransactionFromMap);
                //this.open_doc = new IDocumentEvents_OpenDocumentEventHandler(LoadTransactionFromMap);

                _pMxDoc = this._app.Document as IMxDocument;

                //IDocumentEvents_Event ide = _pMxDoc as IDocumentEvents_Event;

                //ide.CloseDocument += this.doc_close;
                //ide.NewDocument += this.new_doc;
                //ide.OpenDocument += this.open_doc;

                // TM init
                this._tm = new TransactionManager(this._app, this);

                // QA init
                this._qa = new QAManager(this._app);

                UID pUID;
                pUID = new UIDClass();

                pUID.Value = "esriEditor.Editor";
                IEditor pEditor = (IEditor)_app.FindExtensionByCLSID(pUID);

                //m_OnStartEditing = new IEditEvents_OnStartEditingEventHandler(OnStartEditing_Handler2);
                //add delgates to the appropriate events to enable listening
                //((IEditEvents_Event)pEditor).OnStartEditing += m_OnStartEditing;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message + "\n" + ex.StackTrace);

            }
        }
示例#4
0
        public bool CommitTransaction(string comment)
        {
            bool result = false;

            // get the path
            string pgdbDirectory = "";
            string pgdbFile = "";
            string mxdFile = "";
            // get the see ID
            string seeID = "";

            try
            {
                Logger.Write("Testing valid tranasaction state...");

                if (BaseTransactionManager.Current() == null)
                {
                    throw new Exception("The current transaction manager has timed out. Please reload ArcMap. Transaction is no longer valid.");
                }

                if (BaseTransactionManager.Current().PGDB == null)
                {
                    throw new Exception("The current transaction manager has timed out. Please reload ArcMap. FGDB reference is no longer valid.");
                }

                bool usePgdbDirectory = false;
                if (BaseTransactionManager.Current().MXD == null)
                {
                    // check the PGDB directory
                    if (Directory.Exists(BaseTransactionManager.Current().PGDB.DirectoryName) && !File.Exists(BaseTransactionManager.Current().PGDB.DirectoryName + "\\" + BaseTransactionManager.Current().PGDB.Name.Replace(".gdb", ".mxd")))
                    {
                        usePgdbDirectory = true;
                        BaseTransactionManager.Current().MXD = new FileInfo(BaseTransactionManager.Current().PGDB.DirectoryName + "\\" + BaseTransactionManager.Current().PGDB.Name.Replace(".gdb", ".mxd"));
                    }
                    else throw new Exception("The current transaction manager has timed out. Please reload ArcMap. MXD reference is no longer valid.");
                }

                if (string.IsNullOrEmpty(BaseTransactionManager.Current().TxId))
                {
                    throw new Exception("The current transaction manager has timed out. Please reload ArcMap. SEE ID reference is no longer valid.");
                }

                BaseTransactionManager.startHourGlass("Creating Temproary Directory...");

                try
                {
                    pgdbDirectory = BaseTransactionManager.Current().PGDB.DirectoryName;
                    pgdbFile = BaseTransactionManager.Current().PGDB.Name;
                    mxdFile = usePgdbDirectory ? BaseTransactionManager.Current().PGDB.DirectoryName + "\\" + BaseTransactionManager.Current().PGDB.Name.Replace(".gdb", ".mxd") : BaseTransactionManager.Current().MXD.DirectoryName + "\\" + BaseTransactionManager.Current().MXD.Name;
                    // get the see ID
                    seeID = BaseTransactionManager.Current().TxId;
                    Logger.Write("Located transaction documents at " + pgdbDirectory);
                }
                catch (Exception parseEx)
                {
                    Logger.Write("Could not locate FGDB directory. " + parseEx.Message);
                    throw new Exception(parseEx.Message + ". An error occured reading the transaction directories from Metadata. Please ensure you're FGDB and MXD exist in the correct metadata location.");
                }

                if (!Directory.Exists(pgdbDirectory + "\\temp\\"))
                {
                    Logger.Write("Creating temporary directory...");
                    Directory.CreateDirectory(pgdbDirectory + "\\temp\\");
                }
                else
                {
                    Logger.Write("Deleting old temporary directory...");
                    Directory.Delete(pgdbDirectory + "\\temp\\", true);
                    Logger.Write("Creating temporary directory...");
                    Directory.CreateDirectory(pgdbDirectory + "\\temp\\");
                }

                BaseTransactionManager.Close();

                //Marshal.ReleaseComObject(BaseTransactionManager.Current().PGDBConnection);
                //BaseTransactionManager.Current().PGDB = null;

                // close the PGDB, maintain the file state
                SystemDefaults defaults = new SystemDefaults();

                BaseTransactionManager.app.SaveDocument(null);
                BaseTransactionManager.app.NewDocument(false, defaults.get_Default("tm.temp"));

                GC.Collect();

                BaseTransactionManager.startHourGlass("Creating transaction FGDB Backup...");
                Logger.Write("Creating transaction backup");

                // create temp file of PGDB
                IWorkspaceName sourceWS = (IWorkspaceName)new WorkspaceName();
                sourceWS.WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory";
                sourceWS.PathName = pgdbDirectory + "\\" + pgdbFile;

                IWorkspaceFactory2 wf2 = new FileGDBWorkspaceFactoryClass();
                IWorkspaceName wsResult = null;
                wf2.Copy(sourceWS, pgdbDirectory + "\\temp\\", out wsResult);

                string tempFileLocation = "";

                if (wsResult != null) tempFileLocation = pgdbDirectory + "\\temp\\" + pgdbFile;
                else throw new Exception("Commit failed. Could not create temporary transaction file.");

                Marshal.ReleaseComObject(wf2);
                Marshal.ReleaseComObject(wsResult);
                wf2 = null;
                wsResult = null;

                Logger.Write("Renaming transaction backup to see ID: " + seeID.Replace("-", "").ToUpper());

                string newTempFolder = pgdbDirectory + "\\temp\\" + seeID.Replace("-", "").ToUpper() + ".gdb";

                Directory.Move(pgdbDirectory + "\\temp\\" + pgdbFile, newTempFolder);

                BaseTransactionManager.startHourGlass("Creating ZIP file...");
                Logger.Write("Creating Zip File...");

                // zip the temp folder.
                ZipFile zip = new ZipFile();
                zip.AddDirectory(pgdbDirectory + "\\temp\\");
                zip.Save(newTempFolder + ".zip");
                zip = null;

                // flag the transaction as checked in. Once complete, we'll set the flag back to checked out on an error, or complete on success
                //SetTransactionStatus("CHECKED_IN", "The Transaction has been checked in", seeID);

                BaseTransactionManager.startHourGlass("Waiting for SUITT FME Server. This may take a while...");
                Logger.Write("Subitting transaction...");

                RestRequest checkinRequest = ClientRequest("sees/" + seeID + "/features", Method.POST, true);
                checkinRequest.RequestFormat = DataFormat.Json;
                checkinRequest.AddFile("file", File.ReadAllBytes(newTempFolder + ".zip"), seeID.Replace("-", "").ToUpper() + ".gdb.zip");

                var checkinResponse = ApplicationClient.Execute(checkinRequest);
                if (checkinResponse.StatusCode == System.Net.HttpStatusCode.Accepted)
                {
                    Logger.Write("Submission successful, completeing transaction...");
                    result = CompleteCheckin(seeID, comment);
                }
                else
                {
                    string[] status = GetTransactionStatus(seeID);

                    MessageBox.Show("An error has occured commiting the transaction, and could not be completed at this time. Please verify your transaction is valid, with no spatial errors, and your transaction does not conflict with other transactions.");
                    SetTransactionStatus("CHECKED_OUT", "The Transaction has been checked out", seeID);
                }
            }
            catch (Exception e)
            {
                result = false;
                MessageBox.Show("An error has occured while committing your transaction: " + e.Message + Environment.NewLine + e.StackTrace);
                Logger.Write("#### COMMIT TRANSACTION ENDED: " + e + Environment.NewLine + e.StackTrace);
                SetTransactionStatus("CHECKED_OUT", "The Transaction has been checked out", seeID);
            }

            if (result)
            {
                MessageBox.Show("Transaction check-in completed successfully. No check-in errors were reported. Click 'OK' to clean up your ArcMap session and close the completed transaction.");

                BaseTransactionManager.Close();

                SystemDefaults defaults = new SystemDefaults();
                BaseTransactionManager.app.NewDocument(false, defaults.get_Default("tm.temp"));
            }
            else
            {
                if(!string.IsNullOrEmpty(mxdFile)) BaseTransactionManager.app.OpenDocument(mxdFile);
                MessageBox.Show("Transaction check-in did not complete successfully. Please review the log for errors");
            }

            return result;
        }