예제 #1
0
파일: Program.cs 프로젝트: gliljas/sfcat
        static Dictionary <string, string> readSwitches(string[] args, int index, out Intention intention)
        {
            intention = null;
            Dictionary <string, string> ret = new Dictionary <string, string>();
            string switchKey = "";

            for (int i = index; i < args.Length; i++)
            {
                if (string.IsNullOrEmpty(switchKey))
                {
                    if (args[i].StartsWith("--"))
                    {
                        switchKey = args[i].Substring(2);
                    }
                    else if (args[i].StartsWith("-"))
                    {
                        switchKey = args[i].Substring(1);
                    }
                    else
                    {
                        intention = new Intention {
                            Commands = { new CreateHelpCommand() }
                        };
                        return(ret);
                    }
                }
                else
                {
                    ret[switchKey] = args[i];
                    switchKey      = "";
                }
            }
            ret.Add("CatalogServiceEndpoint", ConfigurationManager.AppSettings["CatalogServiceEndpoint"]);
            return(ret);
        }
예제 #2
0
 protected override Intention CheckSwitches(Intention intention = null)
 {
     if (!mySwitches.ContainsKey("file") && !mySwitches.ContainsKey("f"))
     {
         return new Intention {
                    Commands = { new CreateServiceInstanceHelpCommand() }
         }
     }
     ;
     return(base.CheckSwitches(new Intention {
         Commands = { new CreateServiceInstanceHelpCommand() }
     }));
 }
예제 #3
0
 protected override Intention CheckSwitches(Intention intention = null)
 {
     if (!mySwitches.ContainsKey("file") && !mySwitches.ContainsKey("f") ||
         (!mySwitches.ContainsKey("instance-id") || string.IsNullOrEmpty(mySwitches["instance-id"])))
     {
         return new HelpConclusion {
                    Commands = { new CreateBindingHelpCommand() }
         }
     }
     ;
     return(base.CheckSwitches(new Intention {
         Commands = { new CreateBindingHelpCommand() }
     }));
 }
예제 #4
0
 protected override Intention CheckSwitches(Intention intention = null)
 {
     if (!mySwitches.ContainsKey("id") || string.IsNullOrEmpty(mySwitches["id"]))
     {
         if (intention != null)
         {
             return(intention);
         }
         else
         {
             throw new InvalidOperationException("The 'id' field is missing from switches.");
         }
     }
     return(base.CheckSwitches(intention));
 }
예제 #5
0
 protected override Intention RunCommand()
 {
     try
     {
         string    content   = BuildPayload();
         Intention intention = CheckPayload(content);
         if (intention != null)
         {
             return(intention);
         }
         CatalogServiceClient.CatalogServiceClient.PutEntityAsync(mySwitches["CatalogServiceEndpoint"], mEntityType, mySwitches["id"], content).Wait();
         return(new SuccessConclusion("Entity created."));
     }
     catch (Exception exp)
     {
         return(new ExceptionConclusion(exp));
     }
 }
예제 #6
0
 protected override Intention CheckSwitches(Intention intention = null)
 {
     if (!mySwitches.ContainsKey("id") || string.IsNullOrEmpty(mySwitches["id"]))
     {
         if (intention != null)
         {
             return(intention);
         }
         else
         {
             return new HelpConclusion {
                        Commands = new List <Command> {
                            new DeleteHelpCommand()
                        }
             }
         };
     }
     return(base.CheckSwitches(intention));
 }
예제 #7
0
파일: Program.cs 프로젝트: gliljas/sfcat
        static Intention GetUserIntention(string[] args)
        {
            Intention help = null;

            if (args == null || args.Length == 0)
            {
                return(new Intention
                {
                    Commands = { new LogoCommand(), new HelpCommand() }
                });
            }
            else
            {
                switch (args[0].ToLower())
                {
                case "get":
                    if (args.Length == 1)
                    {
                        return new Intention {
                                   Commands = { new ListSettingsCommand() }
                        }
                    }
                    ;
                    if (args.Length == 2)
                    {
                        switch (args[1].ToLower())
                        {
                        case "namespace":
                        case "ns":
                            return(new Intention {
                                Commands = { new GetSettingCommand("Namespace") }
                            });

                        case "cs":
                            return(new Intention {
                                Commands = { new GetSettingCommand("CatalogServiceEndpoint") }
                            });

                        default:
                            return(new Intention {
                                Commands = { CreateCommand(args[1], args[1], null) }
                            });
                        }
                    }
                    else if (args.Length == 3)
                    {
                        return new Intention {
                                   Commands = { CreateCommand(args[1], args[1], args[2]) }
                        }
                    }
                    ;
                    else
                    {
                        return new Intention {
                                   Commands = { new HelpCommand() }
                        }
                    };

                case "update":
                    if (args.Length >= 2)
                    {
                        switch (args[1].ToLower())
                        {
                        case "si":
                        case "service-instance":
                            var iSwitches = readSwitches(args, 2, out help);
                            OSBSchemaChecker schemaChecker = new ServiceInstanceSchemaChecker(ConfigurationManager.AppSettings["CatalogServiceEndpoint"]);
                            if (help != null)
                            {
                                return(help);
                            }
                            else
                            {
                                return new Intention {
                                           Commands = { new UpdateServiceInstanceCommand(iSwitches, schemaChecker) }
                                }
                            };

                        default:
                            return(new Intention {
                                Commands = { new UpdateServiceInstanceHelpCommand() }
                            });
                        }
                    }
                    else
                    {
                        return new Intention {
                                   Commands = { new CreateHelpCommand() }
                        }
                    };

                case "create":
                    if (args.Length >= 2)
                    {
                        switch (args[1].ToLower())
                        {
                        case "bk":
                        case "broker":
                            var rSwitches = readSwitches(args, 2, out help);
                            if (help != null)
                            {
                                return(help);
                            }
                            else
                            {
                                return new Intention {
                                           Commands = { new CreateBrokerCommand(rSwitches) }
                                }
                            };

                        case "si":
                        case "service-instance":
                            var iSwitches = readSwitches(args, 2, out help);
                            OSBSchemaChecker schemaChecker = new ServiceInstanceSchemaChecker(ConfigurationManager.AppSettings["CatalogServiceEndpoint"]);
                            if (help != null)
                            {
                                return(help);
                            }
                            else
                            {
                                return new Intention {
                                           Commands = { new CreateServiceInstanceCommand(iSwitches, schemaChecker) }
                                }
                            };

                        case "bd":
                        case "binding":
                            var bSwitches = readSwitches(args, 2, out help);
                            if (help != null)
                            {
                                return(help);
                            }
                            else
                            {
                                return new Intention {
                                           Commands = { new CreateBindingCommand(bSwitches) }
                                }
                            };

                        default:
                            return(new Intention {
                                Commands = { new CreateHelpCommand() }
                            });
                        }
                    }
                    else
                    {
                        return new Intention {
                                   Commands = { new CreateHelpCommand() }
                        }
                    };

                case "delete":
                    if (args.Length == 4)
                    {
                        switch (args[1].ToLower())
                        {
                        case "si":
                        case "service-instance":
                            var sSwitches = readSwitches(args, 2, out help);
                            if (help != null)
                            {
                                return(help);
                            }
                            else
                            {
                                return new Intention {
                                           Commands = { new DeleteServiceInstanceCommand(sSwitches) }
                                }
                            };

                        case "bd":
                        case "binding":
                            var bSwitches = readSwitches(args, 2, out help);
                            if (help != null)
                            {
                                return(help);
                            }
                            else
                            {
                                return new Intention {
                                           Commands = { new DeleteBindingCommand(bSwitches) }
                                }
                            };

                        default:
                            return(new Intention {
                                Commands = { new DeleteHelpCommand() }
                            });
                        }
                    }
                    else
                    {
                        return new Intention {
                                   Commands = { new DeleteHelpCommand() }
                        }
                    };

                case "watch":
                    if (args.Length == 3)
                    {
                        switch (args[1].ToLower())
                        {
                        case "si":
                        case "service-instance":
                            var sSwitches = readSwitches(args, 3, out help);
                            if (help != null)
                            {
                                return(help);
                            }
                            else
                            {
                                return new Intention {
                                           Commands = { new ObserveServiceInstanceCommand("service-instance", args[2], sSwitches) }
                                }
                            };

                        default:
                            return(new Intention {
                                Commands = { new HelpCommand() }
                            });
                        }
                    }
                    else
                    {
                        return new Intention {
                                   Commands = { new HelpCommand() }
                        }
                    };

                case "demo":
                    if (args.Length == 2)
                    {
                        switch (args[1].ToLower())
                        {
                        case "osb":
                            return(new Intention {
                                Commands = { new DemoOSBCommand() }
                            });

                        default:
                            return(new Intention {
                                Commands = { new HelpCommand() }
                            });
                        }
                    }
                    else
                    {
                        return new Intention {
                                   Commands = { new HelpCommand() }
                        }
                    };

                case "set":
                    if (args.Length == 3)
                    {
                        switch (args[1].ToLower())
                        {
                        case "ns":
                        case "namespace":
                            return(new Intention {
                                Commands = { new SetSettingCommand("Namespace", args[2]) }
                            });

                        case "cs":
                            return(new Intention {
                                Commands = { new SetSettingCommand("CatalogServiceEndpoint", args[2]) }
                            });

                        default:
                            return(new Intention {
                                Commands = { new SetSettingCommand(args[1], args[2]) }
                            });
                        }
                    }
                    else
                    {
                        return new Intention {
                                   Commands = { new SetHelpCommand() }
                        }
                    };

                default:
                    return(new Intention {
                        Commands = { new HelpCommand() }
                    });
                }
            }
        }
예제 #8
0
 protected virtual Intention CheckSwitches(Intention intention = null)
 {
     return(null);
 }