예제 #1
0
 public void Dispose()
 {
     try
     {
         _invokeHandle?.Dispose();
     }
     catch (Exception)
     {
         try
         {
             _testOutputHelper.WriteLine("GSSAPI trace:");
             _testOutputHelper.WriteLine(File.ReadAllText(_tracePath));
         }
         catch (IOException)
         {
         }
         throw;
     }
     finally
     {
         _kdcListener.Stop();
         File.Delete(_tracePath);
         File.Delete(_krb5Path);
         File.Delete(_keytabPath);
     }
 }
예제 #2
0
        public static void SerializeWithBinaryFormatter_DeserializeWithBinaryWriter(string key)
        {
            AppContext.SetSwitch(enableBinaryFormatter, true);
            AppContext.SetSwitch(enableBinaryFormatterInTypeConverter, true);
            var context = new DesigntimeLicenseContext();

            context.SetSavedLicenseKey(typeof(int), key);
            string tempPath = Path.GetTempPath();

            try
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    long position = stream.Position;
                    DesigntimeLicenseContextSerializer.Serialize(stream, key, context);
                    stream.Seek(position, SeekOrigin.Begin);
                    VerifyStreamFormatting(stream);

                    using (FileStream outStream = File.Create(Path.Combine(tempPath, "_temp_SerializeWithBinaryFormatter_DeserializeWithBinaryWriter")))
                    {
                        stream.Seek(position, SeekOrigin.Begin);
                        stream.CopyTo(outStream);
                    }
                }

                RemoteInvokeHandle handle = RemoteExecutor.Invoke((key) =>
                {
                    var assembly = typeof(DesigntimeLicenseContextSerializer).Assembly;
                    Type runtimeLicenseContextType = assembly.GetType("System.ComponentModel.Design.RuntimeLicenseContext");
                    Assert.NotNull(runtimeLicenseContextType);
                    object runtimeLicenseContext = Activator.CreateInstance(runtimeLicenseContextType);
                    Assert.NotNull(runtimeLicenseContext);
                    FieldInfo _savedLicenseKeys = runtimeLicenseContextType.GetField("_savedLicenseKeys", BindingFlags.NonPublic | BindingFlags.Instance);
                    Assert.NotNull(_savedLicenseKeys);
                    _savedLicenseKeys.SetValue(runtimeLicenseContext, new Hashtable());

                    Type designtimeLicenseContextSerializer = assembly.GetType("System.ComponentModel.Design.DesigntimeLicenseContextSerializer");
                    Assert.NotNull(designtimeLicenseContextSerializer);
                    MethodInfo deserializeMethod = designtimeLicenseContextSerializer.GetMethod("Deserialize", BindingFlags.NonPublic | BindingFlags.Static);
                    Assert.NotNull(deserializeMethod);

                    string tempPath = Path.GetTempPath();
                    using (FileStream stream = File.Open(Path.Combine(tempPath, "_temp_SerializeWithBinaryFormatter_DeserializeWithBinaryWriter"), FileMode.Open))
                    {
                        TargetInvocationException exception = Assert.Throws <TargetInvocationException>(() => deserializeMethod.Invoke(null, new object[] { stream, key, runtimeLicenseContext }));
                        Assert.IsType <NotSupportedException>(exception.InnerException);
                    }
                }, key);

                handle.Process.WaitForExit();
                handle.Dispose();
            }
            finally
            {
                File.Delete(Path.Combine(tempPath, "_temp_SerializeWithBinaryFormatter_DeserializeWithBinaryWriter"));
            }
        }
예제 #3
0
        protected Process CreateProcess(Func <string, int> method, string arg)
        {
            RemoteInvokeHandle handle = RemoteInvoke(method, arg, new RemoteInvokeOptions {
                Start = false
            });
            Process p = handle.Process;

            handle.Process = null;
            handle.Dispose();
            AddProcessForDispose(p);
            return(p);
        }
예제 #4
0
        protected Process CreateProcess(Func <int> method = null)
        {
            RemoteInvokeHandle handle = RemoteInvoke(method ?? (() => SuccessExitCode), new RemoteInvokeOptions {
                Start = false
            });
            Process p = handle.Process;

            handle.Process = null;
            handle.Dispose();
            AddProcessForDispose(p);
            return(p);
        }