Пример #1
0
        public async Task Serialize_TestMethodResultRecord()
        {
            var    grain  = this.GrainFactory.GetGrain <IRoundtripSerializationGrain>(GetRandomGrainId());
            RetVal retVal = await grain.GetRetValForParamVal(new ParamVal(42));

            Assert.Equal(42, retVal.Value);
        }
Пример #2
0
        public string AutoDetectEnumifiedOverrideReturn(AncestorDescendantCache cache)
        {
            if (RetVal.FullName != "int")
            {
                return(null);
            }

            var classes = cache.GetAncestorsAndDescendants(DeclaringType);

            classes = classes.Concat(classes.SelectMany(x => x.GetAllImplementedInterfaces()));

            foreach (var t in classes)
            {
                foreach (var candidate in t.GetAllMethods().Where(m => m.Name == Name && m.Parameters.Count == Parameters.Count))
                {
                    if (JniSignature != candidate.JniSignature)
                    {
                        continue;
                    }
                    if (candidate.IsReturnEnumified)
                    {
                        RetVal.SetGeneratedEnumType(candidate.RetVal.FullName);
                    }
                }
            }
            return(null);
        }
Пример #3
0
        private DataTable GetICTableWLevel(ref System.Data.DataTable table)
        {
            DataTable RetVal;
            DataRow   NewRow;

            DataRow[] Rows;
            int       Level = 0;

            table.Constraints.Clear();
            //- Allow db null
            table.Columns[IndicatorClassifications.ICType].AllowDBNull = true;

            //Step 1: Set indicator classification levels
            table.Columns.Add(LanguageKeys.Level, System.Type.GetType("System.Int32"));
            this.SetIndicatorClassificationLevel(table, -1, 0);

            //Step 2: Get maximum level from table
            table.DefaultView.Sort = LanguageKeys.Level + " DESC";
            if (table.Rows.Count > 0)
            {
                this.MaxLevel = Convert.ToInt32(table.DefaultView.ToTable().Rows[0][LanguageKeys.Level]);
            }
            else
            {
                this.MaxLevel = 1;
            }

            //Step 2: Create New Data Table to fill the list view
            RetVal = table.Clone();

            //insert columns for classification level info.
            for (Level = 1; Level <= this.MaxLevel; Level++)
            {
                RetVal.Columns.Add(LanguageKeys.Level + " " + Level);
            }

            //insert rows into new table
            foreach (DataRow Row in table.Rows)
            {
                Rows = RetVal.Select(IndicatorClassifications.ICNId + " =" + Row[IndicatorClassifications.ICParent_NId].ToString());

                NewRow = RetVal.NewRow();
                NewRow[IndicatorClassifications.ICNId]        = Row[IndicatorClassifications.ICNId];
                NewRow[IndicatorClassifications.ICParent_NId] = Row[IndicatorClassifications.ICParent_NId];
                NewRow[IndicatorClassifications.ICName]       = Row[IndicatorClassifications.ICName].ToString();
                NewRow[IndicatorClassifications.ICGlobal]     = Row[IndicatorClassifications.ICGlobal];
                NewRow[IndicatorClassifications.ICInfo]       = Row[IndicatorClassifications.ICInfo];
                NewRow[IndicatorClassifications.ICGId]        = Row[IndicatorClassifications.ICGId];

                NewRow[LanguageKeys.Level] = Row[LanguageKeys.Level];
                NewRow[LanguageKeys.Level + " " + Convert.ToInt32(Row[LanguageKeys.Level])] = Row[IndicatorClassifications.ICName].ToString();
                RetVal.Rows.Add(NewRow);
            }

            RetVal.AcceptChanges();
            this.SetIndicatorClassificationLevelName(RetVal);
            RetVal.DefaultView.Sort = IndicatorClassifications.ICNId;

            return(RetVal);
        }
Пример #4
0
        private void VisitRepeat(repeat_node stmt)
        {
            RetVal rv = GetConstantValue(stmt.condition);

            VisitStatement(stmt.body);
            VisitExpression(stmt.condition);
        }
Пример #5
0
        public override Vector3D normal(Vector3D intersectPoint)
        {
            Vector3D RetVal;

            RetVal = intersectPoint - Center;                    // Point
            RetVal.Normalize();                                  // Normalise operator, need unit vector.

            return(RetVal);
        }
Пример #6
0
        private void VisitWhile(while_node stmt)
        {
            RetVal rv = GetConstantValue(stmt.condition);

            VisitExpression(stmt.condition);
            if (rv == RetVal.False)
            {
                is_break_stmt = true;
            }
            VisitStatement(stmt.body);
        }
Пример #7
0
        //private void DeleteExtraRows(DataTable table)
        //{
        //    int IndicatorNid = 0;
        //    int UnitNid = 0;
        //    int SubgroupValNid = 0;
        //    int ICNid = 0;
        //    string FilterString = string.Empty;
        //    string LevelColumnName = string.Empty;

        //    List<ExtaRowInfo> ExtraRows = new List<ExtaRowInfo>();
        //    try
        //    {
        //        for (int Level = 1; Level < this.MaxLevel; Level++)
        //        {
        //            DataRow[] Rows = table.Select(Constants.LanguageKeys.Level + "=" + Level);

        //            // Get records where level is equal to 1
        //            foreach (DataRow Row in Rows)
        //            {
        //                ICNid = Convert.ToInt32(Row[IndicatorClassifications.ICNId]);
        //                IndicatorNid = Convert.ToInt32(Row[Indicator.IndicatorNId]);

        //                //create filterstring
        //                FilterString = string.Empty;
        //                for (int i = 1; i <= Level; i++)
        //                {
        //                    LevelColumnName = Constants.LanguageKeys.Level + " " + i;
        //                    FilterString += "[" + LevelColumnName + "]='" + Row[LevelColumnName].ToString() + "' And ";
        //                }


        //                FilterString += " " + Indicator.IndicatorNId + "=" + IndicatorNid;


        //                if (this._ShowIUS)
        //                {
        //                    UnitNid = Convert.ToInt32(Row[Unit.UnitNId]);
        //                    SubgroupValNid = Convert.ToInt32(Row[SubgroupVals.SubgroupValNId]);

        //                    FilterString += " and " + Unit.UnitNId + "=" + UnitNid;
        //                    FilterString += " and " + SubgroupVals.SubgroupValNId + "=" + SubgroupValNid;
        //                }



        //                //delete row if this is not the lowest IC level for the current IUS
        //                if (table.Select(FilterString).Length > 1)
        //                {
        //                    //ExtraRows.Add(new ExtaRowInfo(ICNid, IndicatorNid, UnitNid, SubgroupValNid));
        //                    Row.Delete();
        //                    table.AcceptChanges();
        //                }

        //            }

        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new ApplicationException(ex.ToString());
        //    }
        //}


        private DataTable DeleteExtraRows(DataTable table)
        {
            DataTable RetVal;
            int       IndicatorNid    = 0;
            int       UnitNid         = 0;
            int       SubgroupValNid  = 0;
            int       ICNid           = 0;
            string    FilterString    = string.Empty;
            string    LevelColumnName = string.Empty;

            try
            {
                RetVal = table.Clone();
                DataRow NewRow;

                for (int Level = this.MaxLevel; Level > 0; Level--)
                {
                    DataRow[] Rows = table.Select(Constants.LanguageKeys.Level + "=" + Level);

                    // Get records by level
                    foreach (DataRow Row in Rows)
                    {
                        IndicatorNid = Convert.ToInt32(Row[Indicator.IndicatorNId]);


                        LevelColumnName = Constants.LanguageKeys.Level + " " + Level;
                        FilterString    = "[" + LevelColumnName + "]='" + DICommon.RemoveQuotes(Row[LevelColumnName].ToString()) + "' And ";
                        FilterString   += " " + Indicator.IndicatorNId + "=" + IndicatorNid;

                        if (this._ShowIUS)
                        {
                            UnitNid        = Convert.ToInt32(Row[Unit.UnitNId]);
                            SubgroupValNid = Convert.ToInt32(Row[SubgroupVals.SubgroupValNId]);

                            FilterString += " and " + Unit.UnitNId + "=" + UnitNid;
                            FilterString += " and " + SubgroupVals.SubgroupValNId + "=" + SubgroupValNid;
                        }

                        if (RetVal.Select(FilterString).Length == 0)
                        {
                            RetVal.Rows.Add(Row.ItemArray);
                        }
                    }
                }
                RetVal.AcceptChanges();
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }

            return(RetVal);
        }
        public static MediaItem PopulateMetaData(MediaResource R, FileInfo F)
        {
            MediaItem RetVal;

            MediaBuilder.item Item   = null;
            DText             parser = new DText();

            parser.ATTRMARK = "-";
            parser.MULTMARK = ".";

            switch (F.Extension.ToUpper())
            {
            case ".MP3":
                Item = ParseMP3_V1(F);
                if (Item == null)
                {
                    parser[0] = F.Name;
                    if (parser.DCOUNT() == 2)
                    {
                        Item         = new MediaBuilder.musicTrack(parser[2, 1].Trim());
                        Item.creator = parser[1].Trim();
                        ((MediaBuilder.musicTrack)Item).artist = new PersonWithRole[1] {
                            new PersonWithRole()
                        };
                        ((MediaBuilder.musicTrack)Item).artist[0].Name = Item.creator;
                        ((MediaBuilder.musicTrack)Item).artist[0].Role = null;
                    }
                }
                break;
            }

            if (Item != null)
            {
                RetVal = MediaBuilder.CreateItem(Item);
                RetVal.AddResource(R);
                return(RetVal);
            }
            else
            {
                // Create a Generic Item
                string fname    = F.Name;
                int    fnameidx = fname.IndexOf(".");
                if (fnameidx != -1)
                {
                    fname = fname.Substring(0, fnameidx);
                }
                MediaBuilder.item genericItem = new MediaBuilder.item(fname);
                RetVal = MediaBuilder.CreateItem(genericItem);
                RetVal.AddResource(R);
                return(RetVal);
            }
        }
Пример #9
0
        internal void UIValue(StationInfo Record)
        {
            Record = StationInfo.GetRecord();
            int a = Record.retCode;

            db       = Record.retVal;
            savePath = "C:\\Users\\user\\Desktop\\rawdata\\" + db.Station_0001.mday;
            Console.WriteLine(db.Station_0001.mday);
            //board.AppendText("站點:  "+db.Station_0001.sna+"\n"
            //    +"資料更新時間:  "+db.Station_0001.mday+"\n"
            //    +"目前車輛數:  "+db.Station_0001.sbi+"\n"
            //    +"空位數量:  "+db.Station_0001.bemp+"\n"
            //    +"總停車格:  "+db.Station_0001.tot+"\n"
            //    +"*******************"+"\n");
        }
Пример #10
0
        private void VisitIf(if_node stmt)
        {
            RetVal rv = GetConstantValue(stmt.condition);

            VisitExpression(stmt.condition);
            if (rv == RetVal.False)
            {
                is_break_stmt = true;
            }
            VisitStatement(stmt.then_body);
            is_break_stmt = false;
            if (rv == RetVal.True)
            {
                is_break_stmt = true;
            }
            VisitStatement(stmt.else_body);
            is_break_stmt = false;
        }
Пример #11
0
 void GenerateGenericBody(StreamWriter sw, string indent, CodeGenerationOptions opt, string property_name, string container_prefix, Dictionary <string, string> mappings)
 {
     if (String.IsNullOrEmpty(property_name))
     {
         string call = container_prefix + Name + " (" + Parameters.GetGenericCall(opt, mappings) + ")";
         sw.WriteLine("{0}{1}{2};", indent, IsVoid ? String.Empty : "return ", RetVal.GetGenericReturn(opt, call, mappings));
     }
     else
     {
         if (IsVoid)                 // setter
         {
             sw.WriteLine("{0}{1} = {2};", indent, container_prefix + property_name, Parameters.GetGenericCall(opt, mappings));
         }
         else                 // getter
         {
             sw.WriteLine("{0}return {1};", indent, RetVal.GetGenericReturn(opt, container_prefix + property_name, mappings));
         }
     }
 }
Пример #12
0
 GetHomeConnection(Guid CustomerKey, string HomeFeatures)
 {
     lock (allSources)
     {
         InfostoreBase RetVal;
         if (!ValidHomeKey(CustomerKey))
         {
             throw new
                   InvalidKeyException("not valid for Home Edition");
         }
         allSources.TryGetValue(CustomerKey, out RetVal);
         if (RetVal == null)
         {
             RetVal = new InfostoreHomeEdition();
             allSources.Add(CustomerKey, RetVal);
         }
         var ActualVersion = (InfostoreHomeEdition)RetVal;
         RetVal.SetFeatures(HomeFeatures);
         return(RetVal);
     }
 }
Пример #13
0
 GetEnterpriseConnection(Guid CustomerKey, decimal BaseDiscount)
 {
     lock (allSources)
     {
         InfostoreBase RetVal;
         if (!ValidEnterpriseKey(CustomerKey))
         {
             throw new
                   InvalidKeyException("not valid for Enterprise Edition");
         }
         allSources.TryGetValue(CustomerKey, out RetVal);
         if (RetVal == null)
         {
             RetVal = new InfostoreHomeEdition();
             allSources.Add(CustomerKey, RetVal);
         }
         var ActualVersion = (InfostoreEnterpriseEdition)RetVal;
         RetVal.SetBaseDiscount(CostBase);
         return(RetVal);
     }
 }
Пример #14
0
        } //dg_ML_Futures_DragDrop()

        private String EnsureUnique(String inStr)
        {
            /*
             * Make sure comma seperated string only has unique values
             */
            // Local Variables
            String    RetVal  = "";
            ArrayList arr_Str = new ArrayList();

            String[] mySplit = inStr.Split(',');

            if (mySplit.Length == 1)
            {
                RetVal = inStr;
            }
            else
            {
                for (int i = 0; i < mySplit.Length; i++)
                {
                    if (!arr_Str.Contains(mySplit[i]) && mySplit[i] != "")
                    {
                        arr_Str.Add(mySplit[i]);
                        arr_Str.Sort();
                    }
                }

                for (int i = 0; i < arr_Str.Count; i++)
                {
                    RetVal = RetVal + arr_Str[i].ToString() + ",";
                }
                //Strip of last ","
                if (RetVal.EndsWith(","))
                {
                    RetVal = RetVal.Substring(0, RetVal.Length - 1);
                }
            }

            return(RetVal);
        } //EnsureUnique()
Пример #15
0
        /// <summary>
        /// Load the deserialize XML file
        /// </summary>
        /// <param name="fileNameWPath">File of cache file</param>
        /// <returns></returns>
        /// <remarks> Convention used for auto selected cache file : First letter as prefix of Indicator, Area, Timeperiod, & source and their selected NIds in the ascending order.
        /// For Available Nids cache file : DIWizard.xml
        /// </remarks>
        public static CacheInfo Load(string fileNameWPath)
        {
            CacheInfo RetVal;

            try
            {
                XmlSerializer CacheSerialize = new XmlSerializer(typeof(CacheInfo));
                TextReader    CacheReader    = new StreamReader(fileNameWPath);
                RetVal = (CacheInfo)CacheSerialize.Deserialize(CacheReader);
                CacheReader.Close();
                if (!RetVal.IsValidCache())
                {
                    // -- If the cache contain invalid or incomplete information.
                    RetVal = null;
                }
            }
            catch (Exception)
            {
                RetVal = null;
            }
            return(RetVal);
        }
Пример #16
0
        } // GetNextOrderRefID

        public static String GetNextFileName(ref String Basket)
        {
            // Local Variables Colin000009.inc";
            String RetVal;
            Char   FoundChar;

            RetVal = SystemLibrary.SQLSelectString("Exec sp_GetNextId 'BasketNo'");
            // Strip off leading text and leading zeros to get the BasketNo
            Char[] myArray = RetVal.ToCharArray();
            for (int i = myArray.Length - 1; i >= 0; i--)
            {
                FoundChar = myArray[i];
                if (FoundChar >= '0' && FoundChar <= '9')
                {
                    Basket = FoundChar.ToString() + Basket;
                }
                else
                {
                    break;
                }
            }
            Basket = Convert.ToInt16(Basket).ToString().Trim();
            return(RetVal + ".inc");
        } // GetNextFileName
Пример #17
0
        public static dynamic GetSetting(string Name, object DefaultValue = null, string SubKey = "")
        {
            //regkey is built from CompanyName\ProductName\MajorVersion.MinorVersion
            Version AN      = Assembly.GetExecutingAssembly().GetName().Version;
            string  Cname   = System.Windows.Forms.Application.CompanyName;
            string  Pname   = System.Windows.Forms.Application.ProductName;
            string  version = AN.Major + "." + AN.Minor;
            object  RetVal  = DefaultValue;
            string  SKey    = "";

            if (!string.IsNullOrWhiteSpace(SubKey))
            {
                SKey = "\\" + SubKey.Trim();
            }
            try
            {
                string RKey = $"Software\\{Cname}\\{Pname}\\{version}{SKey}";

                using (RegistryKey reg = Registry.CurrentUser.OpenSubKey(RKey, false))

                    if (reg != null)
                    {
                        bool     Found  = false;
                        string[] Values = reg.GetValueNames();
                        foreach (string valu in Values)
                        {
                            if (valu.ToLower() == Name.ToLower())
                            {
                                Found  = true;
                                RetVal = reg.GetValue(Name, DefaultValue);
                                break;
                            }
                        }
                        if (Found)
                        {
                            if (reg.GetValueKind(Name) == RegistryValueKind.MultiString)
                            {
                                if (DefaultValue is List <string> )
                                {
                                    RetVal = ((string[])RetVal).ToList();
                                }
                                else if (DefaultValue is object[])
                                {
                                    RetVal = (string[])RetVal;
                                }
                                else if (DefaultValue is string[])
                                {
                                    RetVal = (string[])RetVal;
                                }
                            }
                            else if (RetVal is string && DefaultValue is Point)
                            {
                                //{X=965,Y=399}
                                int X = GetNumberInt(Global.GetWordBetween(RetVal.ToString(), "X=", ","));
                                int Y = GetNumberInt(Global.GetWordBetween(RetVal.ToString(), "Y=", "}"));
                                RetVal = new Point(X, Y);
                            }
                            else if (RetVal is string && DefaultValue is Size)
                            {
                                //{Width=931, Height=592}
                                int Wid = GetNumberInt(Global.GetWordBetween(RetVal.ToString(), "Width=", ","));
                                int Hei = GetNumberInt(Global.GetWordBetween(RetVal.ToString(), "Height=", "}"));
                                RetVal = new Size(Wid, Hei);
                            }
                            else if (DefaultValue != null)
                            {
                                RetVal = Convert.ChangeType(RetVal, DefaultValue.GetType());
                            }
                            //Else
                            //    RetVal = Convert.ChangeType(RetVal, DefaultValue.GetType)
                        }
                    }
            }
            catch (Exception ex)
            {
                Global.Log($"Error: {Global.ExMsg(ex)}");
            }

            return(RetVal);
        }
Пример #18
0
        public T GetValue <T>(string KeyName, string SubKey, T DefaultValue)
        {
            if (LOG_CONFIGURATION_CALLS)
            {
                ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Getting {0} value '{1}' in subkey '{2}', default: '{3}'", typeof(T).Name, KeyName, SubKey, DefaultValue.ToString()));
            }

            if (typeof(T) == typeof(bool))
            {
                string registryValue;
                if (SubKey == "")
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
                    }
                    registryValue = (string)baseRegistryKey.GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }
                else
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
                    }
                    registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }

                if (registryValue == null)
                {
                    SetValueInvariant <T>(KeyName, SubKey, DefaultValue);
                    bool defaultValue = Convert.ToBoolean(DefaultValue);
                    registryValue = defaultValue.ToString(CultureInfo.InvariantCulture);
                }

                bool RetVal = Convert.ToBoolean(registryValue, CultureInfo.InvariantCulture);
                if (LOG_CONFIGURATION_CALLS)
                {
                    ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
                }
                return((T)((object)RetVal));
            }

            if (typeof(T) == typeof(string))
            {
                string RetVal;
                if (SubKey == "")
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
                    }
                    RetVal = (string)baseRegistryKey.GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + RetVal);
                    }
                }
                else
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
                    }
                    RetVal = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + RetVal);
                    }
                }

                if (RetVal == null)
                {
                    SetValue <T>(KeyName, SubKey, DefaultValue);
                    RetVal = DefaultValue.ToString();
                }
                if (LOG_CONFIGURATION_CALLS)
                {
                    ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
                }
                return((T)((object)RetVal));
            }

            if (typeof(T) == typeof(decimal))
            {
                string registryValue;
                if (SubKey == "")
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
                    }
                    registryValue = (string)baseRegistryKey.GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }
                else
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
                    }
                    registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }

                if (registryValue == null)
                {
                    SetValueInvariant <T>(KeyName, SubKey, DefaultValue);
                    decimal defaultValue = Convert.ToDecimal(DefaultValue);
                    registryValue = defaultValue.ToString(CultureInfo.InvariantCulture);
                }

                decimal RetVal = Convert.ToDecimal(registryValue, CultureInfo.InvariantCulture);
                if (LOG_CONFIGURATION_CALLS)
                {
                    ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
                }
                return((T)((object)RetVal));
            }

            if (typeof(T) == typeof(DateTime))
            {
                string registryValue;
                if (SubKey == "")
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
                    }
                    registryValue = (string)baseRegistryKey.GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }
                else
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
                    }
                    registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }

                if (registryValue == null)
                {
                    SetValueInvariant <T>(KeyName, SubKey, DefaultValue);
                    return(DefaultValue);
                }

                if (LOG_CONFIGURATION_CALLS)
                {
                    ServerForm.LogMessage(0, 0, 0, "GetValue DateTime", $"String value prior to Convert: {registryValue}");
                }

                if (DateTime.TryParse(registryValue, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out DateTime RetVal))
                {
                    // The string parsed OK so return the parsed value;
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue DateTime", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
                    }
                    return((T)((object)RetVal));
                }
                else // If the string fails to parse, overwrite with the default value and return this
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue DateTime", $"Failed to parse registry value, persisting and returning the default value: {DefaultValue}");
                    }
                    SetValueInvariant <T>(KeyName, SubKey, DefaultValue);
                    return(DefaultValue);
                }
            }

            if ((typeof(T) == typeof(Int32)) | (typeof(T) == typeof(int)))
            {
                string registryValue;
                if (SubKey == "")
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
                    }
                    registryValue = (string)baseRegistryKey.GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }
                else
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
                    }
                    registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }

                if (registryValue == null)
                {
                    SetValueInvariant <T>(KeyName, SubKey, DefaultValue);
                    int defaultValue = Convert.ToInt32(DefaultValue);
                    registryValue = defaultValue.ToString(CultureInfo.InvariantCulture);
                }

                int RetVal = Convert.ToInt32(registryValue, CultureInfo.InvariantCulture);
                if (LOG_CONFIGURATION_CALLS)
                {
                    ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
                }
                return((T)((object)RetVal));
            }

            throw new DriverException("GetValue: Unknown type: " + typeof(T).Name);
        }
Пример #19
0
        private static ItemCollection ParseComplexType_SequenceChoice(XmlTextReader X)
        {
            bool           done = false;
            ItemCollection RetVal;
            string         elementName = X.LocalName;
            DText          p           = new DText();

            p.ATTRMARK = ":";

            if (X.LocalName == "choice")
            {
                RetVal = new Choice();
            }
            else
            {
                RetVal = new Sequence();
            }

            if (X.HasAttributes)
            {
                for (int i = 0; i < X.AttributeCount; i++)
                {
                    X.MoveToAttribute(i);
                    switch (X.LocalName)
                    {
                    case "minOccurs":
                        RetVal.MinOccurs = X.Value;
                        break;

                    case "maxOccurs":
                        RetVal.MaxOccurs = X.Value;
                        break;
                    }
                }
                X.MoveToElement();
            }
            X.Read();


            do
            {
                switch (X.NodeType)
                {
                case XmlNodeType.Element:
                    switch (X.LocalName)
                    {
                    case "group":
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                switch (X.LocalName)
                                {
                                case "ref":
                                    break;
                                }
                            }
                            X.MoveToElement();
                        }
                        break;

                    case "sequence":
                    case "choice":
                        RetVal.AddCollection(ParseComplexType_SequenceChoice(X));
                        break;

                    case "element":
                        RetVal.AddContentItem(new Element());
                        if (X.HasAttributes)
                        {
                            for (int i = 0; i < X.AttributeCount; i++)
                            {
                                X.MoveToAttribute(i);
                                switch (X.LocalName)
                                {
                                case "name":
                                    RetVal.CurrentItem.Name = X.Value;
                                    break;

                                case "type":
                                    p[0] = X.Value;
                                    if (p.DCOUNT() == 1)
                                    {
                                        RetVal.CurrentItem.Type   = X.Value;
                                        RetVal.CurrentItem.TypeNS = X.LookupNamespace("");
                                    }
                                    else
                                    {
                                        RetVal.CurrentItem.Type   = p[2];
                                        RetVal.CurrentItem.TypeNS = X.LookupNamespace(p[1]);
                                    }
                                    break;

                                case "minOccurs":
                                    RetVal.CurrentItem.MinOccurs = X.Value;
                                    break;

                                case "maxOccurs":
                                    RetVal.CurrentItem.MaxOccurs = X.Value;
                                    break;
                                }
                            }
                            X.MoveToElement();
                        }
                        break;

                    case "attribute":
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (X.LocalName == elementName)
                    {
                        done = true;
                    }
                    break;

                case XmlNodeType.Text:
                    break;
                }
            }while(!done && X.Read());

            return(RetVal);
        }
Пример #20
0
        public void GenerateInvokerBody(StreamWriter sw, string indent, CodeGenerationOptions opt)
        {
            sw.WriteLine("{0}if ({1} == IntPtr.Zero)", indent, EscapedIdName);
            sw.WriteLine("{0}\t{1} = JNIEnv.GetMethodID (class_ref, \"{2}\", \"{3}\");", indent, EscapedIdName, JavaName, JniSignature);
            foreach (string prep in Parameters.GetCallPrep(opt))
            {
                sw.WriteLine("{0}{1}", indent, prep);
            }
            Parameters.WriteCallArgs(sw, indent, opt, invoker: true);
            string env_method = "Call" + RetVal.CallMethodPrefix + "Method";
            string call       = "JNIEnv." + env_method + " (" +
                                opt.ContextType.GetObjectHandleProperty("this") + ", " + EscapedIdName + Parameters.GetCallArgs(opt, invoker: true) + ")";

            if (IsVoid)
            {
                sw.WriteLine("{0}{1};", indent, call);
            }
            else
            {
                sw.WriteLine("{0}{1}{2};", indent, Parameters.HasCleanup ? opt.GetOutputName(RetVal.FullName) + " __ret = " : "return ", RetVal.FromNative(opt, call, true));
            }

            foreach (string cleanup in Parameters.GetCallCleanup(opt))
            {
                sw.WriteLine("{0}{1}", indent, cleanup);
            }

            if (!IsVoid && Parameters.HasCleanup)
            {
                sw.WriteLine("{0}return __ret;", indent);
            }
        }
Пример #21
0
        public T GetValue <T>(string KeyName, string SubKey, T DefaultValue)
        {
            if (LOG_CONFIGURATION_CALLS)
            {
                ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Getting {0} value '{1}' in subkey '{2}', default: '{3}'", typeof(T).Name, KeyName, SubKey, DefaultValue.ToString()));
            }
            if (typeof(T) == typeof(bool))
            {
                string registryValue;
                if (SubKey == "")
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
                    }
                    registryValue = (string)baseRegistryKey.GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }
                else
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
                    }
                    registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }

                if (registryValue == null)
                {
                    SetValue <T>(KeyName, SubKey, DefaultValue);
                    registryValue = DefaultValue.ToString();
                }
                bool RetVal = Convert.ToBoolean(registryValue, CultureInfo.InvariantCulture);
                if (LOG_CONFIGURATION_CALLS)
                {
                    ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
                }
                return((T)((object)RetVal));
            }

            if (typeof(T) == typeof(string))
            {
                string RetVal;
                if (SubKey == "")
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
                    }
                    RetVal = (string)baseRegistryKey.GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + RetVal);
                    }
                }
                else
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
                    }
                    RetVal = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + RetVal);
                    }
                }

                if (RetVal == null)
                {
                    SetValue <T>(KeyName, SubKey, DefaultValue);
                    RetVal = DefaultValue.ToString();
                }
                if (LOG_CONFIGURATION_CALLS)
                {
                    ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
                }
                return((T)((object)RetVal));
            }

            if (typeof(T) == typeof(decimal))
            {
                string registryValue;
                if (SubKey == "")
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
                    }
                    registryValue = (string)baseRegistryKey.GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }
                else
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
                    }
                    registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }

                if (registryValue == null)
                {
                    SetValue <T>(KeyName, SubKey, DefaultValue);
                    registryValue = DefaultValue.ToString();
                }
                decimal RetVal = Convert.ToDecimal(registryValue, CultureInfo.InvariantCulture);
                if (LOG_CONFIGURATION_CALLS)
                {
                    ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
                }
                return((T)((object)RetVal));
            }

            if ((typeof(T) == typeof(Int32)) | (typeof(T) == typeof(int)))
            {
                string registryValue;
                if (SubKey == "")
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey is empty so getting value directly");
                    }
                    registryValue = (string)baseRegistryKey.GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }
                else
                {
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "SubKey has a value so using it...");
                    }
                    registryValue = (string)baseRegistryKey.CreateSubKey(SubKey).GetValue(KeyName);
                    if (LOG_CONFIGURATION_CALLS)
                    {
                        ServerForm.LogMessage(0, 0, 0, "GetValue", "Value retrieved OK: " + registryValue);
                    }
                }

                if (registryValue == null)
                {
                    SetValue <T>(KeyName, SubKey, DefaultValue);
                    registryValue = DefaultValue.ToString();
                }
                Int32 RetVal = Convert.ToInt32(registryValue, CultureInfo.InvariantCulture);
                if (LOG_CONFIGURATION_CALLS)
                {
                    ServerForm.LogMessage(0, 0, 0, "GetValue", string.Format("Retrieved {0} = {1}", KeyName, RetVal.ToString()));
                }
                return((T)((object)RetVal));
            }

            throw new DriverException("GetValue: Unknown type: " + typeof(T).Name);
        }
Пример #22
0
        void GenerateCallback(StreamWriter sw, string indent, CodeGenerationOptions opt, GenBase type, string property_name, bool as_formatted)
        {
            string delegate_type = GetDelegateType();

            sw.WriteLine("{0}static Delegate {1};", indent, EscapedCallbackName);
            sw.WriteLine("#pragma warning disable 0169");
            sw.WriteLine("{0}static Delegate {1} ()", indent, ConnectorName);
            sw.WriteLine("{0}{{", indent);
            sw.WriteLine("{0}\tif ({1} == null)", indent, EscapedCallbackName);
            sw.WriteLine("{0}\t\t{1} = JNINativeWrapper.CreateDelegate (({2}) n_{3});", indent, EscapedCallbackName, delegate_type, Name + IDSignature);
            sw.WriteLine("{0}\treturn {1};", indent, EscapedCallbackName);
            sw.WriteLine("{0}}}", indent);
            sw.WriteLine();
            sw.WriteLine("{0}static {1} n_{2} (IntPtr jnienv, IntPtr native__this{3})", indent, RetVal.NativeType, Name + IDSignature, Parameters.GetCallbackSignature(opt));
            sw.WriteLine("{0}{{", indent);
            sw.WriteLine("{0}\t{1} __this = global::Java.Lang.Object.GetObject<{1}> (jnienv, native__this, JniHandleOwnership.DoNotTransfer);", indent, opt.GetOutputName(type.FullName));
            foreach (string s in Parameters.GetCallbackPrep(opt))
            {
                sw.WriteLine("{0}\t{1}", indent, s);
            }
            if (String.IsNullOrEmpty(property_name))
            {
                string call = "__this." + Name + (as_formatted ? "Formatted" : String.Empty) + " (" + Parameters.GetCall(opt) + ")";
                if (IsVoid)
                {
                    sw.WriteLine("{0}\t{1};", indent, call);
                }
                else
                {
                    sw.WriteLine("{0}\t{1} {2};", indent, Parameters.HasCleanup ? RetVal.NativeType + " __ret =" : "return", RetVal.ToNative(opt, call));
                }
            }
            else
            {
                if (IsVoid)
                {
                    sw.WriteLine("{0}\t__this.{1} = {2};", indent, property_name, Parameters.GetCall(opt));
                }
                else
                {
                    sw.WriteLine("{0}\t{1} {2};", indent, Parameters.HasCleanup ? RetVal.NativeType + " __ret =" : "return", RetVal.ToNative(opt, "__this." + property_name));
                }
            }
            foreach (string cleanup in Parameters.GetCallbackCleanup(opt))
            {
                sw.WriteLine("{0}\t{1}", indent, cleanup);
            }
            if (!IsVoid && Parameters.HasCleanup)
            {
                sw.WriteLine("{0}\treturn __ret;", indent);
            }
            sw.WriteLine("{0}}}", indent);
            sw.WriteLine("#pragma warning restore 0169");
            sw.WriteLine();
        }