/// <summary> /// Creates a dummy <code>ConverionManeger</code> to be used by unit tests. /// </summary> /// <returns>An instance of a dummy <code>ConversionManager</code></returns> public static ConversionManager DummyConversionManager() { IXWikiClient client = null; client = XWikiClientTestUtil.CreateMockInstance(); XOfficeCommonSettings settings = new XOfficeCommonSettings(); return new ConversionManager(settings, serverURL, localFolder, docFullName, localFileName, client); }
/// <summary> /// Writes the settings to Isolated Storage. /// </summary> /// <param name="settings">The settings to be saved.</param> /// <returns>True if the operation succeded. False if the operation failed.</returns> public static bool WriteRepositorySettings(XOfficeCommonSettings settings) { IsolatedStorageFile isFile = null; IsolatedStorageFileStream stream = null; BinaryFormatter formatter = null; try { isFile = IsolatedStorageFile.GetUserStoreForAssembly(); stream = new IsolatedStorageFileStream(filename, FileMode.Create, isFile); formatter = new BinaryFormatter(); formatter.Serialize(stream, settings); } catch (IOException ioException) { Log.Exception(ioException); } finally { if (stream != null) { stream.Close(); } if (isFile != null) { isFile.Dispose(); isFile.Close(); } } return(true); }
/// <summary> /// Creates a new instance of the ConversionManager class. /// </summary> /// <param name="serverURL">The url of the server.</param> /// <param name="localFolder">The local folder where documents are saved/</param> /// <param name="docFullName">The full name of the wiki page.</param> /// <param name="localFileName">The local file coresponding to the edited wiki page.</param> /// <param name="client">IXWikiClient implementation, handling Client server communication.</param> public ConversionManager(XOfficeCommonSettings settings, String serverURL, String localFolder, String docFullName, String localFileName, IXWikiClient client) { states = new BidirectionalConversionStates(serverURL); states.LocalFolder = localFolder; states.PageFullName = docFullName; states.LocalFileName = localFileName; xwikiClient = client; this.settings = settings; localToWebHtml = new LocalToWebHTML(this); webToLocalHtml = new WebToLocalHTML(this); newAttachments = new List<string>(); }
private static void NullsToDefaults(XOfficeCommonSettings settings) { if (settings.DownloadedAttachmentsRepository == null) { settings.DownloadedAttachmentsRepository = Path.GetTempPath(); } if (settings.PagesRepository == null) { settings.PagesRepository = Path.GetTempPath(); } if (settings.PrefetchSettings == null) { settings.PrefetchSettings = new XWiki.Prefetching.PrefetchSettings(); } if (settings.MetaDataFolderSuffix == null) { settings.MetaDataFolderSuffix = ""; } }
/// <summary> /// Gets the settings from Isolated Storage. /// </summary> /// <returns>A instance containing the settings.</returns> public static XOfficeCommonSettings GetSettings() { XOfficeCommonSettings settings = new XOfficeCommonSettings(); IsolatedStorageFile isFile = null; IsolatedStorageFileStream stream = null; BinaryFormatter formatter; try { isFile = IsolatedStorageFile.GetUserStoreForAssembly(); stream = new IsolatedStorageFileStream(filename, FileMode.Open, isFile); formatter = new BinaryFormatter(); settings = (XOfficeCommonSettings)formatter.Deserialize(stream); NullsToDefaults(settings); } catch (InvalidCastException ce) { Log.ExceptionSummary(ce); settings = new XOfficeCommonSettings(); } catch (Exception ex) { Log.ExceptionSummary(ex); settings = new XOfficeCommonSettings(); } finally { if (stream != null) { stream.Close(); } if (isFile != null) { isFile.Dispose(); isFile.Close(); } } return(settings); }
/// <summary> /// Gets the settings from Isolated Storage. /// </summary> /// <returns>A instance containing the settings.</returns> public static XOfficeCommonSettings GetSettings() { XOfficeCommonSettings settings=new XOfficeCommonSettings(); IsolatedStorageFile isFile=null; IsolatedStorageFileStream stream=null; BinaryFormatter formatter; try { isFile = IsolatedStorageFile.GetUserStoreForAssembly(); stream = new IsolatedStorageFileStream(filename, FileMode.Open, isFile); formatter = new BinaryFormatter(); settings = (XOfficeCommonSettings)formatter.Deserialize(stream); NullsToDefaults(settings); } catch (InvalidCastException ce) { Log.ExceptionSummary(ce); settings = new XOfficeCommonSettings(); } catch (Exception ex) { Log.ExceptionSummary(ex); settings = new XOfficeCommonSettings(); } finally { if (stream != null) { stream.Close(); } if (isFile != null) { isFile.Dispose(); isFile.Close(); } } return settings; }
/// <summary> /// Writes the settings to Isolated Storage. /// </summary> /// <param name="settings">The settings to be saved.</param> /// <returns>True if the operation succeded. False if the operation failed.</returns> public static bool WriteRepositorySettings(XOfficeCommonSettings settings) { IsolatedStorageFile isFile=null; IsolatedStorageFileStream stream = null; BinaryFormatter formatter = null; try { isFile = IsolatedStorageFile.GetUserStoreForAssembly(); stream = new IsolatedStorageFileStream(filename, FileMode.Create, isFile); formatter = new BinaryFormatter(); formatter.Serialize(stream, settings); } catch (IOException ioException) { Log.Exception(ioException); } finally { if (stream != null) { stream.Close(); } if (isFile != null) { isFile.Dispose(); isFile.Close(); } } return true; }
private void SetFolderSuffix(XOfficeCommonSettings settings) { Object _false = false; Object _true = true; String defaultSuffixValue = "_files"; Word.Document newDoc = Application.Documents.Add(ref missing, ref missing, ref missing, ref _false); String uniqueName = "XOffice" + DateTime.Now.Ticks.ToString(); Object uniquePath = Path.Combine(settings.PagesRepository, uniqueName); //required by COM interop Object format = Word.WdSaveFormat.wdFormatHTML; newDoc.SaveAs(ref uniquePath, ref format, ref missing, ref missing, ref _false, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); newDoc.Close(ref _false, ref missing, ref missing); DirectoryInfo dirInfo = new DirectoryInfo(settings.PagesRepository); //search for the metadata directory. foreach (DirectoryInfo subDir in dirInfo.GetDirectories()) { if (subDir.Name.StartsWith(uniqueName)) { String suffix = subDir.Name.Replace(uniqueName, ""); settings.MetaDataFolderSuffix = suffix; XOfficeCommonSettingsHandler.WriteRepositorySettings(settings); } } if (settings.MetaDataFolderSuffix == "") { settings.MetaDataFolderSuffix = defaultSuffixValue; } }
/// <summary> /// Makes the login to the server, using the ConnectionSettingsForm /// or the last stored credentials. /// Adds the taskpanes. /// </summary> public void InitializeAddin() { //Set encoding to ISO-8859-1(Western) Application.Options.DefaultTextEncoding = Microsoft.Office.Core.MsoEncoding.msoEncodingWestern; Application.Options.UseNormalStyleForList = true; this.SaveFormat = Word.WdSaveFormat.wdFormatHTML; timer = new System.Timers.Timer(TIMER_INTERVAL); //Repositories and temporary files settings if (XOfficeCommonSettingsHandler.HasSettings()) { addinSettings = XOfficeCommonSettingsHandler.GetSettings(); if (addinSettings.MetaDataFolderSuffix == "") { SetFolderSuffix(addinSettings); } } else { this.AddinSettings = new XOfficeCommonSettings(); } timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); timer.Start(); InitializeEventsHandlers(); bool connected = false; bool hasCredentials = LoadCredentials(); if (hasCredentials && AddinSettings.AutoLogin) { Client = XWikiClientFactory.CreateXWikiClient(AddinSettings.ClientType, serverURL, username, password); connected = Client.LoggedIn; } else if (!hasCredentials) { //if the user wants to login at startup, and enter the credentials if (AddinSettings.AutoLogin) { if (ShowConnectToServerUI()) { connected = Client.LoggedIn; this.AddinStatus.Syntax = this.DefaultSyntax; } } } if (!connected) { Globals.Ribbons.XWikiRibbon.SwitchToOfflineMode(); } else if (Client.LoggedIn) { Globals.Ribbons.XWikiRibbon.SwitchToOnlineMode(); } this.AnnotationMaintainer = new AnnotationMaintainer(); addinActions = new AddinActions(this); Log.Success("XWord started"); }