예제 #1
0
        public int TranspileProject(ProjectTranspiler projectTranspiler = null)
        {
            bool updateProject = false;

            try
            {
                var hasRemainingArguments = this.HasRemainingArguments;
                var zfsFileSetFile        = this.ZFSFileSetFile;
                if (this.register)
                {
                    if (String.IsNullOrEmpty(this.emailAddress) || String.IsNullOrEmpty(this.account))
                    {
                        ShowError("Syntax: ssotme -register [email protected] -account=pickAccount");
                        return(-1);
                    }
                    else
                    {
                        this.AccountHolder = new SMQAccountHolder();
                        throw new NotImplementedException();
                    }
                }
                else if (this.authenticate)
                {
                    if (String.IsNullOrEmpty(this.emailAddress))
                    {
                        ShowError("Syntax: ssotme -auth -emailAddress=\"[email protected]\"");
                        return(-1);
                    }
                    else
                    {
                        this.PublicUser          = new SMQPublicUser();
                        this.PublicUser.ReplyTo += PublicUser_ReplyTo;
                        this.PublicUser.PublicUserPing();
                    }
                }
                else if (this.describe)
                {
                    this.SSoTmeProject.Describe(Environment.CurrentDirectory);
                }
                else if (this.descibeAll)
                {
                    this.SSoTmeProject.Describe();
                }
                else if (this.listSettings)
                {
                    this.SSoTmeProject.ListSettings();
                }
                else if (this.addSetting.Any())
                {
                    foreach (var setting in this.addSetting)
                    {
                        this.SSoTmeProject.AddSetting(setting);
                    }

                    this.SSoTmeProject.Save();
                }
                else if (this.removeSetting.Any())
                {
                    foreach (var setting in this.removeSetting)
                    {
                        this.SSoTmeProject.RemoveSetting(setting);
                    }
                    this.SSoTmeProject.Save();
                }
                else if (!String.IsNullOrEmpty(this.setAccountAPIKey))
                {
                    var key = SSOTMEKey.GetSSoTmeKey(this.runAs);
                    if (ReferenceEquals(key.APIKeys, null))
                    {
                        key.APIKeys = new Dictionary <String, String>();
                    }
                    var apiKey = this.setAccountAPIKey.SafeToString().Replace("=", "/");
                    var values = apiKey.Split("/".ToCharArray());
                    if (!values.Skip(1).Any())
                    {
                        throw new Exception("Sytnax: -setAccountAPIKey=account/KEY");
                    }
                    key.APIKeys[values[0]] = values[1];
                    SSOTMEKey.SetSSoTmeKey(key, this.runAs);
                }
                else if (!String.IsNullOrEmpty(this.execute))
                {
                    this.ProcessCommandLine(this.execute);
                    if (this.install)
                    {
                        object o = 1; // Need to write code to save the execute command line
                    }
                }
                else if (this.build)
                {
                    this.SSoTmeProject.Rebuild(Environment.CurrentDirectory, this.includeDisabled);
                    if (this.checkResults)
                    {
                        this.SSoTmeProject.CreateDocs();
                    }
                }
                else if (this.buildAll)
                {
                    this.SSoTmeProject.Rebuild(this.includeDisabled);
                    this.SSoTmeProject.CreateDocs();
                }
                else if (this.checkResults || this.createDocs && !hasRemainingArguments)
                {
                    if (this.checkResults)
                    {
                        this.SSoTmeProject.CheckResults();
                    }
                    else
                    {
                        this.SSoTmeProject.CreateDocs();
                    }
                    updateProject = true;
                }
                else if (this.clean && !ReferenceEquals(zfsFileSetFile, null))
                {
                    var zfsFI = new FileInfo(zfsFileSetFile.RelativePath);
                    if (zfsFI.Exists)
                    {
                        var zippedFileSet = File.ReadAllBytes(zfsFI.FullName);
                        zippedFileSet.CleanZippedFileSet();
                        if (!this.preserveZFS)
                        {
                            zfsFI.Delete();
                        }
                    }
                }
                else if (this.clean && !hasRemainingArguments)
                {
                    this.SSoTmeProject.Clean(Environment.CurrentDirectory, this.preserveZFS);
                }
                else if (this.cleanAll && !hasRemainingArguments)
                {
                    this.SSoTmeProject.Clean(this.preserveZFS);
                }
                else if (!hasRemainingArguments && !this.clean)
                {
                    ShowError("Missing argument name of transpiler");
                    return(-1);
                }
                else
                {
                    StartTranspile();

                    if (!ReferenceEquals(result.Exception, null))
                    {
                        ShowError("ERROR: " + result.Exception.Message);
                        ShowError(result.Exception.StackTrace);
                        return(-1);
                    }
                    else
                    {
                        var finalResult = 0;

                        if (!ReferenceEquals(result.Transpiler, null))
                        {
                            Console.WriteLine("\n\nTRANSPILER MATCHED: {0}\n\n", result.Transpiler.Name);
                        }

                        if (this.clean)
                        {
                            result.CleanFileSet();
                        }
                        else
                        {
                            finalResult   = result.SaveFileSet(this.skipClean);
                            updateProject = true;
                        }
                        return(finalResult);
                    }
                }

                return(0);
            }
            finally
            {
                if (!ReferenceEquals(AccountHolder, null))
                {
                    AccountHolder.Disconnect();
                }
                if (updateProject)
                {
                    if (this.install)
                    {
                        this.SSoTmeProject.Install(result, this.transpilerGroup);
                    }
                    else if (!ReferenceEquals(projectTranspiler, null))
                    {
                        this.SSoTmeProject.Update(projectTranspiler, result);
                    }
                }
            }
        }