Exemple #1
0
        // download the catalog entry contents and view in an editor
        private void ViewInEditor(string catEntry)
        {
            SAS.FileService fs = null;
            SAS.IFileref    fr = null;
            SAS.Workspace   ws = null;
            SAS.TextStream  ts = null;
            string          fileref;
            StringBuilder   sb = new StringBuilder();

            try
            {
                // use SAS workspace and fileservice to download the file
                ws = consumer.Workspace(currentServer) as SAS.Workspace;
                fs = ws.FileService;
                // using the FILENAME CATALOG access method
                fr           = fs.AssignFileref("", "CATALOG", catEntry, "", out fileref);
                ts           = fr.OpenTextStream(SAS.StreamOpenMode.StreamOpenModeForReading, 16500);
                ts.Separator = Environment.NewLine;

                // downloading catalog entry contents to local temp file
                int   lines = 1;
                Array truncLines, readLines;
                // iterate through until all lines are read in
                while (lines > 0)
                {
                    ts.ReadLines(100, out truncLines, out readLines);
                    lines = readLines.GetLength(0);
                    for (int i = 0; i < lines; i++)
                    {
                        sb.AppendLine(readLines.GetValue(i).ToString());
                    }
                }
                ts.Close();
                fs.DeassignFileref(fileref);

                // show the text in a modal dialog
                SAS.Tasks.Toolkit.Controls.SASCodeViewDialog dlg = new SAS.Tasks.Toolkit.Controls.SASCodeViewDialog(
                    Control.FromHandle(this.Handle),
                    catEntry, sb.ToString());
                dlg.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format(Translate.MessageCatalogReadError, catEntry, ex.Message), Translate.TitleError);
            }
            finally
            {
                ts = null;
                fr = null;
                fs = null;
                ws = null;
            }
        }
        // download the catalog entry contents and view in an editor

        override public void ReadEntry(ISASTaskConsumer3 consumer, string serverName, string catEntry)
        {
            Consumer = consumer;

            SAS.FileService fs = null;
            SAS.IFileref    fr = null;
            SAS.Workspace   ws = null;
            SAS.TextStream  ts = null;
            string          fileref;

            try
            {
                // use SAS workspace and fileservice to download the file

                ws = consumer.Workspace(serverName) as SAS.Workspace;
                fs = ws.FileService;

                // using the FILENAME CATALOG access method
                fr           = fs.AssignFileref("", "CATALOG", catEntry, "", out fileref);
                ts           = fr.OpenTextStream(SAS.StreamOpenMode.StreamOpenModeForReading, 16500);
                ts.Separator = Environment.NewLine;

                StringBuilder sb = new StringBuilder();

                // downloading catalog entry contents
                int   lines = 1;
                Array truncLines, readLines;
                // iterate through until all lines are read in
                while (lines > 0)
                {
                    ts.ReadLines(100, out truncLines, out readLines);
                    lines = readLines.GetLength(0);
                    for (int i = 0; i < lines; i++)
                    {
                        sb.AppendLine(readLines.GetValue(i).ToString());
                    }
                }

                txtEntry.Text = sb.ToString();

                // cleanup
                ts.Close();
                fs.DeassignFileref(fr.FilerefName);
            }

            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Cannot open the catalog entry {0}.  Reason: {1}", catEntry, ex.Message));
            }
        }
Exemple #3
0
        private string GetTextFromFileref(string fileref)
        {
            SAS.FileService fs = null;
            SAS.IFileref    fr = null;
            SAS.Workspace   ws = null;
            SAS.TextStream  ts = null;
            StringBuilder   sb = new StringBuilder();

            try
            {
                // use SAS workspace and fileservice to download the file
                ws           = consumer.Workspace(currentServer) as SAS.Workspace;
                fs           = ws.FileService;
                fr           = fs.UseFileref(fileref);
                ts           = fr.OpenTextStream(SAS.StreamOpenMode.StreamOpenModeForReading, 16500);
                ts.Separator = Environment.NewLine;

                // downloading catalog entry contents to local temp file
                int   lines = 1;
                Array truncLines, readLines;
                // iterate through until all lines are read in
                while (lines > 0)
                {
                    ts.ReadLines(100, out truncLines, out readLines);
                    lines = readLines.GetLength(0);
                    for (int i = 0; i < lines; i++)
                    {
                        sb.AppendLine(readLines.GetValue(i).ToString());
                    }
                }

                ts.Close();
                fs.DeassignFileref(fileref);
            }
            catch (Exception)
            {
            }
            finally
            {
                ts = null;
                fr = null;
                fs = null;
                ws = null;
            }

            return(sb.ToString());
        }