示例#1
0
        /// <summary>
        /// Register a supplied Type, with its corresponding Getter and Setter to be storable.
        /// </summary>
        public static void RegisterStorableType<TValue>(Func<byte[], TValue> Getter, Func<TValue, byte[]> Setter)
        {
            General.ContractRequiresNotNull(Getter, Setter);

            RegisteredTypes[typeof(TValue)] = Tuple.Create<object, object>(Getter, Setter);
        }
示例#2
0
        /// <summary>
        /// Initialization of internal resources.
        /// Must be called at the start of the application execution.
        /// </summary>
        public static void Initialize(string AppName, string AppVersion, string AppDefinitions, string UserDataName)
        {
            if (Initialized)
            {
                Console.WriteLine("Reinitializing");
            }

            General.ContractRequiresNotAbsent(AppName, AppVersion, UserDataName);
            General.ContractAssert(AppName.IsValidIdentifier());
            General.ContractAssert(UserDataName.IsValidIdentifier());

            ApplicationName        = AppName;
            ApplicationVersion     = AppVersion; // Very important. License version is check against this
            ApplicationDefinitions = AppDefinitions;
            UserDataNaming         = UserDataName;

            string    DetectedProblem = "";
            Exception DetectedError   = null;

            SessionStart = DateTime.Now;

            // MUST BE THE SAME FOLDERS AS IN InstallerCustomAction.Installer1.cs (Commit method)

            // This is: - "C:\ProgramData\" on Windows Vista and Windows 7
            //          - "C:\Documents and Settings\<User-Account>\Application Data\" on Windows XP
            ApplicationsCommonDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), General.TextToIdentifier(Company.NAME_SIMPLE));

            ApplicationsClipartDirectory = Path.Combine(ApplicationsCommonDataDirectory, CLIPART_SUBDIR);

            // This is: "C:\Users\<User-Account>\AppData\Local\Instrumind" on Windows 7
            ApplicationUserDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), General.TextToIdentifier(Company.NAME_SIMPLE));

            // My Documents\My Compositions
            UserDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), USERDATA_DIR_PREFIX + UserDataNaming);

            try
            {
                // Create [Common]\Instrumind
                if (!Directory.Exists(ApplicationsCommonDataDirectory))
                {
                    Directory.CreateDirectory(ApplicationsCommonDataDirectory);
                }

                // Create [Common]\Instrumind\ThinkComposer (currently not used, as it cannot be saved without UAC/admin privileges)
                ApplicationSpecificDataDirectory = Path.Combine(ApplicationsCommonDataDirectory, AppExec.ApplicationName.TextToIdentifier());
                if (!Directory.Exists(ApplicationSpecificDataDirectory))
                {
                    Directory.CreateDirectory(ApplicationSpecificDataDirectory);
                }

                // Create [Common]\Instrumind\Domains
                ApplicationSpecificDefinitionsDirectory = Path.Combine(ApplicationsCommonDataDirectory, AppExec.ApplicationDefinitions.TextToIdentifier());
                if (!Directory.Exists(ApplicationSpecificDefinitionsDirectory))
                {
                    Directory.CreateDirectory(ApplicationSpecificDefinitionsDirectory);
                }

                // Create [User]\Instrumind
                if (!Directory.Exists(ApplicationUserDirectory))
                {
                    Directory.CreateDirectory(ApplicationUserDirectory);
                }

                // Create [User]\Instrumind\_temp
                ApplicationUserTemporalDirectory = Path.Combine(ApplicationUserDirectory, TEMPORAL_SUBDIR);
                if (!Directory.Exists(ApplicationUserTemporalDirectory))
                {
                    Directory.CreateDirectory(ApplicationUserTemporalDirectory);
                }

                // Create [User]\Instrumind\ThinkComposer
                ApplicationUserDirectory = Path.Combine(ApplicationUserDirectory, AppExec.ApplicationName.TextToIdentifier());
                if (!Directory.Exists(ApplicationUserDirectory))
                {
                    Directory.CreateDirectory(ApplicationUserDirectory);
                }

                // Third: Create ...\MyCompositions
                if (!Directory.Exists(UserDataDirectory))
                {
                    Directory.CreateDirectory(UserDataDirectory);
                }
            }
            catch (Exception Anomaly)
            {
                DetectedProblem = "Cannot create Application Directory.";
                DetectedError   = Anomaly;
            }

            if (DetectedError == null)
            {
                LicenseFilePath         = ApplicationUserDirectory + "\\" + AppExec.ApplicationName.TextToIdentifier() + "." + LICENSE_EXTENSION;
                ConfigurationFilePath   = ApplicationUserDirectory + "\\" + AppExec.ApplicationName.TextToIdentifier() + "." + CONFIG_EXTENSION;
                RecentDocumentsFilePath = ApplicationUserDirectory + "\\" + "RecentDocuments." + LISTS_EXTENSION;

                try
                {
                    // new StreamWriter(new FileStream(LogFileName, FileMode.Append, FileAccess.Write, FileShare.Read));
                    LogWriter = TextWriter.Synchronized(new StreamWriter(ConfigurationFilePath, true));
                }
                catch (Exception Anomaly)
                {
                    DetectedProblem = "Cannot open or create Configuration file.";
                    DetectedError   = Anomaly;
                }
            }

            if (DetectedError == null)
            {
                if (LogWriter != null)
                {
                    LogWriter.Close();
                }

                LogFilePath = ApplicationUserDirectory + "\\" + AppExec.ApplicationName.TextToIdentifier() + "." + LOG_EXTENSION;

                try
                {
                    // new StreamWriter(new FileStream(LogFileName, FileMode.Append, FileAccess.Write, FileShare.Read));
                    LogWriter = TextWriter.Synchronized(new StreamWriter(LogFilePath, true));
                }
                catch (Exception Anomaly)
                {
                    DetectedProblem = "Cannot open Log file.";
                    DetectedError   = Anomaly;
                }
            }

            if (DetectedError != null)
            {
                // At this point, there could not be an application unhandled exception event attached,
                // so this problem will just be logged to the console.
                var Here = System.Reflection.MethodBase.GetCurrentMethod();

                LogException(new WarningAnomaly(new ExternalAnomaly(DetectedProblem, DetectedError)),
                             Here.DeclaringType.FullName + "." + Here.Name);

                LogWriter = null;
            }

            Initialized = true;
        }
示例#3
0
        /// <summary>
        /// Registers the specified Centralizer Global-ID with the new Shared References dictionary .
        /// </summary>
        public static void RegisterSharedReferencesCentralizer(Guid Centralizer, Dictionary<Guid, byte[]> SharedReferences)
        {
            General.ContractRequiresNotNull(SharedReferences);

            ReferenceCentralizers[Centralizer] = SharedReferences;
        }