Exemplo n.º 1
0
        public void Save()
        {
            if (!Valid)
            {
                return;
            }

            IContractEditor edit = Editor as IContractEditor;

            edit.Save();

            IResultGetter result      = Editor as IResultGetter;
            XmlElement    authElement = result.GetAuthElement();

            XmlHelper h = new XmlHelper("<Definition/>");

            h.AddElement(".", authElement);

            try
            {
                Contract.SetDefinition(h.GetElement("."), _owner);

                MessageBox.Show("儲存完畢!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("儲存失敗!" + ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// SqlServer 2005 upwards supports XML data types. 
        /// You could have xml text node containing data you wish converted to an int array for simpler data mapping
        /// within your mapper file.
        /// </summary>
        /// <param name="getter"></param>
        /// <returns></returns>
        public object GetResult(IResultGetter getter)
        {
            if (getter.Value == null)
                return null;

            var xmlString = getter.Value.ToString();

            if (String.IsNullOrEmpty(xmlString) || xmlString.Trim().Length == 0)
                return null;

            var integerArray = new List<int>();

            using (var reader = new XmlTextReader(new StringReader(xmlString)))
            {
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Text)
                        continue;

                    if (String.IsNullOrEmpty(reader.Value))
                        continue;

                    integerArray.Add(reader.ReadContentAsInt());
                }
            }

            return integerArray.ToArray();
        }
 public object GetResult(IResultGetter getter)
 {
     if ((getter.Value == null) || (getter.Value == DBNull.Value))
     {
         return DateTime.MinValue;
     }
     return getter.Value;
 }
Exemplo n.º 4
0
 object ITypeHandlerCallback.GetResult(IResultGetter getter)
 {
     if ((getter.Value == null) || (getter.Value == DBNull.Value))
     {
         return(DateTime.MinValue);
     }
     return(getter.Value);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Performs processing on a value before after it has been retrieved
 /// from a IDataReader.
 /// </summary>
 /// <param name="getter">The interface for getting the value from the IDataReader.</param>
 /// <returns>The processed value.</returns>
 public object GetResult(IResultGetter getter)
 {
     if (getter != null)
     {
         return(getter.Value.ToString());
     }
     return(string.Empty);
 }
Exemplo n.º 6
0
 public object GetResult(IResultGetter getter)
 {
     if ((getter.Value == null) || (getter.Value == DBNull.Value))
     {
         return(DateTime.MinValue);
     }
     return(getter.Value);
 }
        /// <summary>
        /// Performs processing on a value before after it has been retrieved
        /// from a IDataReader.
        /// </summary>
        /// <param name="getter">The interface for getting the value from the IDataReader.</param>
        /// <returns>The processed value.</returns>
        public object GetResult(IResultGetter getter)
        {
            if (getter.Value != null && getter.Value != System.DBNull.Value)
            {
                return(getter.Value.ToString());
            }

            return(string.Empty);
        }
Exemplo n.º 8
0
 public object GetResult(IResultGetter getter)
 {
     try {
         Guid result = new Guid(getter.Value.ToString());
         return(result);
     }
     catch
     {
         throw new Exception("Unexpected value " + getter.Value.ToString() + " found where a valid GUID string value was expected.");
     }
 }
		public object GetResult(IResultGetter getter)
		{
			try {
				Guid result = new Guid(getter.Value.ToString());
				return result;
			} 
			catch
			{
 				 throw new Exception("Unexpected value " + getter.Value.ToString() + " found where a valid GUID string value was expected.");
			}
		}
Exemplo n.º 10
0
        public void ShouldCreateTreeWithAComplexArrangementOfFactories()
        {
            (DependencyInjector pdi, Assembly assembly) = Utils.CreateIOCCinAssembly("MultipleCallsTestData", "ComplexFactory");
            (object factory1, InjectionState injectionState)
                = pdi.CreateAndInjectDependencies(
                      "IOCCTest.MultipleCallsTestData.ComplexFactory", assemblies: new Assembly[] { assembly });
            IResultGetter result = factory1 as IResultGetter;

            ;
            Assert.IsNotNull(result.GetResults()?.ChildOne);
            Assert.IsNotNull(result.GetResults()?.ChildTwo);
            Assert.IsNotNull(((IResultGetter)result.GetResults()?.ChildOne)?.GetResults().ChildTwo);
            Assert.AreEqual(result?.GetResults().ChildTwo
                            , ((IResultGetter)result.GetResults()?.ChildOne)?.GetResults().ChildTwo);
        }
Exemplo n.º 11
0
        private void DockControl(IContractEditor editor)
        {
            Control ctrl = editor as UserControl;

            panel.Controls.Clear();
            ctrl.Dock = DockStyle.Fill;
            panel.Controls.Add(ctrl);
            this.Editor = ctrl;

            if (Contract.Definition != null)
            {
                IResultGetter rg = ctrl as IResultGetter;
                rg.SetDefinition(Contract.Definition);
            }
        }
Exemplo n.º 12
0
    public object GetResult(IResultGetter getter)
    {
        IDataReader reader = getter.DataReader;

        // (A) define whatever type you want to
        // (B) read rows from DataReader and populate your type from (A)
        while (reader.Read())
        {
            // iterate over the columns of the current row
            for (int i = 0; i < reader.FieldCount; i++)
            {
                // populate your type from (A)
            }
        }
        return(...);      // return your type from (A)
    }
 public object GetResult(IResultGetter getter)
 {
     int i = int.Parse(getter.Value.ToString());
     if (TRUE.Equals(i))
     {
         return true;
     }
     else if (FALSE.Equals(i))
     {
         return false;
     }
     else
     {
      				 throw new DataMapperException("Unexpected value " + i + " found where "+TRUE+" or "+FALSE+" was expected.");
     }
 }
Exemplo n.º 14
0
        public void ShouldCreateTreeWithNamedRootConstructor()
        {
            (DependencyInjector pdi, Assembly assembly) =
                CreateIOCCinAssembly(CONSTRUCTOR_TEST_NAMESPACE
                                     , "NamedRootConstructor");
            (object bean, InjectionState injectionState) = pdi.CreateAndInjectDependencies(
                "IOCCTest.ConstructorTestData.NamedRootConstructor"
                , assemblies: new Assembly[] { assembly }
                , rootBeanSpec: new RootBeanSpec(rootConstructorName: "TestConstructor"));
            Diagnostics   diagnostics = injectionState.Diagnostics;
            IResultGetter result      = bean as IResultGetter;

            System.Diagnostics.Debug.WriteLine(diagnostics);
            Assert.AreEqual("stuff", result?.GetResults().Stuff);
            Assert.IsFalse(Falsify(diagnostics.HasWarnings));
        }
		public object GetResult(IResultGetter getter)
		{
			string s = getter.Value as string;
			if (YES.Equals(s)) 
			{
				return true;
			}
			else if (NO.Equals(s)) 
			{
				return false;
			} 
			else 
			{
				throw new Exception("Unexpected value " + s + " found where "+YES+" or "+NO+" was expected.");
			}
		}
Exemplo n.º 16
0
        public void ShouldCreateTreeWithDerivedConstructor()
        {
            (PDependencyInjector pdi, Assembly assembly) =
                CreateIOCCinAssembly(DERIVED_ATTRIBUTE_TEST_NAMESPACE
                                     , "DerivedConstructor");
            (object obj, InjectionState InjectionState)
                = pdi.CreateAndInjectDependencies(
                      "IOCCTest.DerivedAttributeTestData.DerivedConstructor"
                      , assemblies: new Assembly[] { assembly }
                      , rootBeanSpec: new RootBeanSpec(rootConstructorName: "TestConstructor"));
            IResultGetter result      = obj as IResultGetter;
            Diagnostics   diagnostics = InjectionState.Diagnostics;

            System.Diagnostics.Debug.WriteLine(diagnostics);
            Assert.AreEqual("somestuff", result?.GetResults().Stuff);
            Assert.IsFalse(Falsify(diagnostics.HasWarnings));
        }
Exemplo n.º 17
0
        public object GetResult(IResultGetter getter)
        {
            string type = getter.Value.ToString();

            if (type == "Monograph" || type == "Book")
            {
                return("Book");
            }
            else if (type == "Tabloid" || type == "Broadsheet" || type == "Newspaper")
            {
                return("Newspaper");
            }
            else
            {
                return("Document");
            }
        }
Exemplo n.º 18
0
        public object GetResult(IResultGetter getter)
        {
            string s = getter.Value as string;

            if (YES.Equals(s))
            {
                return(true);
            }
            else if (NO.Equals(s))
            {
                return(false);
            }
            else
            {
                throw new Exception("Unexpected value " + s + " found where " + YES + " or " + NO + " was expected.");
            }
        }
Exemplo n.º 19
0
        public void ShouldAddFactoryCreatedParameterBeansToInjectionState()
        {
            (DependencyInjector pdi, Assembly assembly) = Utils.CreateIOCCinAssembly(
                "MultipleCallsTestData", "FactoryMadeWithConstructor");
//            Assembly assembly = this.GetType().Assembly;
//            var pdi = new DependencyInjector();
            (object fmwc, InjectionState injectionState)
                = pdi.CreateAndInjectDependencies(
                      "IOCCTest.MultipleCallsTestData.FactoryMadeWithConstructor", assemblies: new Assembly[] { assembly });
            IResultGetter result = fmwc as IResultGetter;

            Assert.AreEqual(1, result?.GetResults().FurthestCtr);
            (object furthest, _)
                = pdi.CreateAndInjectDependencies(
                      "IOCCTest.MultipleCallsTestData.Furthest", injectionState: injectionState, assemblies: new Assembly[] { assembly });
            Assert.AreEqual(1, result?.GetResults().FurthestCtr);
        }
        public object GetResult(IResultGetter getter)
        {
            int i = int.Parse(getter.Value.ToString());

            if (TRUE.Equals(i))
            {
                return(true);
            }
            else if (FALSE.Equals(i))
            {
                return(false);
            }
            else
            {
                throw new DataMapperException("Unexpected value " + i + " found where " + TRUE + " or " + FALSE + " was expected.");
            }
        }
Exemplo n.º 21
0
 public object GetResult(IResultGetter getter)
 {
     try
     {
         var res = getter.Value.ToString();
         return(res);
     }
     catch (IndexOutOfRangeException indexEx)
     {
         return(NullValue);
     }
     catch (Exception ee)
     {
         throw new Exception("Unexpected value " + getter.Value.ToString() +
                             " found where a valid string value was expected.");
     }
 }
Exemplo n.º 22
0
        public object GetResult(IResultGetter getter)
        {
            string type = getter.Value.ToString();

            if (type=="Monograph" || type=="Book")
            {
                return "Book";
            }
            else if (type=="Tabloid" || type=="Broadsheet" || type=="Newspaper")
            {

                return "Newspaper";
            }
            else
            {
                return "Document";
            }
        }
Exemplo n.º 23
0
        public void ShouldCreateLinuxTypesOnLinux()
        {
            (DependencyInjector pdi, Assembly assembly) = Utils.CreateIOCCinAssembly("TestData", "CrossPlatform");
            (object rootBean, InjectionState injectionState)
                = pdi.CreateAndInjectDependencies("IOCCTest.TestData.CrossPlatform"
                                                  , assemblies: new Assembly[] { assembly });
            IResultGetter result = rootBean as IResultGetter;

#if WINDOWSTEST
            Assert.IsNotNull(result.GetResults().Windows, "try \"dotnet run -c LinuxTest\" or \"dotnet run -c MacOsTest\"");
#endif
#if LINUXTEST
            Assert.IsNotNull(result.GetResults().Linux);
#endif
#if MACOSTEST
            Assert.IsNotNull(result.GetResults().Macos);
#endif
        }
Exemplo n.º 24
0
 public object GetResult(IResultGetter getter)
 {
     try
     {
         string retVal = "非正式";
         string getVal = getter.Value.ToString();
         if (getVal.StartsWith("pro"))
         {
             retVal = "正式";
         }
         return(retVal);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
         return("");
     }
 }
Exemplo n.º 25
0
        /// <summary>
        /// Performs processing on a value before after it has been retrieved
        /// from a IDataReader.
        /// </summary>
        /// <param name="getter">The interface for getting the value from the IDataReader.</param>
        /// <returns>The processed value.</returns>
        public object GetResult(IResultGetter getter)
        {
            if (getter.Value != null && getter.Value != System.DBNull.Value)
            {
                try
                {
                    if (getter.Value.ToString() == string.Empty)
                    {
                        return(new DateTime(2000, 1, 1));
                    }

                    return(DateTime.Parse(getter.Value.ToString()));
                }
                catch
                {
                    return(new DateTime(2000, 1, 1));
                }
            }

            return(new DateTime(2000, 1, 1));
        }
 public object GetResult(IResultGetter getter)
 {
     if (getter.Value != null && getter.Value != System.DBNull.Value) {
         int i = Convert.ToInt32(getter.Value);
         if (i == 100)
         {
             return true;
         }
         else if (i == 200)
         {
             return false;
         }
         else
         {
             throw new DataMapperException("Unexpected value " + i + " found where 100 or 200 was expected.");
         }
     }
     else
     {
         throw new DataMapperException("Unexpected null value found where 100 or 200 was expected.");
     }
 }
 public object GetResult(IResultGetter getter)
 {
     if (getter.Value != null && getter.Value != System.DBNull.Value)
     {
         int i = Convert.ToInt32(getter.Value);
         if (i == 100)
         {
             return(true);
         }
         else if (i == 200)
         {
             return(false);
         }
         else
         {
             throw new DataMapperException("Unexpected value " + i + " found where 100 or 200 was expected.");
         }
     }
     else
     {
         throw new DataMapperException("Unexpected null value found where 100 or 200 was expected.");
     }
 }
        /// <summary>
        /// SqlServer 2005 upwards supports XML data types.
        /// You could have xml text node containing data you wish converted to an int array for simpler data mapping
        /// within your mapper file.
        /// </summary>
        /// <param name="getter"></param>
        /// <returns></returns>
        public object GetResult(IResultGetter getter)
        {
            if (getter.Value == null)
            {
                return(null);
            }

            var xmlString = getter.Value.ToString();

            if (String.IsNullOrEmpty(xmlString) || xmlString.Trim().Length == 0)
            {
                return(null);
            }

            var integerArray = new List <int>();

            using (var reader = new XmlTextReader(new StringReader(xmlString)))
            {
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Text)
                    {
                        continue;
                    }

                    if (String.IsNullOrEmpty(reader.Value))
                    {
                        continue;
                    }

                    integerArray.Add(reader.ReadContentAsInt());
                }
            }

            return(integerArray.ToArray());
        }
 public object GetResult(IResultGetter getter)
 {
     EnumTryParse(getter.Value.ToString(), out T output);
     return(output);
 }
        public object GetResult(IResultGetter getter)
        {
            var output = getter.Value.ToString().GetValue <T>();

            return(output);
        }
Exemplo n.º 31
0
 public object GetResult(IResultGetter getter)
 {
     throw new Exception("这个方法不准使用");
 }
 /// <summary>
 /// 从DataReader读取的数值的转换
 /// </summary>
 /// <param name="getter">DataReader获取器</param>
 /// <returns>返回转化后的C#类型</returns>
 public object GetResult(IResultGetter getter)
 {
     return(Convert.ToString(getter.Value));
 }
Exemplo n.º 33
0
 /// <summary>
 /// 从DataReader读取的数值的转换
 /// </summary>
 /// <param name="getter">DataReader获取器</param>
 /// <returns>返回转化后的C#类型</returns>
 public object GetResult(IResultGetter getter)
 {
     return(getter.Value is System.DBNull ? 0.0d : Convert.ToDouble(getter.Value));
 }