Exemple #1
0
        //--- Class Methods ---
        public static bool Convert(string confluenceXMLRPCUrl, string confluenceAPIUrl, string confluenceUserName, string confluenceUserPassword, string dreamAPI,
                                   string dekiUserName, string dekiUserPassword, bool compatibleConvertUserPermissions,
                                   List <string> spacesToConvert, bool processNewsPages, bool processPersonalSpaces, string fallbackSpacePrefix)
        {
            using (ACConverter converter = new ACConverter()) {
                try {
                    Log.Info("Connecting to MindTouch API");
                    converter.ConnectToDeki(dreamAPI, dekiUserName, dekiUserPassword);
                } catch (DreamResponseException dre) {
                    Log.Fatal("Can not connect to MindTouch API server.", dre);
                    return(false);
                }

                if (converter._connectedToDeki)
                {
                    Log.Info("Successfully connected to MindTouch");
                }
                else
                {
                    Log.Fatal("Can not connect to MindTouch server.");
                    return(false);
                }

                try {
                    Log.Info("Connecting to Confluence API");
                    converter.ConnectToConfluence(confluenceAPIUrl, confluenceUserName, confluenceUserPassword);
                } catch (System.Net.WebException e) {
                    Log.ErrorExceptionFormat(e, "Can not connect to Confluence");
                    return(false);
                } catch (System.Web.Services.Protocols.SoapException e) {
                    if ((e.Detail != null) && (e.Detail.OuterXml != null))
                    {
                        Log.Fatal("Can not connect to Confluence: " + e.Detail.OuterXml, e);
                    }
                    else
                    {
                        Log.Fatal("Can not connect to Confluence", e);
                    }
                    return(false);
                }

                // The base URL needs to be set globally in a static variable so that macros can access it.
                // For example so the "include" macro knows if a given link is for a page on the current confluence site or not.
                ConfluenceBaseURL = converter._confluenceService.GetServerInfo().baseUrl;

                Log.Info("Connecting to Confluence XMLRPC API");
                if (!converter.ConnectToConfluenceRPC(confluenceXMLRPCUrl, confluenceUserName, confluenceUserPassword))
                {
                    Log.Fatal("Can not connect to Confluence XML RPC server.");
                }

                Log.Info("Successfully connected to Confluence");
                RemoteServerInfo confluenceServerInfo = converter._confluenceService.GetServerInfo();
                Log.InfoFormat("Confluence version: {0}.{1}.{2}", confluenceServerInfo.majorVersion.ToString(),
                               confluenceServerInfo.minorVersion.ToString(), confluenceServerInfo.patchLevel.ToString());

                converter.Convert(new XUri(confluenceServerInfo.baseUrl), compatibleConvertUserPermissions, processNewsPages, spacesToConvert, processPersonalSpaces, fallbackSpacePrefix);
                return(true);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            using (System.IO.StreamWriter logStream = new System.IO.StreamWriter("mindtouch.deki.acconverter.log")) {
                logStream.AutoFlush = true;
                try {
                    string assemblyName   = System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    string configFileName = assemblyName + ".xml";
                    if (!System.IO.File.Exists(configFileName))
                    {
                        string mess = "File: \"" + configFileName + "\" not found";
                        logStream.WriteLine(mess);
                        Console.WriteLine(mess);
                        Console.ReadLine();
                        return;
                    }

                    XDoc settings = XDocFactory.LoadFrom(configFileName, MimeType.XML);
                    if (settings.IsEmpty)
                    {
                        string mess = "Invalid settings file";
                        logStream.WriteLine(mess);
                        Console.WriteLine(mess);
                        Console.ReadLine();
                        return;
                    }

                    string confluenceAPIUrl                 = settings["ConfluenceAPIUrl"].AsText;
                    string ConfluenceXMLRPCUrl              = settings["ConfluenceXMLRPCUrl"].AsText;
                    string confluenceUserName               = settings["ConfluenceUserName"].AsText;
                    string confluenceUserPassword           = settings["ConfluenceUserPassword"].AsText;
                    string dreamAPIUrl                      = settings["DreamAPIUrl"].AsText;
                    string dekiUserName                     = settings["DekiUserName"].AsText;
                    string dekiUserPassword                 = settings["DekiUserPassword"].AsText;
                    bool?  compatibleConvertUserPermissions = settings["CompatibleConvertUserPermissions"].AsBool;
                    bool   processNewsPages                 = settings["ProcessNewsPages"].AsBool ?? true;
                    bool   processPersonalSpaces            = settings["ProcessPersonalSpaces"].AsBool ?? true;
                    string fallbackSpacePrefix              = settings["FallbackSpacePrefix"].AsText;

                    if ((confluenceAPIUrl == null) || (confluenceUserName == null) || (confluenceUserPassword == null) ||
                        (dreamAPIUrl == null) || (dekiUserName == null) || (dekiUserPassword == null) ||
                        (!compatibleConvertUserPermissions.HasValue))
                    {
                        string mess = "Invalid settings file";
                        logStream.WriteLine(mess);
                        Console.WriteLine(mess);
                        Console.ReadLine();
                        return;
                    }

                    List <string> spacesToConvert = new List <string>();
                    if (!settings["SpacesToImport"].IsEmpty)
                    {
                        foreach (XDoc spaceDoc in settings["SpacesToImport"].Elements)
                        {
                            string spaceTitle = spaceDoc.AsText.ToLower();
                            spacesToConvert.Add(spaceTitle);
                        }
                    }

                    bool success = ACConverter.Convert(ConfluenceXMLRPCUrl, confluenceAPIUrl, confluenceUserName, confluenceUserPassword,
                                                       dreamAPIUrl, dekiUserName, dekiUserPassword, compatibleConvertUserPermissions.Value,
                                                       spacesToConvert, processNewsPages, processPersonalSpaces, fallbackSpacePrefix);

                    if (success)
                    {
                        string mess = "Conversion successfully completed!";
                        logStream.WriteLine(mess);
                        Console.WriteLine(mess);
                    }
                } catch (DreamResponseException e) {
                    string mess = DateTime.Now.ToString("HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat) +
                                  "   An unexpected error has occurred:";
                    logStream.WriteLine(mess);
                    logStream.WriteLine(e.Response.ToString());
                    logStream.WriteLine(e);
                    Console.WriteLine(mess);
                    Console.WriteLine(e);
                } catch (System.Web.Services.Protocols.SoapException e) {
                    string mess = DateTime.Now.ToString("HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat) +
                                  "   An unexpected error has occurred:";
                    logStream.WriteLine(mess);
                    if ((e.Detail != null) && (e.Detail.OuterXml != null))
                    {
                        logStream.WriteLine(e.Detail.OuterXml);
                    }
                    logStream.WriteLine(e);
                    Console.WriteLine(mess);
                    Console.WriteLine(e);
                } catch (Exception e) {
                    string mess = DateTime.Now.ToString("HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat) +
                                  "   An unexpected error has occurred:";
                    logStream.WriteLine(mess);
                    logStream.WriteLine(e);
                    Console.WriteLine(mess);
                    Console.WriteLine(e);
                }
                Console.ReadLine();
            }
        }
Exemple #3
0
        //--- Class Methods ---
        public static bool Convert(string confluenceXMLRPCUrl, string confluenceAPIUrl, string confluenceUserName, string confluenceUserPassword, string dreamAPI,
            string dekiUserName, string dekiUserPassword, bool compatibleConvertUserPermissions,
            List<string> spacesToConvert, bool processNewsPages, bool processPersonalSpaces, string fallbackSpacePrefix) {
            using(ACConverter converter = new ACConverter()) {
                try {
                    Log.Info("Connecting to MindTouch API");
                    converter.ConnectToDeki(dreamAPI, dekiUserName, dekiUserPassword);
                } catch(DreamResponseException dre) {
                    Log.Fatal("Can not connect to MindTouch API server.", dre);
                    return false;
                }

                if(converter._connectedToDeki) {
                    Log.Info("Successfully connected to MindTouch");
                } else {
                    Log.Fatal("Can not connect to MindTouch server.");
                    return false;
                }
                
                try {
                    Log.Info("Connecting to Confluence API");
                    converter.ConnectToConfluence(confluenceAPIUrl, confluenceUserName, confluenceUserPassword);
                } catch(System.Net.WebException e) {
                    Log.ErrorExceptionFormat(e, "Can not connect to Confluence");
                    return false;
                } catch(System.Web.Services.Protocols.SoapException e) {
                    if((e.Detail != null) && (e.Detail.OuterXml != null)) {
                        Log.Fatal("Can not connect to Confluence: "+ e.Detail.OuterXml, e);
                    } else {
                        Log.Fatal("Can not connect to Confluence", e);
                    }
                    return false;
                }

                // The base URL needs to be set globally in a static variable so that macros can access it. 
                // For example so the "include" macro knows if a given link is for a page on the current confluence site or not.
                ConfluenceBaseURL = converter._confluenceService.GetServerInfo().baseUrl;

               Log.Info("Connecting to Confluence XMLRPC API");
               if (!converter.ConnectToConfluenceRPC(confluenceXMLRPCUrl, confluenceUserName, confluenceUserPassword))
               {
                   Log.Fatal("Can not connect to Confluence XML RPC server.");
               }               

                Log.Info("Successfully connected to Confluence");
                RemoteServerInfo confluenceServerInfo = converter._confluenceService.GetServerInfo();
                Log.InfoFormat("Confluence version: {0}.{1}.{2}", confluenceServerInfo.majorVersion.ToString(),
                    confluenceServerInfo.minorVersion.ToString(), confluenceServerInfo.patchLevel.ToString());

                converter.Convert(new XUri(confluenceServerInfo.baseUrl), compatibleConvertUserPermissions, processNewsPages, spacesToConvert, processPersonalSpaces, fallbackSpacePrefix);
                return true;
            }
        }