Beispiel #1
0
        public override void Collided(Model with, Displayable.CollisionStatus status)
        {
            if (status == Displayable.CollisionStatus.TOP) return; //lol???
            if (status == Displayable.CollisionStatus.BOTTOM)
            {
                DisableFreeFall();
                this.Velocity = new Velocity();
                return;
            }

            if (with.GetType() == typeof(Wall))
            {
                mBlockedWallId = with.ModelId;
                return;
            }

            if (with.GetType() != typeof(Character))
            {
                return;
            }

            if (mBlockedWallId != -1) return;

            if (status == Displayable.CollisionStatus.LEFT)
            {
                this.mPosition.X = with.Left - this.Origin.X;
            }
            else if (status == Displayable.CollisionStatus.RIGHT)
            {
                this.mPosition.X = with.Right + this.Origin.X;
            }
        }
 public static View.IDisplayItem produce(Model.IStoryContent storyContent)
 {
     if (storyContent.GetType().Equals(typeof(Model.RssStoryContent))) {
         Model.RssStoryContent rssStoryContent = (Model.RssStoryContent)storyContent;
         return new View.RssDisplayStory(rssStoryContent.Title, rssStoryContent.Description, rssStoryContent.Published, rssStoryContent.Link);
     }
     else if (storyContent.GetType().Equals(typeof(Model.AtomStoryContent))) {
         Model.AtomStoryContent atomStoryContent = (Model.AtomStoryContent)storyContent;
         return new View.AtomDisplayStory(atomStoryContent.Title, atomStoryContent.Summary, atomStoryContent.Updated, atomStoryContent.Link);
     }
     else
     {
         throw new Exception("Cannot display unsupported news content");
     }
 }
        public Handlers.Jobs.IJobRunner GetRunnerFor( Model.Job job )
        {
            var jt = job.GetType();
            var generic = typeof( IJobRunner<> );
            var runner = generic.MakeGenericType( jt );

            return ( IJobRunner )this.container.GetService( runner );
        }
        public Handlers.Tasks.IJobTaskRunner GetRunnerFor( Model.JobTask task )
        {
            var tt = task.GetType();
            var generic = typeof( IJobTaskRunner<> );
            var runner = generic.MakeGenericType( tt );

            return ( IJobTaskRunner )this.container.GetService( runner );
        }
        public IJobTaskWorker GetWorkerFor( Model.JobTask task )
        {
            var tt = task.GetType();
            var generic = typeof( IJobTaskWorker<> );
            var worker = generic.MakeGenericType( tt );

            return ( IJobTaskWorker )this.container.GetService( worker );
        }
        public override void NotColliding(Model with)
        {
            if (with.GetType() != typeof(Character)) return;
            Character chara = (Character)with;
            if (mPlayerIndex != (PlayerIndex)chara.Index) return;

            mDoorStatus = DoorStatus.CLOSED;
        }
Beispiel #7
0
 // POST api/clientes
 public void Post(Model.Cidade model)
 {
     using (TextWriter textWriter = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(string.Format("~/XMLFiles/{0}.xml", ((Model.Cidade)model).Codigo.ToString()))))
     {
         XmlSerializer serializer = new XmlSerializer(model.GetType(), new XmlRootAttribute("Cidade"));
         serializer.Serialize(textWriter, model);
     }
 }
        public IJobWorker GetWorkerFor( Model.Job job )
        {
            var jt = job.GetType();
            var generic = typeof( IJobWorker<> );
            var worker = generic.MakeGenericType( jt );

            return ( IJobWorker )this.container.GetService( worker );
        }
        public override void Collided(Model with, Displayable.CollisionStatus status)
        {
            if (status == Displayable.CollisionStatus.TOP) return;
            if (with.GetType() != typeof(Character)) return;
            Character chara = (Character)with;
            if (mPlayerIndex != (PlayerIndex)chara.Index) return;

            mDoorStatus = DoorStatus.OPEN;
        }
Beispiel #10
0
        /// <summary>
        /// 生成插入语句
        /// </summary>
        /// <param name="model">模型对象</param>
        /// <returns></returns>
        public virtual string BuildInsertSQL(Model.Model model)
        {
            List<string> fileds = new List<string>();
            List<string> values = new List<string>();
            var propertys = model.GetType().GetProperties();
            var identity = model.getIdentify();
            foreach (var p in propertys)
            {
                if (!Magic.Mvc.Equals.IsNull(identity) && identity.Name == p.Name) continue;

                var notmaps = p.GetCustomAttributes(typeof(Model.NotMapingAttribute), false);
                if (notmaps != null && notmaps.Length > 0) continue;

                fileds.Add(string.Format("[{0}]", p.Name));
                values.Add(string.Format("@{0}", p.Name));
            }

            return string.Format(" INSERT INTO [{0}]({1}) VALUES({2}) ", model.GetType().Name, string.Join(",", fileds.ToArray()), string.Join(",", values.ToArray()));
        }
Beispiel #11
0
        /// <summary>
        /// 获取sql参数
        /// </summary>
        /// <returns></returns>
        public virtual IDataParameter[] GetParameters(Model.Model model)
        {
            var propertys = model.GetType().GetProperties();

            List<IDataParameter> listSQLParamter = new List<IDataParameter>();
            foreach (var p in propertys)
            {
                listSQLParamter.Add(new SqlParameter() { ParameterName = p.Name, Value = model.Property(p.Name) });
            }
            return listSQLParamter.ToArray();
        }
        public void Example_from_property_should_return_an_empty_string()
        {
            Model m = new Model() { String = "foo" };
            var pi = m.GetType().GetProperty("String");
            //arrange

            //act
            var result = _conventions.ExampleForPropertyConvention(pi);

            //assert
            Assert.AreEqual("", result);
        }
Beispiel #13
0
 public override void Collided(Model with, Displayable.CollisionStatus status)
 {
     if (ProjectHelper.IsDebugNoKill) return;
     if (status != Displayable.CollisionStatus.BOTTOM) return;
     if (with.IsDestroyed) return;
     if (with.GetType() != typeof(Character)) return;
     Character chara = (Character)with;
     if (chara.CharacterPlayerIndex == mPlayerIndex || mPlayerIndex == PlayerIndex.Three)
     {
         with.Destroy();
     }
 }
        public void Label_from_property_should_return_the_property_name()
        {
            Model m = new Model() { String = "foo" };
            var pi = m.GetType().GetProperty("String");
            //arrange

            //act
            var result = _conventions.LabelForPropertyConvention(pi);

            //assert
            Assert.AreEqual("String", result);
        }
        public void Label_from_property_should_return_the_example()
        {
            Model m = new Model() { Enum = Foo.Bar };
            var pi = m.GetType().GetProperty("Enum");
            //arrange

            //act
            var result = _conventions.LabelForPropertyConvention(pi);

            //assert
            Assert.AreEqual("label", result);
        }
        public void Model_is_invalid_should_return_true()
        {
            Model m = new Model() { String = "foo" };
            var pi = m.GetType().GetProperty("String");
            //arrange
            var helper = InputModelPropertyFactoryTester.CreateHelper(m);
            helper.ViewData.ModelState.AddModelError("String","foo bar");
            //act
            var result = _conventions.ModelIsInvalidConvention(pi, helper);

            //assert
            Assert.IsTrue(result);
        }
Beispiel #17
0
        /// <summary>
        /// 生成删除语句
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual string BuildDeleteSQL(Model.Model model)
        {
            List<string> wheres = new List<string>();
            var primarys = model.getPrimaryKeys();
            foreach (var p in primarys)
            {
                var notmaps = p.GetCustomAttributes(typeof(Model.NotMapingAttribute), false);
                if (notmaps != null && notmaps.Length > 0) continue;

                wheres.Add(string.Format("[{0}]=@{0}", p.Name));
            }

            return string.Format(" DELETE FROM [{0}]  WHERE {1}", model.GetType().Name, string.Join(" and ", wheres.ToArray()));
        }
        protected virtual void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (_validationErrors.ContainsKey(e.PropertyName))
            {
                _validationErrors.Remove(e.PropertyName);
                HasErrors = _validationErrors.Count > 0;
                RaiseErrorsChanged(e.PropertyName);
            }
            var property = Model?.GetType().GetProperty(e.PropertyName);

            if (property != null)
            {
                IsChanged = true;
            }
        }
Beispiel #19
0
 public Type HolderType() => Model == null ? Accessor.DeclaringType : Model?.GetType();
Beispiel #20
0
 /// <summary>Get the scripts parameters as a returned xmlElement.</summary>
 /// <param name="script">The script.</param>
 /// <returns></returns>
 private XmlElement GetParametersInObject(Model script)
 {
     XmlDocument doc = new XmlDocument();
     doc.AppendChild(doc.CreateElement("Script"));
     foreach (PropertyInfo property in script.GetType().GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
     {
         if (property.CanRead && property.CanWrite &&
             ReflectionUtilities.GetAttribute(property, typeof(XmlIgnoreAttribute), false) == null)
         {
             object value = property.GetValue(script, null);
             if (value == null)
                 value = "";
             XmlUtilities.SetValue(doc.DocumentElement, property.Name,
                                  ReflectionUtilities.ObjectToString(value));
         }
     }
     return doc.DocumentElement;
 }
Beispiel #21
0
        /// <summary>
        /// This method is used to get the organization data and print the response.
        /// </summary>
        public static void GetOrganization()
        {
            //Get instance of OrgOperations Class
            OrgOperations orgOperations = new OrgOperations();

            //Call getOrganization method
            APIResponse <ResponseHandler> response = orgOperations.GetOrganization();

            if (response != null)
            {
                //Get the status code from response
                Console.WriteLine("Status Code: " + response.StatusCode);

                //Check if expected response is received
                if (response.IsExpected)
                {
                    //Get object from response
                    ResponseHandler responseHandler = response.Object;

                    if (responseHandler is ResponseWrapper)
                    {
                        //Get the received ResponseWrapper instance
                        ResponseWrapper responseWrapper = (ResponseWrapper)responseHandler;

                        //Get the list of obtained Org instances
                        List <API.Org.Org> orgs = responseWrapper.Org;

                        foreach (API.Org.Org org in orgs)
                        {
                            //Get the Country of each Organization
                            Console.WriteLine("Organization Country: " + org.Country);

                            //Get the PhotoId of each Organization
                            Console.WriteLine("Organization PhotoId: " + org.PhotoId);

                            //Get the City of each Organization
                            Console.WriteLine("Organization City: " + org.City);

                            //Get the Description of each Organization
                            Console.WriteLine("Organization Description: " + org.Description);

                            //Get the McStatus of each Organization
                            Console.WriteLine("Organization McStatus: " + org.McStatus);

                            //Get the GappsEnabled of each Organization
                            Console.WriteLine("Organization GappsEnabled: " + org.GappsEnabled);

                            //Get the DomainName of each Organization
                            Console.WriteLine("Organization DomainName: " + org.DomainName);

                            //Get the TranslationEnabled of each Organization
                            Console.WriteLine("Organization TranslationEnabled: " + org.TranslationEnabled);

                            //Get the Street of each Organization
                            Console.WriteLine("Organization Street: " + org.Street);

                            //Get the Alias of each Organization
                            Console.WriteLine("Organization Alias: " + org.Alias);

                            //Get the Currency of each Organization
                            Console.WriteLine("Organization Currency: " + org.Currency);

                            //Get the Id of each Organization
                            Console.WriteLine("Organization Id: " + org.Id);

                            //Get the State of each Organization
                            Console.WriteLine("Organization State: " + org.State);

                            //Get the Fax of each Organization
                            Console.WriteLine("Organization Fax: " + org.Fax);

                            //Get the EmployeeCount of each Organization
                            Console.WriteLine("Organization EmployeeCount: " + org.EmployeeCount);

                            //Get the Zip of each Organization
                            Console.WriteLine("Organization Zip: " + org.Zip);

                            //Get the Website of each Organization
                            Console.WriteLine("Organization Website: " + org.Website);

                            //Get the CurrencySymbol of each Organization
                            Console.WriteLine("Organization CurrencySymbol: " + org.CurrencySymbol);

                            //Get the Mobile of each Organization
                            Console.WriteLine("Organization Mobile: " + org.Mobile);

                            //Get the CurrencyLocale of each Organization
                            Console.WriteLine("Organization CurrencyLocale: " + org.CurrencyLocale);

                            //Get the PrimaryZuid of each Organization
                            Console.WriteLine("Organization PrimaryZuid: " + org.PrimaryZuid);

                            //Get the ZiaPortalId of each Organization
                            Console.WriteLine("Organization ZiaPortalId: " + org.ZiaPortalId);

                            //Get the TimeZone of each Organization
                            Console.WriteLine("Organization TimeZone: " + org.TimeZone);

                            //Get the Zgid of each Organization
                            Console.WriteLine("Organization Zgid: " + org.Zgid);

                            //Get the CountryCode of each Organization
                            Console.WriteLine("Organization CountryCode: " + org.CountryCode);

                            //Get the Object obtained LicenseDetails instance
                            LicenseDetails licenseDetails = org.LicenseDetails;

                            //Check if licenseDetails is not null
                            if (licenseDetails != null)
                            {
                                //Get the PaidExpiry of each LicenseDetails
                                Console.WriteLine("Organization LicenseDetails PaidExpiry: " + licenseDetails.PaidExpiry);

                                //Get the UsersLicensePurchased of each LicenseDetails
                                Console.WriteLine("Organization LicenseDetails UsersLicensePurchased: " + licenseDetails.UsersLicensePurchased);

                                //Get the TrialType of each LicenseDetails
                                Console.WriteLine("Organization LicenseDetails TrialType: " + licenseDetails.TrialType);

                                //Get the TrialExpiry of each LicenseDetails
                                Console.WriteLine("Organization LicenseDetails TrialExpiry: " + licenseDetails.TrialExpiry);

                                //Get the Paid of each LicenseDetails
                                Console.WriteLine("Organization LicenseDetails Paid: " + licenseDetails.Paid);

                                //Get the PaidType of each LicenseDetails
                                Console.WriteLine("Organization LicenseDetails PaidType: " + licenseDetails.PaidType);
                            }

                            //Get the Phone of each Organization
                            Console.WriteLine("Organization Phone: " + org.Phone);

                            //Get the CompanyName of each Organization
                            Console.WriteLine("Organization CompanyName: " + org.CompanyName);

                            //Get the PrivacySettings of each Organization
                            Console.WriteLine("Organization PrivacySettings: " + org.PrivacySettings);

                            //Get the PrimaryEmail of each Organization
                            Console.WriteLine("Organization PrimaryEmail: " + org.PrimaryEmail);

                            //Get the IsoCode of each Organization
                            Console.WriteLine("Organization IsoCode: " + org.IsoCode);
                        }
                    }
                    //Check if the request returned an exception
                    else if (responseHandler is APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException)responseHandler;

                        //Get the Status
                        Console.WriteLine("Status: " + exception.Status.Value);

                        //Get the Code
                        Console.WriteLine("Code: " + exception.Code.Value);

                        Console.WriteLine("Details: ");

                        //Get the details map
                        foreach (KeyValuePair <string, object> entry in exception.Details)
                        {
                            //Get each value in the map
                            Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                        }

                        //Get the Message
                        Console.WriteLine("Message: " + exception.Message.Value);
                    }
                }
                else
                { //If response is not as expected
                    //Get model object from response
                    Model responseObject = response.Model;

                    //Get the response object's class
                    Type type = responseObject.GetType();

                    //Get all declared fields of the response class
                    Console.WriteLine("Type is: {0}", type.Name);

                    PropertyInfo[] props = type.GetProperties();

                    Console.WriteLine("Properties (N = {0}):", props.Length);

                    foreach (var prop in props)
                    {
                        if (prop.GetIndexParameters().Length == 0)
                        {
                            Console.WriteLine("{0} ({1}) : {2}", prop.Name, prop.PropertyType.Name, prop.GetValue(responseObject));
                        }
                        else
                        {
                            Console.WriteLine("{0} ({1}) : <Indexed>", prop.Name, prop.PropertyType.Name);
                        }
                    }
                }
            }
        }
        public void Model_property_builder_should_return_a_model_of_datetime()
        {
            Model m = new Model(){timestamp = DateTime.Today};
            var pi = m.GetType().GetProperty("timestamp");
            //arrange

            //act
            var result = _conventions.ModelPropertyBuilder(pi, m.timestamp);

            //assert
            Assert.IsInstanceOf(typeof(PropertyViewModel<DateTime>),result);

            Assert.AreEqual(((PropertyViewModel<DateTime>) result).Value, DateTime.Today);
        }
Beispiel #23
0
 //Move the selected barricade to a location.
 public Boolean moveBarricade(Model.Field field)
 {
     if (field.Pawn == null &&
         field.Barricade == null &&
         (field.GetType() == typeof(Model.Field) ||
         field.GetType() == typeof(Model.Barricade)))
     {
         //If the row is in the array it can not contain a barricade
         if (!level.ANoBarricades.Contains(field.Y))
         {
             barricade.setLocation(field);
             barricade = null;
             level.setCursor("arrow", field);
             nextPlayer();
             return true;
         }
     }
     return false;
 }
Beispiel #24
0
        /// <summary>
        /// This method is used to create Organization Taxes and print the response.
        /// </summary>
        public static void CreateTaxes()
        {
            //Get instance of TaxesOperations Class
            TaxesOperations taxesOperations = new TaxesOperations();

            //Get instance of BodyWrapper Class that will contain the request body
            BodyWrapper request = new BodyWrapper();

            //List of Tax instances
            List <Com.Zoho.Crm.API.Taxes.Tax> taxList = new List <Com.Zoho.Crm.API.Taxes.Tax>();

            //Get instance of Tax Class
            Com.Zoho.Crm.API.Taxes.Tax tax1 = new Com.Zoho.Crm.API.Taxes.Tax();

            tax1.Name = "MyTax11";

            tax1.SequenceNumber = 2;

            tax1.Value = 10.0;

            taxList.Add(tax1);

            tax1 = new Com.Zoho.Crm.API.Taxes.Tax();

            tax1.Name = "MyTax21";

            tax1.Value = 12.0;

            taxList.Add(tax1);

            request.Taxes = taxList;

            //Call CreateTaxes method that takes BodyWrapper class instance as parameter
            APIResponse <ActionHandler> response = taxesOperations.CreateTaxes(request);

            if (response != null)
            {
                //Get the status code from response
                Console.WriteLine("Status Code: " + response.StatusCode);

                //Check if expected response is received
                if (response.IsExpected)
                {
                    //Get object from response
                    ActionHandler actionHandler = response.Object;

                    if (actionHandler is ActionWrapper)
                    {
                        //Get the received ActionWrapper instance
                        ActionWrapper actionWrapper = (ActionWrapper)actionHandler;

                        //Get the list of obtained ActionResponse instances
                        List <ActionResponse> actionResponses = actionWrapper.Taxes;

                        foreach (ActionResponse actionResponse in actionResponses)
                        {
                            //Check if the request is successful
                            if (actionResponse is SuccessResponse)
                            {
                                //Get the received SuccessResponse instance
                                SuccessResponse successResponse = (SuccessResponse)actionResponse;

                                //Get the Status
                                Console.WriteLine("Status: " + successResponse.Status.Value);

                                //Get the Code
                                Console.WriteLine("Code: " + successResponse.Code.Value);

                                Console.WriteLine("Details: ");

                                //Get the details map
                                foreach (KeyValuePair <string, object> entry in successResponse.Details)
                                {
                                    //Get each value in the map
                                    Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                                }

                                //Get the Message
                                Console.WriteLine("Message: " + successResponse.Message.Value);
                            }
                            //Check if the request returned an exception
                            else if (actionResponse is APIException)
                            {
                                //Get the received APIException instance
                                APIException exception = (APIException)actionResponse;

                                //Get the Status
                                Console.WriteLine("Status: " + exception.Status.Value);

                                //Get the Code
                                Console.WriteLine("Code: " + exception.Code.Value);

                                Console.WriteLine("Details: ");

                                //Get the details map
                                foreach (KeyValuePair <string, object> entry in exception.Details)
                                {
                                    //Get each value in the map
                                    Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                                }

                                //Get the Message
                                Console.WriteLine("Message: " + exception.Message.Value);
                            }
                        }
                    }
                    //Check if the request returned an exception
                    else if (actionHandler is APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException)actionHandler;

                        //Get the Status
                        Console.WriteLine("Status: " + exception.Status.Value);

                        //Get the Code
                        Console.WriteLine("Code: " + exception.Code.Value);

                        Console.WriteLine("Details: ");

                        //Get the details map
                        foreach (KeyValuePair <string, object> entry in exception.Details)
                        {
                            //Get each value in the map
                            Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                        }

                        //Get the Message
                        Console.WriteLine("Message: " + exception.Message.Value);
                    }
                }
                else
                { //If response is not as expected
                    //Get model object from response
                    Model responseObject = response.Model;

                    //Get the response object's class
                    Type type = responseObject.GetType();

                    //Get all declared fields of the response class
                    Console.WriteLine("Type is: {0}", type.Name);

                    PropertyInfo[] props = type.GetProperties();

                    Console.WriteLine("Properties (N = {0}):", props.Length);

                    foreach (var prop in props)
                    {
                        if (prop.GetIndexParameters().Length == 0)
                        {
                            Console.WriteLine("{0} ({1}) : {2}", prop.Name, prop.PropertyType.Name, prop.GetValue(responseObject));
                        }
                        else
                        {
                            Console.WriteLine("{0} ({1}) : <Indexed>", prop.Name, prop.PropertyType.Name);
                        }
                    }
                }
            }
        }
Beispiel #25
0
        /// <summary>
        /// This method is used to upload the brand logo or image of the organization and print the response.
        /// </summary>
        /// <param name="absoluteFilePath">The absolute file path of the file to be attached</param>
        public static void UploadOrganizationPhoto(string absoluteFilePath)
        {
            //example
            //string absoluteFilePath = "/Users/user_name/Desktop/download.png";

            //Get instance of OrgOperations Class
            OrgOperations orgOperations = new OrgOperations();

            //Get instance of FileBodyWrapper class that will contain the request file
            FileBodyWrapper fileBodyWrapper = new FileBodyWrapper();

            //Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
            StreamWrapper streamWrapper = new StreamWrapper(absoluteFilePath);

            //Set file to the FileBodyWrapper instance
            fileBodyWrapper.File = streamWrapper;

            //Call uploadOrganizationPhoto method that takes FileBodyWrapper instance
            APIResponse <ActionResponse> response = orgOperations.UploadOrganizationPhoto(fileBodyWrapper);

            if (response != null)
            {
                //Get the status code from response
                Console.WriteLine("Status Code: " + response.StatusCode);

                //Check if expected response is received
                if (response.IsExpected)
                {
                    //Get object from response
                    ActionResponse actionResponse = response.Object;

                    //Check if the request is successful
                    if (actionResponse is SuccessResponse)
                    {
                        //Get the received SuccessResponse instance
                        SuccessResponse successResponse = (SuccessResponse)actionResponse;

                        //Get the Status
                        Console.WriteLine("Status: " + successResponse.Status.Value);

                        //Get the Code
                        Console.WriteLine("Code: " + successResponse.Code.Value);

                        Console.WriteLine("Details: ");

                        if (successResponse.Details != null)
                        {
                            //Get the details map
                            foreach (KeyValuePair <string, object> entry in successResponse.Details)
                            {
                                //Get each value in the map
                                Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                            }
                        }

                        //Get the Message
                        Console.WriteLine("Message: " + successResponse.Message.Value);
                    }
                    //Check if the request returned an exception
                    else if (actionResponse is APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException)actionResponse;

                        //Get the Status
                        Console.WriteLine("Status: " + exception.Status.Value);

                        //Get the Code
                        Console.WriteLine("Code: " + exception.Code.Value);

                        Console.WriteLine("Details: ");

                        if (exception.Details != null)
                        {
                            //Get the details map
                            foreach (KeyValuePair <string, object> entry in exception.Details)
                            {
                                //Get each value in the map
                                Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                            }
                        }

                        //Get the Message
                        Console.WriteLine("Message: " + exception.Message.Value);
                    }
                }
                else
                { //If response is not as expected
                    //Get model object from response
                    Model responseObject = response.Model;

                    //Get the response object's class
                    Type type = responseObject.GetType();

                    //Get all declared fields of the response class
                    Console.WriteLine("Type is: {0}", type.Name);

                    PropertyInfo[] props = type.GetProperties();

                    Console.WriteLine("Properties (N = {0}):", props.Length);

                    foreach (var prop in props)
                    {
                        if (prop.GetIndexParameters().Length == 0)
                        {
                            Console.WriteLine("{0} ({1}) : {2}", prop.Name, prop.PropertyType.Name, prop.GetValue(responseObject));
                        }
                        else
                        {
                            Console.WriteLine("{0} ({1}) : <Indexed>", prop.Name, prop.PropertyType.Name);
                        }
                    }
                }
            }
        }
        public void verify_logic_with_context()
        {
            var now = DateTime.Now;
            var model = new Model
            {
                NDate = now,
                Date = now,
                NSpan = now - new DateTime(1999, 1, 1),
                Span = new TimeSpan(0),
                Number = 0,
                Flag = true,
                Text = "hello world",
                PoliticalStability = Utility.Stability.High,
                SbyteNumber = SbyteEnum.First,
                ByteNumber = ByteEnum.First,
                ShortNumber = ShortEnum.First,
                UshortNumber = UshortEnum.First,
                IntNumber = IntEnum.First,
                UintNumber = UintEnum.First,
                LongNumber = LongEnum.First,
                UlongNumber = UlongEnum.First,
                Guid1 = Guid.NewGuid(),
                Guid2 = Guid.Empty,
                SubModel = new Model
                {
                    NDate = now.AddDays(1),
                    Date = now.AddDays(1),
                    Number = 1,
                    Flag = false,
                    Text = " hello world ",
                    PoliticalStability = null,
                }
            };

            var parser = new Parser();
            parser.RegisterMethods();

            Assert.IsTrue(parser.Parse(model.GetType(), "Number < 1").Invoke(model));
            Assert.IsTrue(parser.Parse(model.GetType(), "Number == 0").Invoke(model));
            Assert.IsTrue(parser.Parse(model.GetType(), "Number != null").Invoke(model));
            Assert.IsTrue(parser.Parse(model.GetType(), "SubModel.Number / 2 == 0.5").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("SbyteNumber / SbyteEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("ByteNumber / ByteEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("ShortNumber / ShortEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("UshortNumber / UshortEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("IntNumber / IntEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("UintNumber / UintEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("LongNumber / LongEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("UlongNumber / UlongEnum.Second == 0.5").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("PoliticalStability == 0").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("PoliticalStability == Utility.Stability.High").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("PoliticalStability < Utility.Stability.Low").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("SubModel.PoliticalStability == null").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("SubModel.PoliticalStability != Utility.Stability.High").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("Const != Utility.Const").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("Flag").Invoke(model));
            Assert.IsFalse(parser.Parse<Model>("!Flag").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Flag && true").Invoke(model));

            Assert.IsFalse(parser.Parse<Model>("SubModel.Flag").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("!SubModel.Flag").Invoke(model));
            Assert.IsFalse(parser.Parse<Model>("SubModel.Flag && true").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("Number < SubModel.Number").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Date <= NDate").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("NDate != null").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Span <= NSpan").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("NSpan != null").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("SubModel.Date < NextWeek()").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("IncNumber(0) == SubModel.Number").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("IncNumber(Number) == SubModel.Number").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Today() - Today() == Span").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Today() - Today() == Date - Date").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Today() - Today() == Span - Span").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Today() - Today() == NSpan - NSpan").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Span + NSpan == NSpan + Span").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Now() - Span > Date - NSpan").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("DecNumber(SubModel.Number) == Number").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("DecNumber(Number) == 0").Invoke(model.SubModel));

            Assert.IsTrue(parser.Parse<Model>("SubModel.Date > Today()").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("'hello world' == Trim(SubModel.Text)").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("CompareOrdinal(Text, Trim(SubModel.Text)) == 0").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("Guid1 != Guid('00000000-0000-0000-0000-000000000000')").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Guid2 == Guid('00000000-0000-0000-0000-000000000000')").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Guid1 != Guid2").Invoke(model));

            model.NDate = null;
            model.NSpan = null;
            Assert.IsTrue(parser.Parse<Model>("NDate == null && Date != NDate").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("NSpan == null && Span != NSpan").Invoke(model));

            var subModel = new Model();
            var newModel = new Model {SubModel = subModel, SubModelObject = subModel};
            Assert.IsTrue(parser.Parse<Model>("SubModel == SubModelObject").Invoke(newModel));

            const string expression =
                @"Flag == !false
                      && (
                             (Text != 'hello world' && Date < SubModel.Date)
                             || (
                                    (Number >= 0 && Number < 1) && PoliticalStability == Utility.Stability.High
                                )
                         )
                      && Const + Utility.Const == 'insideoutside'";
            var func = parser.Parse(model.GetType(), expression);
            Assert.IsTrue(func(model));

            parser.GetFields()["Flag"] = null; // try to mess up with internal fields - original data should not be affected
            var parsedFields = parser.GetFields();
            var expectedFields = new Dictionary<string, Type>
            {
                {"Flag", typeof (bool)},
                {"Text", typeof (string)},
                {"Date", typeof (DateTime)},
                {"SubModel.Date", typeof (DateTime)},
                {"Number", typeof (int?)},
                {"PoliticalStability", typeof (Utility.Stability?)}
            };
            Assert.AreEqual(expectedFields.Count, parsedFields.Count);
            Assert.IsTrue(
                expectedFields.Keys.All(
                    key => parsedFields.ContainsKey(key) &&
                           EqualityComparer<Type>.Default.Equals(expectedFields[key], parsedFields[key])));

            parser.GetConsts()["Const"] = null; // try to mess up with internal fields - original data should not be affected
            var parsedConsts = parser.GetConsts();
            var expectedConsts = new Dictionary<string, object>
            {
                {"Utility.Stability.High", Utility.Stability.High},
                {"Const", Model.Const},
                {"Utility.Const", Utility.Const}
            };
            Assert.AreEqual(expectedConsts.Count, parsedConsts.Count);
            Assert.IsTrue(
                expectedConsts.Keys.All(
                    key => parsedConsts.ContainsKey(key) &&
                           EqualityComparer<object>.Default.Equals(expectedConsts[key], parsedConsts[key])));
        }
Beispiel #27
0
        /// <summary>
        /// This method is used to get all the Organization Taxes and print the response.
        /// </summary>
        public static void GetTaxes()
        {
            //Get instance of TaxesOperations Class
            TaxesOperations taxesOperations = new TaxesOperations();

            //Call GetTaxes method
            APIResponse <ResponseHandler> response = taxesOperations.GetTaxes();

            if (response != null)
            {
                //Get the status code from response
                Console.WriteLine("Status Code: " + response.StatusCode);

                if (new List <int>()
                {
                    204, 304
                }.Contains(response.StatusCode))
                {
                    Console.WriteLine(response.StatusCode == 204? "No Content" : "Not Modified");

                    return;
                }

                //Check if expected response is received
                if (response.IsExpected)
                {
                    //Get object from response
                    ResponseHandler responseHandler = response.Object;

                    if (responseHandler is ResponseWrapper)
                    {
                        //Get the received ResponseWrapper instance
                        ResponseWrapper responseWrapper = (ResponseWrapper)responseHandler;

                        //Get the list of obtained Tax instances
                        List <Com.Zoho.Crm.API.Taxes.Tax> taxes = responseWrapper.Taxes;

                        foreach (Com.Zoho.Crm.API.Taxes.Tax tax in taxes)
                        {
                            //Get the DisplayLabel of each Tax
                            Console.WriteLine("Tax DisplayLabel: " + tax.DisplayLabel);

                            //Get the Name of each Tax
                            Console.WriteLine("Tax Name: " + tax.Name);

                            //Get the ID of each Tax
                            Console.WriteLine("Tax ID: " + tax.Id);

                            //Get the Value of each Tax
                            Console.WriteLine("Tax Value: " + tax.Value);
                        }

                        //Get the Preference instance of Tag
                        Preference preference = responseWrapper.Preference;

                        //Check if preference is not null
                        if (preference != null)
                        {
                            //Get the AutoPopulateTax of each Preference
                            Console.WriteLine("Preference AutoPopulateTax: " + preference.AutoPopulateTax);

                            //Get the ModifyTaxRates of each Preference
                            Console.WriteLine("Preference ModifyTaxRates: " + preference.ModifyTaxRates);
                        }
                    }
                    //Check if the request returned an exception
                    else if (responseHandler is APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException)responseHandler;

                        //Get the Status
                        Console.WriteLine("Status: " + exception.Status.Value);

                        //Get the Code
                        Console.WriteLine("Code: " + exception.Code.Value);

                        Console.WriteLine("Details: ");

                        //Get the details map
                        foreach (KeyValuePair <string, object> entry in exception.Details)
                        {
                            //Get each value in the map
                            Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                        }

                        //Get the Message
                        Console.WriteLine("Message: " + exception.Message.Value);
                    }
                }
                else
                { //If response is not as expected
                    //Get model object from response
                    Model responseObject = response.Model;

                    //Get the response object's class
                    Type type = responseObject.GetType();

                    //Get all declared fields of the response class
                    Console.WriteLine("Type is: {0}", type.Name);

                    PropertyInfo[] props = type.GetProperties();

                    Console.WriteLine("Properties (N = {0}):", props.Length);

                    foreach (var prop in props)
                    {
                        if (prop.GetIndexParameters().Length == 0)
                        {
                            Console.WriteLine("{0} ({1}) : {2}", prop.Name, prop.PropertyType.Name, prop.GetValue(responseObject));
                        }
                        else
                        {
                            Console.WriteLine("{0} ({1}) : <Indexed>", prop.Name, prop.PropertyType.Name);
                        }
                    }
                }
            }
        }
        public void Value_from_model_should_return_the_enum_name()
        {
            Model m = new Model() { Enum = Foo.Bar };
            var pi = m.GetType().GetProperty("Enum");
            //arrange

            //act
            var result = _conventions.ValueFromModelPropertyConvention(pi,m);

            //assert
            Assert.AreEqual(Foo.Bar, result);
        }
        public void Partial_Name_should_return_the_uihint()
        {
            Model m = new Model() { UiHintProperty = "foo"};
            var pi = m.GetType().GetProperty("UiHintProperty");
            //arrange

            //act
            var result = _conventions.PartialNameConvention(pi);

            //assert
            Assert.AreEqual("theview", result);
        }
        public void Partial_Name_should_return_the_property()
        {
            Model m = new Model() { String = "foo" };
            var pi = m.GetType().GetProperty("String");
            //arrange

            //act
            var result = _conventions.PartialNameConvention(pi);

            //assert
            Assert.AreEqual("String", result);
        }
Beispiel #31
0
        /// <summary>
        /// Create the HTML for the descriptive summary display of a supplied component
        /// </summary>
        /// <param name="modelToSummarise">Model to create summary fpr</param>
        /// <param name="darkTheme">Boolean representing if in dark mode</param>
        /// <param name="bodyOnly">Only produve the body html</param>
        /// <param name="apsimFilename">Create master simulation summary header</param>
        /// <returns></returns>
        public static string CreateDescriptiveSummaryHTML(Model modelToSummarise, bool darkTheme = false, bool bodyOnly = false, string apsimFilename = "")
        {
            // currently includes autoupdate script for display of summary information in browser
            // give APSIM Next Gen no longer has access to WebKit HTMLView in GTK for .Net core
            // includes <!-- graphscript --> to add graphing js details if needed
            // includes <!-- CLEMZoneBody --> to add multiple components for overall summary

            string htmlString = "<!DOCTYPE html>\r\n" +
                                "<html>\r\n<head>\r\n<script type=\"text / javascript\" src=\"https://livejs.com/live.js\"></script>\r\n" +
                                "<meta http-equiv=\"Cache-Control\" content=\"no-cache, no-store, must-revalidate\" />\r\n" +
                                "<meta http-equiv = \"Pragma\" content = \"no-cache\" />\r\n" +
                                "<meta http-equiv = \"Expires\" content = \"0\" />\r\n" +
                                "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\r\n" +
                                "<style>\r\n" +
                                "body {color: [FontColor]; max-width:1000px; font-size:1em; font-family: Segoe UI, Arial, sans-serif}" +
                                "table {border-collapse: collapse; font-size:0.8em; }" +
                                ".resource table,th,td {border: 1px solid #996633; }" +
                                "table th {padding:8px; color:[HeaderFontColor];}" +
                                "table td {padding:8px; }" +
                                " td:nth-child(n+2) {text-align:center;}" +
                                " th:nth-child(1) {text-align:left;}" +
                                ".resource th {background-color: #996633 !important; }" +
                                ".resource tr:nth-child(2n+3) {background:[ResRowBack] !important;}" +
                                ".resource tr:nth-child(2n+2) {background:[ResRowBack2] !important;}" +
                                ".resource td.fill {background-color: #c1946c !important;}" +
                                ".resourceborder {border-color:#996633; border-width:1px; border-style:solid; padding:0px; background-color:Cornsilk !important; }" +
                                ".resource h1,h2,h3 {color:#996633; } .activity h1,h2,h3 { color:#009999; margin-bottom:5px; }" +
                                ".resourcebanner {background-color:#996633 !important; color:[ResFontBanner]; padding:5px; font-weight:bold; border-radius:5px 5px 0px 0px; }" +
                                ".resourcebannerlight {background-color:#c1946c !important; color:[ResFontBanner]; border-radius:5px 5px 0px 0px; padding:5px 5px 5px 10px; margin-top:12px; font-weight:bold }" +
                                ".resourcebannerdark {background-color:#996633 !important; color:[ResFontBanner]; border-radius:5px 5px 0px 0px; padding:5px 5px 5px 10px; margin-top:12px; font-weight:bold }" +
                                ".resourcecontent {background-color:[ResContBack] !important; margin-bottom:40px; border-radius:0px 0px 5px 5px; border-color:#996633; border-width:1px; border-style:none solid solid solid; padding:10px;}" +
                                ".resourcebanneralone {background-color:[ResContBack] !important; margin:10px 0px 5px 0px; border-radius:5px 5px 5px 5px; border-color:#996633; border-width:1px; border-style:solid solid solid solid; padding:5px;}" +
                                ".resourcecontentlight {background-color:[ResContBackLight] !important; margin-bottom:10px; border-radius:0px 0px 5px 5px; border-color:#c1946c; border-width:0px 1px 1px 1px; border-style:none solid solid solid; padding:10px;}" +
                                ".resourcecontentdark {background-color:[ResContBackDark] !important; margin-bottom:10px; border-radius:0px 0px 5px 5px; border-color:#996633; border-width:0px 1px 1px 1px; border-style:none solid solid solid; padding:10px;}" +
                                ".resourcelink {color:#996633; font-weight:bold; background-color:Cornsilk !important; border-color:#996633; border-width:1px; border-style:solid; padding:0px 5px 0px 5px; border-radius:3px; }" +
                                ".activity th,td {padding:5px; }" +
                                ".activity table,th,td {border: 1px solid #996633; }" +
                                ".activity th {background-color: #996633 !important; }" +
                                ".activity td.fill {background-color: #996633 !important; }" +
                                ".activity table {border-collapse: collapse; font-size:0.8em; }" +
                                ".activity h1 {color:#009999; } .activity h1,h2,h3 { color:#009999; margin-bottom:5px; }" +
                                ".activityborder {border-color:#009999; border-width:2px; border-style:none none none solid; padding:0px 0px 0px 10px; margin-bottom:15px; }" +
                                ".activityborderfull {border-color:#009999; border-radius:5px; background-color:#f0f0f0 !important; border-width:1px; border-style:solid; margin-bottom:40px; }" +
                                ".activitybanner {background-color:#009999 !important; border-radius:5px 5px 0px 0px; color:#f0f0f0; padding:5px; font-weight:bold }" +
                                ".activitybannerlight {background-color:#86b2b1 !important; border-radius:5px 5px 0px 0px; color:white; padding:5px 5px 5px 10px; margin-top:12px; font-weight:bold }" +
                                ".activitybannerdark {background-color:#009999 !important; border-radius:5px 5px 0px 0px; color:white; padding:5px 5px 5px 10px; margin-top:12px; font-weight:bold }" +
                                ".activitybannercontent {background-color:#86b2b1 !important; border-radius:5px 5px 0px 0px; padding:5px 5px 5px 10px; margin-top:5px; }" +
                                ".activitycontent {background-color:[ActContBack] !important; margin-bottom:10px; border-radius:0px 0px 5px 5px; border-color:#009999; border-width:0px 1px 1px 1px; border-style:none solid solid solid; padding:10px;}" +
                                ".activitycontentlight {background-color:[ActContBackLight] !important; margin-bottom:10px; border-radius:0px 0px 5px 5px; border-color:#86b2b1; border-width:0px 1px 1px 1px; border-style:solid; padding:10px;}" +
                                ".activitycontentdark {background-color:[ActContBackDark] !important; margin-bottom:10px; border-radius:0px 0px 5px 5px; border-color:#86b2b1; border-width:0px 1px 1px 1px; border-style:none solid solid solid; padding:10px;}" +
                                ".activitypadding {padding:10px; }" +
                                ".activityentry {padding:5px 0px 5px 0px; }" +
                                ".activityarea {padding:10px; }" +
                                ".activitygroupsborder {border-color:#86b2b1; background-color:[ActContBackGroups] !important; border-width:1px; border-style:solid; padding:10px; margin-bottom:5px; margin-top:5px;}" +
                                ".activitylink {color:#009999; font-weight:bold; background-color:[ActContBack] !important; border-color:#009999; border-width:1px; border-style:solid; padding:0px 5px 0px 5px; border-radius:3px; }" +
                                ".topspacing { margin-top:10px; }" +
                                ".disabled { color:#CCC; }" +
                                ".clearfix { overflow: auto; }" +
                                ".namediv { float:left; vertical-align:middle; }" +
                                ".typediv { float:right; vertical-align:middle; font-size:0.6em; }" +
                                ".partialdiv { font-size:0.8em; float:right; text-transform: uppercase; color:white; font-weight:bold; vertical-align:middle; border-color:white; border-width:1px; border-style:solid; padding:0px 5px 0px 5px; margin-left: 10px;  border-radius:3px; }" +
                                ".filelink {color:green; font-weight:bold; background-color:mintcream !important; border-color:green; border-width:1px; border-style:solid; padding:0px 5px 0px 5px; border-radius:3px; }" +
                                ".errorlink {color:white; font-weight:bold; background-color:red !important; border-color:darkred; border-width:1px; border-style:solid; padding:0px 5px 0px 5px; border-radius:3px; }" +
                                ".setvalue {font-weight:bold; background-color: [ValueSetBack] !important; Color: [ValueSetFont]; border-color:#697c7c; border-width:1px; border-style:solid; padding:0px 5px 0px 5px; border-radius:3px;}" +
                                ".folder {color:#666666; font-style: italic; font-size:1.1em; }" +
                                ".cropmixedlabel {color:#666666; font-style: italic; font-size:1.1em; padding: 5px 0px 10px 0px; }" +
                                ".croprotationlabel {color:#666666; font-style: italic; font-size:1.1em; padding: 5px 0px 10px 0px; }" +
                                ".cropmixedborder {border-color:#86b2b1; background-color:[CropRotationBack] !important; border-width:1px; border-style:solid; padding:0px 10px 0px 10px; margin-bottom:5px;margin-top:10px; }" +
                                ".croprotationborder {border-color:#86b2b1; background-color:[CropRotationBack] !important; border-width:2px; border-style:solid; padding:0px 10px 0px 10px; margin-bottom:5px;margin-top:10px; }" +
                                ".labourgroupsborder {border-color:[LabourGroupBorder]; background-color:[LabourGroupBack] !important; border-width:1px; border-style:solid; padding:10px; margin-bottom:5px; margin-top:5px;}" +
                                ".labournote {font-style: italic; color:#666666; padding-top:7px;}" +
                                ".warningbanner {background-color:Orange !important; border-radius:5px 5px 5px 5px; color:Black; padding:5px; font-weight:bold; margin-bottom:10px;margin-top:10px; }" +
                                ".errorbanner {background-color:Red !important; border-radius:5px 5px 5px 5px; color:Black; padding:5px; font-weight:bold; margin-bottom:10px;margin-top:10px; }" +
                                ".filterlink {font-weight:bold; color:#cc33cc; background-color:[FiltContBack] !important; border-color:#cc33cc; border-width:1px; border-style:solid; padding:0px 5px 0px 5px; border-radius:3px; }" +
                                ".filtername {margin:10px 0px 5px 0px; font-size:0.9em; color:#cc33cc;font-weight:bold;}" +
                                ".filterborder {display: block; width: 100% - 40px; border-color:#cc33cc; background-color:[FiltContBack] !important; border-width:1px; border-style:solid; padding:5px; margin:0px 0px 5px 0px; border-radius:5px; }" +
                                ".filterset {float: left; font-size:0.85em; font-weight:bold; color:#cc33cc; background-color:[FiltContBack] !important; border-width:0px; border-style:none; padding: 0px 3px; margin: 2px 0px 0px 5px; border-radius:3px; }" +
                                ".filteractivityborder {background-color:[FiltContActivityBack] !important; color:#fff; }" +
                                ".filter {float: left; border-color:#cc33cc; background-color:#cc33cc !important; color:white; border-width:1px; border-style:solid; padding: 0px 5px 0px 5px; font-weight:bold; margin: 0px 5px 0px 5px;  border-radius:3px;}" +
                                ".filtererror {float: left; border-color:red; background-color:red !important; color:white; border-width:1px; border-style:solid; padding: 0px 5px 0px 5px; font-weight:bold; margin: 0px 5px 0px 5px;  border-radius:3px;}" +
                                ".filebanner {background-color:green !important; border-radius:5px 5px 0px 0px; color:mintcream; padding:5px; font-weight:bold }" +
                                ".filecontent {background-color:[ContFileBack] !important; margin-bottom:20px; border-radius:0px 0px 5px 5px; border-color:green; border-width:1px; border-style:none solid solid solid; padding:10px;}" +
                                ".defaultbanner {background-color:[ContDefaultBanner] !important; border-radius:5px 5px 0px 0px; color:white; padding:5px; font-weight:bold }" +
                                ".defaultcontent {background-color:[ContDefaultBack] !important; margin-bottom:20px; border-radius:0px 0px 5px 5px; border-color:[ContDefaultBanner]; border-width:1px; border-style:none solid solid solid; padding:10px;}" +
                                ".holdermain {margin: 20px 0px 20px 0px}" +
                                ".holdersub {margin: 5px 0px 5px}" +
                                ".otherlink {font-weight:bold; color:black; background-color:[ContDefaultBack] !important; border-color:black; border-width:1px; border-style:solid; padding:0px 5px 0px 5px; border-radius:3px; }" +
                                "@media print { body { -webkit - print - color - adjust: exact; }}" +
                                "\r\n</style>\r\n<!-- graphscript --></ head>\r\n<body>\r\n<!-- CLEMZoneBody -->";

            // apply theme based settings
            if (!darkTheme)
            {
                // light theme
                htmlString = htmlString.Replace("[FontColor]", "black");
                htmlString = htmlString.Replace("[HeaderFontColor]", "white");

                // resources
                htmlString = htmlString.Replace("[ResRowBack]", "floralwhite");
                htmlString = htmlString.Replace("[ResRowBack2]", "white");
                htmlString = htmlString.Replace("[ResContBack]", "floralwhite");
                htmlString = htmlString.Replace("[ResContBackLight]", "white");
                htmlString = htmlString.Replace("[ResContBackDark]", "floralwhite");
                htmlString = htmlString.Replace("[ResFontBanner]", "white");
                htmlString = htmlString.Replace("[ResFontContent]", "black");

                //activities
                htmlString = htmlString.Replace("[ActContBack]", "#fdffff");
                htmlString = htmlString.Replace("[ActContBackLight]", "#ffffff");
                htmlString = htmlString.Replace("[ActContBackDark]", "#fdffff");
                htmlString = htmlString.Replace("[ActContBackGroups]", "#ffffff");

                htmlString = htmlString.Replace("[ContDefaultBack]", "#FAFAFA");
                htmlString = htmlString.Replace("[ContDefaultBanner]", "#000");

                htmlString = htmlString.Replace("[ContFileBack]", "#FCFFFC");

                htmlString = htmlString.Replace("[CropRotationBack]", "#FFFFFF");
                htmlString = htmlString.Replace("[LabourGroupBack]", "#FFFFFF");
                htmlString = htmlString.Replace("[LabourGroupBorder]", "#996633");

                // filters
                htmlString = htmlString.Replace("[FiltContBack]", "#fbe8fc");
                htmlString = htmlString.Replace("[FiltContActivityBack]", "#cc33cc");

                // values
                htmlString = htmlString.Replace("[ValueSetBack]", "#e8fbfc");
                htmlString = htmlString.Replace("[ValueSetFont]", "#000000");
            }
            else
            {
                // dark theme
                htmlString = htmlString.Replace("[FontColor]", "#E5E5E5");
                htmlString = htmlString.Replace("[HeaderFontColor]", "black");

                // resources
                htmlString = htmlString.Replace("[ResRowBack]", "#281A0E");
                htmlString = htmlString.Replace("[ResRowBack2]", "#3F2817");
                htmlString = htmlString.Replace("[ResContBack]", "#281A0E");
                htmlString = htmlString.Replace("[ResContBackLight]", "#3F2817");
                htmlString = htmlString.Replace("[ResContBackDark]", "#281A0E");
                htmlString = htmlString.Replace("[ResFontBanner]", "#ffffff");
                htmlString = htmlString.Replace("[ResFontContent]", "#ffffff");

                //activities
                htmlString = htmlString.Replace("[ActContBack]", "#003F3D");
                htmlString = htmlString.Replace("[ActContBackLight]", "#005954");
                htmlString = htmlString.Replace("[ActContBackDark]", "#f003F3D");
                htmlString = htmlString.Replace("[ActContBackGroups]", "#f003F3D");

                htmlString = htmlString.Replace("[ContDefaultBack]", "#282828");
                htmlString = htmlString.Replace("[ContDefaultBanner]", "#686868");

                htmlString = htmlString.Replace("[ContFileBack]", "#0C440C");

                htmlString = htmlString.Replace("[CropRotationBack]", "#97B2B1");
                htmlString = htmlString.Replace("[LabourGroupBack]", "#c1946c");
                htmlString = htmlString.Replace("[LabourGroupBorder]", "#c1946c");

                // filters
                htmlString = htmlString.Replace("[FiltContBack]", "#5c195e");
                htmlString = htmlString.Replace("[FiltContActivityBack]", "#cc33cc");

                // values
                htmlString = htmlString.Replace("[ValueSetBack]", "#49adc4");
                htmlString = htmlString.Replace("[ValueSetFont]", "#0e2023");
            }

            using (StringWriter htmlWriter = new StringWriter())
            {
                if (!bodyOnly)
                {
                    htmlWriter.Write(htmlString);

                    if (apsimFilename == "")
                    {
                        htmlWriter.Write("\r\n<span style=\"font-size:0.8em; font-weight:bold\">You will need to keep refreshing this page to see changes relating to the last component selected</span><br /><br />");
                    }
                }
                htmlWriter.Write("\r\n<div class=\"clearfix defaultbanner\">");

                string fullname = modelToSummarise.Name;
                if (modelToSummarise is CLEMModel)
                {
                    fullname = (modelToSummarise as CLEMModel).NameWithParent;
                }

                if (apsimFilename != "")
                {
                    htmlWriter.Write($"<div class=\"namediv\">Full simulation settings</div>");
                }
                else
                {
                    htmlWriter.Write($"<div class=\"namediv\">Component {fullname} named {modelToSummarise.GetType().Name}</div>");
                }
                htmlWriter.Write($"<div class=\"typediv\">Details</div>");
                htmlWriter.Write("</div>");
                htmlWriter.Write("\r\n<div class=\"defaultcontent\">");

                if (apsimFilename != "")
                {
                    htmlWriter.Write($"\r\n<div class=\"activityentry\">Filename: {apsimFilename}</div>");
                    Model sim = (modelToSummarise as Model).FindAncestor <Simulation>();
                    htmlWriter.Write($"\r\n<div class=\"activityentry\">Simulation: {sim.Name}</div>");
                }

                htmlWriter.Write($"\r\n<div class=\"activityentry\">Summary last created on {DateTime.Now.ToShortDateString()} at {DateTime.Now.ToShortTimeString()}</div>");
                htmlWriter.Write("\r\n</div>");

                if (modelToSummarise is ZoneCLEM)
                {
                    htmlWriter.Write((modelToSummarise as ZoneCLEM).GetFullSummary(modelToSummarise, true, htmlWriter.ToString()));
                }
                else if (modelToSummarise is Market)
                {
                    htmlWriter.Write((modelToSummarise as Market).GetFullSummary(modelToSummarise, true, htmlWriter.ToString()));
                }
                else if (modelToSummarise is CLEMModel)
                {
                    htmlWriter.Write((modelToSummarise as CLEMModel).GetFullSummary(modelToSummarise, false, htmlWriter.ToString()));
                }
                else if (modelToSummarise is ICLEMDescriptiveSummary)
                {
                    htmlWriter.Write((modelToSummarise as ICLEMDescriptiveSummary).GetFullSummary(modelToSummarise, false, htmlWriter.ToString()));
                }
                else
                {
                    htmlWriter.Write("<b>This component has no descriptive summary</b>");
                }

                if (!bodyOnly)
                {
                    htmlWriter.WriteLine("\r\n</body>\r\n</html>");
                }

                if (htmlWriter.ToString().Contains("<canvas"))
                {
                    Assembly     assembly         = Assembly.GetExecutingAssembly();
                    StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("Models.Resources.CLEM.Chart.min.js"));
                    string       graphString      = textStreamReader.ReadToEnd();
                    if (!darkTheme)
                    {
                        graphString = graphString.Replace("[GraphGridLineColour]", "#eee");
                        graphString = graphString.Replace("[GraphGridZeroLineColour]", "#999");
                        graphString = graphString.Replace("[GraphPointColour]", "#00bcd6");
                        graphString = graphString.Replace("[GraphLineColour]", "#fda50f");
                        graphString = graphString.Replace("[GraphLabelColour]", "#888");
                    }
                    else
                    {
                        // dark theme
                        graphString = graphString.Replace("[GraphGridLineColour]", "#555");
                        graphString = graphString.Replace("[GraphGridZeroLineColour]", "#888");
                        graphString = graphString.Replace("[GraphPointColour]", "#00bcd6");
                        graphString = graphString.Replace("[GraphLineColour]", "#ff0");
                        graphString = graphString.Replace("[GraphLabelColour]", "#888");
                    }

                    return(htmlWriter.ToString().Replace("<!-- graphscript -->", $"<script>{graphString}</script>"));
                }
                return(htmlWriter.ToString());
            }
        }
Beispiel #32
0
        /// <summary>
        /// 生成更新语句
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual string BuildUpdateSQL(Model.Model model)
        {
            List<string> fileds = new List<string>();
            List<string> wheres = new List<string>();
            var propertys = model.GetType().GetProperties();
            var primarys = model.getPrimaryKeys();
            var identity = model.getIdentify();
            foreach (var p in propertys)
            {
                var notmaps = p.GetCustomAttributes(typeof(Model.NotMapingAttribute), false);
                if (notmaps != null && notmaps.Length > 0) continue;

                if (primarys.Any(m => m.Name == p.Name))
                {
                    wheres.Add(string.Format("[{0}]=@{0}", p.Name));
                }
                if (!Magic.Mvc.Equals.IsNull(identity) && identity.Name == p.Name) continue;

                fileds.Add(string.Format("[{0}]=@{0}", p.Name));

            }

            return string.Format(" UPDATE [{0}] SET {1} WHERE {2}", model.GetType().Name, string.Join(",", fileds.ToArray()), string.Join(" and ", wheres.ToArray()));
        }
Beispiel #33
0
        /// <summary>
        /// Gets the cache associated with a type derived from the abstract class Model.
        /// If the cache hasn't been accessed yet, this creates one for the type.
        /// </summary>
        public static ModelCache Get(Model instance)
        {
            Type type = instance.GetType();

            return Get(type);
        }
        public void Model_property_builder_should_return_a_model_of_select_items_for_an_enum()
        {
            Model m = new Model() { Enum=Foo.Bar };
            var pi = m.GetType().GetProperty("Enum");
            //arrange

            //act
            var result = _conventions.ModelPropertyBuilder(pi, m.Enum);

            //assert
            Assert.IsInstanceOf(typeof(PropertyViewModel<IEnumerable<SelectListItem>>), result);

            Assert.AreEqual(((PropertyViewModel<IEnumerable<SelectListItem>>)result).Value.Count(), 2);
        }
        public void Partial_Name_should_return_the_datatype()
        {
            Model m = new Model() { DataType = "foo" };
            var pi = m.GetType().GetProperty("DataType");
            //arrange

            //act
            var result = _conventions.PartialNameConvention(pi);

            //assert
            Assert.AreEqual("EmailAddress", result);
        }
        public void Partial_Name_should_return_the_enum_name()
        {
            Model m = new Model() { Enum = Foo.Bar };
            var pi = m.GetType().GetProperty("Enum");
            //arrange

            //act
            var result = _conventions.PartialNameConvention(pi);

            //assert
            Assert.AreEqual("Enum", result);
        }
Beispiel #37
0
        /// <summary>
        /// Find all properties from the model and fill this.properties.
        /// </summary>
        /// <param name="model">The model to search for properties</param>
        /// <param name="properties">The list of properties to fill</param>
        private static void FindAllProperties(Model model, List<VariableProperty> properties)
        {
            if (model != null)
            {
                foreach (PropertyInfo property in model.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy))
                {
                    // Properties must have a [Summary] attribute
                    bool includeProperty = property.IsDefined(typeof(SummaryAttribute), false);

                    if (includeProperty)
                    {
                        properties.Add(new VariableProperty(model, property));
                    }
                }
            }
        }
        public void CreateModelList(object parentCode)
        {
            Recordset rstExistsParent = (Recordset)SBOApp.Company.GetBusinessObject(BoObjectTypes.BoRecordset);
            string    sql             = "SELECT TOP 1 1 FROM [{0}] WHERE Code = '{1}'";

            sql = String.Format(sql, ParentTableName, parentCode);

            try
            {
                rstExistsParent.DoQuery(sql);

                if (rstExistsParent.RecordCount == 0)
                {
                    throw new Exception(String.Format("Código {0} do item pai não encontrado", parentCode));
                }
            }
            finally
            {
                Marshal.ReleaseComObject(rstExistsParent);
                rstExistsParent = null;
            }

            CompanyService oCompanyService = SBOApp.Company.GetCompanyService();
            GeneralService oGeneralService = oCompanyService.GetGeneralService(ParentTableName.Replace("@", ""));

            GeneralDataParams oGeneralParams = (GeneralDataParams)oGeneralService.GetDataInterface(SAPbobsCOM.GeneralServiceDataInterfaces.gsGeneralDataParams);

            oGeneralParams.SetProperty("Code", parentCode);

            GeneralData           oGeneralData = oGeneralService.GetByParams(oGeneralParams);
            GeneralDataCollection oChildren    = oGeneralData.Child(TableName.Replace("@", ""));
            GeneralData           oChild       = null;

            try
            {
                foreach (object model in ModelList)
                {
                    Model  = model;
                    oChild = oChildren.Add();

                    ModelControllerAttribute modelController;
                    object value;
                    // Percorre as propriedades do Model
                    foreach (PropertyInfo property in Model.GetType().GetProperties())
                    {
                        // Busca os Custom Attributes
                        foreach (Attribute attribute in property.GetCustomAttributes(true))
                        {
                            modelController = attribute as ModelControllerAttribute;
                            if (property.GetType() != typeof(DateTime))
                            {
                                value = property.GetValue(Model, null);
                            }
                            else
                            {
                                value = ((DateTime)property.GetValue(Model, null)).ToString("yyyy-MM-dd HH:mm:ss");
                            }

                            if (modelController != null)
                            {
                                // Se não for DataBaseField não seta nas properties
                                if (!modelController.DataBaseFieldYN)
                                {
                                    break;
                                }
                                if (String.IsNullOrEmpty(modelController.ColumnName))
                                {
                                    modelController.ColumnName = property.Name;
                                }
                                if (modelController.ColumnName == "Code" || modelController.ColumnName == "LineId")
                                {
                                    continue;
                                }

                                if (value == null)
                                {
                                    if (property.PropertyType == typeof(string))
                                    {
                                        value = String.Empty;
                                    }
                                    else if (property.PropertyType != typeof(DateTime) && property.PropertyType != typeof(Nullable <DateTime>))
                                    {
                                        value = 0;
                                    }
                                    else
                                    {
                                        value = new DateTime();
                                    }
                                }

                                if (property.PropertyType != typeof(decimal) && property.PropertyType != typeof(Nullable <decimal>))
                                {
                                    oChild.SetProperty(modelController.ColumnName, value);
                                }
                                else
                                {
                                    oChild.SetProperty(modelController.ColumnName, Convert.ToDouble(value));
                                }
                                break;
                            }
                        }
                    }
                }

                oGeneralService.Update(oGeneralData);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                Marshal.ReleaseComObject(oGeneralService);
                Marshal.ReleaseComObject(oGeneralData);
                Marshal.ReleaseComObject(oCompanyService);

                oGeneralService = null;
                oGeneralData    = null;
                oCompanyService = null;

                if (oChildren != null)
                {
                    Marshal.ReleaseComObject(oChildren);
                    oChildren = null;
                }
                if (oChild != null)
                {
                    Marshal.ReleaseComObject(oChild);
                    oChild = null;
                }
            }
        }