Esempio n. 1
0
        /// <summary>
        /// See if current user can modify supplied annotation table or calc field
        /// </summary>
        /// <param name="mt"></param>
        /// <returns></returns>

        public static bool CanModifyTable(
            MetaTable mt)
        {
            if (mt.MetaBrokerType == MetaBrokerType.Unknown)
            {
                return(true);                                                         // Allow if no broker type (i.e. Transient Conditional Formatting control, etc)
            }
            else if (mt.MetaBrokerType == MetaBrokerType.Annotation || mt.MetaBrokerType == MetaBrokerType.CalcField)
            {
                if (mt.Code == null || mt.Code == "" || mt.Code == "0")
                {
                    return(true);                                                               // assume ok if new object with no code assigned
                }
                return(UserObjectUtil.UserHasWriteAccess(SS.I.UserName, Int32.Parse(mt.Code))); // the code for the table is the object id
            }

            else if (mt.IsUserDatabaseStructureTable)
            {
                if (mt.Code == null || mt.Code == "" || mt.Code == "0")
                {
                    return(true);                    // assume ok if new object with no code assigned
                }
                long databaseId = Int64.Parse(mt.Code);

                UserCmpndDbDao udbs = new UserCmpndDbDao();
                return(udbs.CanModifyDatabase(databaseId, SS.I.UserName));
            }

            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        static string SerializeDatabaseHeaderForGrid(
            List <UcdbUoAssoc> ucdbUoAssoc,
            int position,
            UserCmpndDbDao udbs)
        {
            UcdbDatabase  ucdb = ucdbUoAssoc[position].Ucdb;
            StringBuilder sb   = new StringBuilder();

            sb.Append((position + 1).ToString());
            sb.Append("\t");
            sb.Append(ucdb.Name);
            sb.Append("\t");
            sb.Append(ucdb.Public.ToString());
            sb.Append("\t");
            sb.Append(ucdb.CompoundCount.ToString());
            sb.Append("\t");
            sb.Append(ucdb.ModelCount.ToString());
            sb.Append("\t");

            if (ucdb.PendingStatus == UcdbWaitState.DatabaseStorage ||
                ucdb.PendingStatus == UcdbWaitState.ModelPredictions)
            {             // color to show if update is running
                CellStyleMx cs = new CellStyleMx();
                Font        f  = new Font("Arial", 9, FontStyle.Regular);
                cs = new CellStyleMx(f, Color.Black, Color.White);

                //if (udbs.UpdateIsRunning(ucdb))
                //	cs.ForeColor = Color.Green; // running
                //else if (udbs.UpdateIsPending(ucdb))
                //	cs.ForeColor = Color.Orange; // waiting to start
                //else cs.ForeColor = Color.Red; // started but stalled

                sb.Append("<CellStyle " + cs.Serialize() + ">");
                sb.Append(ucdb.PendingCompoundCount.ToString());
            }
            else
            {
                sb.Append("Complete");
            }
            sb.Append("\t");

            sb.Append(ucdb.CreationDate.ToShortDateString());
            sb.Append("\t");
            sb.Append(ucdb.UpdateDate.ToShortDateString());
            sb.Append("\t");
            sb.Append(ucdb.OwnerUserName);
            sb.Append("\t");
            sb.Append(ucdb.DatabaseId.ToString());
            sb.Append("\n");
            return(sb.ToString());
        }
Esempio n. 3
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;
        }