Example #1
0
        private Assembly BuildAssembly(String Code)
        {
            Microsoft.CSharp.CSharpCodeProvider provider = new CSharpCodeProvider();
            ICodeCompiler compiler = provider.CreateCompiler();
            CompilerParameters compilerparams = new CompilerParameters();
            compilerparams.GenerateExecutable = false;
            compilerparams.GenerateInMemory = true;

            String assembliesPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
            assembliesPath = assembliesPath.Replace("file:\\","");

            Listing listing = new FileListing();

            listing.Search(assembliesPath, "*.dll", true);

            foreach (String assembly in listing.Results)
            {

                compilerparams.ReferencedAssemblies.Add(assembly);

            }

            compilerparams.ReferencedAssemblies.Add("C:\\WINDOWS\\assembly\\GAC\\System.Windows.Forms\\1.0.5000.0__b77a5c561934e089\\System.Windows.Forms.dll");

            CompilerResults results =
               compiler.CompileAssemblyFromSource(compilerparams, Code);
            if (results.Errors.HasErrors)
            {
                StringBuilder errors = new StringBuilder("Compiler Errors :\r\n");
                foreach (CompilerError error in results.Errors)
                {
                    errors.AppendFormat("Line {0},{1}\t: {2}\n",
                           error.Line, error.Column, error.ErrorText);
                }
                throw new Exception(errors.ToString());
            }
            else
            {
                return results.CompiledAssembly;
            }
        }
Example #2
0
        public static Boolean TryCopy(String SourcePath, String TargetPath, String WildCard, Boolean Recursive, Boolean Slient, out String Error)
        {
            Boolean notCopied = true;
            Boolean copyFailed = false;
            Boolean copyAbortedIgnored = false;
            Dictionary<String, String> failedCopies = new Dictionary<string, string>();

            if (!Directory.Exists(TargetPath))
            {
                Directory.CreateDirectory(TargetPath);
            }

            while (notCopied && !copyFailed && !copyAbortedIgnored)
            {
                Listing copyListing = new FileListing();

                copyListing.Search(SourcePath, WildCard, Recursive);

                int copyCount = 1;

                foreach (String sourceFilename in copyListing.Results)
                {
                    String targetFilename = String.Format("{0}\\{1}", TargetPath, Path.GetFileName(sourceFilename));

                    notCopied = true;

                    while (!copyAbortedIgnored && notCopied)
                    {
                        try
                        {
                            File.Copy(sourceFilename, targetFilename);

                            notCopied = false;
                        }
                        catch (Exception ex)
                        {
                            if (Slient)
                            {
                                failedCopies.Add(sourceFilename, ex.ToString());
                                copyFailed = true;
                                break;
                            }
                            else
                            {
                                System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(String.Format("Copy of File [{0}/{1}] Failed!\nSource Filename: [{2}]\nTarget Filename: [{3}]\nError: {4}\n\nDo you Wish to Abort Copy, Retry or Ignore?", copyCount, copyListing.Results, SourcePath, TargetPath, ex.Message), "Copy File Error", System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore);

                                switch (result)
                                {
                                    case System.Windows.Forms.DialogResult.Ignore:
                                        failedCopies.Add(SourcePath, String.Format("{0}\nUser Action: Ignored", ex.ToString()));
                                        break;
                                    case System.Windows.Forms.DialogResult.Abort:
                                        copyAbortedIgnored = true;
                                        break;
                                    case System.Windows.Forms.DialogResult.Retry:
                                        copyAbortedIgnored = false;
                                        break;
                                }
                            }
                        }
                    }
                }
            }

            bool sucess = !copyFailed && !copyAbortedIgnored && notCopied == false;

            if (sucess)
            {
                Error = String.Empty;
            }
            else
            {
                StringBuilder builder = new StringBuilder();

                builder.AppendLine(String.Format("Copy Failed!\n  {0} Failed Copy(s)", failedCopies.Count));

                foreach (String failedFilename in failedCopies.Keys)
                {
                    builder.AppendLine(String.Format("  Filename: [{0}]\n  Error: [{1}]", failedFilename, failedCopies[failedFilename]));
                }

                Error = builder.ToString();
            }

            return sucess;
        }