Exemplo n.º 1
0
 public InfoPlusServices(string workflow)
 {
     this.App = ApplicationSettings.FindApp(workflow);
     if (null == this.App)
     {
         throw new Exception("INVALID_APP");
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Default contructor
 /// </summary>
 public InfoPlusServices(InfoPlusApplication app)
 {
     this.App = app;
     if (null == this.App)
     {
         throw new Exception("INVALID_APP");
     }
 }
Exemplo n.º 3
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            lock (_lock)
            {
                // 1. Parse services we invoke.
                var    nodes     = section.SelectNodes("services");
                string serviceId = (string)this.parseAttribute <string>(nodes[0], "identification", null);
                // default domain
                ApplicationSettings._DEFAULT_DOMAIN = (string)this.parseAttribute <string>(nodes[0], "domain", "localhost");
                // auth endpoint
                string _AuthEndPoint = (string)this.parseAttribute <string>(nodes[0], "authorize", null);
                // for "Insecure" sevice type only
                ApplicationSettings._INFOPLUS_MAGIC = (string)this.parseAttribute <string>(nodes[0], "secret", "INFOPLUS_MAGIC");

                // service type
                var typeAttr = nodes[0].Attributes["type"];
                ApplicationSettings._ServiceType = ServiceType.Entitle;
                var sType = null == typeAttr ? string.Empty : typeAttr.Value;
                if (Enum.IsDefined(typeof(ServiceType), sType))
                {
                    ApplicationSettings._ServiceType = (ServiceType)Enum.Parse(typeof(ServiceType), sType, true);
                }

                nodes    = section.SelectNodes("services/service");
                SERVICES = new List <EndPointDescription>();
                foreach (XmlNode s in nodes)
                {
                    EndPointDescription ep = new EndPointDescription();
                    ep.Identification = serviceId;
                    ep.Address        = s.Attributes["address"].Value;
                    SERVICES.Add(ep);
                    if ((bool)this.parseAttribute <bool>(nodes[0], "trustAllCert", false))
                    {
                        ServicePointManager.ServerCertificateValidationCallback = TrustAllCertHandler;
                    }
                }

                // let's choose one.
                int i = DICE.Next(ApplicationSettings.SERVICES.Count);
                ApplicationSettings.SERVICE = ApplicationSettings.SERVICES[i];

                // 2. Parse messengers we provide.
                nodes = section.SelectNodes("messengers");
                // compatable 1
                if (null == nodes || nodes.Count == 0)
                {
                    nodes = section.SelectNodes("workflows/workflow");
                }

                ApplicationSettings.MESSENGERS = new List <AbstractMessenger>();
                foreach (XmlNode ms in nodes)
                {
                    string subscriber          = (string)this.parseAttribute <string>(ms, "address", null);
                    bool   requireVerification = (bool)this.parseAttribute <bool>(ms, "requireVerification", true);
                    var    code       = (string)this.parseAttribute <string>(ms, "code", null);
                    var    secret     = (string)this.parseAttribute <string>(ms, "secret", null);
                    var    scope      = (string)this.parseAttribute <string>(ms, "scope", null);
                    var    release    = (bool)this.parseAttribute <bool>(ms, "release", true);
                    var    minVersion = (long)this.parseAttribute <long>(ms, "minVersion", 0);
                    var    maxVersion = (long)this.parseAttribute <long>(ms, "maxVersion", long.MaxValue);

                    // compatable 2
                    if (string.IsNullOrEmpty(code) && ApplicationSettings.ServiceType != ServiceType.Entitle)
                    {
                        throw new ConfigurationErrorsException("workflow code is not set.", ms);
                    }
                    InfoPlusApplication app = null;
                    if (null != code)
                    {
                        app = new InfoPlusApplication(code, secret, scope, _AuthEndPoint, release, minVersion, maxVersion);
                        ApplicationSettings.workflows[app.FullCode] = app;
                    }
                    foreach (XmlNode m in ms)
                    {
                        string type = m.Attributes["type"].Value;

                        InfoPlusApplication appOverride = null;
                        var code2       = (string)this.parseAttribute <string>(m, "workflow", null);
                        var secret2     = (string)this.parseAttribute <string>(m, "secret", null);
                        var scope2      = (string)this.parseAttribute <string>(m, "scope", null);
                        var release2    = (bool)this.parseAttribute <bool>(m, "release", true);
                        var minVersion2 = (long)this.parseAttribute <long>(m, "minVersion", 0);
                        var maxVersion2 = (long)this.parseAttribute <long>(m, "maxVersion", long.MaxValue);

                        if (false == string.IsNullOrEmpty(code2))
                        {
                            appOverride = new InfoPlusApplication(code2, secret2, scope2, _AuthEndPoint, release2, minVersion2, maxVersion2);
                            ApplicationSettings.workflows[appOverride.FullCode] = appOverride;
                        }

                        if (null == app && null == appOverride)
                        {
                            throw new ConfigurationErrorsException("app not set.", ms);
                        }

                        // Cache timeout
                        int timeout = (int)this.parseAttribute <int>(m, "timeout", 0);
                        if (timeout < 0)
                        {
                            timeout = 10;
                        }

                        if (string.IsNullOrEmpty(subscriber))
                        {
                            continue;
                        }
                        string[] splits   = type.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);;
                        string   assembly = "App_Code";
                        if (splits.Length > 1)
                        {
                            assembly = splits[1];
                        }
                        AbstractMessenger messenger = (AbstractMessenger)Assembly.Load(assembly).CreateInstance(splits[0]);
                        messenger.Subscriber          = subscriber;
                        messenger.Workflow            = app ?? appOverride;
                        messenger.RequireVerification = requireVerification;
                        messenger.Timeout             = timeout;
                        ApplicationSettings.MESSENGERS.Add(messenger);
                        System.Diagnostics.Trace.WriteLine("Create messenger:" + type);
                    }
                }
                // 3.Mashups
                nodes   = section.SelectNodes("mashups");
                mashups = new Dictionary <string, string>();
                foreach (XmlNode ms in nodes)
                {
                    string bs = ms.Attributes["base"].Value;
                    foreach (XmlNode m in ms)
                    {
                        string key = m.Attributes["key"].Value;
                        string val = m.Attributes["value"].Value;
                        mashups[key] = bs + val;
                    }
                }
                // return nothing. we'v already saved this section to ApplicationSettings.
                return(null);
            }
        }