Esempio n. 1
0
        }        //end ShowAsciiTable

        public bool ValueToAlpha()
        {
            int  iNow  = 0;
            bool bGood = true;

            RReporting.Debug("ValueToAlpha...");
            try {
                if (animarrGlyphType != null)
                {
                    for (iNow = 0; iNow < animarrGlyphType.Length; iNow++)
                    {
                        if (animarrGlyphType[iNow] != null)
                        {
                            if (animarrGlyphType[iNow] == null)
                            {
                                throw new ApplicationException("current glyphtype was null (self-generated exception)");
                            }
                            else
                            {
                                animarrGlyphType[iNow] = animarrGlyphType[iNow].CopyAsGray();
                            }
                            if (animarrGlyphType[iNow] == null)
                            {
                                throw new ApplicationException("current glyphtype copied as gray became null (self-generated exception)");
                            }
                        }
                        else
                        {
                            RReporting.ShowErr("GlyphType is null", "converting monochrome font to alpha font", "");
                        }
                    }
                }
                RReporting.Debug("ValueToAlpha...OK");
            }
            catch (Exception exn) {
                RReporting.Debug("ValueToAlpha...FAILED");
                bGood = false;
                string sDebugMethod = "ValueToAlpha() {iNow:" + iNow;
                if (animarrGlyphType != null)
                {
                    sDebugMethod += "; glyphtypes-array-length:" + animarrGlyphType.Length;
                    sDebugMethod += "; converting-glyphtype-number:" + iNow.ToString();
                    if (iNow < animarrGlyphType.Length)
                    {
                        sDebugMethod += "animarrGlyphType[" + iNow.ToString() + "]:" + animarrGlyphType[iNow].ToString(true);
                    }
                    else
                    {
                        sDebugMethod += "[beyond maximum]";
                    }
                }
                else
                {
                    sDebugMethod += "; animarrGlyphType:null";
                }
                sDebugMethod += "}";
                RReporting.ShowExn(exn, "copying value to alpha", sDebugMethod);
            }
            return(bGood);
        } //end ValueToAlpha
Esempio n. 2
0
 public static byte[] ToByteArray(string sData)
 {
     byte[] byarrReturn = null;
     try {
         if (sData != null && sData.Length > 0)
         {
             byarrReturn = new byte[sData.Length];
             for (int iNow = 0; iNow < sData.Length; iNow++)
             {
                 byarrReturn[iNow] = (byte)(sData[iNow] & 0xFF);
             }
         }
         else
         {
             if (bDebug)
             {
                 RReporting.Debug("ToByteArray warning: no data");
             }
         }
         if (RReporting.SafeLength(sData) != RReporting.SafeLength(byarrReturn))
         {
             Console.Error.WriteLine("ToByteArray error: source string length was {0} but result was a {1}-length byte array",
                                     RReporting.SafeLength(sData), RReporting.SafeLength(byarrReturn));
         }
     }
     catch (Exception exn) {
         RReporting.ShowExn(exn);
     }
     return(byarrReturn);
 }        //end ToByteArray
Esempio n. 3
0
 public static int SafeLength(PictureBox[] val)
 {
     try {
         if (val != null)
         {
             return(val.Length);
         }
     }
     catch (Exception e) {
         RReporting.Debug(e, "", "Base SafeLength(PictureBox[])");
     }
     return(0);
 }
Esempio n. 4
0
 public static byte[] SubArrayReversed(byte[] byarrNow, int iLocNow, int iLen)
 {
     byte[] byarrNew = null;
     try {
         byarrNew = new byte[iLen];
         int iNew = 0;
         //TODO: check for bad values
         int iLastIndex = iLen - 1;
         while (iNew < iLen)
         {
             byarrNew[iLastIndex - iNew] = byarrNow[iLocNow];
             iNew++;
             iLocNow++;
         }
     }
     catch (Exception e) {
         RReporting.Debug(e, "", "SubArrayReversed");
     }
     return(byarrNew);
 }        //end SubArrayReversed
Esempio n. 5
0
        }        //end SubArray

        public static char[] SubArray(char[] arrNow, int iLocNow, int iLen)
        {
            char[] arrNew   = null;
            int    iLocOrig = iLocNow;

            try {
                arrNew = new char[iLen];
                int iNew = 0;
                //TODO: check for bad values
                while (iNew < iLen)
                {
                    arrNew[iNew] = arrNow[iLocNow];
                    iNew++;
                    iLocNow++;
                }
            }
            catch (Exception e) {
                RReporting.Debug(e, "", "SubArray(char array" + (arrNow == null?" is null":" length " + arrNow.Length.ToString()) + ", " + iLocOrig.ToString() + ", " + iLen.ToString() + ")");
            }
            return(arrNew);
        }        //end SubArray(char[],start,len)
		public bool Load(string sFile, bool FirstRowHasTitles) {
			sLastFile=sFile;
			if (sLastFile==null) sLastFile="";
			bool bGood=false;
			bFirstRowLoadAndSaveAsTitles=FirstRowHasTitles;
			StreamReader fsSource=null;
			string sLine=null;
			try {
				fsSource=new StreamReader(sFile);
				if (bFirstRowLoadAndSaveAsTitles) {
					sLine=fsSource.ReadLine();
					if ( bShowNewlineWarning && (RString.Contains(sLine,'\n')||RString.Contains(sLine,'\r')) ) {
						MessageBox.Show("Warning: newline character found in field.  File may have been saved in a different operating system and need line breaks converted.");
						bShowNewlineWarning=false;
					}
					teTitles=new TableEntry(RTable.SplitCSV(sLine,cFieldDelimiter,cTextDelimiter));
					//Parse TYPE NAME{METANAME:METAVALUE;...} title row notation:
					if (teTitles.Columns>0) {
						sarrFieldMetaData=new string[teTitles.Columns];
						iarrFieldType=new int[teTitles.Columns];
						for (int iColumn=0; iColumn<teTitles.Columns; iColumn++) {
							string FieldDataNow=teTitles.Field(iColumn);
							if (FieldDataNow==null) {
								RReporting.ShowErr("Field is not accessible","loading csv file","Load("+RReporting.StringMessage(sFile,true)+",...){Row 0:Titles; Column:"+iColumn+"}");
							}
							int iType=StartsWithType(FieldDataNow);
							int iStartName=0;
							if (iType>-1) {
								iarrFieldType[iColumn]=iType;
								iStartName=sarrType[iType].Length+1; //teTitles.SetField(iColumn,RString.SafeSubstring(teTitles.Field(iColumn),sarrType[iType].Length+1));
							}
							else {
								RReporting.Debug("Unknown type in column#"+iColumn.ToString()+"("+RReporting.StringMessage(FieldDataNow,true)+")");
							}
							int iMetaData=-1;
							//if (FieldDataNow!=null) {
							iMetaData=FieldDataNow.IndexOf("{");
							//}
							if (iMetaData>-1) {
								//string FieldDataNow=teTitles.Field(iColumn);
								if (FieldDataNow==null) {
									RReporting.ShowErr("Can't access field","loading csv file","rtable Load("+RReporting.StringMessage(sFile,true)+"){Row:titles; Column:"+iColumn+"}");
								}
								this.sarrFieldMetaData[iColumn]=FieldDataNow.Substring(iMetaData);
								while (iMetaData>=0 && (FieldDataNow[iMetaData]=='{'||FieldDataNow[iMetaData]==' ')) iMetaData--;
								teTitles.SetField(iColumn,RString.SafeSubstringByInclusiveEnder(FieldDataNow,iStartName,iMetaData));
							}
							else {
								teTitles.SetField(iColumn,RString.SafeSubstring(FieldDataNow,iStartName));
							}
						}//end for iColumn in title row
					}//end if teTitles.Columns>0
				}//if bFirstRowLoadAndSaveAsTitles
				tearr=new TableEntry[256];
				for (int iNow=0; iNow<tearr.Length; iNow++) {
					tearr[iNow]=null;
				}
				iRows=0;
				//if (!bFirstRowLoadAndSaveAsTitles||sLine!=null) {
				if (bAllowNewLineInQuotes) {
					bool bInQuotes=false;
					string sLineCombined="";
					while ( (sLine=fsSource.ReadLine()) != null ) {
						if (iRows>=Maximum) Maximum=iRows+iRows/2+1;
						for (int iChar=0; iChar<RString.SafeLength(sLine); iChar++) {
							if (sLine[iChar]==this.cTextDelimiter) bInQuotes=!bInQuotes;
						}
						sLineCombined+=sLine;
						if (!bInQuotes) {
							tearr[iRows]=new TableEntry(RTable.SplitCSV(sLineCombined,cFieldDelimiter,cTextDelimiter));
							iRows++;
							sLineCombined="";
						}
					}//end while not end of file
					if (sLineCombined!="") { //get bad data so it doesn't get lost
						tearr[iRows]=new TableEntry(RTable.SplitCSV(sLineCombined,cFieldDelimiter,cTextDelimiter));
						iRows++;
					}
				}
				else {
					while ( (sLine=fsSource.ReadLine()) != null ) {
						if (iRows>=Maximum) Maximum=iRows+iRows/2+1;
						tearr[iRows]=new TableEntry(RTable.SplitCSV(sLine,cFieldDelimiter,cTextDelimiter));
						iRows++;
					}
				}
				//}//if any data rows
				if (iRows<Maximum) {
					for (int i=iRows; i<Maximum; i++) {
						tearr[i]=new TableEntry();
					}
				}
				bGood=true;
				fsSource.Close();
			}
			catch (Exception exn) {
				RReporting.ShowExn(exn,"Loading table","rtable Load(\""+RReporting.StringMessage(sFile,true)+"\",FirstRowHasTitles="+(FirstRowHasTitles?"yes":"no")+")");
				try { fsSource.Close(); }
				catch (Exception exn2) {
					RReporting.ShowExn(exn2,"closing file after exception","rtable Load");
				}
			}
			return bGood;
		}//end Load