示例#1
0
        ///////////////////////////////////////////////////////////////////////

        private /* protected virtual */ void Dispose(
            bool disposing
            )
        {
            TraceOps.DebugTrace(String.Format(
                                    "Dispose: disposing = {0}, interpreter = {1}, disposed = {2}",
                                    disposing, FormatOps.InterpreterNoThrow(interpreter), disposed),
                                typeof(VariableContext).Name, TracePriority.CleanupDebug);

            if (!disposed)
            {
                if (disposing)
                {
                    ////////////////////////////////////
                    // dispose managed resources here...
                    ////////////////////////////////////

                    Free(true);
                }

                //////////////////////////////////////
                // release unmanaged resources here...
                //////////////////////////////////////

                disposed = true;
            }
        }
示例#2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        private static ReturnCode WaitForSingleHandle(
            WaitHandle waitHandle,
            int milliseconds,
            bool userInterface,
            ref uint returnValue
            )
        {
            ReturnCode code;
            Result     error = null;

            code = WaitForSingleHandle(
                waitHandle, milliseconds, userInterface, ref returnValue, ref error);

            if (code != ReturnCode.Ok)
            {
                DebugOps.Complain(code, error);
            }

            if (traceWait)
            {
                TraceOps.DebugTrace(String.Format(
                                        "WaitForSingleHandle: exited, waitHandle = {0}, " +
                                        "milliseconds = {1}, userInterface = {2}, " +
                                        "returnValue = {3}, code = {4}, error = {5}",
                                        FormatOps.DisplayWaitHandle(waitHandle), milliseconds,
                                        userInterface, returnValue, code, FormatOps.WrapOrNull(
                                            true, true, error)), typeof(WindowOps).Name,
                                    TracePriority.NativeDebug);
            }

            return(code);
        }
示例#3
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode GetCertificate(
            byte[] assemblyBytes,
            ref X509Certificate certificate,
            ref Result error
            )
        {
            if (assemblyBytes != null)
            {
                try
                {
                    certificate = new X509Certificate(assemblyBytes);
                    return(ReturnCode.Ok);
                }
                catch (Exception e)
                {
                    error = e;
                }
            }
            else
            {
                error = "invalid assembly bytes";
            }

            TraceOps.DebugTrace(String.Format(
                                    "GetCertificate: query failure, error = {0}",
                                    FormatOps.WrapOrNull(
                                        true, true, error)),
                                typeof(AssemblyOps).Name, TracePriority.SecurityError);

            return(ReturnCode.Error);
        }
示例#4
0
        ///////////////////////////////////////////////////////////////////////

        public static EventWaitHandle OpenEvent(
            string name
            )
        {
            EventWaitHandle @event = null;

            try
            {
                @event = EventWaitHandle.OpenExisting(name);
            }
            catch (Exception e)
            {
                TraceOps.DebugTrace(
                    e, typeof(ThreadOps).Name,
                    TracePriority.HandleError);
            }

#if DEBUG && VERBOSE
            TraceOps.DebugTrace(String.Format(
                                    "OpenEvent: {0}, name = {1}",
                                    (@event != null) ? "success" : "failure",
                                    FormatOps.WrapOrNull(name)), typeof(ThreadOps).Name,
                                TracePriority.EventDebug);
#endif

            return(@event);
        }
示例#5
0
        ///////////////////////////////////////////////////////////////////////

        public void Report()
        {
            TraceOps.DebugTrace(String.Format(
                                    "Report: completed operation {0} in {1}",
                                    FormatOps.WrapOrNull(operation), this),
                                typeof(PerformanceClientData).Name,
                                TracePriority.TestDebug);
        }
示例#6
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

#if CACHE_STATISTICS
        public bool HaveCacheCounts()
        {
            if (Count > 0)
            {
                return(true);
            }

            return(FormatOps.HaveCacheCounts(cacheCounts));
        }
示例#7
0
        ///////////////////////////////////////////////////////////////////////

        #region Private Methods
        private static bool IsUsable(
            string version
            )
        {
            if (version == null)
            {
                TraceOps.DebugTrace(
                    "IsUsable: invalid version string",
                    typeof(NativeUtility).Name,
                    TracePriority.NativeError);

                return(false);
            }

            if (version.IndexOf(
                    optionUse32BitSizeT,
                    StringOps.SystemStringComparisonType) == Index.Invalid)
            {
                TraceOps.DebugTrace(String.Format(
                                        "IsUsable: missing option {0}",
                                        FormatOps.WrapOrNull(optionUse32BitSizeT)),
                                    typeof(NativeUtility).Name,
                                    TracePriority.NativeError);

                return(false);
            }

#if NATIVE_UTILITY_BSTR
            if (version.IndexOf(
                    optionUseSysStringLen,
                    StringOps.SystemStringComparisonType) == Index.Invalid)
            {
                TraceOps.DebugTrace(String.Format(
                                        "IsUsable: missing option {0}",
                                        FormatOps.WrapOrNull(optionUseSysStringLen)),
                                    typeof(NativeUtility).Name,
                                    TracePriority.NativeError);

                return(false);
            }
#else
            if (version.IndexOf(
                    optionUseSysStringLen,
                    StringOps.SystemStringComparisonType) != Index.Invalid)
            {
                TraceOps.DebugTrace(String.Format(
                                        "IsUsable: mismatched option {0}",
                                        FormatOps.WrapOrNull(optionUseSysStringLen)),
                                    typeof(NativeUtility).Name,
                                    TracePriority.NativeError);

                return(false);
            }
#endif

            return(true);
        }
示例#8
0
        ///////////////////////////////////////////////////////////////////////

        #region Background Error Reporter
        private static void ReportBackgroundError(
            Interpreter interpreter,
            string handlerName,
            string description0,
            string description1,
            ReturnCode code1,
            Result result1,
            int errorLine1,
            string description2,
            ReturnCode code2,
            Result result2,
            int errorLine2
            )
        {
            bool[] haveDescription =
            {
                !String.IsNullOrEmpty(description0),
                !String.IsNullOrEmpty(description1),
                !String.IsNullOrEmpty(description2)
            };

            Result bgReport = String.Concat(
                haveDescription[0] ?
                String.Format(description0,
                              FormatOps.WrapOrNull(handlerName)) :
                String.Empty, haveDescription[0] ?
                Environment.NewLine : String.Empty,
                haveDescription[1] ?
                String.Format("{0}{1}: {2}", haveDescription[0] ?
                              BackgroundErrorDetailIndent : String.Empty,
                              description1,
                              ResultOps.Format(code1,
                                               result1, errorLine1, false, true)) :
                String.Empty, haveDescription[1] ?
                Environment.NewLine : String.Empty,
                haveDescription[2] ?
                String.Format("{0}{1}: {2}", haveDescription[0] ?
                              BackgroundErrorDetailIndent : String.Empty,
                              description2,
                              ResultOps.Format(code2,
                                               result2, errorLine2, false, true)) :
                String.Empty, haveDescription[2] ?
                Environment.NewLine : String.Empty);

            //
            // TODO: Something else here as well?
            //
            if ((bgReport != null) && !String.IsNullOrEmpty(bgReport))
            {
                DebugOps.Complain(interpreter, code2, bgReport);
            }
        }
示例#9
0
        ///////////////////////////////////////////////////////////////////////

        private /* protected virtual */ void Dispose(
            bool disposing
            )
        {
            TraceOps.DebugTrace(String.Format(
                                    "Dispose: disposing = {0}, interpreter = {1}, disposed = {2}",
                                    disposing, FormatOps.InterpreterNoThrow(interpreter), disposed),
                                typeof(InteractiveContext).Name, TracePriority.CleanupDebug);

            if (!disposed)
            {
                if (disposing)
                {
                    ////////////////////////////////////
                    // dispose managed resources here...
                    ////////////////////////////////////

                    interpreter = null; /* NOT OWNED: Do not dispose. */
                    threadId    = 0;

                    ///////////////////////////////////////////////////////////

                    interactive              = false;
                    interactiveInput         = null;
                    previousInteractiveInput = null;
                    interactiveMode          = null;
                    activeInteractiveLoops   = 0;
                    totalInteractiveLoops    = 0;

                    interactiveLoopData        = null;
                    interactiveCommandCallback = null;

#if HISTORY
                    historyLoadData = null;
                    historySaveData = null;

                    historyInfoFilter = null;
                    historyLoadFilter = null;
                    historySaveFilter = null;

                    historyFileName = null;
#endif
                }

                //////////////////////////////////////
                // release unmanaged resources here...
                //////////////////////////////////////

                disposed = true;
            }
        }
示例#10
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode GetCertificate2(
            Assembly assembly,
            bool strict,
            ref X509Certificate2 certificate2,
            ref Result error
            )
        {
            X509Certificate certificate = null;

            if (GetCertificate(assembly, ref certificate,
                               ref error) == ReturnCode.Ok)
            {
                if (certificate != null)
                {
                    try
                    {
                        certificate2 = new X509Certificate2(certificate);
                        return(ReturnCode.Ok);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }
                }
                else if (!strict)
                {
                    certificate2 = null;

                    return(ReturnCode.Ok);
                }
                else
                {
                    error = "invalid certificate";
                }
            }

#if DEBUG
            if (!GlobalState.IsAssembly(assembly))
#endif
            {
                TraceOps.DebugTrace(String.Format(
                                        "GetCertificate2: assembly {0} query failure, error = {1}",
                                        FormatOps.WrapOrNull(assembly),
                                        FormatOps.WrapOrNull(true, true, error)),
                                    typeof(AssemblyOps).Name, TracePriority.SecurityError);
            }

            return(ReturnCode.Error);
        }
示例#11
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode GetHash(
            Assembly assembly,
            ref Hash hash,
            ref Result error
            )
        {
            if (assembly != null)
            {
                Evidence evidence = assembly.Evidence;

                if (evidence != null)
                {
                    try
                    {
                        foreach (object item in evidence)
                        {
                            if (item is Hash)
                            {
                                hash = (Hash)item;
                                return(ReturnCode.Ok);
                            }
                        }

                        error = "no hash found";
                        return(ReturnCode.Error);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }
                }
                else
                {
                    error = "invalid evidence";
                }
            }
            else
            {
                error = "invalid assembly";
            }

            TraceOps.DebugTrace(String.Format(
                                    "GetHash: assembly {0} query failure, error = {1}",
                                    FormatOps.WrapOrNull(assembly),
                                    FormatOps.WrapOrNull(true, true, error)),
                                typeof(AssemblyOps).Name, TracePriority.SecurityError);

            return(ReturnCode.Error);
        }
示例#12
0
        ///////////////////////////////////////////////////////////////////////

        #region Private Methods
        private static ReturnCode IsStrongNameVerified(
            string fileName,
            bool force,
            ref bool returnValue,
            ref bool verified,
            ref Result error
            )
        {
            if (String.IsNullOrEmpty(fileName))
            {
                error = "invalid file name";
                return(ReturnCode.Error);
            }

#if WINDOWS && !MONO
            if (!PlatformOps.IsWindowsOperatingSystem())
            {
                error = "not supported on this operating system";
                return(ReturnCode.Error);
            }

            try
            {
                returnValue =
                    UnsafeNativeMethods.StrongNameSignatureVerificationEx(
                        fileName, force, ref verified);

                return(ReturnCode.Ok);
            }
            catch (Exception e)
            {
                error = e;
            }
#else
            error = "not implemented";
#endif

            TraceOps.DebugTrace(String.Format(
                                    "IsStrongNameVerified: file {0} verification " +
                                    "failure, force = {1}, returnValue = {2}, " +
                                    "verified = {3}, error = {4}",
                                    FormatOps.WrapOrNull(fileName), force,
                                    returnValue, verified, FormatOps.WrapOrNull(error)),
                                typeof(SecurityOps).Name, TracePriority.SecurityError);

            return(ReturnCode.Error);
        }
示例#13
0
        ///////////////////////////////////////////////////////////////////////

        #region Private Windows-Specific Methods
#if WINDOWS
        private static ReturnCode WindowsIsAdministrator(
            ref bool administrator,
            ref Result error
            )
        {
            try
            {
                //
                // NOTE: Are we running on Windows 2000 SP4 or higher?
                //
                if (PlatformOps.CheckVersion(PlatformID.Win32NT, 5, 0, 4, 0))
                {
                    //
                    // HACK: Use a "documented" function for Windows
                    //       2000 SP4+, Windows XP, and Vista (this
                    //       function used to be undocumented).
                    //
                    administrator = UnsafeNativeMethods.IsUserAnAdmin();
                }
                else
                {
                    //
                    // HACK: Use a different undocumented function for
                    //       Windows NT and Windows 2000 RTM to SP3.
                    //
                    uint reserved2 = 0;

                    administrator = UnsafeNativeMethods.IsNTAdmin(
                        0, ref reserved2);
                }

                return(ReturnCode.Ok);
            }
            catch (Exception e)
            {
                error = e;
            }

            TraceOps.DebugTrace(String.Format(
                                    "WindowsIsAdministrator: administrator = {0}, error = {1}",
                                    administrator, FormatOps.WrapOrNull(error)),
                                typeof(SecurityOps).Name, TracePriority.SecurityError);

            return(ReturnCode.Error);
        }
示例#14
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode GetCertificate(
            Assembly assembly,
            ref X509Certificate certificate,
            ref Result error
            )
        {
            if (assembly != null)
            {
                Module module = assembly.ManifestModule;

                if (module != null)
                {
                    try
                    {
                        certificate = module.GetSignerCertificate();
                        return(ReturnCode.Ok);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }
                }
                else
                {
                    error = "invalid module";
                }
            }
            else
            {
                error = "invalid assembly";
            }

#if DEBUG
            if (!GlobalState.IsAssembly(assembly))
#endif
            {
                TraceOps.DebugTrace(String.Format(
                                        "GetCertificate: assembly {0} query failure, error = {1}",
                                        FormatOps.WrapOrNull(assembly),
                                        FormatOps.WrapOrNull(true, true, error)),
                                    typeof(AssemblyOps).Name, TracePriority.SecurityError);
            }

            return(ReturnCode.Error);
        }
示例#15
0
        public static void DebugTrace(
            int?threadId,
            string message,
            string category,
            TracePriority priority
            )
        {
            if (!IsTracePossible())
            {
                return;
            }

            if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */
            {
                return;
            }

            string traceFormat = GetTraceFormat();

            if (traceFormat == null)
            {
                return;
            }

            bool traceDateTime;
            bool tracePriority;
            bool traceAppDomain;
            bool traceInterpreter;
            bool traceThreadId;
            bool traceMethod;

            GetTraceFormatFlags(
                out traceDateTime, out tracePriority, out traceAppDomain,
                out traceInterpreter, out traceThreadId, out traceMethod);

            string methodName = null;

            DebugTraceRaw(FormatOps.TraceOutput(traceFormat,
                                                traceDateTime ? (DateTime?)TimeOps.GetNow() : null,
                                                tracePriority ? (TracePriority?)priority : null,
                                                traceAppDomain ? AppDomainOps.GetCurrent() : null,
                                                traceInterpreter ? Interpreter.GetActive() : null,
                                                traceThreadId ? threadId : null, message, traceMethod,
                                                ref methodName), category, methodName, priority);
        }
示例#16
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode GetCertificate2(
            string fileName,
            ref X509Certificate2 certificate2,
            ref Result error
            )
        {
            X509Certificate certificate = null;

            if (GetCertificate(fileName, ref certificate,
                               ref error) == ReturnCode.Ok)
            {
                if (certificate != null)
                {
                    try
                    {
                        certificate2 = new X509Certificate2(certificate);
                        return(ReturnCode.Ok);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }
                }
                else
                {
                    error = "invalid certificate";
                }
            }

#if DEBUG
            if (!PathOps.IsSameFile(
                    Interpreter.GetActive(), fileName,
                    GlobalState.GetAssemblyLocation()))
#endif
            {
                TraceOps.DebugTrace(String.Format(
                                        "GetCertificate2: file {0} query failure, error = {1}",
                                        FormatOps.WrapOrNull(fileName),
                                        FormatOps.WrapOrNull(true, true, error)),
                                    typeof(CertificateOps).Name, TracePriority.SecurityError);
            }

            return(ReturnCode.Error);
        }
示例#17
0
        ///////////////////////////////////////////////////////////////////////

        public static string ToHexadecimalString(
            byte[] array
            )
        {
            if (array == null)
            {
                return(null);
            }

            StringBuilder result = StringOps.NewStringBuilder();

            int length = array.Length;

            for (int index = 0; index < length; index++)
            {
                result.Append(FormatOps.Hexadecimal(array[index], false));
            }

            return(result.ToString());
        }
示例#18
0
        public static void DebugTrace(
            Exception exception,
            string category,
            TracePriority priority
            )
        {
            if (!IsTracePossible())
            {
                return;
            }

            if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */
            {
                return;
            }

            DebugTrace(
                GlobalState.GetCurrentSystemThreadId(),
                FormatOps.TraceException(exception), category, priority);
        }
示例#19
0
        public static void DebugTrace(
            int?threadId,
            Exception exception,
            string category,
            TracePriority priority
            )
        {
            if (!IsTracePossible())
            {
                return;
            }

            if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */
            {
                return;
            }

            DebugTrace(
                threadId, FormatOps.TraceException(exception), category,
                priority);
        }
示例#20
0
        ///////////////////////////////////////////////////////////////////////

        #region Public Certificate Methods
        public static ReturnCode GetCertificate(
            string fileName,
            ref X509Certificate certificate,
            ref Result error
            )
        {
            if (!String.IsNullOrEmpty(fileName))
            {
                try
                {
                    certificate = X509Certificate.CreateFromSignedFile(
                        fileName);

                    return(ReturnCode.Ok);
                }
                catch (Exception e)
                {
                    error = e;
                }
            }
            else
            {
                error = "invalid file name";
            }

#if DEBUG
            if (!PathOps.IsSameFile(
                    Interpreter.GetActive(), fileName,
                    GlobalState.GetAssemblyLocation()))
#endif
            {
                TraceOps.DebugTrace(String.Format(
                                        "GetCertificate: file {0} query failure, error = {1}",
                                        FormatOps.WrapOrNull(fileName),
                                        FormatOps.WrapOrNull(true, true, error)),
                                    typeof(CertificateOps).Name, TracePriority.SecurityError);
            }

            return(ReturnCode.Error);
        }
示例#21
0
        ///////////////////////////////////////////////////////////////////////

        #region Private Unix-Specific Methods
#if UNIX
        private static ReturnCode UnixIsAdministrator(
            ref bool administrator,
            ref Result error
            )
        {
            try
            {
                administrator = (UnsafeNativeMethods.getuid() == 0);

                return(ReturnCode.Ok);
            }
            catch (Exception e)
            {
                error = e;
            }

            TraceOps.DebugTrace(String.Format(
                                    "UnixIsAdministrator: administrator = {0}, error = {1}",
                                    administrator, FormatOps.WrapOrNull(error)),
                                typeof(SecurityOps).Name, TracePriority.SecurityError);

            return(ReturnCode.Error);
        }
示例#22
0
        ///////////////////////////////////////////////////////////////////////

        public static bool TryGetAppSetting(
            string name,      /* in */
            out string value, /* out */
            ref Result error  /* out */
            )
        {
            Initialize();

            lock (syncRoot) /* TRANSACTIONAL */
            {
                NameValueCollection appSettings = GetAppSettings();

                if (appSettings == null)
                {
                    value = null;

                    error = "invalid application settings";

                    return(false);
                }

                string stringValue = appSettings.Get(name);

                if (stringValue == null)
                {
                    value = null;

                    error = String.Format(
                        "setting {0} not found", FormatOps.WrapOrNull(name));

                    return(false);
                }

                value = stringValue;
                return(true);
            }
        }
示例#23
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode SetExclusive(
            bool exclusive,
            ref Result error
            )
        {
            lock (syncRoot) /* TRANSACTIONAL */
            {
                bool wasExclusive = IsExclusive();

                if (exclusive != wasExclusive)
                {
                    UpdateOps.exclusive = exclusive;

                    TraceOps.DebugTrace(String.Format(
                                            "SetExclusive: exclusive mode {0}",
                                            exclusive ? "enabled" : "disabled"),
                                        typeof(UpdateOps).Name,
                                        TracePriority.SecurityDebug);

                    return(ReturnCode.Ok);
                }
                else
                {
                    error = String.Format(
                        "already {0}", exclusive ?
                        "exclusive" : "non-exclusive");
                }
            }

            TraceOps.DebugTrace(String.Format(
                                    "SetExclusive: exclusive = {0}, error = {1}",
                                    exclusive, FormatOps.WrapOrNull(error)),
                                typeof(UpdateOps).Name,
                                TracePriority.SecurityError);

            return(ReturnCode.Error);
        }
示例#24
0
        ///////////////////////////////////////////////////////////////////////

        private static void DumpSetup(
            Interpreter interpreter,
            string friendlyName,
            string baseDirectory,
            string packagePath,
            bool useBasePath,
            AppDomainSetup appDomainSetup
            )
        {
            StringPairList list = new StringPairList();

            AddInfo(appDomainSetup, list, DetailFlags.DebugTrace);

            TraceOps.DebugTrace(String.Format(
                                    "DumpSetup: interpreter = {0}, friendlyName = {1}, " +
                                    "baseDirectory = {2}, packagePath = {3}, " +
                                    "useBasePath = {4}, appDomainSetup = {5}",
                                    FormatOps.InterpreterNoThrow(interpreter),
                                    FormatOps.WrapOrNull(friendlyName),
                                    FormatOps.WrapOrNull(baseDirectory),
                                    FormatOps.WrapOrNull(packagePath),
                                    useBasePath, list), typeof(AppDomainOps).Name,
                                TracePriority.SecurityDebug);
        }
示例#25
0
        public static void DebugWriteTo(
            Interpreter interpreter,
            string value,
            bool force
            )
        {
            if (!IsTracePossible())
            {
                return;
            }

            string traceFormat = GetTraceFormat();

            if (traceFormat == null)
            {
                return;
            }

            bool traceDateTime;
            bool tracePriority;
            bool traceAppDomain;
            bool traceInterpreter;
            bool traceThreadId;
            bool traceMethod;

            GetTraceFormatFlags(
                out traceDateTime, out tracePriority, out traceAppDomain,
                out traceInterpreter, out traceThreadId, out traceMethod);

            DebugOps.WriteTo(interpreter, FormatOps.TraceOutput(traceFormat,
                                                                traceDateTime ? (DateTime?)TimeOps.GetNow() : null, null,
                                                                traceAppDomain ? AppDomainOps.GetCurrent() : null,
                                                                traceInterpreter ? interpreter : null, traceThreadId ?
                                                                (int?)GlobalState.GetCurrentSystemThreadId() : null,
                                                                value, traceMethod), force);
        }
示例#26
0
        ///////////////////////////////////////////////////////////////////////

        #region Public Parsing Methods
        public static bool ParseData(
            Configuration configuration,
            string text,
            ref IEqualityComparer <Configuration> comparer,
            ref IDictionary <Configuration, Release> releases,
            ref int[] protocolCounts,
            ref string error
            )
        {
            if (configuration == null)
            {
                error = "Invalid configuration.";
                return(false);
            }

            if (text == null)
            {
                error = "Invalid release data.";
                return(false);
            }

            //
            // NOTE: This will contain the counts of the protocols encountered
            //       while parsing the release data (e.g. "1", "2", "3", or
            //       other).
            //
            if (protocolCounts == null)
            {
                protocolCounts = new int[4];
            }

            int parseCount = 0;

            string[] lines = text.Split(Line.Separators);

            for (int lineIndex = 0; lineIndex < lines.Length; lineIndex++)
            {
                string line = lines[lineIndex];

                if (line == null)
                {
                    continue;
                }

                line = line.Trim(Characters.Space);

                if (line.Length == 0)
                {
                    continue;
                }

                if (GenericOps <char> .Contains(Line.Comments, line[0]))
                {
                    continue;
                }

                Release release = ParseLine(
                    configuration, NextId(), lineIndex, line, ref error);

                if (release != null)
                {
                    /* IGNORED */
                    release.MaybeUseDownloadBaseUri(configuration.Assembly);

                    parseCount++;

                    if (release.ProtocolId != null)
                    {
                        switch (release.ProtocolId)
                        {
                        case Protocol.Build:     /* NOTE: Release build. */
                        {
                            protocolCounts[0]++;
                            break;
                        }

                        case Protocol.Script:     /* NOTE: Update script. */
                        {
                            protocolCounts[1]++;
                            break;
                        }

                        case Protocol.Self:     /* NOTE: Updater itself. */
                        {
                            protocolCounts[2]++;
                            break;
                        }

                        default:     /* NOTE: Other and/or unknown. */
                        {
                            protocolCounts[3]++;
                            break;
                        }
                        }
                    }

                    if (comparer == null)
                    {
                        comparer = new _Comparers._Configuration(
                            StringComparison.Ordinal, Defaults.Encoding);
                    }

                    if (releases == null)
                    {
                        releases = new Dictionary <Configuration, Release>(
                            comparer);
                    }

                    Configuration releaseConfiguration =
                        Configuration.CreateFrom(release);

                    if (releaseConfiguration == null)
                    {
                        Trace(configuration, String.Format(
                                  "Could not create configuration from parsed " +
                                  "release {0} on line #{1}, using the " +
                                  "pre-existing one...", FormatOps.ForDisplay(
                                      release), lineIndex), TraceCategory);

                        releaseConfiguration = configuration;
                    }

                    releases[releaseConfiguration] = release;
                }
            }

            return((parseCount > 0) ? true : false);
        }
示例#27
0
        ///////////////////////////////////////////////////////////////////////

        public bool VerifyFile(
            Configuration configuration,
            string fileName,
            bool strongName
            )
        {
            try
            {
                if (!File.Exists(fileName))
                {
                    Trace(configuration, String.Format(
                              "File \"{0}\" does not exist.", fileName),
                          TraceCategory);

                    return(false);
                }

                ///////////////////////////////////////////////////////////////

                string error = null;

                if (strongName)
                {
#if NATIVE && WINDOWS
                    if (VersionOps.IsWindowsOperatingSystem() &&
                        !StrongNameEx.IsStrongNameSigned(
                            configuration, fileName, true, ref error))
                    {
                        Trace(configuration, String.Format(
                                  "Assembly in file \"{0}\" is not signed.",
                                  fileName), TraceCategory);

                        Trace(configuration, String.Format(
                                  "Assembly signature error: {0}", error),
                              TraceCategory);

                        return(false);
                    }
#endif

                    ///////////////////////////////////////////////////////////

                    AssemblyName assemblyName =
                        AssemblyName.GetAssemblyName(fileName);

                    if (assemblyName == null)
                    {
                        Trace(configuration, String.Format(
                                  "Assembly in file \"{0}\" has no name.", fileName),
                              TraceCategory);

                        return(false);
                    }

                    byte[] filePublicKeyToken = assemblyName.GetPublicKeyToken();

                    if (!GenericOps <byte> .Equals(
                            filePublicKeyToken, publicKeyToken))
                    {
                        Trace(configuration, String.Format(
                                  "Assembly in file \"{0}\" has incorrect " +
                                  "public key token \"{1}\".", fileName,
                                  FormatOps.ToHexString(filePublicKeyToken)),
                              TraceCategory);

                        return(false);
                    }
                }

                ///////////////////////////////////////////////////////////////

                byte[] hash = null;

                if (FileOps.Hash(
                        configuration, "md5", fileName, ref hash, ref error))
                {
                    if (!GenericOps <byte> .Equals(hash, md5Hash))
                    {
                        Trace(configuration, String.Format(
                                  "File \"{0}\" MD5 hash mismatch, got: {1}.",
                                  fileName, FormatOps.ToHexString(hash)),
                              TraceCategory);

                        return(false);
                    }
                }
                else
                {
                    Trace(configuration, error, TraceCategory);

                    return(false);
                }

                ///////////////////////////////////////////////////////////////

                if (FileOps.Hash(
                        configuration, "sha1", fileName, ref hash, ref error))
                {
                    if (!GenericOps <byte> .Equals(hash, sha1Hash))
                    {
                        Trace(configuration, String.Format(
                                  "File \"{0}\" SHA1 hash mismatch, got: {1}.",
                                  fileName, FormatOps.ToHexString(hash)),
                              TraceCategory);

                        return(false);
                    }
                }
                else
                {
                    Trace(configuration, error, TraceCategory);

                    return(false);
                }

                ///////////////////////////////////////////////////////////////

                if (FileOps.Hash(
                        configuration, "sha512", fileName, ref hash, ref error))
                {
                    if (!GenericOps <byte> .Equals(hash, sha512Hash))
                    {
                        Trace(configuration, String.Format(
                                  "File \"{0}\" SHA512 hash mismatch, got: {1}.",
                                  fileName, FormatOps.ToHexString(hash)),
                              TraceCategory);

                        return(false);
                    }
                }
                else
                {
                    Trace(configuration, error, TraceCategory);

                    return(false);
                }

                return(true);
            }
            catch (Exception e)
            {
                Trace(configuration, e, TraceCategory);
            }

            return(false);
        }
示例#28
0
        ///////////////////////////////////////////////////////////////////////

        #region System.Object Overrides
        public override string ToString()
        {
            return(String.Format("{0} ({1})",
                                 FormatOps.ValueToString(patchLevel),
                                 FormatOps.ValueToString(timeStamp)));
        }
示例#29
0
        ///////////////////////////////////////////////////////////////////////

        #region Public Methods
        public void Dump()
        {
            Trace(configuration, FormatOps.NameAndValue("Id", id),
                  TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("ProtocolId",
                                                        protocolId), TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("PublicKeyToken",
                                                        publicKeyToken), TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("Name", name),
                  TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("Culture", culture),
                  TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("PatchLevel",
                                                        patchLevel), TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("TimeStamp",
                                                        timeStamp), TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("BaseUri", baseUri),
                  TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("UriFormat", uriFormat),
                  TraceCategory);

            BuildType buildType = (configuration != null) ?
                                  configuration.BuildType : BuildType.Default;

            ReleaseType releaseType = (configuration != null) ?
                                      configuration.ReleaseType : ReleaseType.Default;

            Trace(configuration, FormatOps.NameAndValue("RelativeUri",
                                                        Format(buildType, releaseType)), TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("Md5Hash", md5Hash),
                  TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("Sha1Hash", sha1Hash),
                  TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("Sha512Hash",
                                                        sha512Hash), TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("Notes",
                                                        FormatOps.NotesToString(notes)), TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("IsValid", IsValid),
                  TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("IsEqual", IsEqual),
                  TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("IsGreater",
                                                        IsGreater), TraceCategory);

            Trace(configuration, FormatOps.NameAndValue("IsSelf", IsSelf),
                  TraceCategory);
        }
示例#30
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode Wait(
            Interpreter interpreter,
            long microseconds,
            bool timeout,
            bool strict,
            ref Result error
            ) /* THREAD-SAFE */
        {
            ReturnCode code = ReturnCode.Ok;

            if (interpreter != null)
            {
                int waitCount;

                if ((waitCount = interpreter.EnterWait()) > 0)
                {
                    if (microseconds == 0)
                    {
#if WINFORMS
                        //
                        // NOTE: If necessary, process all Windows messages
                        //       from the queue.
                        //
                        if (!strict)
                        {
                            code = WindowOps.ProcessEvents(
                                interpreter, ref error);
                        }

                        if (code == ReturnCode.Ok)
#endif
                        {
                            //
                            // NOTE: Yield to other running threads.  This
                            //       also gives them an opportunity to cancel
                            //       the script in progress on this thread.
                            //
                            HostOps.Yield();
                        }
                    }
                    else
                    {
                        //
                        // NOTE: Keep track of how many iterations through
                        //       the loop we take.
                        //
                        int iterations = 0;

                        //
                        // HACK: Account for our processing overhead; use half
                        //       of the requested delay.
                        //
                        int milliseconds = ConversionOps.ToInt(
                            PerformanceOps.GetMilliseconds(microseconds) /
                            WaitDivisor);

                        if (milliseconds < 0)
                        {
                            milliseconds = 0;
                        }

                        if (milliseconds > WaitMaximumSleepTime)
                        {
                            milliseconds = WaitMaximumSleepTime;
                        }

                        //
                        // NOTE: For more precise timing, use the high-resolution
                        //       CPU performance counter.
                        //
                        long startCount = PerformanceOps.GetCount();

                        //
                        // BUGFIX: Make sure the slop time does not exceed the
                        //         actual wait.
                        //
                        long slopMicroseconds = Math.Min(
                            microseconds / WaitSlopDivisor, WaitSlopMinimumTime);

                        //
                        // NOTE: Delay for approximately the specified number of
                        //       microseconds, optionally timing out if we cannot
                        //       obtain the interpreter lock before the time period
                        //       elapses.
                        //
                        while (((code = Interpreter.EventReady(interpreter,
                                                               timeout ? milliseconds : _Timeout.Infinite,
                                                               ref error)) == ReturnCode.Ok) &&
                               !PerformanceOps.HasElapsed(startCount,
                                                          microseconds, slopMicroseconds))
                        {
#if WINFORMS
                            if (!strict)
                            {
                                code = WindowOps.ProcessEvents(interpreter, ref error);

                                if (code != ReturnCode.Ok)
                                {
                                    break;
                                }
                            }
#endif

                            HostOps.SleepOrMaybeComplain(interpreter, milliseconds); iterations++;
                        }

                        long stopCount = PerformanceOps.GetCount();

                        double elapsedMicroseconds = PerformanceOps.GetMicroseconds(
                            startCount, stopCount, 1);

                        TraceOps.DebugTrace(String.Format(
                                                "Wait: code = {0}, iterations = {1}, microseconds = {2}, " +
                                                "elapsedMicroseconds = {3}, sleepMilliseconds = {4}, " +
                                                "slopMicroseconds = {5}, differenceMicroseconds = {6}, " +
                                                "waitCount = {7}, error = {8}",
                                                code, iterations, microseconds, elapsedMicroseconds, milliseconds,
                                                slopMicroseconds, elapsedMicroseconds - (double)microseconds,
                                                waitCount, FormatOps.WrapOrNull(true, true, error)),
                                            typeof(EventOps).Name, TracePriority.EventDebug);
                    }

                    /* IGNORED */
                    interpreter.ExitWait();
                }
                else
                {
                    error = "wait subsystem locked";
                    code  = ReturnCode.Error;
                }
            }
            else
            {
                error = "invalid interpreter";
                code  = ReturnCode.Error;
            }

            return(code);
        }