예제 #1
0
        public void PropertyIsPropertiesInstance_SaveAndReload()
        {
            var mainProperties       = new Properties();
            var properties           = mainProperties.Get("PropertyInstance", new Properties());
            var propertyDefaultValue = properties.Get <string> ("First");

            properties.Set("First", "Test");

            FilePath directory = Util.CreateTmpDir("PropertyInstanceTest");
            var      fileName  = directory.Combine("Properties.xml");

            mainProperties.Save(fileName);

            mainProperties = Properties.Load(fileName);
            var savedProperties = mainProperties.Get("PropertyInstance", new Properties());
            var savedFirstValue = savedProperties.Get <string> ("First");

            Assert.IsNull(propertyDefaultValue);
            Assert.AreEqual("Test", savedFirstValue);
        }
예제 #2
0
        public void PropertyIsListOfStrings_SaveAndReload()
        {
            var mainProperties = new Properties();
            var list           = mainProperties.Get("ListInstance", new List <string> ());

            list.Add("FirstItem");
            list.Add("SecondItem");

            FilePath directory = Util.CreateTmpDir("ListInstance");
            var      fileName  = directory.Combine("Properties.xml");

            mainProperties.Save(fileName);

            mainProperties = Properties.Load(fileName);
            var savedList = mainProperties.Get("ListInstance", new List <string> ());

            Assert.AreEqual(2, savedList.Count);
            Assert.AreEqual("FirstItem", savedList [0]);
            Assert.AreEqual("SecondItem", savedList [1]);
        }
예제 #3
0
        static void RedirectOutputToFileWindows(FilePath logDirectory, string logName)
        {
            var stream = File.Open(logDirectory.Combine(logName), FileMode.Create, FileAccess.Write, FileShare.Read);
            var writer = new StreamWriter(stream)
            {
                AutoFlush = true
            };

            var stderr = new MonoDevelop.Core.ProgressMonitoring.LogTextWriter();

            stderr.ChainWriter(Console.Error);
            stderr.ChainWriter(writer);
            defaultError = Console.Error;
            Console.SetError(stderr);

            var stdout = new MonoDevelop.Core.ProgressMonitoring.LogTextWriter();

            stdout.ChainWriter(Console.Out);
            stdout.ChainWriter(writer);
            defaultOut = Console.Out;
            Console.SetOut(stdout);
        }
예제 #4
0
        public static FilePath GetFile(string name)
        {
            if (localizedBrandingDir != null)
            {
                var file = localizedBrandingDir.Combine(name);
                if (File.Exists(file))
                {
                    return(file);
                }
            }

            if (brandingDir != null)
            {
                var file = brandingDir.Combine(name);
                if (File.Exists(file))
                {
                    return(file);
                }
            }

            return(null);
        }
예제 #5
0
        public void CanCreateVariousPaths()
        {
            FilePath path;
            string   expected;

            expected = Path.Combine("this", "is", "a", "path");
            path     = FilePath.Build("this", "is", "a", "path");
            Assert.AreEqual(expected, path.ToString());

            expected = "";
            path     = FilePath.Empty;
            Assert.AreEqual(expected, path.ToString());
            Assert.IsTrue(path.IsEmpty);
            Assert.IsTrue(path.IsNullOrEmpty);

            expected = null;
            path     = FilePath.Null;
            Assert.AreEqual(expected, path.ToString());
            Assert.IsTrue(path.IsNull);
            Assert.IsTrue(path.IsNullOrEmpty);

            expected = Path.Combine("this", "is", "a", "path");
            path     = new FilePath(expected);
            Assert.AreEqual(expected, path.ToString());

            expected = Path.Combine(expected, "and", "more");
            path     = path.Combine("and", "more");
            Assert.AreEqual(expected, path.ToString());

            expected = "file.txt";
            path     = new FilePath("file").ChangeExtension(".txt");
            Assert.AreEqual(expected, path.ToString());

            expected = "file.txt";
            path     = new FilePath("file.type").ChangeExtension(".txt");
            Assert.AreEqual(expected, path.ToString());

            // TODO: Test file:// scheme
        }
예제 #6
0
        internal static UserProfile ForUnix(string version)
        {
            FilePath home        = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            FilePath xdgDataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");

            if (xdgDataHome.IsNullOrEmpty)
            {
                xdgDataHome = home.Combine(".local", "share");
            }
            FilePath xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");

            if (xdgConfigHome.IsNullOrEmpty)
            {
                xdgConfigHome = home.Combine(".config");
            }
            FilePath xdgCacheHome = Environment.GetEnvironmentVariable("XDG_CACHE_HOME");

            if (xdgCacheHome.IsNullOrEmpty)
            {
                xdgCacheHome = home.Combine(".cache");
            }

            string   appId  = GetAppId(version);
            FilePath data   = xdgDataHome.Combine(appId);
            FilePath config = xdgConfigHome.Combine(appId);
            FilePath cache  = xdgCacheHome.Combine(appId);

            return(new UserProfile()
            {
                UserDataRoot = data,
                LocalInstallDir = data.Combine("LocalInstall"),
                ConfigDir = config,
                LocalConfigDir = config,
                CacheDir = cache,
                TempDir = cache.Combine("Temp"),
                LogDir = cache.Combine("Logs"),
            });
        }
예제 #7
0
        internal static UserDataLocations ForUnix(string version)
        {
            FilePath home        = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            FilePath xdgDataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");

            if (xdgDataHome.IsNullOrEmpty)
            {
                xdgDataHome = home.Combine(".local", "share");
            }
            FilePath xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");

            if (xdgConfigHome.IsNullOrEmpty)
            {
                xdgConfigHome = home.Combine(".config");
            }
            FilePath xdgCacheHome = Environment.GetEnvironmentVariable("XDG_CACHE_HOME");

            if (xdgCacheHome.IsNullOrEmpty)
            {
                xdgCacheHome = home.Combine(".cache");
            }

            string   appId  = APP_ID + "-" + version;
            FilePath data   = xdgDataHome.Combine(appId);
            FilePath config = xdgConfigHome.Combine(appId);
            FilePath cache  = xdgCacheHome.Combine(appId);

            return(new UserDataLocations()
            {
                Data = data,
                Addins = data.Combine("Addins"),
                Config = config,
                ConfigLocal = config,
                Cache = cache,
                Temp = cache.Combine("Temp"),
                Logs = cache.Combine("Logs"),
            });
        }
예제 #8
0
        internal static UserProfile ForMac(string version)
        {
            string   appId   = GetAppId(version);
            FilePath home    = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            FilePath library = home.Combine("Library");

            FilePath data        = library.Combine(appId);
            FilePath preferences = library.Combine("Preferences", appId);
            FilePath cache       = library.Combine("Caches", appId);
            FilePath logs        = library.Combine("Logs", appId);
            FilePath appSupport  = library.Combine("Application Support", appId);

            return(new UserProfile()
            {
                CacheDir = cache,
                UserDataRoot = data,
                ConfigDir = preferences,
                LocalConfigDir = preferences,
                LogDir = logs,
                LocalInstallDir = appSupport.Combine("LocalInstall"),
                TempDir = cache.Combine("Temp"),
            });
        }
예제 #9
0
        internal static UserDataLocations ForMac(string version)
        {
            string   appId   = APP_ID + "-" + version;
            FilePath home    = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            FilePath library = home.Combine("Library");

            FilePath data        = library.Combine(appId);
            FilePath preferences = library.Combine("Preferences", appId);
            FilePath cache       = library.Combine("Cache", appId);
            FilePath logs        = library.Combine("Logs", appId);
            FilePath appSupport  = library.Combine("Application Support", appId);

            return(new UserDataLocations()
            {
                Cache = cache,
                Data = data,
                Config = preferences,
                ConfigLocal = preferences,
                Logs = logs,
                Addins = appSupport.Combine("Addins"),
                Temp = cache.Combine("Temp"),
            });
        }
예제 #10
0
        public static Stream GetStream(string name)
        {
            //read branding directory, then calling assembly's resources
            if (localizedBrandingDir != null)
            {
                var file = localizedBrandingDir.Combine(name);
                if (File.Exists(file))
                {
                    return(File.OpenRead(file));
                }
            }

            if (brandingDir != null)
            {
                var file = brandingDir.Combine(name);
                if (File.Exists(file))
                {
                    return(File.OpenRead(file));
                }
            }

            return(Assembly.GetCallingAssembly().GetManifestResourceStream(name));
        }
예제 #11
0
        public void BoolAndStringProperties_SaveAndReload()
        {
            var properties = new Properties();
            var stringPropertyDefaultValue = properties.Get <string> ("FirstString");

            properties.Set("FirstString", "Test");
            var defaultBoolValue = properties.Get("FirstBool", true);

            properties.Set("FirstBool", false);

            FilePath directory = Util.CreateTmpDir("StringBoolPropertiesTests");
            var      fileName  = directory.Combine("Properties.xml");

            properties.Save(fileName);

            properties = Properties.Load(fileName);
            var savedFirstStringValue = properties.Get <string> ("FirstString");
            var savedFirstBoolValue   = properties.Get("FirstBool", true);

            Assert.IsNull(stringPropertyDefaultValue);
            Assert.AreEqual("Test", savedFirstStringValue);
            Assert.IsTrue(defaultBoolValue);
            Assert.IsFalse(savedFirstBoolValue);
        }
예제 #12
0
        internal static UserProfile ForWindows(string version)
        {
            string   appId   = GetAppId(version);
            FilePath local   = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            FilePath roaming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            //FilePath localLow = GetKnownFolderPath (new Guid ("A520A1A4-1780-4FF6-BD18-167343C5AF16"));

            local   = local.Combine(appId);
            roaming = roaming.Combine(appId);

            return(new UserProfile()
            {
                UserDataRoot = roaming,
                ConfigDir = roaming.Combine("Config"),
                LocalConfigDir = local.Combine("Config"),
                LocalInstallDir = local.Combine("LocalInstall"),
                LogDir = local.Combine("Logs"),
                CacheDir = local.Combine("Cache"),
                TempDir = local.Combine("Temp"),
            });
        }
예제 #13
0
        internal static UserDataLocations ForWindows(string version)
        {
            string   appId   = APP_ID + "-" + version;
            FilePath local   = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            FilePath roaming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            //FilePath localLow = GetKnownFolderPath (new Guid ("A520A1A4-1780-4FF6-BD18-167343C5AF16"));

            local   = local.Combine(appId);
            roaming = roaming.Combine(appId);

            return(new UserDataLocations()
            {
                Data = roaming,
                Config = roaming.Combine("Config"),
                ConfigLocal = local.Combine("Config"),
                Addins = local.Combine("Addins"),
                Logs = local.Combine("Logs"),
                Cache = local.Combine("Cache"),
                Temp = local.Combine("Temp"),
            });
        }
예제 #14
0
        static BrandingService()
        {
            try {
                FilePath asmPath = typeof(BrandingService).Assembly.Location;
                brandingDir = asmPath.ParentDirectory.Combine("branding");
                if (!Directory.Exists(brandingDir))
                {
                    brandingDir = null;
                }
                else
                {
                    var langCode = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
                    localizedBrandingDir = brandingDir.Combine(langCode);
                    if (!Directory.Exists(localizedBrandingDir))
                    {
                        localizedBrandingDir = null;
                    }
                }

                //read the files after detecting both directories, in case there's an error
                if (brandingDir != null)
                {
                    var brandingFile = brandingDir.Combine("Branding.xml");
                    if (File.Exists(brandingFile))
                    {
                        brandingDocument = XDocument.Load(brandingFile);
                    }
                    if (localizedBrandingDir != null)
                    {
                        var localizedBrandingFile = brandingDir.Combine("Branding.xml");
                        if (File.Exists(localizedBrandingFile))
                        {
                            localizedBrandingDocument = XDocument.Load(localizedBrandingFile);
                        }
                    }
                }
                ApplicationName      = GetString("ApplicationName");
                SuiteName            = GetString("SuiteName");
                ProfileDirectoryName = GetString("ProfileDirectoryName");
                StatusSteadyIconId   = GetString("StatusAreaSteadyIcon");
                HelpAboutIconId      = GetString("HelpAboutIcon");
            } catch (Exception ex) {
                LoggingService.LogError("Could not read branding document", ex);
            }

            if (string.IsNullOrEmpty(ApplicationName))
            {
                ApplicationName = "MonoDevelop";
            }

            if (string.IsNullOrEmpty(SuiteName))
            {
                SuiteName = ApplicationName;
            }

            if (string.IsNullOrEmpty(ProfileDirectoryName))
            {
                ProfileDirectoryName = ApplicationName;
            }

            if (string.IsNullOrEmpty(StatusSteadyIconId))
            {
                StatusSteadyIconId = "md-status-steady";
            }

            if (string.IsNullOrEmpty(HelpAboutIconId))
            {
                HelpAboutIconId = "md-about";
            }
        }
예제 #15
0
        internal static void ReportUnhandledException(Exception ex, bool willShutDown, bool silently, string tag)
        {
            var tags = new List <string> {
                tag
            };

            if (reporting)
            {
                return;
            }

            reporting = true;
            try {
                var oldReportCrashes = ReportCrashes;

                if (UnhandledErrorOccured != null && !silently)
                {
                    ReportCrashes = UnhandledErrorOccured(ReportCrashes, ex, willShutDown);
                }

                // If crash reporting has been explicitly disabled, disregard this crash
                if (ReportCrashes.HasValue && !ReportCrashes.Value)
                {
                    return;
                }

                byte[] data;
                using (var stream = new MemoryStream()) {
                    using (var writer = System.Xml.XmlWriter.Create(stream)) {
                        writer.WriteStartElement("CrashLog");
                        writer.WriteAttributeString("version", ServiceVersion);

                        writer.WriteElementString("SystemInformation", SystemInformation.GetTextDescription());
                        writer.WriteElementString("Exception", ex.ToString());

                        writer.WriteEndElement();
                    }
                    data = stream.ToArray();
                }

                var customData = new Hashtable();
                customData["SystemInformation"] = SystemInformation.GetTextDescription();

                if (raygunClient != null)
                {
                    ThreadPool.QueueUserWorkItem(delegate {
                        raygunClient.Send(ex, tags, customData, BuildInfo.Version);
                    });
                }

                // Log to disk only if uploading fails.
                var filename = string.Format("{0}.{1}.{2}.crashlog", DateTime.UtcNow.ToString("yyyy-MM-dd__HH-mm-ss"), SystemInformation.SessionUuid, Interlocked.Increment(ref CrashId));
                ThreadPool.QueueUserWorkItem(delegate {
                    if (!TryUploadReport(filename, data))
                    {
                        if (!Directory.Exists(CrashLogDirectory))
                        {
                            Directory.CreateDirectory(CrashLogDirectory);
                        }

                        File.WriteAllBytes(CrashLogDirectory.Combine(filename), data);
                    }
                });

                //ensure we don't lose the setting
                if (ReportCrashes != oldReportCrashes)
                {
                    PropertyService.SaveProperties();
                }
            } finally {
                reporting = false;
            }
        }