Exemple #1
0
        internal void ShowRunQueryUrl()
        {
            if (Query == null || Query.UserObject == null || Query.UserObject.Id <= 0)
            {
                MessageBoxMx.ShowError("The query must first be saved.");
                return;
            }

            string folder   = ServicesIniFile.Read("QueryLinksNetworkFolder"); // get unc form of folder
            string fileName = "Run_Query_" + Query.UserObject.Id + ".bat";     // file name
            string uncPath  = folder + '\\' + fileName;                        // unc file to write now and read later

            string       tempFile = TempFile.GetTempFileName();
            StreamWriter sw       = new StreamWriter(tempFile);
            string       cmd      =                                                            // batch command to start the Mobius client and run the specified query
                                    Lex.AddDoubleQuotes(ClientDirs.ExecutablePath) +           // path to executable in quotes
                                    " Mobius:Command='Run Query " + Query.UserObject.Id + "'"; // the mobius command to run

            sw.WriteLine(cmd);
            sw.Close();

            ServerFile.CopyToServer(tempFile, uncPath);
            FileUtil.DeleteFile(tempFile);

            string url = "file:///" + folder.Replace('\\', '/') + "/" + fileName;             // put in "file:" schema & switch slashes to get URL from UNC name

            InputBoxMx.Show(
                "The following URL can be used from a web page " +
                "to start Mobius and run the current query:",
                "Run Query URL",
                url);
            //"Mobius:Command='Run Query " + Query.UserObject.Id + "'"); // this is better but isn't accepted by SharePoint

            return;
        }
Exemple #2
0
        /// <summary>
        /// Thread to check to see if any imports need to started
        /// </summary>

        public void CheckForImportFileUpdatesThreadMethod(Object CheckAll)
        {
            // Check each ImportState user object for the user to see if any imports need to be started.
            // If any are found then start a new hidden Mobius client & server to upload the file(s)
            // and start an import user data process for each one.

            UserDataImportState udis;

            List <UserObject> imps = new List <UserObject>();
            UserCmpndDbDao    udbs = new UserCmpndDbDao();

            int t0 = TimeOfDay.Milliseconds();

            bool checkAllImportFiles = (bool)CheckAll;

            if (checkAllImportFiles)
            {
                imps = UserObjectDao.ReadMultiple(UserObjectType.ImportState, false);
            }
            else
            {
                imps = UserObjectDao.ReadMultiple(UserObjectType.ImportState, SS.I.UserName, false, false);
            }

            int t1 = TimeOfDay.Milliseconds() - t0;

            if (imps.Count == 0)
            {
                return;
            }
            //			return ""; // debug

            int i1 = 0;

            while (i1 < imps.Count)
            {             // pare list down do those needing updating
                UserObject uo = imps[i1];

                try { udis = UserDataImportState.Deserialize(uo); }
                catch (Exception ex)
                {
                    imps.RemoveAt(i1);
                    continue;
                }

                if (udis.CheckForFileUpdates && ((checkAllImportFiles == true && udis.ClientFile.Substring(0, 1) == "\\" && FileUtil.Exists(udis.ClientFile)) || checkAllImportFiles == false))
                {
                    DateTime clientFileModDt = FileUtil.GetFileLastWriteTime(udis.ClientFile); // get client file mod date

                    if (clientFileModDt == DateTime.MinValue ||                                // skip if client file not found or
                        udis.ImportIsRunning ||                                                // import is already running
                        ((clientFileModDt - udis.ClientFileModified).TotalSeconds < 1 &&       // no change in client file mod date and
                         !udis.ImportHasFailed))                                               // prev load attempt hasn't failed
                    {
                        imps.RemoveAt(i1);
                        continue;
                    }

                    udis.ClientFileModified = clientFileModDt;                     // write the updated file date
                    uo.Description          = udis.Serialize();
                    UserObjectDao.Write(uo);
                }

                else                          // running or failed manual background import
                {
                    if (udis.ImportHasFailed) // delete if failed
                    {
                        bool deleted = UserObjectDao.Delete(udis.Id);
                        udbs.LogMessage("Deleted ImportState object for failed manual background import on " + uo.Name);
                    }

                    imps.RemoveAt(i1);                     // don't consider further here
                    continue;
                }

                i1++;
            }

            //write a debug message and return
            udbs.LogMessage(string.Format("Found {0} annotation files that could be updated by the {1} account", imps.Count, SS.I.UserName));

            int t2 = TimeOfDay.Milliseconds() - t0;

            if (imps.Count == 0)
            {
                return;
            }

            // Upload the file to the server and start a background process to update the annotation table

            foreach (UserObject uo2 in imps)
            {
                try
                {
                    udis = UserDataImportState.Deserialize(uo2);
                    string internalUoName = "Annotation_" + uo2.Id;
                    string exportDir      = ServicesIniFile.Read("BackgroundExportDirectory");
                    string serverFileName =                     // location for file on server
                                            exportDir + @"\" + internalUoName + Path.GetExtension(udis.FileName);
                    ServerFile.CopyToServer(udis.FileName, serverFileName);
                    string command = "ImportUserData " + serverFileName + ", " + internalUoName;
                    CommandLine.StartBackgroundSession("ImportUserData " + serverFileName + ", " + uo2.Name);
                    udbs.LogMessage("Auto-upload for ImportState ObjId = " + ", " + uo2.Id + ", Name = " + uo2.Name + ", Desc = " + uo2.Description);
                }

                catch (Exception ex)
                {
                    try
                    {
                        udbs.LogMessage("Auto-upload exception ImportState ObjId = " + uo2.Id + ", Name = " + uo2.Name +
                                        ", Desc = " + uo2.Description +
                                        "\n" + DebugLog.FormatExceptionMessage(ex));
                    }

                    catch (Exception ex2) { ex2 = ex2; }

                    continue;
                }
            }

            Progress.Hide();

            int t3 = TimeOfDay.Milliseconds() - t0;

            return;
        }