Beispiel #1
0
        OnNetworkObtained
        (
            XmlDocument oGraphMLXmlDocument,
            RequestStatistics oRequestStatistics,
            String sNetworkDescription,
            String sNetworkTitle,
            String sPartialFileName
        )
        {
            Debug.Assert(oGraphMLXmlDocument != null);
            Debug.Assert(oRequestStatistics != null);
            Debug.Assert(!String.IsNullOrEmpty(sNetworkDescription));
            Debug.Assert(!String.IsNullOrEmpty(sNetworkTitle));
            Debug.Assert(!String.IsNullOrEmpty(sPartialFileName));
            AssertValid();

            XmlNode oGraphXmlNode = XmlUtil2.SelectRequiredSingleNode(
                oGraphMLXmlDocument, "g:graphml/g:graph",

                GraphMLXmlDocument.CreateXmlNamespaceManager(
                    oGraphMLXmlDocument, "g")
                );

            XmlUtil2.SetAttributes(oGraphXmlNode,
                                   "description", sNetworkDescription);

            XmlUtil2.SetAttributes(oGraphXmlNode,
                                   "suggestedTitle", sNetworkTitle);

            String sSuggestedFileNameNoExtension = String.Format(
                "{0} NodeXL {1}"
                ,
                DateTimeUtil2.ToCultureInvariantFileName(
                    oRequestStatistics.StartTimeUtc),

                sPartialFileName
                );

            XmlUtil2.SetAttributes(oGraphXmlNode,
                                   "suggestedFileNameNoExtension", sSuggestedFileNameNoExtension);

            if (oRequestStatistics.UnexpectedExceptions > 0)
            {
                // The network is partial.

                throw new PartialNetworkException(oGraphMLXmlDocument,
                                                  oRequestStatistics);
            }
        }
Beispiel #2
0
        TrySaveWorkbookIfNeverSaved
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            String sFolderToSaveWorkbookTo
        )
        {
            Debug.Assert(oWorkbook != null);

            // The Workbook.Path is an empty string until the workbook is saved.

            if (String.IsNullOrEmpty(oWorkbook.Path))
            {
                if (String.IsNullOrEmpty(sFolderToSaveWorkbookTo))
                {
                    sFolderToSaveWorkbookTo = Environment.GetFolderPath(
                        Environment.SpecialFolder.MyDocuments);
                }

                String sFileNameNoExtension;

                // Use a suggested file name if available; otherwise use a file
                // name based on the current time.

                if ((new PerWorkbookSettings(oWorkbook)).GraphHistory
                    .TryGetValue(
                        GraphHistoryKeys.ImportSuggestedFileNameNoExtension,
                        out sFileNameNoExtension))
                {
                    if (sFileNameNoExtension.Length >
                        MaximumImportSuggestedFileNameNoExtension)
                    {
                        sFileNameNoExtension = sFileNameNoExtension.Substring(
                            0, MaximumImportSuggestedFileNameNoExtension);
                    }

                    sFileNameNoExtension = FileUtil.ReplaceIllegalFileNameChars(
                        sFileNameNoExtension, " ");
                }
                else
                {
                    sFileNameNoExtension =
                        DateTimeUtil2.ToCultureInvariantFileName(DateTime.Now)
                        + " NodeXL";
                }

                try
                {
                    ExcelUtil.SaveWorkbookAs(oWorkbook,
                                             Path.Combine(sFolderToSaveWorkbookTo,
                                                          sFileNameNoExtension));
                }
                catch (COMException)
                {
                    FormUtil.ShowWarning(
                        "The workbook can't be saved, probably because the folder"
                        + " where the workbook should be saved does not exist.  To"
                        + " fix this, go to NodeXL, Graph, Automate and change the"
                        + " Options for \"Save workbook to a new file if it has"
                        + " never been saved\"."
                        );

                    return(false);
                }
            }

            return(true);
        }