Пример #1
0
        private void StartTranspile()
        {
            this.AccountHolder = new SMQAccountHolder();
            var currentSSoTmeKey = SSOTMEKey.GetSSoTmeKey(this.runAs);

            result = null;

            this.AccountHolder.ReplyTo += AccountHolder_ReplyTo;
            this.AccountHolder.Init(currentSSoTmeKey.EmailAddress, currentSSoTmeKey.Secret);


            var waitForCook = Task.Factory.StartNew(() =>
            {
                while (ReferenceEquals(result, null))
                {
                    Thread.Sleep(100);
                }
            });

            waitForCook.Wait(this.waitTimeout);

            if (ReferenceEquals(result, null))
            {
                result           = AccountHolder.CreatePayload();
                result.Exception = new TimeoutException("Timed out waiting for cook");
            }
            result.SSoTmeProject = this.SSoTmeProject;
        }
Пример #2
0
 private void PublicUser_ReplyTo(object sender, PayloadEventArgs <SSOTMEPayload> e)
 {
     if (e.Payload.IsLexiconTerm(LexiconTermEnum.publicuser_ping_ssotmecoordinator))
     {
         this.CoordinatorProxy = new DMProxy(e.Payload.DirectMessageQueue);
         var payload = this.PublicUser.CreatePayload();
         payload.EmailAddress = this.emailAddress;
         this.PublicUser.PublicUserAuthenticate(payload, this.CoordinatorProxy);
     }
     else if (e.Payload.IsLexiconTerm(LexiconTermEnum.publicuser_authenticate_ssotmecoordinator))
     {
         Console.WriteLine("We sent an auth key to {0}.", e.Payload.EmailAddress);
         Console.Write("AUTH Code: ");
         e.Payload.AuthToken = Console.ReadLine();
         if (!String.IsNullOrEmpty(e.Payload.AuthToken))
         {
             Console.WriteLine("Validating AUTH Code.  One moment...");
             this.PublicUser.PublicUserValidateAuthToken(e.Payload, this.CoordinatorProxy);
         }
         else
         {
             Console.WriteLine("Aborting. No AUTH Code recieved.");
         }
     }
     else if (e.Payload.IsLexiconTerm(LexiconTermEnum.publicuser_validateauthtoken_ssotmecoordinator))
     {
         if (String.IsNullOrEmpty(e.Payload.Secret))
         {
             Console.WriteLine("AUTH Code Validated Failed.");
         }
         else
         {
             Console.WriteLine("AUTH Code Validated.");
             try
             {
                 var key = SSOTMEKey.GetSSoTmeKey(this.account);
                 key.EmailAddress = e.Payload.EmailAddress;
                 key.Secret       = e.Payload.Secret;
                 SSOTMEKey.SetSSoTmeKey(key, this.account);
             }
             catch (Exception ex)
             {
                 Console.WriteLine("ERROR: {0}", ex.Message);
             }
         }
         Console.WriteLine("Press enter to continue.");
         Console.ReadLine();
         this.PublicUser.Disconnect();
     }
 }
Пример #3
0
        private void ParseCommand()
        {
            try
            {
                CommandLineParser parser = new CommandLineParser(this);
                if (!String.IsNullOrEmpty(this.commandLine))
                {
                    parser.Parse(this.commandLine, false);
                }
                else
                {
                    parser.Parse(this.args, false);
                }

                this.HasRemainingArguments = parser.RemainingArguments.Any();

                bool continueToLoad = false;

                if (String.IsNullOrEmpty(this.transpiler))
                {
                    this.transpiler = parser.RemainingArguments.FirstOrDefault().SafeToString();
                    if (this.transpiler.Contains("/"))
                    {
                        this.account    = this.transpiler.Substring(0, this.transpiler.IndexOf("/"));
                        this.transpiler = this.transpiler.Substring(this.transpiler.IndexOf("/") + 1);
                    }
                }

                var additionalArgs = parser.RemainingArguments.Skip(1).ToList();
                for (var i = 0; i < additionalArgs.Count; i++)
                {
                    this.parameters.Add(String.Format("param{0}={1}", i + 1, additionalArgs[i]));
                }

                if (this.help)
                {
                    Console.WriteLine(parser.UsageInfo.GetHeaderAsString(78));

                    Console.WriteLine("\n\nSyntax: ssotme [account/]transpiler [Options]\n\n");

                    Console.WriteLine(parser.UsageInfo.GetOptionsAsString(78));
                    this.SuppressTranspile = true;
                }
                else if (this.init)
                {
                    if (String.IsNullOrEmpty(this.projectName))
                    {
                        this.projectName = Path.GetFileName(Environment.CurrentDirectory);
                    }

                    var force = this.args.Count() == 2 &&
                                this.args[1] == "force";

                    SSoTmeProject.Init(force, this.projectName);

                    continueToLoad = true;
                    this.build     = true;
                }
                else if (parser.HasErrors)
                {
                    var curColor = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(parser.UsageInfo.GetErrorsAsString(78));
                    this.ParseResult        = -1;
                    Console.ForegroundColor = curColor;
                    this.SuppressTranspile  = true;
                }
                else if (this.authenticate || this.register)
                {
                    continueToLoad = false;
                }
                else
                {
                    continueToLoad = true;
                }

                // Check for api keys

                if (continueToLoad)
                {
                    if (String.IsNullOrEmpty(this.setAccountAPIKey) && !this.help && !this.register && !this.authenticate)
                    {
                        this.SSoTmeProject = SSoTmeProject.LoadOrFail(new DirectoryInfo(Environment.CurrentDirectory), false);

                        foreach (var projectSetting in this.SSoTmeProject.ProjectSettings)
                        {
                            if (!this.parameters.Any(anyParam => anyParam.StartsWith(String.Format("{0}=", projectSetting.Name))))
                            {
                                this.parameters.Add(String.Format("{0}={1}", projectSetting.Name, projectSetting.Value));
                            }
                        }
                    }

                    this.LoadInputFiles();

                    var key = SSOTMEKey.GetSSoTmeKey(this.runAs);
                    if (key.APIKeys.ContainsKey(this.account))
                    {
                        this.parameters.Add(String.Format("apiKey={0}", key.APIKeys[this.account]));
                    }

                    if (!ReferenceEquals(this.FileSet, null))
                    {
                        this.ZFSFileSetFile = this.FileSet.FileSetFiles.FirstOrDefault(fodFileSetFile => fodFileSetFile.RelativePath.EndsWith(".zfs", StringComparison.OrdinalIgnoreCase));
                    }
                }
            }
            catch (Exception ex)
            {
                var curColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;

                Console.WriteLine("\n********************************\nERROR: {0}\n********************************\n\n", ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine("\n\nPress any key to continue...\n");
                Console.WriteLine("\n\n");
                Console.ForegroundColor = curColor;

                Console.ReadKey();
            }
        }
Пример #4
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);
                    }
                }
            }
        }