Example #1
0
        public override void Run()
        {
            var appContext = AppContext.Default;

            Utils.VerifyLogin(appContext);

            var group = appContext.YamsterCache.GetGroupById(this.GroupId, nullIfMissing: true);

            if (group == null)
            {
                throw new InvalidOperationException("The group #" + this.GroupId
                                                    + " was not found in Yamster's database; you may need to sync it first");
            }
            var newMessage = YamsterNewMessage.CreateNewThread(group);

            newMessage.Body = this.Body;

            Utils.Log("Posting message...");

            Task <YamsterMessage> task = appContext.YamsterCache.PostMessageAsync(newMessage);

            ForegroundSynchronizationContext.RunSynchronously(task);
            var postedMessage = task.Result;

            Utils.Log("Successfully posted with MessageId={0}", postedMessage.MessageId);
        }
Example #2
0
        static void Main(string[] args)
        {
            Commands = new Command[] {
                new DeleteSyncedThreadsCommand(),
                new LoadCsvDumpCommand(),
                new PostMessageCommand(),
                new SetGroupSyncCommand(),
                new SyncCommand()
            };

            try
            {
                Utils.Log("");
                Utils.Log("YamsterCmd - Command Line for Yamster!");
                Utils.Log("Version {0}", Utilities.YamsterVersion);

                Debug.WriteLine("Parsing Command Line: " + string.Join(" ", args));

                if (args.Length == 0)
                {
                    ShowGeneralHelp();
                    return;
                }

                for (int i = 0; i < args.Length; ++i)
                {
                    var arg = args[i];
                    switch (arg.ToUpperInvariant())
                    {
                    case "/?":
                    case "-?":
                    case "/HELP":
                    case "-HELP":
                        if (i == 0 && i + 1 < args.Length)
                        {
                            var helpCommand = ParseCommand(args[i + 1]);
                            Utils.Log("");
                            Utils.Log("ABOUT THE {0} COMMAND:", helpCommand.CommandId.ToString().ToUpper());
                            Utils.Log("");
                            helpCommand.ShowHelp(detailed: true);
                        }
                        else
                        {
                            ShowGeneralHelp();
                        }
                        return;
                    }
                }

                var command = ParseCommand(args[0]);

                string parseError = command.Parse(args.Skip(1).ToList());

                if (parseError != null)
                {
                    Utils.LogError(parseError);
                    Utils.Log("");
                    Utils.Log("  (Use \"YamsterCmd -Help\" to see usage instructions.)");
                    return;
                }

                Utils.Log("");

                AppContext.InitializeDefaultInstance();

                AppContext.Default.ConnectDatabase(
                    (sender, eventArgs) => {
                    Utils.Log(eventArgs.GetUpgradeMessage());
                },
                    (sender, eventArgs) => {
                    Utils.Log("The upgrade completed successfully.\r\n");
                }
                    );

                PollingSynchronizationContext.Install(AppContext.Default);

                command.Run();

                // Finish any remaining async work
                while (ForegroundSynchronizationContext.ProcessAsyncTasks())
                {
                }
            }
            catch (Exception ex)
            {
                Utils.Log("");
                Utils.LogError(ex.Message);
            }
            finally
            {
                AppContext.UninitializeDefaultInstance();
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
        }