Exemplo n.º 1
0
        /// <summary>
        /// Deserialize a DataTable from a file
        /// </summary>
        /// <param name="tr"></param>
        /// <returns></returns>

        public IDataTableMx DeserializeXml(
            string fileName)
        {
            StreamReader sr       = null;
            string       tempFile = null;

            if (fileName.StartsWith("<"))             // get from server if server file name
            {
                string serverFile = fileName;         // must be a server file name
                tempFile = TempFile.GetTempFileName();
                ServerFile.CopyToClient(serverFile, tempFile);
                sr = new StreamReader(tempFile);
            }

            else
            {
                if (!File.Exists(fileName))
                {
                    throw new FileNotFoundException("File not found: " + fileName);
                }
                sr = new StreamReader(fileName);
            }

            XmlTextReader tr = new XmlTextReader(sr);
            DataTableMx   dt = Deserialize(tr) as DataTableMx;

            sr.Close();

            if (tempFile != null)
            {
                try { File.Delete(tempFile); }
                catch { }
            }

            return(dt);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieve the results of a background export
        /// Example: Retrieve Background Export 231243
        /// </summary>
        /// <param name="objectIdString">Id of BackgroundExport UserObject containing serialized ResultsFormat</param>
        /// <returns></returns>

        public static string RetrieveBackgroundExport(
            string objectIdString)
        {
            ResultsFormat rf;
            Query         q;
            int           objId;

            QbUtil.SetMode(QueryMode.Build);             // be sure in build mode

            if (!int.TryParse(objectIdString, out objId))
            {
                return("Invalid UserObjectId: " + objectIdString);
            }

            UserObject uo = UserObjectDao.Read(objId);

            if (uo == null)
            {
                return("RunInBackground UserObject not found: " + objectIdString);
            }
            if (uo.Type != UserObjectType.BackgroundExport)
            {
                return("Object is not the expected RunInBackground UserObject type");
            }

            rf = ResultsFormat.Deserialize(uo.Content);
            if (rf == null)
            {
                throw new Exception("Failed to deserialize ResultsFormat: " + objectIdString);
            }

            string clientFile = rf.OutputFileName;
            string serverFile = GetServerFileName(rf, objId);

            string ext    = Path.GetExtension(clientFile);
            string filter = "*" + ext + "|*" + ext;

            if (SharePointUtil.IsRegularFileSystemName(clientFile))
            {
                clientFile = UIMisc.GetSaveAsFilename("Retrieve Background Export File", clientFile, filter, ext);
            }

            else
            {
                clientFile =
                    SharePointFileDialog.GetSaveAsFilename("Retrieve Background Export File", clientFile, filter, ext);
            }

            if (String.IsNullOrEmpty(clientFile))
            {
                return("");
            }

            Progress.Show("Retrieving file...");
            try { ServerFile.CopyToClient(serverFile, clientFile); }
            catch (Exception ex)
            {
                string msg =
                    "Unable to retrieve cached export file: " + serverFile + "\n" +
                    "to client file: " + clientFile + "\n" +
                    DebugLog.FormatExceptionMessage(ex);
                ServicesLog.Message(msg);
                Progress.Hide();
                return(msg);
            }

            Progress.Hide();

            if (Lex.Eq(ext, ".xls") || Lex.Eq(ext, ".xlsx") || Lex.Eq(ext, ".doc") || Lex.Eq(ext, ".docx"))
            {
                DialogResult dr = MessageBoxMx.Show("Do you want to open " + clientFile + "?",
                                                    UmlautMobius.String, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    SystemUtil.StartProcess(clientFile);
                }
            }

            return("Background export file retrieved: " + clientFile);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Read in the set of standard calculated fields & send to dropdown menu
        /// </summary>

        void SetupStandardCalculatedFields()
        {
            try
            {
                if (StandardCalculatedFields == null)
                {
                    StandardCalculatedFields = new List <CalcField>();

                    string fileName   = "StandardCalculatedFields.xml";
                    string serverFile = @"<MetaDataDir>\" + fileName;
                    string clientFile = ClientDirs.TempDir + @"\" + fileName;
                    ServerFile.CopyToClient(serverFile, clientFile);
                    StreamReader  sr = new StreamReader(clientFile);
                    XmlTextReader tr = new XmlTextReader(sr);

                    tr.MoveToContent();
                    if (!Lex.Eq(tr.Name, "StandardCalculatedFields"))
                    {
                        throw new Exception("SetupStandardCalculatedFields - \"StandardCalculatedFields\" element not found");
                    }

                    while (true)
                    {
                        tr.Read();                         // get CalcField element
                        tr.MoveToContent();
                        if (Lex.Eq(tr.Name, "CalcField"))
                        {
                            CalcField cf = CalcField.Deserialize(tr);
                            StandardCalculatedFields.Add(cf);
                        }
                        else if (Lex.Eq(tr.Name, "StandardCalculatedFields"))
                        {
                            break;
                        }

                        else
                        {
                            throw new Exception("SetupStandardCalculatedFields unexpected element: " + tr.Name);
                        }
                    }

                    tr.Close();
                    sr.Close();
                }

                ToolStripItemCollection items = StandardCalcContextMenu.Items;
                items.Clear();

                foreach (CalcField cf2 in StandardCalculatedFields)
                {
                    ToolStripMenuItem mi = new System.Windows.Forms.ToolStripMenuItem();
                    mi.Image = StandardCalcMenuItem.Image;
                    mi.ImageTransparentColor = System.Drawing.Color.Cyan;
                    mi.Text   = cf2.UserObject.Name;
                    mi.Click += new System.EventHandler(this.StandardCalcMenuItem_Click);
                    items.Add(mi);
                }

                return;
            }

            catch (Exception ex)
            {
                ServicesLog.Message("Error reading StandardCalculatedFields.xml: " + ex.Message);
            }

            return;
        }