Exemplo n.º 1
0
        /// <summary>
        /// Creates a 3D plan.
        /// </summary>
        /// <param name="fftType">Type of FFT.</param>
        /// <param name="dataType">Data type.</param>
        /// <param name="nx">The number of samples in x dimension.</param>
        /// <param name="ny">The number of samples in y dimension.</param>
        /// <param name="nz">The number of samples in z dimension.</param>
        /// <param name="batchSize">Size of batch.</param>
        /// <returns>Plan.</returns>
        public override FFTPlan3D Plan3D(eFFTType fftType, eDataType dataType, int nx, int ny, int nz, int batchSize)
        {
            int         insize, outsize;
            CUFFTType   cuFFTType = VerifyTypes(fftType, dataType, out insize, out outsize);
            cufftHandle handle    = new cufftHandle();

            CUFFTResult res;

            if (batchSize <= 1)
            {
                res = _driver.cufftPlan3d(ref handle, nx, ny, nz, cuFFTType);
            }
            else
            {
                res = _driver.cufftPlanMany(ref handle, 3, new int[] { nx, ny, nz }, null, 1, 0, null, 1, 0, cuFFTType, batchSize);
            }

            if (res != CUFFTResult.Success)
            {
                throw new CudafyHostException(res.ToString());
            }
            FFTPlan3D   plan   = new FFTPlan3D(nx, ny, nz, batchSize, this);
            FFTPlan3DEx planEx = new FFTPlan3DEx(plan)
            {
                CudaFFTHandle = handle, CudaFFTType = cuFFTType, DataType = dataType
            };

            Plans.Add(plan, planEx);
            return(plan);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Verifies the types.
        /// </summary>
        /// <param name="fftType">Type of the FFT.</param>
        /// <param name="dataType">Type of the data.</param>
        /// <param name="inSize">Size of input elements.</param>
        /// <param name="outSize">Size of output elements.</param>
        /// <returns>The CUFFTType.</returns>
        protected CUFFTType VerifyTypes(eFFTType fftType, eDataType dataType, out int inSize, out int outSize)
        {
            inSize  = 8;
            outSize = 8;
            bool isDouble = dataType == eDataType.Double;

            CUFFTType cuFftType;

            if (fftType == eFFTType.Complex2Complex)
            {
                cuFftType = isDouble ? CUFFTType.Z2Z : CUFFTType.C2C;
            }
            else if (fftType == eFFTType.Complex2Real)
            {
                cuFftType = isDouble ? CUFFTType.Z2D : CUFFTType.C2R;
            }
            else //if (fftType == eFFTType.Real2Complex)
            {
                cuFftType = isDouble ? CUFFTType.D2Z : CUFFTType.R2C;
            }

            inSize  = ((fftType == eFFTType.Complex2Complex || fftType == eFFTType.Complex2Real) ? 8 : 4) * (isDouble ? 2 : 1);
            outSize = ((fftType == eFFTType.Complex2Complex || fftType == eFFTType.Real2Complex) ? 8 : 4) * (isDouble ? 2 : 1);

            return(cuFftType);
        }
Exemplo n.º 3
0
        public cPropertyType(string Name, eDataType PropertyType)
        {
            this.Name = Name;
            this.Type = PropertyType;

            Min = DefaultMin;
            Max = DefaultMax;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a 3D plan.
        /// </summary>
        /// <param name="fftType">Type of FFT.</param>
        /// <param name="dataType">The data type.</param>
        /// <param name="nx">The x length in samples.</param>
        /// <param name="ny">The y length in samples.</param>
        /// <param name="nz">The z length in samples.</param>
        /// <param name="batch">The number of FFTs in batch.</param>
        /// <returns>
        /// Plan.
        /// </returns>
        public override FFTPlan3D Plan3D(eFFTType fftType, eDataType dataType, int nx, int ny, int nz, int batch = 1)
        {
            int       insize, outsize;
            int       totalSize = nx * ny * nz;
            CUFFTType cuFFTType = VerifyTypes(fftType, dataType, out insize, out outsize);
            //Console.WriteLine(size);
            IntPtr pin  = fftwf.malloc(totalSize * insize * batch);
            IntPtr pout = fftwf.malloc(totalSize * outsize * batch);

            Ifftw_plan fwdPlan;
            Ifftw_plan invPlan;

            if (dataType == eDataType.Single)
            {
                if (batch == 1)
                {
                    fwdPlan = fftwf_plan.dft_3d(fftType, nx, ny, nz, pin, pout, fftw_direction.Forward, fftw_flags.Estimate);
                    invPlan = fftwf_plan.dft_3d(fftType, nx, ny, nz, pin, pout, fftw_direction.Backward, fftw_flags.Estimate);
                }
                else
                {
                    fwdPlan = fftwf_plan.dft_many(fftType, 3, new int[] { nx, ny, nz }, batch,
                                                  pin, null, 1, nx * ny * nz,
                                                  pout, null, 1, nx * ny * nz, fftw_direction.Forward, fftw_flags.Estimate);
                    invPlan = fftwf_plan.dft_many(fftType, 3, new int[] { nx, ny, nz }, batch,
                                                  pin, null, 1, nx * ny * nz,
                                                  pout, null, 1, nx * ny * nz, fftw_direction.Backward, fftw_flags.Estimate);
                }
            }
            else
            {
                if (batch == 1)
                {
                    fwdPlan = fftw_plan.dft_3d(fftType, nx, ny, nz, pin, pout, fftw_direction.Forward, fftw_flags.Estimate);
                    invPlan = fftw_plan.dft_3d(fftType, nx, ny, nz, pin, pout, fftw_direction.Backward, fftw_flags.Estimate);
                }
                else
                {
                    fwdPlan = fftw_plan.dft_many(fftType, 3, new int[] { nx, ny, nz }, batch,
                                                 pin, null, 1, nx * ny * nz,
                                                 pout, null, 1, nx * ny * nz, fftw_direction.Forward, fftw_flags.Estimate);
                    invPlan = fftw_plan.dft_many(fftType, 3, new int[] { nx, ny, nz }, batch,
                                                 pin, null, 1, nx * ny * nz,
                                                 pout, null, 1, nx * ny * nz, fftw_direction.Backward, fftw_flags.Estimate);
                }
            }

            FFTPlan3D   plan   = new FFTPlan3D(nx, ny, nz, batch, this);
            FFTPlan3DEx planEx = new FFTPlan3DEx(plan)
            {
                FFTWFwdPlan = fwdPlan, FFTWInvPlan = invPlan, N = totalSize, DataType = dataType
            };

            Plans.Add(plan, planEx);
            return(plan);
        }
Exemplo n.º 5
0
 public DataColumnAttribute(string name, eDataType type, int size, int precision, int scale, bool primaryKey, bool nullable, bool auto, bool enable)
 {
     ColumnName = name;
     ColumnType = type;
     Size       = size;
     PrimaryKey = primaryKey;
     Precision  = precision;
     Scale      = scale;
     Nullable   = nullable;
     Auto       = auto;
     Enabled    = enable;
 }
Exemplo n.º 6
0
 internal ColumnSchema(
     string name,
     eDataType dataType,
     bool notNull        = false,
     bool autoIncrement  = false,
     bool unique         = false,
     object defaultValue = null,
     long?length         = null)
 {
     this.name          = name;
     this.dataType      = dataType;
     this.notNull       = notNull;
     this.autoIncrement = autoIncrement;
     this.unique        = unique;
     this.defaultValue  = defaultValue;
     this.length        = length;
 }
Exemplo n.º 7
0
    public bool IsDone(eDataType eType)
    {
        if (false == m_dicAllLoadData.ContainsKey(eType))
        {
            return(true);
        }

        foreach (var kvp in m_dicAllLoadData[eType])
        {
            if (false == kvp.Value.IsDone())
            {
                return(false);
            }
        }

        return(true);
    }
Exemplo n.º 8
0
    /// <summary>
    /// 데이터를 저장할 경로가 있는지 확인하고, 없으면 경로에 맞는 폴더를 생성합니다.
    /// </summary>
    /// <param name="_t">데이터의 타입입니다 플레이어, 차일드 등이 있습니다.</param>
    /// <param name="_dataSlot">데이터 저장 슬롯의 번호입니다.이 번호에 따라 Data_n의 폴더가 만들어집니다.</param>
    /// <returns></returns>
    public IEnumerator CreatePath(eDataType _t, int _dataSlot)
    {
        string path = Application.dataPath + "/DataSlot_" + _dataSlot + "/";

        currentFilePath = path;
        string tempName = string.Empty;

        SetFileName();
        //dataPath/DataSlot_1/

        switch (_t)
        {
        case eDataType.PLAYER:
            tempName = playerFileName;
            break;

        case eDataType.CHILD:
            tempName = childFileName;
            break;

        case eDataType.SETTINGS:
            tempName = settingsFileName;
            break;

        case eDataType.STAGE:
            tempName = stageFileName;
            break;

        default:
            break;
        }

        yield return(StartCoroutine(fileManager.IsExist(tempName, path)));

        if (fileManager.isExist_Result == false) //파일이 없으면
        {
            DirectoryInfo di = new DirectoryInfo(path);
            di.Create();

            //에디터일 경우 Refresh를 시켜줌.
#if UNITY_EDITOR
            AssetDatabase.Refresh();
#endif
        }
    }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            eDataType dd = (eDataType)Enum.Parse(typeof(eDataType), "open");

            /*
             *
             */
            var token = "AIzaSyBSD5vZpqL2Q0hV-CDwX6T7oYKTbEernjQ";

            // specify your app’s client key when creating the auth provider
            var ap = new FirebaseAuthProvider(new FirebaseConfig(token));

            // var result3=ap.CreateUserWithEmailAndPasswordAsync("xxx", "ccc").Result;
            // var result3 = ap.CreateUserWithEmailAndPasswordAsync("xxx", "ccc").Result;
            // FirebaseAuthLink rr =  ap.SignInWithEmailAndPasswordAsync("", "").Result;

            // sign in with OAuth. You can also sign in anonymously
            var auth = ap.SignInWithEmailAndPasswordAsync("*****@*****.**", "x").Result;

            var ddd   = auth.FirebaseToken;
            var ddddd = ap.GetUserAsync(ddd).Result;

            Console.WriteLine("{0},{1}", ddddd.Email, ddddd.LastName);
            Console.ReadLine();

            var firebase = new FirebaseClient(
                "https://fir-tocrm.firebaseio.com",
                new FirebaseOptions
            {
                AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken)
            });

            var dinos = firebase
                        .Child("posts")
                        .OnceAsync <PostDetail>().Result;

            foreach (var dino in dinos)
            {
                Console.WriteLine($"{dino.Key} is {dino.Object.author }m high.");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a 1D plan.
        /// </summary>
        /// <param name="fftType">Type of FFT.</param>
        /// <param name="dataType">The data type.</param>
        /// <param name="nx">The length in samples.</param>
        /// <param name="batch">The number of FFTs in batch.</param>
        /// <param name="istride">The istride.</param>
        /// <param name="idist">The idist.</param>
        /// <param name="ostride">The ostride.</param>
        /// <param name="odist">The odist.</param>
        /// <returns>Plan.</returns>
        public override FFTPlan1D Plan1D(eFFTType fftType, eDataType dataType, int nx, int batch, int istride, int idist, int ostride, int odist)
        {
            int       insize, outsize;
            CUFFTType cuFFTType = VerifyTypes(fftType, dataType, out insize, out outsize);
            //Console.WriteLine(size);
            IntPtr pin  = fftwf.malloc(nx * insize * batch);
            IntPtr pout = fftwf.malloc(nx * outsize * batch);

            Ifftw_plan fwdPlan;
            Ifftw_plan invPlan;

            if (dataType == eDataType.Single)
            {
                fwdPlan = fftwf_plan.dft_many(fftType, 1, new int[] { nx }, batch,
                                              pin, null, istride, idist,
                                              pout, null, ostride, odist, fftw_direction.Forward, fftw_flags.Estimate);
                invPlan = fftwf_plan.dft_many(fftType, 1, new int[] { nx }, batch,
                                              pin, null, istride, idist,
                                              pout, null, ostride, odist, fftw_direction.Backward, fftw_flags.Estimate);
            }
            else
            {
                fwdPlan = fftw_plan.dft_many(fftType, 1, new int[] { nx }, batch,
                                             pin, null, istride, idist,
                                             pout, null, ostride, odist, fftw_direction.Forward, fftw_flags.Estimate);
                invPlan = fftw_plan.dft_many(fftType, 1, new int[] { nx }, batch,
                                             pin, null, istride, idist,
                                             pout, null, ostride, odist, fftw_direction.Backward, fftw_flags.Estimate);
            }

            FFTPlan1D   plan   = new FFTPlan1D(nx, batch, this);
            FFTPlan1DEx planEx = new FFTPlan1DEx(plan)
            {
                FFTWFwdPlan = fwdPlan, FFTWInvPlan = invPlan, N = nx, DataType = dataType
            };

            Plans.Add(plan, planEx);
            return(plan);
        }
Exemplo n.º 11
0
        public override FFTPlan1D Plan1D(eFFTType fftType, eDataType dataType, int nx, int batchSize, int istride, int idist, int ostride, int odist)
        {
            int         insize, outsize;
            CUFFTType   cuFFTType = VerifyTypes(fftType, dataType, out insize, out outsize);
            cufftHandle handle    = new cufftHandle();
            CUFFTResult res;

            if (batchSize <= 1)
            {
                res = _driver.cufftPlan1d(ref handle, nx, cuFFTType, batchSize);
            }
            else
            {
                res = _driver.cufftPlanMany(ref handle, 1, new int[] { nx },
                                            new int[] { idist }, //inembed
                                            istride,             //istride
                                            idist,               //idist
                                            new int[] { odist }, //onembed
                                            ostride,             //ostride
                                            odist,               //odist
                                            cuFFTType,
                                            batchSize);
            }

            if (res != CUFFTResult.Success)
            {
                throw new CudafyHostException(res.ToString());
            }
            FFTPlan1D   plan   = new FFTPlan1D(nx, batchSize, this);
            FFTPlan1DEx planEx = new FFTPlan1DEx(plan)
            {
                CudaFFTHandle = handle, CudaFFTType = cuFFTType, DataType = dataType
            };

            Plans.Add(plan, planEx);
            return(plan);
        }
Exemplo n.º 12
0
    public bool IsDone(eDataType eType)
    {
        if (false == m_dicTotalLoadData.ContainsKey(eType))
        {
            return(true);
        }

        var dicDataInfo = m_dicTotalLoadData[eType];

        foreach (var kvp in dicDataInfo)
        {
            if (null == kvp.Value)
            {
                continue;
            }

            if (false == kvp.Value.m_bIsDone)
            {
                return(false);
            }
        }

        return(true);
    }
Exemplo n.º 13
0
 public bool IsLoadDone(eDataType eType)
 {
     return(m_pLoader.IsLoadDone(eType));
 }
Exemplo n.º 14
0
 public static string DataTypeToString(eDataType dataType)
 {
     return(Enum.GetName(typeof(eDataType), dataType).ToUpper());
 }
Exemplo n.º 15
0
 // 특정 타입이 로드완료되었는가?(성공/실패유무가 아님)
 public bool IsLoadDone(eDataType eType)
 {
     return(m_pProgress.IsDone(eType));
 }
Exemplo n.º 16
0
        ////public override double ASUM<T>(Types.ComplexD[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override double ASUM<T>(Types.ComplexD[] vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override float ASUM<T>(Types.ComplexF[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override float ASUM<T>(Types.ComplexF[] vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override double ASUM<T>(double[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override double ASUM<T>(double[] vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override float ASUM<T>(float[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override float ASUM<T>(float[] vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////protected override void AXPYEx<T>(object alpha, object vectorx, object vectory, int n = 0, int row = 0, int incx = 1, int y = 0, int incy = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override void AXPY<T>(T alpha, T[] vectorx, T[] vectory, int n = 0, int row = 0, int incx = 1, int y = 0, int incy = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //protected override void COPY<T>(object src, object dst, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //public override T DOT<T>(T[] vectorx, T[] vectory, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //public override T NRM2<T>(T[] vectorx, int n = 0, int rowx = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //protected override int IAMAXEx<T>(object devArray, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override Tuple<int,int> IAMAX<T>(T[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //protected override int IAMINEx<T>(object devArray, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override int IAMIN<T>(T[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override void SCALEx<T>(T alpha, object vector, int n = 0, int row = 0, int incx = 1)
        //{
        //    throw new NotImplementedException();
        //}

        ////public override void SCAL<T>(T alpha, T[,] devMatrix, int n = 0, int row = 0, int col = 0, bool columnWise = true, int incx = 1)
        ////{
        ////    throw new NotImplementedException();
        ////}

        //public override T DOTC<T>(T[] vectorx, T[] vectory, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 1)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROT(float[] vectorx, float[] vectory, float sc, float ss, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROT(double[] vectorx, double[] vectory, double sc, double ss, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROT(Types.ComplexF[] vectorx, Types.ComplexF[] vectory, float sc, Types.ComplexF ss, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROT(Types.ComplexD[] vectorx, Types.ComplexD[] vectory, float sc, Types.ComplexD cs, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}


        //public override void ROTM(float[] vectorx, float[] vectory, float[] sparam, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void ROTM(double[] vectorx, double[] vectory, double[] sparam, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        //public override void SWAP<T>(T[] vectorx, T[] vectory, int n = 0, int rowx = 0, int incx = 1, int rowy = 0, int incy = 0)
        //{
        //    throw new NotImplementedException();
        //}

        private IntPtr SetupVector <T>(object vector, int x, ref int n, ref int incx, out eDataType type)
        {
            EmuDevicePtrEx ptrEx = _gpu.GetDeviceMemory(vector) as EmuDevicePtrEx;

            if (incx == 0)
            {
                throw new CudafyHostException(CudafyHostException.csX_NOT_SET, "incx");
            }
            n    = (n == 0 ? ptrEx.TotalSize / incx : n);
            type = GetDataType <T>();
            int    size = Marshal.SizeOf(typeof(T));
            IntPtr ptr  = ptrEx.GetDevPtrPtr(size * x);// DevPtr + (uint)(size * x);

            return(ptr);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Creates a 3D plan.
 /// </summary>
 /// <param name="fftType">Type of FFT.</param>
 /// <param name="dataType">The data type.</param>
 /// <param name="nx">The x length in samples.</param>
 /// <param name="ny">The y length in samples.</param>
 /// <param name="nz">The z length in samples.</param>
 /// <param name="batch">The number of FFTs in batch.</param>
 /// <returns>Plan.</returns>
 public abstract FFTPlan3D Plan3D(eFFTType fftType, eDataType dataType, int nx, int ny, int nz, int batch = 1);
Exemplo n.º 18
0
 /// <summary>
 /// Plan1s the D.
 /// </summary>
 /// <param name="fftType">Type of the FFT.</param>
 /// <param name="dataType">Type of the data.</param>
 /// <param name="nx">The nx.</param>
 /// <param name="batchSize">Size of the batch.</param>
 /// <param name="istride">The istride.</param>
 /// <param name="idist">The idist.</param>
 /// <param name="ostride">The ostride.</param>
 /// <param name="odist">The odist.</param>
 /// <returns></returns>
 public abstract FFTPlan1D Plan1D(eFFTType fftType, eDataType dataType, int nx, int batchSize, int istride, int idist, int ostride, int odist);
Exemplo n.º 19
0
        public void ProcessData(double[] iSamples, double[] qSamples, eDataType type)
        {
            DirectXFFTDisplay display;
            FFTTransformer    fft;

            switch (type)
            {
            case eDataType.Input:
                display = FFTInput;
                fft     = FFTTransformerInput;
                break;

            case eDataType.Translated:
                display = FFTTranslated;
                fft     = FFTTransformerTranslated;
                break;

            case eDataType.Filtered:
                if (DecimateFiltered)
                {
                    return;
                }
                display = FFTFiltered;
                fft     = FFTTransformerFiltered;
                break;

            case eDataType.Decimated:
                if (!DecimateFiltered)
                {
                    return;
                }
                display = FFTFiltered;
                fft     = FFTTransformerDecimated;
                break;

            default:
                return;
            }

            if (display.EnoughData)
            {
                return;
            }

            lock (FFTLock)
            {
                int samplePairs = iSamples.Length;

                for (int samplePair = 0; samplePair < samplePairs; samplePair++)
                {
                    double I = iSamples[samplePair];
                    double Q = qSamples[samplePair];

                    fft.AddSample(I, Q);

                    if (fft.ResultAvailable)
                    {
                        fft.GetResultSquared(FFTResult);
                        display.ProcessFFTData(FFTResult, 0, 0);
                    }
                }
            }
        }
Exemplo n.º 20
0
            /// <summary>
            /// parses a <see cref="ColumnSchema"/> from <paramref name="columnSchemaXmlNode"/>.
            /// </summary>
            /// <param name="columnSchemaXmlNode"></param>
            /// <returns>
            /// <see cref="ColumnSchema"/> parsed from <paramref name="columnSchemaXmlNode"/>
            /// </returns>
            /// <exception cref="ColumnSchemaParseExcetion">
            /// thrown if <see cref="ColumnSchema"/> parse failed
            /// </exception>
            public static ColumnSchema Parse(XmlNode columnSchemaXmlNode)
            {
                assertContainsRequiredAttributes(columnSchemaXmlNode, "name", "type");

                // get required attributes
                string name       = columnSchemaXmlNode.GetAttributeValue("name");
                string typeString = columnSchemaXmlNode.GetAttributeValue("type");

                try
                {
                    // parse typeString into valid enum format
                    // convert typeString from a single-word string having all letters in uppercase
                    // to a single word in lowercase (which is equivalent to camelCase)
                    // and then to an enum value name format
                    typeString = EnumUtils.camelCaseStringToEnumValueNameFormat(typeString.ToLower());
                    eDataType dataType = EnumUtils.ParseEnum <eDataType>(typeString);

                    // get optional attributes
                    bool   notNull       = false;
                    bool   autoIncrement = false;
                    bool   unique        = false;
                    object defaultValue  = null;
                    long?  length        = null;

                    if (columnSchemaXmlNode.ContainsNodes("not_null"))
                    {
                        notNull = true;
                    }
                    if (columnSchemaXmlNode.ContainsNodes("auto_increment"))
                    {
                        autoIncrement = true;
                    }
                    if (columnSchemaXmlNode.ContainsNodes("unique"))
                    {
                        unique = true;
                    }
                    if (columnSchemaXmlNode.ContainsNodes("default"))
                    {
                        XmlNode defaultValueXmlNode = columnSchemaXmlNode.SelectNodes("default")[0];
                        defaultValue = defaultValueXmlNode.FirstChild.Value;
                    }
                    if (columnSchemaXmlNode.ContainsNodes("length"))
                    {
                        XmlNode lengthXmlNode = columnSchemaXmlNode.SelectNodes("length")[0];
                        length = long.Parse(lengthXmlNode.FirstChild.Value);
                    }

                    ColumnSchema columnSchema = new ColumnSchema(
                        name,
                        dataType,
                        notNull,
                        autoIncrement,
                        unique,
                        defaultValue,
                        length);

                    return(columnSchema);
                }
                // a required attribute was missing from XmlNode
                catch (XmlNodeMissingAttributeException missingAttributeException)
                {
                    string additionalDetails = string.Format(
                        "Required attribute '{0}' was missing from XmlNode.",
                        missingAttributeException.AttributeName);
                    throw new ColumnSchemaParseExcetion(additionalDetails, missingAttributeException);
                }
                catch (EnumParseException enumParseException) // invalid typeString (eDataType parse failed)
                {
                    string additionalDetails = string.Format(
                        "(Column '{0}') had an Invalid data type value: '{1}'.",
                        name,
                        typeString);
                    throw new ColumnSchemaParseExcetion(additionalDetails, enumParseException);
                }
            }
Exemplo n.º 21
0
 public static DbType GetType(eDataType type)
 {
     return(dicDataTypeToType[type]);
 }