Exemplo n.º 1
0
        public void TestSedgwickRuleProcessor()
        {
            const string asiDisabilityAttribute = "ASI:CTA_EMPLOYEE_BEGIN_DISABILITY_DT";

            using (var call = new CallWrapper())
            {
                call.LoadFromDSN("7679", GeneralUtility.GetDsnFromInstance(DbBaseClass.SEDBA));
                var myCall = new CallObject();
                myCall.LoadFromXml(call.GetXML());
                var originalDate = myCall.GetValue(asiDisabilityAttribute);
                //NUnit.Framework.Assert.IsTrue(originalDate.Length == 8, "Bad date format!");
                var records = RuleRecordSet.GetRuleSetByClientAndEvent("18", "CLOSE", "SEDBA");
                NUnit.Framework.Assert.IsTrue(records.Count >= 1, "Problems!");
                foreach (var record in records)
                {
                    var results = Eval.EvaluateCallObject(myCall.ToXml(), record.RuleText);
                    NUnit.Framework.Assert.IsNotEmpty(results, "Nothing returned!");

                    var resultCall = new CallObject();
                    resultCall.LoadFromXml(results);
                    NUnit.Framework.Assert.IsNotEmpty(resultCall.GetValue(asiDisabilityAttribute), "Expected result was not returned!");
                    NUnit.Framework.Assert.IsFalse(originalDate.Equals((resultCall.GetValue(asiDisabilityAttribute))),
                                                   "dates are unchanged!");
                    Console.WriteLine("Original: {0} Transformed: {1}", originalDate, resultCall.GetValue(asiDisabilityAttribute));
                }
            }
        }
Exemplo n.º 2
0
        protected override void DrawOnlyForPrabInScene()
        {
            base.DrawOnlyForPrabInScene();

            EditorLayout.BeginVerticalBox();
            {
                EditorLayout.BeginHorizontal();
                {
                    string status      = CallObject.Pause ? "Resume" : "Pause";
                    var    buttonStyle = new GUIStyle(GUI.skin.button);

                    if (GUILayout.Button(status, buttonStyle, GUILayout.Width(50)))
                    {
                        CallObject.Pause = !CallObject.Pause;
                    }

                    if (GUILayout.Button("Restart", buttonStyle, GUILayout.Width(50)))
                    {
                        CallObject.RestartCurrentLevel();
                    }
                }
                EditorLayout.EndHorizontal();
            }
            EditorLayout.EndVertical();
        }
Exemplo n.º 3
0
        public void TestDatesLogic()
        {
            var myCall      = new CallObject();
            var strTestCall = LoadFileText(@"C:\Documents and Settings\gwynnj\My Documents\call.xml");

            Assert.IsTrue(strTestCall.Length > 0);
            myCall.LoadFromXml(strTestCall);

            var asiNode = myCall["ASI"] as Composite;

            if (asiNode == null)
            {
                return;
            }
            var reg = new Regex("_DT$");

            foreach (CompositeLeaf node in asiNode.GetEnumerator <CompositeLeaf>())
            {
                if (!reg.IsMatch(node.Name) || node.Value.Length <= 0)
                {
                    continue;
                }
                var newDate   = string.Format("{0}{1}{2}", node.Value.Substring(4, 4), node.Value.Substring(0, 2), node.Value.Substring(2, 2));
                var parseDate = string.Format("{0}/{1}/{2}", node.Value.Substring(0, 2), node.Value.Substring(2, 2), node.Value.Substring(4, 4));
                Console.WriteLine("Found Match: {0} Value: {1}", node.Name, node.Value);
                DateTime date;
                if (!DateTime.TryParse(parseDate, out date))
                {
                    continue;
                }
                node.Value = newDate;
                Console.WriteLine("Found Match: {0} Value: {1}", node.Name, node.Value);
            }
        }
Exemplo n.º 4
0
        public void TestEvalwithEmptyCallObject()
        {
            var code = new StringBuilder();

            code.AppendLine("if (_call.LineOfBusiness.Equals(\"PAU\")) {");
            code.AppendLine("\t\t_call.Claim.ClaimNumber = \"123456789\"; }");
            code.AppendLine("else {");
            code.AppendLine("\t\t_call.Claim.SetValue(\"ERRORSTRING\",\"LOB_CD NOT PAU\"); }");

            var eval = new Eval {
                Expression = code.ToString()
            };
            //eval.Parameter = call.ToXml();

            var results = eval.Execute();

            NUnit.Framework.Assert.IsEmpty(eval.LastError, eval.LastError);
            NUnit.Framework.Assert.IsNotEmpty(results, "Nothing returned!");

            var resultCall = new CallObject();

            resultCall.LoadFromXml(results);
            NUnit.Framework.Assert.IsNotEmpty(resultCall.GetValue("LASTERROR"), "Expected error was not returned!");
            Console.WriteLine(resultCall.GetValue("LASTERROR"));
        }
Exemplo n.º 5
0
        private HttpResponseMessage DefaultProcess(CallObject obj)
        {
            var dataManager = MefHelper.Helper.DataAccess;

            object response;

            switch (obj.Method)
            {
            case "single":
                response = dataManager.GetSingle(obj.Target, obj.Parameters, obj.IsCached);
                break;

            case "save":
                response = dataManager.Save(obj.Target, obj.Parameters);
                break;

            case "delete":
                response = dataManager.Delete(obj.Target, obj.Parameters);
                break;

            default:
                response = dataManager.GetList(obj.Target, obj.Parameters, obj.IsCached);
                break;
            }

            return(this.Request.CreateResponse(HttpStatusCode.OK, response));
        }
Exemplo n.º 6
0
        /// <summary>
        /// This method would take the call object
        /// and determine what kind of call to be made to which object
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        ///

        public HttpResponseMessage Post(CallObject obj)
        {
            try
            {
                switch (obj.CallType)
                {
                case "obj":
                    return(this.Request.CreateResponse(HttpStatusCode.OK));

                case "service":
                    return(this.Request.CreateResponse(HttpStatusCode.OK));

                default:
                    return(DefaultProcess(obj));
                }
            }
            catch (Exception ex)
            {
                MefHelper.Error(ex);

                return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpError(ex, true)));

                // return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
        }
Exemplo n.º 7
0
        public void TestNameValues()
        {
            const string accountId = "ACCOUNT_ID";
            const string policyId  = "POLICY_ID";

            _base.SetValue(accountId, "12345");
            _base.SetValue(policyId, "678910");

            var copyCall = new CallObject();

            copyCall.LoadFromXml(_base.ToXml());
            Assert.IsNotEmpty(copyCall.GetValue(accountId));
            Assert.IsNotEmpty(copyCall.GetValue(policyId));
            copyCall.Remove(policyId);
            Assert.IsEmpty(copyCall.GetValue(policyId));

            // subtract method
            var items = _base.ToNameValueCollection();

            foreach (var key in items.AllKeys)
            {
                if (string.IsNullOrEmpty(copyCall.GetValue(key)))
                {
                    _base.Remove(key);
                }
            }
            Assert.IsEmpty(_base.GetValue(policyId));
            Console.WriteLine(_base);
        }
        public ModelInvokeResult <CallObjectPK> Update(string strId, CallObject callObject)
        {
            ModelInvokeResult <CallObjectPK> result = new ModelInvokeResult <CallObjectPK> {
                Success = true
            };

            try
            {
                List <IBatisNetBatchStatement> statements = new List <IBatisNetBatchStatement>();
                /***********************begin 自定义代码*******************/
                int _Id = Convert.ToInt32(strId);
                callObject.OperatedBy = NormalSession.UserId.ToGuid();
                callObject.OperatedOn = DateTime.Now;
                /***********************end 自定义代码*********************/
                statements.Add(new IBatisNetBatchStatement {
                    StatementName = callObject.GetUpdateMethodName(), ParameterObject = callObject.ToStringObjectDictionary(false), Type = SqlExecuteType.UPDATE
                });
                /***********************begin 自定义代码*******************/
                /***********************此处添加自定义代码*****************/
                /***********************end 自定义代码*********************/
                BuilderFactory.DefaultBulder().ExecuteNativeSqlNoneQuery(statements);
                result.instance = new CallObjectPK {
                    Id = _Id
                };
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
    /*
     * create appdomain as usually
     */
    public static object Execute(AppDomain appDomain, Type type, string method, params object[] parameters)
    {
        var call = new CallObject(type, method, parameters);

        appDomain.DoCallBack(call.Execute);
        return(call.GetResult());
    }
Exemplo n.º 10
0
 public void ShowRewardBasedVided(CallObject callObject)
 {
     callEnum = callObject;
     if (this.rewardedAd.IsLoaded())
     {
         this.rewardedAd.Show();
     }
     else
     {
         Debug.Log("Reward based video ad is not ready yet");
     }
 }
Exemplo n.º 11
0
        protected override void DrawOnlyForPrabInScene()
        {
            base.DrawOnlyForPrabInScene();

            AudioClip currentAudioClip = CallObject.CurrentAudioClip;

            EditorLayout.BeginVerticalBox();
            {
                EditorGUILayout.LabelField("Music manager", EditorStyles.boldLabel);

                EditorLayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Total songs: " + CallObject.MusicPlaylistList.Count);
                }
                EditorLayout.EndHorizontal();

                EditorLayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Current song: " + currentAudioClip.name);
                }
                EditorLayout.EndHorizontal();

                EditorLayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(Utility.ConvertTimeToString(CallObject.AudioSource.time) + " / " + Utility.ConvertTimeToString(currentAudioClip.length));
                }
                EditorLayout.EndHorizontal();

                EditorLayout.BeginHorizontal();
                {
                    var buttonStyle = new GUIStyle(GUI.skin.button);
                    if (GUILayout.Button("Play", buttonStyle, GUILayout.Width(50)))
                    {
                        CallObject.Play();
                    }
                    if (GUILayout.Button(CallObject.IsPaused() ? "UnPause" : "Pause", buttonStyle, GUILayout.Width(60)))
                    {
                        CallObject.Pause();
                    }
                    if (GUILayout.Button("Next", buttonStyle, GUILayout.Width(50)))
                    {
                        CallObject.Next();
                    }
                    if (GUILayout.Button("Stop", buttonStyle, GUILayout.Width(50)))
                    {
                        CallObject.Stop();
                    }
                }
                EditorLayout.EndHorizontal();
            }
            EditorLayout.EndVertical();
        }
Exemplo n.º 12
0
 public void Init()
 {
     _call = new CallObject();
     _call.Caller.NameFirst        = "JOHN";
     _call.Caller.NameLast         = "GWYNN";
     _call.Caller.PhoneHome        = "5556667788";
     _call.Caller.Address.Address1 = "529 MAIN STREET";
     _call.Caller.Address.City     = "CHARLESTOWN";
     _call.CallId         = 12345;
     _call.LineOfBusiness = "PAU";
     _call.CarrierCode    = "ESU";
     _call.Instance       = "FNSBA";
     _call.ServerName     = "CHA1ND110";
 }
Exemplo n.º 13
0
        public void TestExecuteServiceMethod()
        {
            var call = new CallObject
            {
                SessionKey = "BJdRMaB+4lZMa8ClLdCGrejStSRXZ2kEacSTppLvwHLWpmBCFmtyX5ViO6DJBRgO"
            };

            call.SetValue("POLICY_ID", "2000000");
            call.SetValue("XPM_USER", "*****@*****.**");
            call.SetValue("USER_NAME", "ESUWEBUSER");
            string results = GeneralUtility.ExecuteMethod("EsuranceServices.ClaimService.ClaimService.GetPolicyXml", call.ToXml());

            Console.WriteLine(results);
        }
Exemplo n.º 14
0
        public void TestNodeCount()
        {
            var call = new CallObject {
                CallId = "12"
            };

            Assert.IsNotEmpty(call.GetValue("CALL_ID"));

            call.SetValue("CLAIM:VEHICLE[0]:VIN", "123456789");
            call.SetValue("CLAIM:VEHICLE[1]:VIN", "123456789");
            call.SetValue("CLAIM:VEHICLE[2]:VIN", "123456789");
            call.SetValue("CLAIM:VEHICLE[3]:VIN", "123456789");

            Assert.IsTrue(call.GetNodeCount("CLAIM:VEHICLE") == 4);
        }
Exemplo n.º 15
0
        public void TestCopyNode()
        {
            var call = new CallObject();

            call.LoadFromXml(_base.ToXml());
            var vehicle = call.GetNode("CLAIM:INSURED:VEHICLE");

            Assert.IsNotNull(vehicle);
            Console.WriteLine(vehicle.ToString());
            var items = vehicle.ToNameValueDictionary();

            foreach (var item in items.Keys)
            {
                Console.WriteLine("{0}={1}", item, items[item]);
            }
        }
Exemplo n.º 16
0
        public void TestCopy()
        {
            const string vehicle = "CLAIM:INSURED:VEHICLE";
            const string vin     = "CLAIM:INSURED:VEHICLE:VIN";
            var          call    = new CallObject();

            call.LoadFromXml(_base.GetXmlTree(vin));
            Assert.IsNotEmpty(call.GetValue(vin), "Nothing returned!");
            Console.WriteLine(call.GetValue(vin));

            call.LoadFromXml(_base.GetXmlTree(vehicle));
            var results = call.ToXml();

            Assert.IsNotEmpty(results, "Nothing returned!");
            Console.WriteLine(results);
        }
Exemplo n.º 17
0
        public void Setup()
        {
            _base = new CallObject();

            var oNode  = new Claim();
            var oNode2 = new Insured();
            var oNode3 = new Vehicle();
            var oNode4 = new Driver();

            _base.Add(oNode);
            oNode.Add(oNode2);
            oNode2.Add(oNode3);
            oNode2.Add(oNode4);

            oNode.SetValue(CallObject.LobCdAttributeName, "WOR");
            oNode.ClaimNumber = "00122345";
            oNode.LossDate    = "12092005";

            oNode2.InsuredName = "Steven Murphy";

            oNode2.SetValue(Address.AddressLine1, "95 Wells Avenue");
            oNode2.SetValue(Address.AddressCity, "Newton");
            oNode2.SetValue(Address.AddressState, "MA");
            oNode2.SetValue(Address.AddressZip, "02459");

            oNode2.PhoneHome = "6178862064";

            oNode3.Make  = "TOYOTA";
            oNode3.Model = "MATRIX";
            oNode3.Vin   = "1234567891011121314";
            oNode3.Year  = "2004";

            oNode4.NameFirst = "Cookie";
            oNode4.NameLast  = " Murphy";

            oNode4.SetValue(Address.AddressLine1, "529 Main Street");
            oNode4.SetValue(Address.AddressCity, "Charlestown");
            oNode4.SetValue(Address.AddressState, "MA");
            oNode4.SetValue(Address.AddressZip, "02129");
            oNode4.SetValue(EntityBase.HomePhoneAttribute, "6178862064");

            _base.Commit();
        }
Exemplo n.º 18
0
        public void TestStaticEvalwithEmptyCallObject()
        {
            var code = new StringBuilder();

            code.AppendLine("if (_call.LineOfBusiness.Equals(\"PAU\")) {");
            code.AppendLine("\t\t_call.Claim.ClaimNumber = \"123456789\"; }");
            code.AppendLine("else {");
            code.AppendLine("\t\t_call.Claim.SetValue(\"ERRORSTRING\",\"LOB_CD NOT PAU\"); }");

            var results = Eval.EvaluateCallObject(string.Empty, code.ToString());

            NUnit.Framework.Assert.IsNotEmpty(results, "Nothing returned!");

            var resultCall = new CallObject();

            resultCall.LoadFromXml(results);
            NUnit.Framework.Assert.IsNotEmpty(resultCall.GetValue("LASTERROR"), "Expected error was not returned!");
            Console.WriteLine(resultCall.GetValue("LASTERROR"));
        }
        public InvokeResult DeleteSelected(string strIds)
        {
            InvokeResult result = new InvokeResult {
                Success = true
            };

            try
            {
                List <IBatisNetBatchStatement> statements = new List <IBatisNetBatchStatement>();
                string[] arrIds = strIds.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (arrIds.Length == 0)
                {
                    result.Success   = false;
                    result.ErrorCode = 59996;
                    return(result);
                }
                string statementName = new CallObject().GetDeleteMethodName();
                foreach (string strId in arrIds)
                {
                    int          _Id = Convert.ToInt32(strId);
                    CallObjectPK pk  = new CallObjectPK {
                        Id = _Id
                    };
                    DeleteCascade(statements, pk);
                    statements.Add(new IBatisNetBatchStatement {
                        StatementName = statementName, ParameterObject = pk, Type = SqlExecuteType.DELETE
                    });
                }
                BuilderFactory.DefaultBulder().ExecuteNativeSqlNoneQuery(statements);
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
Exemplo n.º 20
0
        public void TestJson()
        {
            _base.SetValue("CLAIM:VEHICLE[0]:MAKE", "PLYMOUTH");
            _base.SetValue("CLAIM:VEHICLE[0]:MODEL", "VALIANT");
            _base.SetValue("CLAIM:VEHICLE[1]:MAKE", "DODGE");
            _base.SetValue("CLAIM:VEHICLE[1]:MODEL", "RAM");
            _base.SetValue("CLAIM:VEHICLE[2]:MAKE", "TOYOTA");
            _base.SetValue("CLAIM:VEHICLE[2]:MODEL", "CAMRY");
            _base.Instance      = "TEST";
            _base.CallStartTime = "12:00 PM";
            _base.CallStartDate = "12/12/2008";
            string script = _base.ToJson();

            Console.WriteLine(script);

            var test = new CallObject();

            test.LoadFromJson(script);
            Assert.IsTrue(test.Name == "CALL", "Not working: " + test.Name);

            Assert.IsTrue(test.Instance == "TEST", "Unexpected result INSTANCE!");
            Assert.IsTrue(test.CallStartTime == "12:00 PM", "Unexpected result CALL_START_TIME!");
            Assert.IsTrue(test.CallStartDate == "12/12/2008", "Unexpected result CALL_START_DATE!");
            Assert.IsTrue(test.GetValue("CLAIM:VEHICLE[0]:MODEL") == "VALIANT", "Unexpected result CLAIM:VEHICLE[0]:MODEL!");
            Assert.IsTrue(test.GetValue("CLAIM:VEHICLE[1]:MAKE") == "DODGE", "Unexpected result CLAIM:VEHICLE[1]:MAKE!");
            Assert.IsTrue(test.GetValue("CLAIM:INSURED:VEHICLE:MODEL") == "MATRIX", "Unexpected result CLAIM:INSURED:VEHICLE:MODEL!");
            Assert.IsTrue(test.GetValue("CLAIM:VEHICLE[2]:MODEL") == "CAMRY", "Unexpected result CLAIM:VEHICLE[2]:MODEL!");

            Console.WriteLine(test.ToXml());

            var callObject = Composite.CreateFromJson(script) as CallObject;

            Assert.IsNotNull(callObject, "callObject was null!");
            Assert.IsTrue(callObject.GetType() == typeof(CallObject), "type mismatch");

            Console.WriteLine(callObject.Claim.GetType().ToString());
        }
        protected override void DrawOnlyForPrabInScene()
        {
            base.DrawOnlyForPrabInScene();

            if (this.CallObject.InTransitionSafe())
            {
                EditorLayout.BeginVerticalBox();
                {
                    string status =
                        "RUNNING (" +
                        (CallObject.GetTransitionStatus().TransitionFading ? "Fading" : "Brightening") +
                        ") - " +
                        Mathf.RoundToInt(CallObject.GetTransitionStatus().TransitionPercent * 100) +
                        "%"
                    ;
                    EditorLayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField(status);
                    }
                    EditorLayout.EndHorizontal();
                }
                EditorLayout.EndVertical();
            }
        }
Exemplo n.º 22
0
        public void TestAddress()
        {
            var call        = new CallObject();
            var strTestCall = LoadFileText(@"C:\Documents and Settings\john.gwynn\My Documents\call.xml");

            Assert.IsTrue(strTestCall.Length > 0);
            call.LoadFromXml(strTestCall);

            Assert.IsNotEmpty(call.Claim.Insured.Address.Fips, "Insured Fips is missing!");

            Assert.IsNotEmpty(call.Claim.LossLocation.Address.Address1, "Loss location Address1 is missing!");
            Assert.IsNotEmpty(call.Claim.LossLocation.Address.City, "Loss location City is missing!");
            Assert.IsNotEmpty(call.Claim.LossLocation.Address.State, "Loss location State is missing!");

            call.Claim.Remove("LOSS_LOCATION");

            Assert.IsEmpty(call.Claim.LossLocation.Address.Address1, "Loss location Address1 is not empty!");
            Assert.IsEmpty(call.Claim.LossLocation.Address.City, "Loss location City s not empty!");
            Assert.IsEmpty(call.Claim.LossLocation.Address.State, "Loss location State s not empty!");

            call.Claim.LossLocation.Address.Address1 = "529 Main Street";
            call.Claim.LossLocation.Address.City     = "Charlestown";
            call.Claim.LossLocation.Address.State    = "MA";
            call.Claim.LossLocation.Address.Zip      = "02129";

            Assert.IsNotEmpty(call.GetValue("CLAIM:LOSS_LOCATION:ADDRESS_LINE1"), "Loss location Address1 is missing!");
            Assert.IsNotEmpty(call.GetValue("CLAIM:LOSS_LOCATION:ADDRESS_CITY"), "Loss location City is missing!");
            Assert.IsNotEmpty(call.GetValue("CLAIM:LOSS_LOCATION:ADDRESS_STATE"), "Loss location State is missing!");
            Assert.IsNotEmpty(call.GetValue("CLAIM:LOSS_LOCATION:ADDRESS_ZIP"), "Loss location Zip is missing!");

            Console.WriteLine("{0}\n{1}, {2} {3}",
                              call.Claim.LossLocation.Address.Address1,
                              call.Claim.LossLocation.Address.City,
                              call.Claim.LossLocation.Address.State,
                              call.Claim.LossLocation.Address.Zip);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Tests the claim.
        /// </summary>
        [Test] public void TestClaimInterface()
        {
            //=====================================================
            // we can now directly reference common types as
            // properties of the parent that return the strongly typed
            // node.  I use the CompositeFactory class to create
            // each node from its given type if it exists in this
            // assembly using reflection.
            //=====================================================
            var claim = _base.Claim;

            Assert.IsNotEmpty(claim.ClaimNumber, "Nothing returned from Claim!");
            var insured = claim.Insured;

            Assert.IsNotEmpty(insured.Address.City, "Nothing returned from Address!");
            Assert.IsNotEmpty(insured.Vehicle.Vin, "Nothing returned from Vehicle!");
            //=====================================================
            // create Other vehicle collection
            //=====================================================
            claim.SetValue("VEHICLE[0]:VIN", "123456789");
            claim.SetValue("VEHICLE[0]:MAKE", "AMC");
            claim.SetValue("VEHICLE[0]:MODEL", "Gremlin");
            claim.SetValue("VEHICLE[0]:YEAR", "1999");
            claim.SetValue("VEHICLE[0]:VEHICLE_NUMBER", "1");

            claim.SetValue("VEHICLE[1]:VIN", "A234A234ZZ");
            claim.SetValue("VEHICLE[1]:MAKE", "TOYOTA");
            claim.SetValue("VEHICLE[1]:MODEL", "RAV4");
            claim.SetValue("VEHICLE[1]:YEAR", "2004");
            claim.SetValue("VEHICLE[1]:VEHICLE_NUMBER", "2");

            claim.SetValue("VEHICLE[2]:VIN", "99999999999");
            claim.SetValue("VEHICLE[2]:MAKE", "ACURA");
            claim.SetValue("VEHICLE[2]:MODEL", "LEGEND AE");
            claim.SetValue("VEHICLE[2]:YEAR", "2001");
            claim.SetValue("VEHICLE[2]:VEHICLE_NUMBER", "3");
            claim.SetValue("VEHICLE[2]:TEST", "IT WORKS!");
            //=====================================================
            // we can iterate over each vehicle
            // using the custom iterators defined in composite
            //=====================================================
            foreach (var v in claim.OtherVehicles)
            {
                Console.WriteLine("{0} {1} {2} {3} VIN: {4} {5}", v.VehicleNumber, v.Year, v.Make, v.Model, v.Vin, v.GetValue("TEST"));
            }
            Console.WriteLine("******************************");
            Console.WriteLine(claim.ToXml());
            Console.WriteLine("******************************");
            //=====================================================
            // Test the Xml constructor
            //=====================================================
            var doc = new XmlDocument();

            doc.LoadXml(claim.ToXml());
            var copy = new Claim(doc.DocumentElement);

            copy.SetValue("VEHICLE[2]:TEST", "COPY WORKS TOO!");

            foreach (var v in copy.OtherVehicles)
            {
                Console.WriteLine("{0} {1} {2} {3} VIN: {4} {5}", v.VehicleNumber, v.Year, v.Make, v.Model, v.Vin, v.GetValue("TEST"));
            }
            //=====================================================
            // Test the partial LoadFromXml
            //=====================================================
            var call = new CallObject();

            call.Claim.ReloadFromXML(doc.DocumentElement);
            Console.WriteLine("******************************");
            Console.WriteLine(call.ToXml());
            Console.WriteLine("******************************");
        }
Exemplo n.º 24
0
        public UtilsModule()
        {
            AddCMD("Convert hex to decimal", (sMsg, buffer) =>
            {
                try
                {
                    int val = Convert.ToInt32(buffer.GetRemaining(), 16);
                    sMsg.Channel.SendMessageAsync($"**{val}**");
                }
                catch
                {
                    sMsg.Channel.SendMessageAsync("Couldn't pass text as hex.");
                }
            }, ".hex");

            Commands.Add(new Command("Make the bot say something", (sMsg, buffer) =>
            {
                if (sMsg.MentionedRoles.Count > 0 || sMsg.MentionedUsers.Count > 0)
                {
                    sMsg.Channel.SendMessageAsync("no");
                    return;
                }

                string msg = sMsg.Content.Remove(0, 4);
                if (msg.Contains("@everyone") || msg.Contains("@here"))
                {
                    sMsg.Channel.SendMessageAsync($"no");
                }
                else
                {
                    sMsg.Channel.SendMessageAsync($"{msg}");
                }
            }, ".say")
            {
                IsEnabled = false
            });

            AddCMD("Roll a random number", (sMsg, buffer) =>
            {
                double maxRoll = 100;

                if (double.TryParse(buffer.TakeFirst(), out maxRoll))
                {
                    maxRoll = Math.Abs(maxRoll);
                }
                else
                {
                    maxRoll = 100;
                }

                double roll = Math.Ceiling(Utils.GetRandomDouble() * maxRoll);

                string rollString = $"{sMsg.Author.Mention} :game_die: {roll:F0} :game_die:";

                if (double.IsInfinity(roll))
                {
                    rollString = ":face_with_raised_eyebrow: u trying to kill me?";
                }

                sMsg.Channel.SendMessageAsync(rollString);
            }, ".roll");

            Commands.Add(new Command("Call another server lol", async(sMsg, buffer) =>
            {
                string message = buffer.GetRemaining().Replace("_", " ");

                CallObject activeCall1 = activeCalls.Find((o) => o.Caller == sMsg.Channel.Id);
                CallObject activeCall2 = activeCalls.Find((o) => o.Receiver == sMsg.Channel.Id);
                if (activeCall1 == null && activeCall2 == null)
                {
                    EmbedBuilder builder = new EmbedBuilder();

                    SocketGuild guildToCall = CoreModule.Client.Guilds.ElementAt(Utils.GetRandomNumber(0, CoreModule.Client.Guilds.Count - 1));

                    builder.WithAuthor($"{sMsg.Author.Username} Is calling from {CoreModule.Client.GetGuild(sMsg).Name}", $"{sMsg.Author.GetAvatarUrl()}");
                    builder.WithThumbnailUrl($"{CoreModule.Client.GetGuild(sMsg).IconUrl}");
                    builder.Description = $"With the following message: **{message}**\nDo you want to pick up??";
                    try
                    {
                        var msgSendChannel = guildToCall.TextChannels.First((o) => o.Name.ToLower().StartsWith("general"));

                        await sMsg.Channel.SendMessageAsync($"Found **{msgSendChannel.Guild.Name}**! Waiting for some kind soul to respond...");

                        var msgSend = await msgSendChannel.SendMessageAsync("", false, builder.Build());

                        activeCalls.Add(new CallObject()
                        {
                            Caller = sMsg.Channel.Id, Receiver = msgSend.Channel.Id
                        });

                        await msgSend.AddReactionsAsync(new IEmote[] { new CallAcceptEmote(), new CallDenyEmote() });
                    }
                    catch { await sMsg.Channel.SendMessageAsync("Error lol sad"); }
                }
                else
                {
                    await sMsg.Channel.SendMessageAsync("A call is already active");
                }
            }, ".call")
            {
                IsEnabled = false
            });

            CoreModule.Client.ReactionAdded += async(s, e, x) =>
            {
                if (!x.User.Value.IsBot)
                {
                    var msg = await s.GetOrDownloadAsync();

                    CallObject activeCall = activeCalls.Find((o) => o.Receiver == msg.Channel.Id);
                    if (activeCall != null)
                    {
                        if (x.Emote.Name == new CallAcceptEmote().Name)
                        {
                            activeCall.CallAccepted = true;
                            await(CoreModule.Client.GetChannel(activeCall.Receiver) as IMessageChannel).SendMessageAsync("You have accepted the call now talk!");
                            await(CoreModule.Client.GetChannel(activeCall.Caller) as IMessageChannel).SendMessageAsync("The other party has accepted!");
                        }
                        else if (x.Emote.Name == new CallDenyEmote().Name)
                        {
                            activeCalls.Remove(activeCall);
                            await(CoreModule.Client.GetChannel(activeCall.Receiver) as IMessageChannel).SendMessageAsync("You have closed the call!");
                            await(CoreModule.Client.GetChannel(activeCall.Caller) as IMessageChannel).SendMessageAsync("The other party closed the call!");
                        }
                    }
                }
            };

            CoreModule.OnMessageReceived += (s) =>
            {
                CallObject toSend    = activeCalls.Find((o) => o.Receiver == s.Channel.Id);
                CallObject toReceive = activeCalls.Find((o) => o.Caller == s.Channel.Id);

                if (toSend != null)
                {
                    if (toSend.CallAccepted)
                    {
                        (CoreModule.Client.GetChannel(toSend.Caller) as IMessageChannel).SendMessageAsync($"{s.Author.Username} :speech_balloon: **{s.Content}**");
                    }
                }

                if (toReceive != null)
                {
                    if (toReceive.CallAccepted)
                    {
                        (CoreModule.Client.GetChannel(toReceive.Receiver) as IMessageChannel).SendMessageAsync($"{s.Author.Username} :speech_balloon: **{s.Content}**");
                    }
                }
            };
        }
Exemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RegExprExtractor"/> class.
 /// </summary>
 /// <param name="expression">The expression.</param>
 public RegExprExtractor(string expression)
 {
     _oCall      = new CallObject();
     _name       = String.Empty;
     _expression = expression;
 }
Exemplo n.º 26
0
        public void CallApiAsync(string url, List <Param> post, CallbackDelegate callbackmethod)
        {
            HttpWebRequest request = null;

            try
            {
                url = URLHeader + url;
                string postdata = ChangePostToStr(post);

                string sign    = "";
                string md5str  = "";
                string fmd5str = "";
                if (!string.IsNullOrEmpty(TOKEN) && !string.IsNullOrEmpty(RID))
                {
                    md5str  = url + "~" + postdata + "~" + TOKEN + "~" + RID;
                    fmd5str = md5str;
                    md5str  = md5str.ToUpper();
                    sign    = Utils.MD5Encrypt(md5str + SALT);
                }

                request             = (HttpWebRequest)WebRequest.Create(url);
                request.Credentials = CredentialCache.DefaultCredentials;
                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.Headers.Add("Sign", "sign");
                request.Headers.Add("TokenKey", RID);
                request.Headers.Add("Fmd5str", fmd5str);
                request.Headers.Add("lang", LANG);
                request.AllowAutoRedirect = false;   // 不自动跳转

                if (_cookieContainer != null)
                {
                    request.CookieContainer = _cookieContainer;
                }
                else
                {
                    request.CookieContainer = new CookieContainer();
                    _cookieContainer        = request.CookieContainer;
                }
                request.KeepAlive = true;

                byte[] postdatabytes = Encoding.UTF8.GetBytes(postdata);
                request.ContentLength = postdatabytes.Length;
                Stream stream;
                stream = request.GetRequestStream();

                stream.Write(postdatabytes, 0, postdatabytes.Length);
                stream.Close();

                CallObject call = new CallObject(callbackmethod, this, url, post);

                request.BeginGetResponse(new AsyncCallback(call.GetResponseCallback), request);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                request.Abort();
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddressExtractor"/> class.
 /// </summary>
 public AddressExtractor()
 {
     _call        = new CallObject();
     _curentIndex = 0;
     _name        = String.Empty;
 }