Equals() public method

public Equals ( StringBuilder sb ) : bool
sb StringBuilder
return bool
コード例 #1
0
ファイル: IniControl.cs プロジェクト: kool924jp/BoxUnlocker
 /// <summary>
 /// INIファイルから読み込む
 /// </summary>
 /// <param name="iSection">セクション</param>
 /// <param name="iKey">キー</param>
 /// <param name="iDefault">デフォルト文字列</param>
 /// <returns>INIファイルから読み込んだ値を返す</returns>
 public string GetIniValue(string iSection, string iKey, string iDefault)
 {
     StringBuilder sb = new StringBuilder(BufferLength);
     IniFileHandler.GetPrivateProfileString( iSection, iKey, iDefault, sb, (uint)sb.Capacity, FileName);
     if (sb.Equals(null))
     {
         return null;
     }
     return sb.ToString(); ;
 }
コード例 #2
0
        public void StringBuilderEquals()
        {
            StringBuilder s = new StringBuilder("test");
             StringBuilder idem_s = new StringBuilder("test");
             StringBuilder s3 = new StringBuilder("test1".Substring(0, 4));
             object s4 = s3;

             Assert.IsFalse(object.ReferenceEquals(s, idem_s));
             Assert.IsFalse(s == idem_s);         //!= from string --> operator == pour string est surchargé, ici reference comparison
             Assert.IsTrue(s.Equals(idem_s));

             Assert.IsFalse(object.ReferenceEquals(s, s3));
             Assert.IsFalse(s == s3);
             Assert.IsTrue(s.Equals(s3));

             Assert.IsFalse(object.ReferenceEquals(s, s4));
             Assert.IsFalse(s == s4);  //warning CS0253: Possible unintended reference comparison; to get a value comparison, cast the right hand side to type 'string'
             Assert.IsFalse(s == (StringBuilder)s4);
             Assert.IsFalse(s.Equals(s4));

            //ici, il n'y que .Equals qui marche
        }
コード例 #3
0
ファイル: Config.cs プロジェクト: partizanes/DiscountSharp
        public static string GetParametr(string par)
        {
            StringBuilder buffer = new StringBuilder(100, 350);

            GetPrivateProfileString("SETTINGS", par, "null", buffer, 100, Environment.CurrentDirectory + "\\config.ini");

            if (buffer.Equals("null"))
            {
                Console.WriteLine("[GetPrivateProfileString] Внимание в конфигурационом файле не найден параметр " + par + "\n Для продолжения нажмите любую клавишу.");
                Console.ReadKey(true);
                return "";
            }

            return buffer.ToString();
        }
コード例 #4
0
 static public int Equals__Object(IntPtr l)
 {
     try {
         System.Text.StringBuilder self = (System.Text.StringBuilder)checkSelf(l);
         System.Object             a1;
         checkType(l, 2, out a1);
         var ret = self.Equals(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #5
0
        public static int[] getCourseIDs(string courseName)
        {
            List<int> courseIDs = new List<int>();

            try
            {
                courseName = courseName.Replace(" ", String.Empty);
                string pattern = @"([A-Za-z]+)";
                string[] result = Regex.Split(courseName, pattern);

                string coursePrefix = result[1];
                StringBuilder courseNumber = new StringBuilder();
                for (int i = 2; i < result.Length; i++)
                {
                    courseNumber.Append(result[i]);
                }

                string whereClause = String.Empty;
                if (courseNumber.Equals(String.Empty))
                {
                    whereClause = String.Format("CourseName LIKE '%{0}%'", coursePrefix);
                }
                else
                {
                    whereClause = String.Format("CourseName LIKE '%{0}%{1}%'", coursePrefix, courseNumber.ToString());
                }

                DataAccessLayer DAL = new DataAccessLayer();
                DataTable dt = DAL.select(whereClause, "CourseInfo", new string[] { "CourseID" });

                foreach (DataRow row in dt.Rows)
                {
                    int courseID = Convert.ToInt32(row["CourseID"]);

                    courseIDs.Add(courseID);
                }
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: An error occured in retrieving course IDs by course name --- " + ex.Message);
            }

            return courseIDs.ToArray();
        }
コード例 #6
0
ファイル: StringBuilderTests.cs プロジェクト: dotnet/corefx
 public static void Equals(StringBuilder sb1, StringBuilder sb2, bool expected)
 {
     Assert.Equal(expected, sb1.Equals(sb2));
 }
コード例 #7
0
        public static void Main(string[] args)
        {
            int             iRetVal              = Sepia2_Import.SEPIA2_ERR_NO_ERROR;
              //
              StringBuilder   cLibVersion          = new StringBuilder ("", Sepia2_Import.SEPIA2_VERSIONINFO_LEN);
              StringBuilder   cDescriptor          = new StringBuilder ("", Sepia2_Import.SEPIA2_USB_STRDECR_LEN);
              StringBuilder   cSepiaSerNo          = new StringBuilder ("", Sepia2_Import.SEPIA2_SERIALNUMBER_LEN);
              StringBuilder   cGivenSerNo          = new StringBuilder ("", Sepia2_Import.SEPIA2_SERIALNUMBER_LEN);
              StringBuilder   cProductModel        = new StringBuilder ("", Sepia2_Import.SEPIA2_PRODUCTMODEL_LEN);
              StringBuilder   cGivenProduct        = new StringBuilder ("", Sepia2_Import.SEPIA2_PRODUCTMODEL_LEN);
              StringBuilder   cFWVersion           = new StringBuilder ("", Sepia2_Import.SEPIA2_VERSIONINFO_LEN);
              StringBuilder   cFWErrCond           = new StringBuilder ("", Sepia2_Import.SEPIA2_FW_ERRCOND_LEN);
              StringBuilder   cFWErrPhase          = new StringBuilder ("", Sepia2_Import.SEPIA2_FW_ERRPHASE_LEN);
              StringBuilder   cErrString           = new StringBuilder ("", Sepia2_Import.SEPIA2_ERRSTRING_LEN);
              StringBuilder   cModulType           = new StringBuilder ("", Sepia2_Import.SEPIA2_MODULETYPESTRING_LEN);
              StringBuilder   cFreqTrigMode        = new StringBuilder ("", Sepia2_Import.SEPIA2_SOM_FREQ_TRIGMODE_LEN);
              StringBuilder   cFrequency           = new StringBuilder ("", Sepia2_Import.SEPIA2_SLM_FREQ_TRIGMODE_LEN);
              StringBuilder   cHeadType            = new StringBuilder ("", Sepia2_Import.SEPIA2_SLM_HEADTYPE_LEN);
              StringBuilder   cSerialNumber        = new StringBuilder ("", Sepia2_Import.SEPIA2_SERIALNUMBER_LEN);
              StringBuilder   cSWSModuleType       = new StringBuilder ("", Sepia2_Import.SEPIA2_SWS_MODULETYPE_MAXLEN);
              StringBuilder   cTemp1               = new StringBuilder ("", 65);
              StringBuilder   cTemp2               = new StringBuilder ("", 65);
              StringBuilder   cBuffer              = new StringBuilder ("", 65535);
              StringBuilder   cPreamble            = new StringBuilder ( "\n     Following are system describing common infos,\n     the considerate support team of PicoQuant GmbH\n     demands for your qualified service request:\n\n    =================================================\n\n");
              StringBuilder   cCallingSW           = new StringBuilder ("Demo-Program:   ReadAllDataByMSVCPP.exe\n");
              //
              int []          lBurstChannels       = new int [Sepia2_Import.SEPIA2_SOM_BURSTCHANNEL_COUNT] {0, 0, 0, 0, 0, 0, 0, 0};
              //
              int             iRestartOption                                 = Sepia2_Import.SEPIA2_NO_RESTART;
              int             iDevIdx                                        = -1;
              int             iGivenDevIdx = 0;
              //
              //
              int             iModuleCount;
              int             iFWErrCode;
              int             iFWErrPhase;
              int             iFWErrLocation;
              int             iFWErrSlot;
              int             iMapIdx;
              int             iSlotId;
              int             iModuleType;
              int             iFreqTrigIdx;
              int             iFreq;
              int             iHead;
              int             iTriggerMilliVolt;
              int             iSWSModuleType;
              //
              // byte
              bool   bUSBInstGiven = false;
              bool   bSerialGiven  = false;
              bool   bProductGiven = false;
              bool   bNoWait       = false;
              bool   bStayOpened   = false;
              byte   bIsPrimary;
              byte   bIsBackPlane;
              byte   bHasUptimeCounter;
              byte   bLock;
              byte   bSLock;
              byte   bSynchronize = 0;             // for SOM-D
              byte   bPulseMode;
              byte   bDivider;
              byte   bPreSync;
              byte   bMaskSync;
              byte   bOutEnable;
              byte   bSyncEnable;
              byte   bSyncInverse;
              byte   bFineDelayStepCount;      // for SOM-D
              byte   bDelayed;                 // for SOM-D
              byte   bForcedUndelayed;         // for SOM-D
              byte   bFineDelay;               // for SOM-D
              byte   bOutCombi;                // for SOM-D
              byte   bMaskedCombi;             // for SOM-D
              byte   bTrigLevelEnabled;
              byte   bIntensity;
              byte   bTBNdx;                   // for PPL 400
              //
              // word
              ushort  wIntensity;
              ushort  wDivider;
              ushort  wPAPml;                   // for PPL 400
              ushort  wRRPml;                   // for PPL 400
              ushort  wPSPml;                   // for PPL 400
              ushort  wRSPml;                   // for PPL 400
              ushort  wWSPml;                   // for PPL 400
              //
              float           fFrequency = 1;
              float           fIntensity;
              //
              int             lBurstSum;
              uint   ulWaveLength;
              uint   ulBandWidth;
              short  sBeamVPos;
              short  sBeamHPos;
              uint   ulIntensRaw;
              uint   ulMainPowerUp;
              uint   ulActivePowerUp;
              uint   ulScaledPowerUp;
              //
              double          f64CoarseDelayStep = 1;   // for SOM-D
              double          f64CoarseDelay     = 1;   // for SOM-D
              //
              Sepia2_Import.T_Module_FWVers SWSFWVers;
              //
              int i, j;
              //
              //
              Console.WriteLine (" called with {0} Parameter{1}:", args.Length, (args.Length>1)?"s":"");
              foreach (string s in args)
              {
            if (Regex.IsMatch(s, "^-inst="))
            {
              string sVal = Regex.Replace (s, "^-inst=", "");
              try
              {
            iGivenDevIdx = Int32.Parse (sVal);
              }
              catch (FormatException)
              {
            throw new Exception ("error: param \"-inst=\" is not an integer");
              }
              Console.Write ("    -inst={0}\n", iGivenDevIdx);
              bUSBInstGiven = true;
            } else
              if (Regex.IsMatch(s, "^-serial="))
            {
              string sVal = Regex.Replace (s, "^-serial=", "");
              cGivenSerNo.Append (Regex.Match (sVal, @"\d{1," + Sepia2_Import.SEPIA2_SERIALNUMBER_LEN + "}").Value);
              Console.Write ("    -serial={0}\n", cGivenSerNo);
              bSerialGiven = (cGivenSerNo.Length > 0);
            } else
              if (Regex.IsMatch(s, "^-product="))
            {
              string sVal = Regex.Replace (s, "^-product=", "");
              cGivenProduct.Append (Regex.Match (sVal, @"\d{1," + Sepia2_Import.SEPIA2_PRODUCTMODEL_LEN + "}").Value);
              Console.Write ("    -product={0}\n", cGivenProduct);
              bProductGiven = (cGivenProduct.Length > 0);
            } else
              if (Regex.IsMatch(s, "^-stayopened$"))
            {
              bStayOpened = true;
              Console.Write ("    {0}\n", s);
            } else
              if (Regex.IsMatch(s, "^-nowait$"))
            {
              bNoWait = true;
              Console.Write ("    {0}\n", s);
            } else
              if (Regex.IsMatch(s, "^-restart$"))
            {
              iRestartOption = Sepia2_Import.SEPIA2_RESTART;
              Console.Write ("    {0}\n", s);
            } else
            {
              Console.Write ("    {0} : unknown parameter!\n", s);
            }
              }

              Console.Write ("\n\n     PQLaserDrv   Read ALL Values Demo : \n");
              Console.Write ("    =================================================\n\n");
              //
              // preliminaries: check library version
              //
              try {
            Sepia2_Import.SEPIA2_LIB_GetVersion (cLibVersion);
              }
              catch (Exception ex) {
            Console.Write ("\nerror using Sepia2_Lib");
            Console.Write ("\n  Check the existence of the library 'Sepia2_Lib.dll'!");
            Console.Write ("\n  Make sure that your runtime and the library are both either 32-bit or 64-bit!");
            Console.Write ("\n\n  system message: \n{0}\n", ex.Message);
            if (!bNoWait)
            {
              Console.Write ("\npress RETURN... ");
              Console.Read ();
            }
            return;
              }
              Console.Write ("     Lib-Version    = {0}\n", cLibVersion);
              //
              // establish USB connection to the sepia first matching all given conditions
              //
              for (i = (bUSBInstGiven ? iGivenDevIdx : 0); i < (bUSBInstGiven ? iGivenDevIdx+1 : Sepia2_Import.SEPIA2_MAX_USB_DEVICES); i++)
              {
            cSepiaSerNo.Length = 0;
            cProductModel.Length = 0;
            //
            iRetVal = Sepia2_Import.SEPIA2_USB_OpenGetSerNumAndClose (i, cProductModel, cSepiaSerNo);
            if ( (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
            && (  (  (bSerialGiven && bProductGiven)
               && (cGivenSerNo.Equals (cSepiaSerNo)  )
               && (cGivenProduct.Equals (cProductModel)  )
               )
            ||  (  (!bSerialGiven != !bProductGiven)
             && (  (cGivenSerNo.Equals (cSepiaSerNo)  )
            || (cGivenProduct.Equals (cProductModel)  )
            )
             )
            ||  ( !bSerialGiven && !bProductGiven)
            )
            )
            {
              iDevIdx = bUSBInstGiven ? ((iGivenDevIdx == i) ? i : -1) : i;
              break;
            }
              }
              //
              if ((iRetVal = Sepia2_Import.SEPIA2_USB_OpenDevice (iDevIdx, cProductModel, cSepiaSerNo)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
              {
            Console.Write ("     Product Model  = '{0}'\n\n",     cProductModel);
            Console.Write ("    =================================================\n\n");
            Sepia2_Import.SEPIA2_FWR_GetVersion (iDevIdx, cFWVersion);
            Console.Write ("     FW-Version     = {0}\n",     cFWVersion);
            //
            Console.Write ("     USB Index      = {0}\n", iDevIdx);
            Sepia2_Import.SEPIA2_USB_GetStrDescriptor  (iDevIdx, cDescriptor);
            Console.Write ("     USB Descriptor = {0}\n", cDescriptor);
            Console.Write ("     Serial Number  = '{0}'\n\n", cSepiaSerNo);
            Console.Write ("    =================================================\n\n");
            //
            // get sepia's module map and initialise datastructures for all library functions
            // there are two different ways to do so:
            //
            // first:  if sepia was not touched since last power on, it doesn't need to be restarted
            //         iRestartOption = SEPIA2_NO_RESTART;
            // second: in case of changes with soft restart
            //         iRestartOption = SEPIA2_RESTART;
            //
            if ((iRetVal = Sepia2_Import.SEPIA2_FWR_GetModuleMap (iDevIdx, iRestartOption, out iModuleCount)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
            {
              //
              // this is to inform us about possible error conditions during sepia's last startup
              //
              if ((iRetVal = Sepia2_Import.SEPIA2_FWR_GetLastError (iDevIdx, out iFWErrCode, out iFWErrPhase, out iFWErrLocation, out iFWErrSlot, cFWErrCond)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
              {
            if (iFWErrCode != Sepia2_Import.SEPIA2_ERR_NO_ERROR)
            {
              Sepia2_Import.SEPIA2_LIB_DecodeError  (iFWErrCode,  cErrString);
              Sepia2_Import.SEPIA2_FWR_DecodeErrPhaseName (iFWErrPhase, cFWErrPhase);
              Console.Write ("     Error detected by firmware on last restart:\n");
              Console.Write ("        error code      : {0:5},   i.e. '{1}'\n", iFWErrCode,  cErrString);
              Console.Write ("        error phase     : {0:5},   i.e. '{1}'\n", iFWErrPhase, cFWErrPhase);
              Console.Write ("        error location  : {0:5}\n",  iFWErrLocation);
              Console.Write ("        error slot      : {0:5}\n",  iFWErrSlot);
              if (cFWErrCond.Length > 0)
              {
                Console.Write ("        error condition : '{0}'\n", cFWErrCond);
              }
            }
            else
            {
              // just to show, what sepia2_lib knows about your system, try this:
              Sepia2_Import.SEPIA2_FWR_CreateSupportRequestText (iDevIdx, cPreamble, cCallingSW, 0, cBuffer.Capacity, cBuffer);
              //
              Console.Write (cBuffer);
              //
              // scan sepia map module by module
              // and iterate by iMapIdx for this approach.
              //
              Console.Write ("\n\n\n    =================================================\n\n\n\n");
              //
              for (iMapIdx = 0; iMapIdx < iModuleCount; iMapIdx++)
              {
                Sepia2_Import.SEPIA2_FWR_GetModuleInfoByMapIdx (iDevIdx, iMapIdx, out iSlotId, out bIsPrimary, out bIsBackPlane, out bHasUptimeCounter);
                //
                if (bIsBackPlane != 0)
                {
                  if ((iRetVal = Sepia2_Import.SEPIA2_COM_GetModuleType (iDevIdx, -1, Sepia2_Import.SEPIA2_PRIMARY_MODULE, out iModuleType)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                  {
                    Sepia2_Import.SEPIA2_COM_DecodeModuleType (iModuleType, cModulType);
                    Sepia2_Import.SEPIA2_COM_GetSerialNumber  (iDevIdx, -1, Sepia2_Import.SEPIA2_PRIMARY_MODULE, cSerialNumber);
                    Console.Write (" backplane:   module type     '{0}'\n", cModulType);
                    Console.Write ("              serial number   '{0}'\n\n", cSerialNumber);
                  }
                }
                else
                {
                  //
                  // identify sepiaobject (module) in slot
                  //
                  if ((iRetVal = Sepia2_Import.SEPIA2_COM_GetModuleType (iDevIdx, iSlotId, Sepia2_Import.SEPIA2_PRIMARY_MODULE, out iModuleType)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                  {
                    Sepia2_Import.SEPIA2_COM_DecodeModuleType (iModuleType, cModulType);
                    Sepia2_Import.SEPIA2_COM_GetSerialNumber  (iDevIdx, iSlotId, Sepia2_Import.SEPIA2_PRIMARY_MODULE, cSerialNumber);
                    Console.Write (" slot {0:000} :   module type     '{1}'\n", iSlotId, cModulType);
                    Console.Write ("              serial number   '{0}'\n\n", cSerialNumber);
                    //
                    // now, continue with modulespecific information
                    //
                    switch (iModuleType)
                    {
                      case Sepia2_Import.SEPIA2OBJECT_SCM  :
                      Sepia2_Import.SEPIA2_SCM_GetLaserSoftLock (iDevIdx, iSlotId, out bSLock);
                      Sepia2_Import.SEPIA2_SCM_GetLaserLocked   (iDevIdx, iSlotId, out bLock);
                      Console.Write ("                              laser lock state   :    {0}locked\n", (!((bLock != 0) || (bSLock != 0))? " un": (bLock != bSLock ? " hard" : " soft")));
                      Console.Write ("\n");
                      //
                      break;

                      case Sepia2_Import.SEPIA2OBJECT_SOM:
                      goto case Sepia2_Import.SEPIA2OBJECT_SOMD;
                      case Sepia2_Import.SEPIA2OBJECT_SOMD :
                      for (iFreqTrigIdx = 0; ((iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR) && (iFreqTrigIdx < Sepia2_Import.SEPIA2_SOM_FREQ_TRIGMODE_COUNT)); iFreqTrigIdx++)
                      {
                        if (iModuleType == Sepia2_Import.SEPIA2OBJECT_SOM)
                        {
                          iRetVal = Sepia2_Import.SEPIA2_SOM_DecodeFreqTrigMode (iDevIdx, iSlotId, iFreqTrigIdx, cFreqTrigMode);
                        }
                        else
                        {
                          iRetVal = Sepia2_Import.SEPIA2_SOMD_DecodeFreqTrigMode (iDevIdx, iSlotId, iFreqTrigIdx, cFreqTrigMode);
                        }
                        if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                        {
                          if (iFreqTrigIdx == 0)
                          {
                            Console.Write ("{0,46}", "freq./trigmodes ");
                          }
                          else
                          {
                            Console.Write ("{0,46}", "                ");
                          }
                          //
                          Console.Write ("{0:C0}) =     '{1}'", iFreqTrigIdx+1, cFreqTrigMode);
                          //
                          if (iFreqTrigIdx == (Sepia2_Import.SEPIA2_SOM_FREQ_TRIGMODE_COUNT-1))
                          {
                            Console.Write ("\n");
                          }
                          else
                          {
                            Console.Write (",\n");
                          }
                        }
                      }
                      Console.Write ("\n");
                      if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        if (iModuleType == Sepia2_Import.SEPIA2OBJECT_SOM)
                        {
                          iRetVal = Sepia2_Import.SEPIA2_SOM_GetFreqTrigMode (iDevIdx, iSlotId, out iFreqTrigIdx);
                        }
                        else
                        {
                          iRetVal = Sepia2_Import.SEPIA2_SOMD_GetFreqTrigMode (iDevIdx, iSlotId, out iFreqTrigIdx, out bSynchronize);
                        }
                        if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                        {
                          if (iModuleType == Sepia2_Import.SEPIA2OBJECT_SOM)
                          {
                            iRetVal = Sepia2_Import.SEPIA2_SOM_DecodeFreqTrigMode (iDevIdx, iSlotId, iFreqTrigIdx, cFreqTrigMode);
                          }
                          else
                          {
                            iRetVal = Sepia2_Import.SEPIA2_SOMD_DecodeFreqTrigMode (iDevIdx, iSlotId, iFreqTrigIdx, cFreqTrigMode);
                          }
                          if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                          {
                            Console.Write ("{0,47}  =     '{1}'\n", "act. freq./trigm.", cFreqTrigMode);
                            if ((iModuleType == Sepia2_Import.SEPIA2OBJECT_SOMD) && (iFreqTrigIdx < Sepia2_Import.SEPIA2_SOM_INT_OSC_A))
                            {
                              if (bSynchronize != 0)
                              {
                                Console.Write ("{0,47}        (synchronized,)\n", " ");
                              }
                            }
                            //
                            if (iModuleType == Sepia2_Import.SEPIA2OBJECT_SOM)
                            {
                              iRetVal = Sepia2_Import.SEPIA2_SOM_GetBurstValues (iDevIdx, iSlotId, out bDivider, out bPreSync, out bMaskSync);
                              wDivider = bDivider;
                            }
                            else
                            {
                              iRetVal = Sepia2_Import.SEPIA2_SOMD_GetBurstValues (iDevIdx, iSlotId, out wDivider, out bPreSync, out bMaskSync);
                            }
                            if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                            {
                              Console.Write ("{0,48} = {1,5:D}\n", "divider           ", wDivider);
                              Console.Write ("{0,48} = {1,5:D}\n", "pre sync          ", bPreSync);
                              Console.Write ("{0,48} = {1,5:D}\n", "masked sync pulses", bMaskSync);
                              //
                              if ( (iFreqTrigIdx == Sepia2_Import.SEPIA2_SOM_TRIGMODE_RISING)
                                  || (iFreqTrigIdx == Sepia2_Import.SEPIA2_SOM_TRIGMODE_FALLING))
                              {
                                if (iModuleType == Sepia2_Import.SEPIA2OBJECT_SOM)
                                {
                                  iRetVal = Sepia2_Import.SEPIA2_SOM_GetTriggerLevel (iDevIdx, iSlotId, out iTriggerMilliVolt);
                                }
                                else
                                {
                                  iRetVal = Sepia2_Import.SEPIA2_SOMD_GetTriggerLevel (iDevIdx, iSlotId, out iTriggerMilliVolt);
                                }
                                if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                                {
                                  Console.Write ("{0,47}  = {1,5:D} mV\n", "triggerlevel     ", iTriggerMilliVolt);
                                }
                              }
                              else
                              {
                                fFrequency  = float.Parse ( Regex.Match (cFreqTrigMode.ToString(), @"\d*\.\d*").ToString()) * 1.0e6f;
                                fFrequency /= wDivider;
                                Console.Write ("{0,47}  =  {1}\n", "oscillator period", FormatEng (cTemp1, 1.0 / fFrequency, 6, "s",  11, 3));
                                Console.Write ("{0,47}     {1}\n", "i.e.", FormatEng (cTemp1, fFrequency,       6, "Hz", 12, 3));
                                Console.Write ("\n");
                              }
                              if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                              {
                                if (iModuleType == Sepia2_Import.SEPIA2OBJECT_SOM)
                                {
                                  iRetVal = Sepia2_Import.SEPIA2_SOM_GetOutNSyncEnable (iDevIdx, iSlotId, out bOutEnable, out bSyncEnable, out bSyncInverse);
                                }
                                else
                                {
                                  iRetVal = Sepia2_Import.SEPIA2_SOMD_GetOutNSyncEnable (iDevIdx, iSlotId, out bOutEnable, out bSyncEnable, out bSyncInverse);
                                }
                                if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                                {
                                  Console.Write ("{0,47}  =     {1}\n\n", "sync mask form   ", (bSyncInverse != 0 ? "inverse" : "regular"));
                                  if (iModuleType == Sepia2_Import.SEPIA2OBJECT_SOM)
                                  {
                                    iRetVal = Sepia2_Import.SEPIA2_SOM_GetBurstLengthArray (iDevIdx, iSlotId, out lBurstChannels[0], out lBurstChannels[1], out lBurstChannels[2], out lBurstChannels[3], out lBurstChannels[4], out lBurstChannels[5], out lBurstChannels[6], out lBurstChannels[7]);
                                  }
                                  else
                                  {
                                    iRetVal = Sepia2_Import.SEPIA2_SOMD_GetBurstLengthArray (iDevIdx, iSlotId, out lBurstChannels[0], out lBurstChannels[1], out lBurstChannels[2], out lBurstChannels[3], out lBurstChannels[4], out lBurstChannels[5], out lBurstChannels[6], out lBurstChannels[7]);
                                  }
                                  if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                                  {
                                    Console.Write ("{0,44} ch. | sync | burst len |  out\n", "burst data    ");
                                    Console.Write ("{0,44}-----+------+-----------+------\n", " ");
                                    //
                                    for (i = 0, lBurstSum = 0; i < Sepia2_Import.SEPIA2_SOM_BURSTCHANNEL_COUNT; i++)
                                    {
                                      Console.Write ("{0,46}{1,1}  |    {2,1} | {3,9} |    {4,1}\n", " ", i+1, ((bSyncEnable >> i) & 1), lBurstChannels[i], ((bOutEnable >> i) & 1));
                                      lBurstSum += lBurstChannels[i];
                                    }
                                    Console.Write ("{0,41}--------+------+ +  -------+------\n", " ");
                                    Console.Write ("{0,41}Hex/Sum | 0x{1:X2} | ={2,8} | 0x{3:X2}\n", " ", bSyncEnable, lBurstSum, bOutEnable);
                                    Console.Write ("\n");
                                    if ( (iFreqTrigIdx != Sepia2_Import.SEPIA2_SOM_TRIGMODE_RISING)
                                        && (iFreqTrigIdx != Sepia2_Import.SEPIA2_SOM_TRIGMODE_FALLING))
                                    {
                                      fFrequency /= lBurstSum;
                                      Console.Write ("{0,47}  =  {1}\n", "sequencer period", FormatEng (cTemp1, 1.0 / fFrequency, 6, "s",  11, 3));
                                      Console.Write ("{0,47}     {1}\n", "i.e.", FormatEng (cTemp1, fFrequency,       6, "Hz", 12, 3));
                                      Console.Write ("\n");
                                    }
                                    if (iModuleType == Sepia2_Import.SEPIA2OBJECT_SOMD)
                                    {
                                      iRetVal = Sepia2_Import.SEPIA2_SOMD_GetDelayUnits (iDevIdx, iSlotId, ref f64CoarseDelayStep, out bFineDelayStepCount);
                                      Console.Write ("{0,44}     | combiner |\n", " ");
                                      Console.Write ("{0,44}     | channels |\n", " ");
                                      Console.Write ("{0,44} out | 12345678 | delay\n", " ");
                                      Console.Write ("{0,44}-----+----------+------------------\n", " ");
                                      for (j = 0; j < Sepia2_Import.SEPIA2_SOM_BURSTCHANNEL_COUNT; j++)
                                      {
                                        iRetVal = Sepia2_Import.SEPIA2_SOMD_GetSeqOutputInfos (iDevIdx, iSlotId, Convert.ToByte(j), out bDelayed, out bForcedUndelayed, out bOutCombi, out bMaskedCombi, ref f64CoarseDelay, out bFineDelay);
                                        if ((bDelayed | bForcedUndelayed) == 0)
                                        {
                                          StringBuilder sOutCombi = new StringBuilder( Convert.ToString (bOutCombi, 2).PadLeft (8, '0') );
                                          sOutCombi.Replace ('0', '_');
                                          sOutCombi.Replace ('1', bMaskedCombi != 0 ? '1' : 'B');
                                          char[] aOutCombi = sOutCombi.ToString().ToCharArray();
                                          Array.Reverse (aOutCombi);
                                          sOutCombi.Length = 0;
                                          sOutCombi.Append (aOutCombi);
                                          Console.Write ("{0,46}{1,1}  | {2} |\n", " ", j+1, sOutCombi);
                                        }
                                        else
                                        {
                                          StringBuilder sOutCombi = new StringBuilder( Convert.ToString (1 << j, 2).PadLeft (8, '0') );
                                          sOutCombi.Replace ('0', '_');
                                          sOutCombi.Replace ('1', 'D');
                                          char[] aOutCombi = sOutCombi.ToString().ToCharArray();
                                          Array.Reverse (aOutCombi);
                                          sOutCombi.Length = 0;
                                          sOutCombi.Append (aOutCombi);
                                          Console.Write ("{0,46}{1,1}  | {2} |{3} + {4,2}a.u.\n", " ", j+1, sOutCombi, FormatEng (cTemp2, f64CoarseDelay * 1e-9, 4, "s", 9, 1, false), bFineDelay);
                                        }
                                      }
                                      Console.Write ("\n");
                                      Console.Write ("{0,46}   = D: delayed burst,   no combi\n",   "combiner legend ");
                                      Console.Write ("{0,46}     B: combi burst, any non-zero\n",   " ");
                                      Console.Write ("{0,46}     1: 1st pulse,   any non-zero\n\n", " ");
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                      break;

                      case Sepia2_Import.SEPIA2OBJECT_SLM  :

                      if ((iRetVal = Sepia2_Import.SEPIA2_SLM_GetPulseParameters (iDevIdx, iSlotId,  out iFreqTrigIdx, out bPulseMode, out iHead)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Sepia2_Import.SEPIA2_SLM_DecodeFreqTrigMode (iFreqTrigIdx, cFrequency);
                        Sepia2_Import.SEPIA2_SLM_DecodeHeadType     (iHead, cHeadType);
                        //
                        Console.Write ("{0,47}  =     '{1}'\n",        "freq / trigmode  ", cFrequency);
                        Console.Write ("{0,47}  =     'pulses {1}'\n", "pulsmode         ", (bPulseMode != 0 ? "enabled" : "disabled"));
                        Console.Write ("{0,47}  =     '{1}'\n",        "headtype         ", cHeadType);
                      }
                      if ((iRetVal = Sepia2_Import.SEPIA2_SLM_GetIntensityFineStep (iDevIdx, iSlotId, out wIntensity)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Console.Write ("{0,47}  =   {1,5:F1}%\n",     "intensity        ", 0.1*wIntensity);
                      }
                      Console.Write ("\n");
                      break;

                      case Sepia2_Import.SEPIA2OBJECT_SML  :
                      if ((iRetVal = Sepia2_Import.SEPIA2_SML_GetParameters (iDevIdx, iSlotId, out bPulseMode, out iHead, out bIntensity)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Sepia2_Import.SEPIA2_SML_DecodeHeadType     (iHead, cHeadType);
                        //
                        Console.Write ("{0,47}  =     pulses %s\n", "pulsmode         ", (bPulseMode != 0 ? "enabled" : "disabled"));
                        Console.Write ("{0,47}  =     {1}\n",        "headtype         ", cHeadType);
                        Console.Write ("{0,47}  =   {1,3}%\n",        "intensity        ", bIntensity);
                        Console.Write ("\n");
                      }
                      break;

                      case Sepia2_Import.SEPIA2OBJECT_SPM  :
                      if ((iRetVal = Sepia2_Import.SEPIA2_SPM_GetFWVersion (iDevIdx, iSlotId, out SWSFWVers)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Console.Write ("{0,47}  =     {1}.{2}.{3}\n", "firmware version ", SWSFWVers.VersMaj, SWSFWVers.VersMin, SWSFWVers.BuildNr);
                      }
                      break;

                      case Sepia2_Import.SEPIA2OBJECT_SWS  :
                      if ((iRetVal = Sepia2_Import.SEPIA2_SWS_GetFWVersion (iDevIdx, iSlotId, out SWSFWVers)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Console.Write ("{0,47}  =     {1}.{2}.{3}\n", "firmware version ", SWSFWVers.VersMaj, SWSFWVers.VersMin, SWSFWVers.BuildNr);
                      }
                      if ((iRetVal = Sepia2_Import.SEPIA2_SWS_GetModuleType (iDevIdx, iSlotId, out iSWSModuleType)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Sepia2_Import.SEPIA2_SWS_DecodeModuleType (iSWSModuleType, cSWSModuleType);
                        Console.Write ("{0,47}  =     {1}\n",       "SWS module type ", cSWSModuleType);
                      }
                      if ((iRetVal = Sepia2_Import.SEPIA2_SWS_GetParameters (iDevIdx, iSlotId, out ulWaveLength, out ulBandWidth)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        //
                        Console.Write ("{0,47}  =  {1,8:F3} nm \n",    "wavelength       ", 0.001 * ulWaveLength);
                        Console.Write ("{0,47}  =  {1,8:F3} nm \n",    "bandwidth        ", 0.001 * ulBandWidth);
                        Console.Write ("\n");
                      }
                      if ((iRetVal = Sepia2_Import.SEPIA2_SWS_GetIntensity (iDevIdx, iSlotId, out ulIntensRaw, out fIntensity)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Console.Write ("{0,47}  = 0x{1,4:X4} a.u. i.e. ~ {2:F1}nA\n",    "power diode      ", ulIntensRaw, fIntensity);
                        Console.Write ("\n");
                      }
                      if ((iRetVal = Sepia2_Import.SEPIA2_SWS_GetBeamPos (iDevIdx, iSlotId, out sBeamVPos, out sBeamHPos)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Console.Write ("{0,47}  =   {1,3} steps\n",    "horiz. beamshift ", sBeamHPos);
                        Console.Write ("{0,47}  =   {1,3} steps\n",    "vert.  beamshift ", sBeamVPos);
                        Console.Write ("\n");
                      }
                      break;

                      case Sepia2_Import.SEPIA2OBJECT_SSM  :
                      if ((iRetVal = Sepia2_Import.SEPIA2_SSM_GetTriggerData (iDevIdx, iSlotId, out iFreqTrigIdx, out iTriggerMilliVolt)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        //
                        Sepia2_Import.SEPIA2_SSM_DecodeFreqTrigMode    (iDevIdx, iSlotId, iFreqTrigIdx, cFreqTrigMode, out iFreq, out bTrigLevelEnabled);
                        Console.Write ("{0,47}  =     '{1}'\n", "act. freq./trigm.", cFreqTrigMode);
                        if (bTrigLevelEnabled != 0)
                        {
                          Console.Write ("{0,47}  = {1:D5} mV\n", "triggerlevel     ", iTriggerMilliVolt);
                        }
                      }
                      break;

                      case Sepia2_Import.SEPIA2OBJECT_SWM  :
                      if ((iRetVal = Sepia2_Import.SEPIA2_SWM_GetCurveParams (iDevIdx, iSlotId, 1, out bTBNdx, out wPAPml, out wRRPml, out wPSPml, out wRSPml, out wWSPml)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Console.Write ("{0,47}\n",                "Curve 1:         ");
                        Console.Write ("{0,47}  =   {1,3}\n",      "TBNdx            ", bTBNdx);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "PAPml            ", 0.1 * wPAPml);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "RRPml            ", 0.1 * wRRPml);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "PSPml            ", 0.1 * wPSPml);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "RSPml            ", 0.1 * wRSPml);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "WSPml            ", 0.1 * wWSPml);
                      }
                      if ((iRetVal = Sepia2_Import.SEPIA2_SWM_GetCurveParams (iDevIdx, iSlotId, 2, out bTBNdx, out wPAPml, out wRRPml, out wPSPml, out wRSPml, out wWSPml)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                      {
                        Console.Write ("{0,47}\n",                "Curve 2:         ");
                        Console.Write ("{0,47}  =   {1,3}\n",      "TBNdx            ", bTBNdx);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "PAPml            ", 0.1 * wPAPml);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "RRPml            ", 0.1 * wRRPml);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "PSPml            ", 0.1 * wPSPml);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "RSPml            ", 0.1 * wRSPml);
                        Console.Write ("{0,47}  =  {1,6:F1}%\n",    "WSPml            ", 0.1 * wWSPml);
                      }
                      break;

                      default : break;
                    }
                  }
                }
                //
                if (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                {
                  //
                  if (bIsPrimary == 0)
                  {
                    if ((iRetVal = Sepia2_Import.SEPIA2_COM_GetModuleType (iDevIdx, iSlotId, Sepia2_Import.SEPIA2_SECONDARY_MODULE, out iModuleType)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
                    {
                      Sepia2_Import.SEPIA2_COM_DecodeModuleType (iModuleType, cModulType);
                      Sepia2_Import.SEPIA2_COM_GetSerialNumber  (iDevIdx, iSlotId, Sepia2_Import.SEPIA2_SECONDARY_MODULE, cSerialNumber);
                      Console.Write ("\n              secondary mod.  '{0}'\n", cModulType);
                      Console.Write ("              serial number   '{0}'\n\n", cSerialNumber);
                    }
                  }
                  //
                  if (bHasUptimeCounter != 0)
                  {
                    Sepia2_Import.SEPIA2_FWR_GetUptimeInfoByMapIdx (iDevIdx, iMapIdx, out ulMainPowerUp, out ulActivePowerUp, out ulScaledPowerUp);
                    PrintUptimers (ulMainPowerUp, ulActivePowerUp, ulScaledPowerUp);
                  }
                }
              }
            }
              }
            } // get module map
            else
            {
              Sepia2_Import.SEPIA2_LIB_DecodeError (iRetVal, cErrString);
              Console.Write ("     ERROR {0:D5}:    '{1}'\n\n", iRetVal, cErrString);
              if ((iRetVal = Sepia2_Import.SEPIA2_FWR_GetLastError (iDevIdx, out iFWErrCode, out iFWErrPhase, out iFWErrLocation, out iFWErrSlot, cFWErrCond)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
              {
            if (iFWErrCode != Sepia2_Import.SEPIA2_ERR_NO_ERROR)
            {
              Sepia2_Import.SEPIA2_LIB_DecodeError  (iFWErrCode,  cErrString);
              Sepia2_Import.SEPIA2_FWR_DecodeErrPhaseName (iFWErrPhase, cFWErrPhase);
              Console.Write ("     Firmware error detected:\n");
              Console.Write ("        error code      : {0:D5},   i.e. '{1}'\n", iFWErrCode,  cErrString);
              Console.Write ("        error phase     : {0:D5},   i.e. '{1}'\n", iFWErrPhase, cFWErrPhase);
              Console.Write ("        error location  : {0:D5}\n",  iFWErrLocation);
              Console.Write ("        error slot      : {0:D5}\n",  iFWErrSlot);
              if (cFWErrCond.Length > 0)
              {
                Console.Write ("        error condition : '{0}'\n", cFWErrCond);
              }
            }
              }
            }
            //
            Sepia2_Import.SEPIA2_FWR_FreeModuleMap (iDevIdx);
            if (bStayOpened)
            {
              Console.Write ("\npress RETURN to close Sepia... ");
              Console.Read ();
            }
            Sepia2_Import.SEPIA2_USB_CloseDevice   (iDevIdx);
              }
              else
              {
            Sepia2_Import.SEPIA2_LIB_DecodeError (iRetVal, cErrString);
            Console.Write ("     ERROR {0:D5}:    '{1}'\n\n", iRetVal, cErrString);
              }

              Console.Write ("\n");

              if (!bNoWait)
              {
            Console.Write ("\npress RETURN... ");
            Console.Read ();
              }
        }
コード例 #8
0
ファイル: TextControl.cs プロジェクト: KonajuGames/SharpLang
		/// <summary>
		///  Scans the next paragraph for http:/ ftp:/ www. https:/ etc and marks the tags
		///  as links.
		/// </summary>
		/// <param name="start_line">The line to start on</param>
		/// <param name="link_changed">marks as true if something is changed</param>
		private void ScanForLinks (Line start_line, ref bool link_changed)
		{
			Line current_line = start_line;
			StringBuilder line_no_breaks = new StringBuilder ();
			StringBuilder line_link_record = new StringBuilder ();
			ArrayList cumulative_length_list = new ArrayList ();
			bool update_caret_tag = false;

			cumulative_length_list.Add (0);

			while (current_line != null) {
				line_no_breaks.Append (current_line.text);

				if (link_changed == false)
					current_line.LinkRecord (line_link_record);

				current_line.ClearLinks ();

				cumulative_length_list.Add (line_no_breaks.Length);

				if (current_line.ending == LineEnding.Wrap)
					current_line = GetLine (current_line.LineNo + 1);
				else
					break;
			}

			// search for protocols.. make sure www. is first!
			string [] search_terms = new string [] { "www.", "http:/", "ftp:/", "https:/" };
			int search_found = 0;
			int index_found = 0;
			string line_no_breaks_string = line_no_breaks.ToString ();
			int line_no_breaks_index = 0;
			int link_end = 0;

			while (true) {
				if (line_no_breaks_index >= line_no_breaks_string.Length)
					break;

				index_found = FirstIndexOfAny (line_no_breaks_string, search_terms, line_no_breaks_index, out search_found);

				//no links found on this line
				if (index_found == -1)
					break;

				if (search_found == 0) {
					// if we are at the end of the line to analyse and the end of the line
					// is "www." then there are no links here
					if (line_no_breaks_string.Length == index_found + search_terms [0].Length)
						break;

					// if after www. we don't have a letter a digit or a @ or - or /
					// then it is not a web address, we should continue searching
					if (char.IsLetterOrDigit (line_no_breaks_string [index_found + search_terms [0].Length]) == false &&
						"@/~".IndexOf (line_no_breaks_string [index_found + search_terms [0].Length].ToString ()) == -1) {
						line_no_breaks_index = index_found + search_terms [0].Length;
						continue;
					}
				}

				link_end = line_no_breaks_string.Length - 1;
				line_no_breaks_index = line_no_breaks_string.Length;

				// we've found a link, we just need to find where it ends now
				for (int i = index_found + search_terms [search_found].Length; i < line_no_breaks_string.Length; i++) {
					if (line_no_breaks_string [i - 1] == '.') {
						if (char.IsLetterOrDigit (line_no_breaks_string [i]) == false &&
							"@/~".IndexOf (line_no_breaks_string [i].ToString ()) == -1) {
							link_end = i - 1;
							line_no_breaks_index = i;
							break;
						}
					} else {
						if (char.IsLetterOrDigit (line_no_breaks_string [i]) == false &&
							"@-/:~.?=_&".IndexOf (line_no_breaks_string [i].ToString ()) == -1) {
							link_end = i - 1;
							line_no_breaks_index = i;
							break;
						}
					}
				}

				string link_text = line_no_breaks_string.Substring (index_found, link_end - index_found + 1);
				int current_cumulative = 0;

				// we've found a link - index_found -> link_end
				// now we just make all the tags as containing link and
				// point them to the text for the whole link

				current_line = start_line;

				//find the line we start on
				for (current_cumulative = 1; current_cumulative < cumulative_length_list.Count; current_cumulative++)
					if ((int)cumulative_length_list [current_cumulative] > index_found)
						break;

				current_line = GetLine (start_line.LineNo + current_cumulative - 1);

				// find the tag we start on
				LineTag current_tag = current_line.FindTag (index_found - (int)cumulative_length_list [current_cumulative - 1] + 1);

				if (current_tag.Start != (index_found - (int)cumulative_length_list [current_cumulative - 1]) + 1) {
					if (current_tag == CaretTag)
						update_caret_tag = true;

					current_tag = current_tag.Break ((index_found - (int)cumulative_length_list [current_cumulative - 1]) + 1);
				}

				// set the tag
				current_tag.IsLink = true;
				current_tag.LinkText = link_text;

				//go through each character
				// find the tag we are in
				// skip the number of characters in the tag
				for (int i = 1; i < link_text.Length; i++) {
					// on to a new word-wrapped line
					if ((int)cumulative_length_list [current_cumulative] <= index_found + i) {

						current_line = GetLine (start_line.LineNo + current_cumulative++);
						current_tag = current_line.FindTag (index_found + i - (int)cumulative_length_list [current_cumulative - 1] + 1);

						current_tag.IsLink = true;
						current_tag.LinkText = link_text;

						continue;
					}

					if (current_tag.End < index_found + 1 + i - (int)cumulative_length_list [current_cumulative - 1]) {
						// skip empty tags in the middle of the URL
						do {
							current_tag = current_tag.Next;
						} while (current_tag.Length == 0);

						current_tag.IsLink = true;
						current_tag.LinkText = link_text;
					}
				}

				//if there are characters left in the tag after the link
				// split the tag
				// make the second part a non link
				if (current_tag.End > (index_found + link_text.Length + 1) - (int)cumulative_length_list [current_cumulative - 1]) {
					if (current_tag == CaretTag)
						update_caret_tag = true;

					current_tag.Break ((index_found + link_text.Length + 1) - (int)cumulative_length_list [current_cumulative - 1]);
				}
			}

			if (update_caret_tag) {
				CaretTag = LineTag.FindTag (CaretLine, CaretPosition);
				link_changed = true;
			} else {
				if (link_changed == false) {
					current_line = start_line;
					StringBuilder new_link_record = new StringBuilder ();

					while (current_line != null) {
						current_line.LinkRecord (new_link_record);

						if (current_line.ending == LineEnding.Wrap)
							current_line = GetLine (current_line.LineNo + 1);
						else
							break;
					}

					if (new_link_record.Equals (line_link_record) == false)
						link_changed = true;
				}
			}
		}
コード例 #9
0
        public static void Main(string[] args)
        {
            int             iRetVal        = Sepia2_Import.SEPIA2_ERR_NO_ERROR;
              //
              StringBuilder   cLibVersion    = new StringBuilder("", Sepia2_Import.SEPIA2_VERSIONINFO_LEN);
              StringBuilder   cSepiaSerNo    = new StringBuilder("", Sepia2_Import.SEPIA2_SERIALNUMBER_LEN);
              StringBuilder   cGivenSerNo    = new StringBuilder("", Sepia2_Import.SEPIA2_SERIALNUMBER_LEN);
              StringBuilder   cProductModel  = new StringBuilder("", Sepia2_Import.SEPIA2_PRODUCTMODEL_LEN);
              StringBuilder   cGivenProduct  = new StringBuilder("", Sepia2_Import.SEPIA2_PRODUCTMODEL_LEN);
              StringBuilder   cFWVersion     = new StringBuilder("", Sepia2_Import.SEPIA2_VERSIONINFO_LEN);
              StringBuilder   cDescriptor    = new StringBuilder("", Sepia2_Import.SEPIA2_USB_STRDECR_LEN);
              StringBuilder   cFWErrCond     = new StringBuilder("", Sepia2_Import.SEPIA2_FW_ERRCOND_LEN);
              StringBuilder   cErrString     = new StringBuilder("", Sepia2_Import.SEPIA2_ERRSTRING_LEN);
              StringBuilder   cFWErrPhase    = new StringBuilder("", Sepia2_Import.SEPIA2_FW_ERRPHASE_LEN);
              StringBuilder   cFreqTrigMode  = new StringBuilder("", Sepia2_Import.SEPIA2_SOM_FREQ_TRIGMODE_LEN);
              StringBuilder   cSOMType       = new StringBuilder("", 5);
              StringBuilder   cSLMType       = new StringBuilder("", 5);
              StringBuilder   cTemp          = new StringBuilder("", 1025);
              //
              int []         lBurstChannels  = new int[Sepia2_Import.SEPIA2_SOM_BURSTCHANNEL_COUNT] {0, 0, 0, 0, 0, 0, 0, 0};
              int            lTemp;
              //
              int             iSOM_Slot                                      = 100;
              int             iSLM_Slot                                      = 200;
              int             iDevIdx                                        =  -1;
              int             iGivenDevIdx                                   =   0;
              //
              //
              int             iModuleCount;
              int             iModuleType;
              int             iFWErrCode;
              int             iFWErrPhase;
              int             iFWErrLocation;
              int             iFWErrSlot;
              int             iFreqTrigIdx;
              int             iTemp1;
              int             iTemp2;
              int             iTemp3;
              int             iFreq;
              int             iHead;
              int             i;
              //
              // byte
              bool   bUSBInstGiven = false;
              bool   bSerialGiven  = false;
              bool   bProductGiven = false;
              bool   bIsSOMDModule = false;
              bool   bExtTiggered;
              byte   bDivider;
              byte   bPreSync;
              byte   bMaskSync;
              byte   bOutEnable;
              byte   bSyncEnable;
              byte   bSyncInverse;
              byte   bSynchronized = 0;
              byte   bPulseMode;
              //
              // word
              ushort  wIntensity;
              ushort  wDivider;
              //
              //
              Console.WriteLine (" called with {0} Parameter{1}:", args.Length, (args.Length>1)?"s":"");
              foreach (string s in args)
              {
            if (Regex.IsMatch(s, "^-inst="))
            {
              string sVal = Regex.Replace (s, "^-inst=", "");
              try
              {
            iGivenDevIdx = Int32.Parse (sVal);
              }
              catch (FormatException)
              {
            throw new Exception ("error: param \"-inst=\" is not an integer");
              }
              Console.Write ("    -inst={0}\n", iGivenDevIdx);
              bUSBInstGiven = true;
            } else
              if (Regex.IsMatch(s, "^-serial="))
            {
              string sVal = Regex.Replace (s, "^-serial=", "");
              cGivenSerNo.Append (Regex.Match (sVal, @"\d{1," + Sepia2_Import.SEPIA2_SERIALNUMBER_LEN + "}").Value);
              Console.Write ("    -serial={0}\n", cGivenSerNo);
              bSerialGiven = (cGivenSerNo.Length > 0);
            } else
              if (Regex.IsMatch(s, "^-product="))
            {
              string sVal = Regex.Replace (s, "^-product=", "");
              cGivenProduct.Append (Regex.Match (sVal, @"\d{1," + Sepia2_Import.SEPIA2_PRODUCTMODEL_LEN + "}").Value);
              Console.Write ("    -product={0}\n", cGivenProduct);
              bProductGiven = (cGivenProduct.Length > 0);
            } else
            {
              Console.Write ("    {0} : unknown parameter!\n", s);
            }
              }

              Console.Write ("\n\n     PQLaserDrv   Set SOME Values Demo : \n");
              Console.Write ("    =================================================\n\n\n");
              //
              // preliminaries: check library version
              //
              Sepia2_Import.SEPIA2_LIB_GetVersion (cLibVersion);
              Console.Write ("     Lib-Version   = {0}\n", cLibVersion);

            //      if (0 != strncmp (cLibVersion, LIB_VERSION_REFERENCE, LIB_VERSION_REFERENCE_COMPLEN))
            //      {
            //        Console.Write ("\n     Warning: This demo application was built for version  %s!\n", LIB_VERSION_REFERENCE);
            //        Console.Write ("              Continuing may cause unpredictable results!\n");
            //        Console.Write ("\n     Do you want to continue anyway? (y/n): ");
            //
            //        c = Console.Read();
            //        if ((c != 'y') && (c != 'Y'))
            //        {
            //          exit (-1);
            //        }
            //        while ((c = Console.Read()) != 0x0A ); // reject userinput 'til end of line
            //        Console.Write ("\n");
            //      }
              //
              // establish USB connection to the sepia first matching all given conditions
              //
              for (i = (bUSBInstGiven ? iGivenDevIdx : 0); i < (bUSBInstGiven ? iGivenDevIdx+1 : Sepia2_Import.SEPIA2_MAX_USB_DEVICES); i++)
              {
            cSepiaSerNo.Length = 0;
            cProductModel.Length = 0;
            //
            iRetVal = Sepia2_Import.SEPIA2_USB_OpenGetSerNumAndClose (i, cProductModel, cSepiaSerNo);
            if ( (iRetVal == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
            && (  (  (bSerialGiven && bProductGiven)
               && (cGivenSerNo.Equals (cSepiaSerNo)  )
               && (cGivenProduct.Equals (cProductModel)  )
               )
            ||  (  (!bSerialGiven != !bProductGiven)
             && (  (cGivenSerNo.Equals (cSepiaSerNo)  )
            || (cGivenProduct.Equals (cProductModel)  )
            )
             )
            ||  ( !bSerialGiven && !bProductGiven)
            )
            )
            {
              iDevIdx = bUSBInstGiven ? ((iGivenDevIdx == i) ? i : -1) : i;
              break;
            }
              }
              //
              if ((iRetVal = Sepia2_Import.SEPIA2_USB_OpenDevice (iDevIdx, cProductModel, cSepiaSerNo)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
              {
            Sepia2_Import.SEPIA2_FWR_GetVersion (iDevIdx, cFWVersion);
            Console.Write ("     FW-Version    = {0}\n",     cFWVersion);
            //
            Sepia2_Import.SEPIA2_USB_GetStrDescriptor  (iDevIdx, cDescriptor);
            Console.Write ("     Descriptor    = {0}\n", cDescriptor);
            Console.Write ("     Serial Number = '{0}'\n\n\n", cSepiaSerNo);
            Console.Write ("    =================================================\n\n\n");
            //
            // get sepia's module map and initialise datastructures for all library functions
            // there are two different ways to do so:
            //
            // first:  if sepia was not touched since last power on, it doesn't need to be restarted
            //
            if ((iRetVal = Sepia2_Import.SEPIA2_FWR_GetModuleMap (iDevIdx, Sepia2_Import.SEPIA2_NO_RESTART, out iModuleCount)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
              //
              // second: in case of changes with soft restart
              //
              //  if ((iRetVal = Sepia2_Import.SEPIA2_FWR_GetModuleMap (iDevIdx, Sepia2_Import.SEPIA2_RESTART, out iModuleCount)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
            {
              //
              // this is to inform us about possible error conditions during sepia's last startup
              //
              if ((iRetVal = Sepia2_Import.SEPIA2_FWR_GetLastError (iDevIdx, out iFWErrCode, out iFWErrPhase, out iFWErrLocation, out iFWErrSlot, cFWErrCond)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
              {
            if (iFWErrCode != Sepia2_Import.SEPIA2_ERR_NO_ERROR)
            {
              Sepia2_Import.SEPIA2_LIB_DecodeError  (iFWErrCode,  cErrString);
              Sepia2_Import.SEPIA2_FWR_DecodeErrPhaseName (iFWErrPhase, cFWErrPhase);
              Console.Write ("     Error detected by firmware on last restart:\n");
              Console.Write ("        error code      : {0:5},   i.e. '{1}'\n", iFWErrCode,  cErrString);
              Console.Write ("        error phase     : {0:5},   i.e. '{1}'\n", iFWErrPhase, cFWErrPhase);
              Console.Write ("        error location  : {0:5}\n",  iFWErrLocation);
              Console.Write ("        error slot      : {0:5}\n",  iFWErrSlot);
              if (cFWErrCond.Length > 0)
              {
                Console.Write ("        error condition : '{0}'\n", cFWErrCond);
              }
            }
            else
            {
              //
              // SOM-Type - Initialization
              //
              if ((iRetVal = Sepia2_Import.SEPIA2_COM_GetModuleType (iDevIdx, iSOM_Slot, Sepia2_Import.SEPIA2_PRIMARY_MODULE, out iModuleType)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
              {
                bIsSOMDModule = (iModuleType == Sepia2_Import.SEPIA2OBJECT_SOMD);
                Sepia2_Import.SEPIA2_COM_DecodeModuleTypeAbbr (iModuleType, cSOMType);
              }
              //
              // SLM-Type - Initialization
              //
              if ((iRetVal = Sepia2_Import.SEPIA2_COM_GetModuleType (iDevIdx, iSLM_Slot, Sepia2_Import.SEPIA2_PRIMARY_MODULE, out iModuleType)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
              {
                Sepia2_Import.SEPIA2_COM_DecodeModuleTypeAbbr (iModuleType, cSLMType);
              }
              //
              //
              // we want to restore the changed values ...
              //
              if (File.Exists ("OrigData.txt"))
              {
                // ... so we have to read the original data from file
                //
                ScanFile ("SOM.*FreqTrigIdx", cTemp, out iFreqTrigIdx);
                bExtTiggered = (iFreqTrigIdx == Sepia2_Import.SEPIA2_SOM_TRIGMODE_RISING) || (iFreqTrigIdx == Sepia2_Import.SEPIA2_SOM_TRIGMODE_FALLING);
                //

                if (cTemp.Equals ("SOMD") && bExtTiggered)
                {
                  ScanFile ("ExtTrig.Sync.", cTemp, out iTemp1);
                  bSynchronized = (byte)((iTemp1 != 0) ? 1 : 0);
                }
                //
                ScanFile ("Divider", cTemp, out iTemp1);
                ScanFile ("PreSync", cTemp, out iTemp2);
                ScanFile ("MaskSync", cTemp, out iTemp3);
                bDivider   = (byte)(iTemp1 % 256);
                wDivider   = (ushort)iTemp1;
                bPreSync   = (byte)iTemp2;
                bMaskSync  = (byte)iTemp3;
                //
                ScanFile ("Output Enable", cTemp, out iTemp1);
                ScanFile ("Sync Enable", cTemp, out iTemp2);
                ScanFile ("Sync Inverse", cTemp, out iTemp3);
                bOutEnable   = (byte)iTemp1;
                bSyncEnable  = (byte)iTemp2;
                bSyncInverse = (byte)iTemp3;
                for (i = 0; i < Sepia2_Import.SEPIA2_SOM_BURSTCHANNEL_COUNT; i++)
                {
                  ScanFile (string.Format("BurstLength {0}", i+1), cTemp, out lTemp);
                  lBurstChannels[i] = lTemp;
                }
                //
                ScanFile ("SLM.*FreqTrigIdx", cTemp, out iFreq);
                ScanFile ("Pulse Mode", cTemp, out iTemp1);
                ScanFile ("Intensity",  cTemp, out iTemp2);
                bPulseMode = (byte)iTemp1;
                wIntensity = (ushort)(iTemp2);

                // ... and delete it afterwards
                Console.Write ("     original data read from file 'OrigData.txt'\n\n");
                File.Delete ("OrigData.txt");
              }
              else
              {
                // ... so we have to save the original data in a file
                // ... and may then set arbitrary values
                //
                try
                {
                  File.WriteAllText ("OrigData.txt", "");
                }
                catch
                {
                  Console.Write ("     You tried to start this demo in a write protected directory.\n");
                  Console.Write ("     demo execution aborted.\n");
                  Console.Write ("\n\n");
                  Console.Write ("press RETURN...\n");
                  Console.Read ();

                  return;
                }
                //
                // SOM
                //
                // FreqTrigMode
                if (bIsSOMDModule)
                {
                  Sepia2_Import.SEPIA2_SOMD_GetFreqTrigMode (iDevIdx, iSOM_Slot, out iFreqTrigIdx, out bSynchronized);
                  File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} FreqTrigIdx   =        {1:D1}\n", cSOMType, iFreqTrigIdx));
                  if ((iFreqTrigIdx == Sepia2_Import.SEPIA2_SOM_TRIGMODE_RISING) || (iFreqTrigIdx == Sepia2_Import.SEPIA2_SOM_TRIGMODE_FALLING))
                  {
                    File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} ExtTrig.Sync. =        {1:D1}\n", cSOMType, bSynchronized != 0 ? 1 : 0));
                  }
                }
                else
                {
                  Sepia2_Import.SEPIA2_SOM_GetFreqTrigMode  (iDevIdx, iSOM_Slot, out iFreqTrigIdx);
                  File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} FreqTrigIdx   =        {1:D1}\n", cSOMType, iFreqTrigIdx));
                }
                iFreqTrigIdx = Sepia2_Import.SEPIA2_SOM_INT_OSC_C;
                //
                // BurstValues
                if (bIsSOMDModule)
                {
                  Sepia2_Import.SEPIA2_SOMD_GetBurstValues (iDevIdx, iSOM_Slot, out wDivider, out bPreSync, out bMaskSync);
                }
                else
                {
                  Sepia2_Import.SEPIA2_SOM_GetBurstValues  (iDevIdx, iSOM_Slot, out bDivider, out bPreSync, out bMaskSync);
                  wDivider = bDivider;
                }
                File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} Divider       =    {1,5}\n",   cSOMType, wDivider));
                File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} PreSync       =      {1,3}\n", cSOMType, bPreSync));
                File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} MaskSync      =      {1,3}\n", cSOMType, bMaskSync));
                bDivider  = 200;
                bPreSync  =  10;
                bMaskSync =   1;
                //
                // Out'n'SyncEnable
                if (bIsSOMDModule)
                {
                  Sepia2_Import.SEPIA2_SOMD_GetOutNSyncEnable   (iDevIdx, iSOM_Slot, out bOutEnable, out bSyncEnable, out bSyncInverse);
                  Sepia2_Import.SEPIA2_SOMD_GetBurstLengthArray (iDevIdx, iSOM_Slot, out lBurstChannels[0], out lBurstChannels[1], out lBurstChannels[2], out lBurstChannels[3], out lBurstChannels[4], out lBurstChannels[5], out lBurstChannels[6], out lBurstChannels[7]);
                }
                else
                {
                  Sepia2_Import.SEPIA2_SOM_GetOutNSyncEnable   (iDevIdx, iSOM_Slot, out bOutEnable, out bSyncEnable, out bSyncInverse);
                  Sepia2_Import.SEPIA2_SOM_GetBurstLengthArray (iDevIdx, iSOM_Slot, out lBurstChannels[0], out lBurstChannels[1], out lBurstChannels[2], out lBurstChannels[3], out lBurstChannels[4], out lBurstChannels[5], out lBurstChannels[6], out lBurstChannels[7]);
                }
                File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} Output Enable =     0x{1,2:X2}\n", cSOMType, bOutEnable));
                File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} Sync Enable   =     0x{1,2:X2}\n", cSOMType, bSyncEnable));
                File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} Sync Inverse  =        {1:D1}\n",  cSOMType,  bSyncInverse));
                bOutEnable   = 0xA5;
                bSyncEnable  = 0x93;
                bSyncInverse =    1;
                //
                // BurstLengthArray
                for (i = 0; i < Sepia2_Import.SEPIA2_SOM_BURSTCHANNEL_COUNT; i++)
                {
                  File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} BurstLength {1} = {2,8}\n", cSOMType, i+1, lBurstChannels[i]));
                }
                // just change places of burstlenght channel 2 & 3
                lTemp             = lBurstChannels[2];
                lBurstChannels[2] = lBurstChannels[1];
                lBurstChannels[1] = lTemp;
                //
                //
                // SLM
                //
                Sepia2_Import.SEPIA2_SLM_GetIntensityFineStep (iDevIdx, iSLM_Slot, out wIntensity);
                Sepia2_Import.SEPIA2_SLM_GetPulseParameters   (iDevIdx, iSLM_Slot, out iFreq, out bPulseMode, out iHead);
                File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} FreqTrigIdx   =        {1:D1}\n",   cSLMType, iFreq));
                File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} Pulse Mode    =        {1:D1}\n",   cSLMType, bPulseMode));
                File.AppendAllText ("OrigData.txt", string.Format ("{0,-4} Intensity     =      {1,2:F1}%\n", cSLMType, 0.1 * wIntensity));
                iFreq      = (2 + iFreq) % Sepia2_Import.SEPIA2_SLM_FREQ_TRIGMODE_COUNT;
                bPulseMode = (byte)(1 - bPulseMode);
                wIntensity = (ushort)(1000 - wIntensity);
                //
                //
                Console.Write ("     original data stored in file 'OrigData.txt'\n\n");
              }
              //
              // and here we finally set the new (resp. old) values
              //
              if (bIsSOMDModule)
              {
                Sepia2_Import.SEPIA2_SOMD_SetFreqTrigMode     (iDevIdx, iSOM_Slot, iFreqTrigIdx, bSynchronized);
                Sepia2_Import.SEPIA2_SOMD_DecodeFreqTrigMode  (iDevIdx, iSOM_Slot, iFreqTrigIdx, cFreqTrigMode);
                Sepia2_Import.SEPIA2_SOMD_SetBurstValues      (iDevIdx, iSOM_Slot, wDivider, bPreSync, bMaskSync);
                Sepia2_Import.SEPIA2_SOMD_SetOutNSyncEnable   (iDevIdx, iSOM_Slot, bOutEnable, bSyncEnable, bSyncInverse);
                Sepia2_Import.SEPIA2_SOMD_SetBurstLengthArray (iDevIdx, iSOM_Slot, lBurstChannels[0], lBurstChannels[1], lBurstChannels[2], lBurstChannels[3], lBurstChannels[4], lBurstChannels[5], lBurstChannels[6], lBurstChannels[7]);
              }
              else
              {
                bDivider = (byte)(wDivider % 256);
                Sepia2_Import.SEPIA2_SOM_SetFreqTrigMode     (iDevIdx, iSOM_Slot, iFreqTrigIdx);
                Sepia2_Import.SEPIA2_SOM_DecodeFreqTrigMode  (iDevIdx, iSOM_Slot, iFreqTrigIdx, cFreqTrigMode);
                Sepia2_Import.SEPIA2_SOM_SetBurstValues      (iDevIdx, iSOM_Slot, bDivider, bPreSync, bMaskSync);
                Sepia2_Import.SEPIA2_SOM_SetOutNSyncEnable   (iDevIdx, iSOM_Slot, bOutEnable, bSyncEnable, bSyncInverse);
                Sepia2_Import.SEPIA2_SOM_SetBurstLengthArray (iDevIdx, iSOM_Slot, lBurstChannels[0], lBurstChannels[1], lBurstChannels[2], lBurstChannels[3], lBurstChannels[4], lBurstChannels[5], lBurstChannels[6], lBurstChannels[7]);
              }
              Console.Write ("     {0,-4} FreqTrigMode  =      '{1}'\n", cSOMType, cFreqTrigMode);
              if ((iModuleType == Sepia2_Import.SEPIA2OBJECT_SOMD) && ((iFreqTrigIdx == Sepia2_Import.SEPIA2_SOM_TRIGMODE_RISING) || (iFreqTrigIdx == Sepia2_Import.SEPIA2_SOM_TRIGMODE_FALLING)))
              {
                Console.Write ("     {0,-4} ExtTrig.Sync. =        {1:D1}\n", cSOMType, bSynchronized != 0 ? 1 : 0);
              }
              //
              Console.Write ("     {0,-4} Divider       =    {1,5}\n",   cSOMType,   wDivider);
              Console.Write ("     {0,-4} PreSync       =      {1,3}\n", cSOMType,   bPreSync);
              Console.Write ("     {0,-4} MaskSync      =      {1,3}\n", cSOMType,   bMaskSync);
              //
              Console.Write ("     {0,-4} Output Enable =     0x{1,2:X2}\n", cSOMType, bOutEnable);
              Console.Write ("     {0,-4} Sync Enable   =     0x{1,2:X2}\n", cSOMType, bSyncEnable);
              Console.Write ("     {0,-4} Sync Inverse  =        {1:D1}\n",  cSOMType,  bSyncInverse);
              //
              Console.Write ("     {0,-4} BurstLength 2 = {1,8}\n",   cSOMType, lBurstChannels[1]);
              Console.Write ("     {0,-4} BurstLength 3 = {1,8}\n\n", cSOMType, lBurstChannels[2]);
              //
              // SLM
              //
              Sepia2_Import.SEPIA2_SLM_SetPulseParameters   (iDevIdx, iSLM_Slot, iFreq, bPulseMode);
              Sepia2_Import.SEPIA2_SLM_SetIntensityFineStep (iDevIdx, iSLM_Slot, wIntensity);
              Sepia2_Import.SEPIA2_SLM_DecodeFreqTrigMode (iFreq, cFreqTrigMode);
              Console.Write ("     {0,-4} FreqTrigMode  =      '{1}'\n", cSLMType,  cFreqTrigMode);
              Console.Write ("     {0,-4} Pulse Mode    =        {1:D1}\n", cSLMType, bPulseMode);
              Console.Write ("     {0,-4} Intensity     =       {1,2:F1}%\n", cSLMType, 0.1 * wIntensity);
            }
              }
            } // get module map
            else
            {
              Sepia2_Import.SEPIA2_LIB_DecodeError (iRetVal, cErrString);
              Console.Write ("     ERROR {0,5}:    '{1}'\n\n", iRetVal, cErrString);
              if ((iRetVal = Sepia2_Import.SEPIA2_FWR_GetLastError (iDevIdx, out iFWErrCode, out iFWErrPhase, out iFWErrLocation, out iFWErrSlot, cFWErrCond)) == Sepia2_Import.SEPIA2_ERR_NO_ERROR)
              {
            if (iFWErrCode != Sepia2_Import.SEPIA2_ERR_NO_ERROR)
            {
              Sepia2_Import.SEPIA2_LIB_DecodeError  (iFWErrCode,  cErrString);
              Sepia2_Import.SEPIA2_FWR_DecodeErrPhaseName (iFWErrPhase, cFWErrPhase);
              Console.Write ("     Firmware error detected:\n");
              Console.Write ("        error code      : {0,5},   i.e. '{1}'\n", iFWErrCode,  cErrString);
              Console.Write ("        error phase     : {0,5},   i.e. '{1}'\n", iFWErrPhase, cFWErrPhase);
              Console.Write ("        error location  : {0,5}\n",  iFWErrLocation);
              Console.Write ("        error slot      : {0,5}\n",  iFWErrSlot);
              if (cFWErrCond.Length > 0)
              {
                Console.Write ("        error condition : '{0}'\n", cFWErrCond);
              }
            }
              }
            }

            //
            Sepia2_Import.SEPIA2_FWR_FreeModuleMap (iDevIdx);
            Sepia2_Import.SEPIA2_USB_CloseDevice   (iDevIdx);
              }
              else
              {
            Sepia2_Import.SEPIA2_LIB_DecodeError (iRetVal, cErrString);
            Console.Write ("     ERROR {0,5}:    '{1}'\n\n", iRetVal, cErrString);
              }

              Console.Write ("\n\n");
              Console.Write ("press RETURN...\n");
              Console.Read ();
        }
コード例 #10
0
        private bool IsLastDoc(TsImage tsImageInfo)
        {
            try
            {
                //  Get the LastDoc of the Batch string
                var sLastDocId = new StringBuilder();
                sLastDocId.Append(TsMemFiles.GetInt("Image", "Level4", 0, LastDocInfo));
                sLastDocId.Append("-");
                sLastDocId.Append(TsMemFiles.GetInt("Image", "Level3", 0, LastDocInfo));
                sLastDocId.Append("-");
                sLastDocId.Append(TsMemFiles.GetInt("Image", "Level2", 0, LastDocInfo));
                var sCurrentDocId = new StringBuilder();
                sLastDocId.Append(tsImageInfo.Level4);
                sLastDocId.Append("-");
                sLastDocId.Append(tsImageInfo.Level3);
                sLastDocId.Append("-");
                sLastDocId.Append(tsImageInfo.Level2);

                if (sLastDocId.Equals(sCurrentDocId))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
コード例 #11
0
        /// <summary>
        /// Gets the duration between the two specified GEDCOM X dates.
        /// </summary>
        /// <param name="startDate">The simple start date.</param>
        /// <param name="endDate">The simple end date.</param>
        /// <returns>A <see cref="GedcomxDateDuration"/> representing the duration between the two specified dates.</returns>
        /// <exception cref="Gedcomx.Date.GedcomxDateException">
        /// Thrown if one of the input dates is null
        /// or
        /// Thrown if the start date occurs after the end date, or is equal to the end time.
        /// </exception>
        public static GedcomxDateDuration GetDuration(GedcomxDateSimple startDate, GedcomxDateSimple endDate)
        {

            if (startDate == null || endDate == null)
            {
                throw new GedcomxDateException("Start and End must be simple dates");
            }

            Date start = new Date(startDate, true);
            Date end = new Date(endDate, true);
            bool hasTime = false;
            StringBuilder duration = new StringBuilder();

            ZipDates(start, end);

            // Build the duration backwards so we can grab the correct diff
            // Also we need to roll everything up so we don't generate an invalid max year
            if (end.seconds != null)
            {
                while (end.seconds - start.seconds < 0)
                {
                    end.minutes -= 1;
                    end.seconds += 60;
                }
                if (end.seconds - start.seconds > 0)
                {
                    hasTime = true;
                    duration.Insert(0, 'S').Insert(0, String.Format("{0:00}", end.seconds - start.seconds));
                }
            }

            if (end.minutes != null)
            {
                while (end.minutes - start.minutes < 0)
                {
                    end.hours -= 1;
                    end.minutes += 60;
                }
                if (end.minutes - start.minutes > 0)
                {
                    hasTime = true;
                    duration.Insert(0, 'M').Insert(0, String.Format("{0:00}", end.minutes - start.minutes));
                }
            }

            if (end.hours != null)
            {
                while (end.hours - start.hours < 0)
                {
                    end.day -= 1;
                    end.hours += 24;
                }
                if (end.hours - start.hours > 0)
                {
                    hasTime = true;
                    duration.Insert(0, 'H').Insert(0, String.Format("{0:00}", end.hours - start.hours));
                }
            }

            if (hasTime)
            {
                duration.Insert(0, 'T');
            }

            if (end.day != null)
            {
                while (end.day - start.day < 0)
                {
                    end.day += DateTime.DaysInMonth(end.year.Value, end.month.Value);
                    end.month -= 1;
                    if (end.month < 1)
                    {
                        end.year -= 1;
                        end.month += 12;
                    }
                }
                if (end.day - start.day > 0)
                {
                    duration.Insert(0, 'D').Insert(0, String.Format("{0:00}", end.day - start.day));
                }
            }

            if (end.month != null)
            {
                while (end.month - start.month < 0)
                {
                    end.year -= 1;
                    end.month += 12;
                }
                if (end.month - start.month > 0)
                {
                    duration.Insert(0, 'M').Insert(0, String.Format("{0:00}", end.month - start.month));
                }
            }

            if (end.year - start.year > 0)
            {
                duration.Insert(0, 'Y').Insert(0, String.Format("%04d", end.year - start.year));
            }

            String finalDuration = duration.ToString();

            if (end.year - start.year < 0 || duration.Equals(""))
            {
                throw new GedcomxDateException("Start Date must be less than End Date");
            }

            return new GedcomxDateDuration("P" + finalDuration);
        }
コード例 #12
0
ファイル: SoundManager.cs プロジェクト: yggy123/closed-sky
        /// <summary>
        /// Check and fix any problem with hardware.
        /// </summary>
        private void CheckDriver()
        {
            //Get number of driver available
            int DriverNumber = 0;
            CheckError(m_System.getNumDrivers(ref DriverNumber));

            //Driver checking
            #region Solve hardware problems
            //If there's 0 driver, no sound
            if (DriverNumber <= 0) CheckError(m_System.setOutput(OUTPUTTYPE.NOSOUND));
            else {
                //Get driver capability
                int			MinFreq = 0, MaxFreq = 0;
                CAPS		Capability	= CAPS.NONE;
                SPEAKERMODE Speakermode = SPEAKERMODE.STEREO;
                CheckError(m_System.getDriverCaps(0, ref Capability, ref MinFreq, ref MaxFreq, ref Speakermode));

                //Set spearker mode according to the driver
                CheckError(m_System.setSpeakerMode(Speakermode));

                //Set buffer if not using hardware accceleration
                if ((Capability & CAPS.HARDWARE_EMULATED) == CAPS.HARDWARE_EMULATED)
                    CheckError(m_System.setDSPBufferSize(Global.EMULATED_BUFFERSIZE, Global.EMULATED_BUFFERCOUNT));

                //Get user driver data
                GUID			Guid = new GUID();
                StringBuilder	DriverName = new StringBuilder(Global.MAX_DRIVERNAME);
                CheckError(m_System.getDriverInfo(0, DriverName, Global.MAX_DRIVERNAME, ref  Guid));

                //If driver is sigmatel
                if (DriverName.Equals(new StringBuilder((Global.SIGMATEL_DRIVERNAME)))) {
                    //Fix crackling
                    CheckError(m_System.setSoftwareFormat(
                        Global.SIGMATEL_SAMPLERATE,
                        SOUND_FORMAT.PCMFLOAT,
                        0,
                        0,
                        DSP_RESAMPLER.LINEAR));
                }
            }
            #endregion
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: yuanzheng/logs-analysis
        public static bool TrainingClusterSet(Dictionary<string, int> clusterMap, string[] methods, ref int index, StringBuilder result)
        {
            var cluster = new StringBuilder();
            cluster.Append(methods[index] + "_"); // add the first important id
            string current = methods[index];

            var allclusters = clusterMap.Keys; // get all current found keys
            // if current method is the last one then return

            if (index + 1 > methods.Length - 1)
                return false;

            string next = methods[index + 1];

            cluster.Append(methods[index + 1] + "_"); // add the second important id

            //existedClusters(clusterMap, methods, index);

            int N = 1;
            int length = 2;  // record the number of ids in the cluster

            bool found = false;
            var size = methods.Length;
            int start;
            for (start = index + length; start < size; start++)
            {
                // length of rest part is less than cluster
                if (length > methods.Length - start)
                {
                    /*
                    for (int i = start; i < methods.Length; i++)
                    {
                        cluster.Append(methods[i] + "_");
                    }
                     * */
                    break;
                }

                var substring = new StringBuilder();
                int j;
                // find out next N numbers, see if they match cluster
                for (j = 0; j < length; j++)
                {
                    if (start + j == size) // over pipeline size
                        break;

                    substring.Append(methods[start + j] + "_");
                }

                if (cluster.Equals(substring))
                {
                    N++;
                    found = true;
                    start += length - 1;
                }
                else
                {
                    if (found)
                    {
                        break;
                    }

                    cluster.Append(methods[start] + "_");
                    length++; // cluster size increase

                }

            }

            if (N > 1)
            {
                string clusterString = cluster.Remove(cluster.Length - 1, 1).ToString();
                string temp = "[" + clusterString + "]x" + N;
                result.Append(temp + " "); // [12_3]x2 4 67
                //result.Append(substring.ToString());

                if (clusterMap.ContainsKey(temp))
                    clusterMap[temp]++;
                else
                    clusterMap.Add(temp, 1);
                /*
                if (!methodsMap.ContainsKey(temp))
                {
                    string origCluster = clusterString.Replace('_', ' ');
                    methodsMap.Add(temp, origCluster);

                }
                 */
                index = start - 1;
            }
            else
                return false;

            return true;
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: yuanzheng/logs-analysis
        public static bool checkCluster2(Dictionary<string, int> diffClusterMap, Dictionary<string, int> clusterMap, Dictionary<string, int> uniqueCluster, Dictionary<string, string> methodsMap, string[] methods, ref int index, StringBuilder result)
        {
            var cluster = new StringBuilder();
            cluster.Append(methods[index] + "_"); // add the first important id
            //string current = methods[index];

            //var allclusters = diffClusterMap.Keys; // get all current found keys
            // if current method is the last one then return
            if (index + 1 > methods.Length - 1)
                return false;

            string next = methods[index+1];
            if (!methodsMap.ContainsKey(next))
                return false;
            cluster.Append(methods[index+1] + "_"); // add the second important id

            //existedClusters(clusterMap, methods, index);

            int N = 1;
            int length = 2;  // record the number of ids in the cluster

            bool found = false;
            var size = methods.Length;
            int start;
            for ( start = index + length ; start < size; start++)
            {
                // length of rest part is less than cluster
                if (length > methods.Length - start)
                    break;

                var substring = new StringBuilder();
                int j;
                // find out next N numbers, see if they match cluster
                for (j = 0; j < length; j++)
                {
                    if (start + j == size) // over pipeline size
                        break;

                    substring.Append(methods[start + j] + "_");
                }

                if (cluster.Equals(substring))
                {
                    N++;
                    found = true;
                    start += length-1;
                }
                else
                {
                    if (found)
                    {
                        break;
                    }

                    // if next length long string doesn't match cluster, then cluster add the start number
                    if (methodsMap.ContainsKey(methods[start]))
                    {
                        cluster.Append(methods[start] + "_");
                        length++; // cluster size increase

                    }
                    else
                        break;
                }

            }

            if (N >= 1)
            {
                string clusterString = cluster.Remove(cluster.Length-1, 1).ToString();
                string temp = "[" + clusterString + "]x" + N;
                result.Append(temp + " "); // [12_3]x2 4 67   ???     " " ???
                //result.Append(substring.ToString());
                buildCluster(N, temp, diffClusterMap, clusterMap, uniqueCluster, methodsMap);
                index = start-1;
            }
            else
            {
                /*
                size = methods.Length - index;
                for (int i = 0; i < size; i++)
                {
                    if (methodsMap.ContainsKey(methods[index + i]))
                    {
                        if (checkCluster2(clusterMap, methodsMap, modifiedPipeLine, ref i, secondStep_result))
                            continue;
                    }

                    secondStep_result.Append(modifiedPipeLine[i] + " ");  // current method id is not important

                }
                 * */
            }

            return true;
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: Aegisub/SSATool
        private void cmdDoEffects_Click(object sender, System.EventArgs e)
        {
            double startTime = 0, endTime = 0;
            string syllableText = string.Empty, sFiltCode;
            int[,] times;
            System.Text.StringBuilder sb, thisFiltCode, conditionOne;
            MatchCollection mc;
            Condition c;
            List<Line> newList = new List<Line>();
            Line mainline, line;
            DialogueLine dl;
            Match m;
            Layer thislayer;
            Filter thisfilter;
            FilterOption thisoption;
            int layerNumLPSTot, totKaraNum, karaIndex, thisKaraLen, thisKaraStart;
            int filterIndex, optionIndex, thisKaraEnd, layerIndex, lineindex, lastindex;
            int textstart, textlen;
            bool conditionMet;
            labelSelLine.Text = string.Empty;

            for (lineindex = 0; lineindex != lineColl.Count; lineindex+=1) {
                mainline = lineColl[lineindex];

                if ((mainline.enabled == false) || (mainline.lineType != LineType.dialogue) || ((dl = (DialogueLine)mainline.line).style.enabled == false) || (r.IsMatch(((DialogueLine)mainline.line).text) == false)) {
                    newList.Add(mainline);
                    continue;
                }
                mc = r.Matches(dl.text);

                startTime = dl.start.TotalSeconds;
                endTime = dl.end.TotalSeconds;

                totKaraNum = mc.Count;
                times = new int[totKaraNum, 5];
                for (karaIndex = 0; karaIndex != mc.Count; karaIndex+=1) {
                    m = mc[karaIndex];
                    if (karaIndex != 0) {
                        times[karaIndex, 0] = times[karaIndex - 1, 2]; // end time of last syllable is start time of this syllable
                        times[karaIndex, 3] = times[karaIndex - 1, 3] + times[karaIndex - 1, 4];
                    }
                    times[karaIndex, 1] = int.Parse(m.Groups[2].Value, Util.nfi) * 10;
                    times[karaIndex, 2] = times[karaIndex, 0] + times[karaIndex, 1]; // end time of this syllable is start time + length
                    times[karaIndex, 4] = m.Groups[5].Value.Length;
                }

                for (layerIndex = 0; layerIndex != layerColl.Count; layerIndex+=1) {
                    thislayer = layerColl[layerIndex];
                    if (thislayer.Enabled == false) continue;

                    layerNumLPSTot = (thislayer.PerSyllable) ? totKaraNum : thislayer.Repetitions;

                    // The following loop is for layer-per-syllable
                    for (int layerIndexInside = 0; layerIndexInside != layerNumLPSTot; layerIndexInside+=1) {
                        line = (Line)mainline.Clone();
                        dl = (DialogueLine)line.line;

                        conditionMet = true;

                        for (int layercondIndex = 0; layercondIndex != thislayer.ConditionCount; layercondIndex+=1) {
                            c = thislayer.GetCondition(layercondIndex);
                            if (c.ConditionEnabled == false) continue;
                            conditionOne = new StringBuilder(32);
                            conditionOne.Append(String.Format("({0}){1}({2})", c.ConditionOne, c.ConditionOp, c.ConditionTwo));

                            if (conditionOne.ToString().Contains("%")) {
                                conditionOne = conditionOne.Replace("%karanumtot%", totKaraNum.ToString(Util.nfi));
                                conditionOne = conditionOne.Replace("%layernumtot%", layerColl.Count.ToString(Util.nfi));
                                conditionOne = conditionOne.Replace("%layernum%", layerIndex.ToString(Util.nfi));
                                conditionOne = conditionOne.Replace("%layernumlpstot%", layerNumLPSTot.ToString(Util.nfi));
                                conditionOne = conditionOne.Replace("%layernumlps%", layerIndexInside.ToString(Util.nfi));
                                conditionOne = conditionOne.Replace("%linenum%", layerIndex.ToString(Util.nfi));
                                conditionOne = conditionOne.Replace("%linelen%", (endTime - startTime).ToString(Util.nfi));
                                conditionOne = conditionOne.Replace("%linestart%", startTime.ToString(Util.nfi));
                                conditionOne = conditionOne.Replace("%lineend%", endTime.ToString(Util.nfi));
                                conditionOne = conditionOne.Replace("%style%", dl.style.name);
                                conditionOne = conditionOne.Replace("%name%", dl.actor);

                                if (conditionOne.ToString().IndexOf("%") != -1) { // see if the % is STILL there
                                    string c1 = conditionOne.ToString();
                                    string cnew = String.Empty;
                                    int lastindex1=0,krindex=0,krcindex=0;
                                    while(true) {
                                        krindex = Math.Min(c1.IndexOf("%karastart[", krcindex) + 10, Math.Min(c1.IndexOf("%karaend[", krcindex) + 8, c1.IndexOf("%karalength[", krcindex) + 11));
                                        if (krindex==-1 || krindex<krcindex) break;
                                        krcindex = c1.IndexOf("]", krindex);
                                        if (krcindex==-1) break;
                                        string r1 = c1.Substring(krindex, krcindex-krindex);
                                        cnew = cnew + c1.Substring(lastindex1, krindex - lastindex1) + Evaluate.ScriptParse(r1);
                                        lastindex1 = krcindex;
                                    }
                                    if (lastindex1 < c1.Length) cnew += c1.Substring(lastindex1, c1.Length - lastindex1);
                                    conditionOne = new StringBuilder(cnew);

                                    for (krindex = 0; krindex != totKaraNum; krindex+=1) {
                                        conditionOne = conditionOne.Replace("%karastart[" + krindex.ToString(Util.cfi) + "]%", times[krindex, 0].ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%karalength[" + krindex.ToString(Util.cfi) + "]%", times[krindex, 1].ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%karaend[" + krindex.ToString(Util.cfi) + "]%", times[krindex, 2].ToString(Util.nfi));
                                    }
                                }
                            }

                            conditionMet = Evaluate.Eval(Evaluate.ScriptParse(conditionOne.ToString())).Equals(true);

                            if (conditionMet == false) break;
                        }

                        if (conditionMet == false) {
                            if ((thislayer.AddAll == true) || ((thislayer.AddOnce == true) && (layerIndexInside == 1)))
                                newList.Add(line);
                            continue;
                        }

                        sb = new System.Text.StringBuilder(1024); // create a new stringbuilder

                        lastindex = 0;
                        for (karaIndex = 0; karaIndex != mc.Count; karaIndex+=1) {
                            m = mc[karaIndex];
                            if (m.Index > lastindex) sb.Append(dl.text.Substring(lastindex, m.Index - lastindex));
                            thisKaraStart = times[karaIndex, 0];
                            thisKaraLen = times[karaIndex, 1];
                            thisKaraEnd = times[karaIndex, 2];
                            textstart = times[karaIndex, 3];
                            textlen = times[karaIndex, 4];

                            for (filterIndex = 0; filterIndex != thislayer.Count; filterIndex+=1) {
                                thisfilter = thislayer.GetFilter(filterIndex);
                                if (thisfilter.Enabled == false) continue;

                                conditionMet = true;

                                //effect conditions
                                for (int effectcondIndex = 0; effectcondIndex != thisfilter.ConditionCount; effectcondIndex+=1) {
                                    c = thisfilter.GetCondition(effectcondIndex);
                                    if (c.ConditionEnabled == false) continue;
                                    conditionOne = new StringBuilder(32);

                                    conditionOne.Append(String.Format("({0}){1}({2})", c.ConditionOne, c.ConditionOp, c.ConditionTwo));

                                    if (conditionOne.ToString().Contains("%")) {
                                        conditionOne = conditionOne.Replace("%karalen%", thisKaraLen.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%karastart%", thisKaraStart.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%karamid%", (thisKaraStart + (thisKaraLen >> 1)).ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%karaend%", thisKaraEnd.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%karanum%", karaIndex.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%karanumtot%", totKaraNum.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%linenum%", lineindex.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%linelen%", (endTime - startTime).ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%linestart%", startTime.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%lineend%", endTime.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%layernumtot%", layerColl.Count.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%layernum%", layerIndex.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%layernumlpstot%", layerNumLPSTot.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%layernumlps%", layerIndexInside.ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%style%", dl.style.name);
                                        conditionOne = conditionOne.Replace("%name%", dl.actor);
                                        conditionOne = conditionOne.Replace("%lastkarastart%", (times[Math.Max(0, karaIndex - 2), 0]).ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%nextkaraend%", (times[Math.Min(totKaraNum - 1, karaIndex + 1), 0]).ToString(Util.nfi));
                                        conditionOne = conditionOne.Replace("%text%", String.IsNullOrEmpty(m.Groups[5].Value) ? string.Empty : m.Groups[5].Value);

                                        if (conditionOne.ToString().IndexOf("%") != -1) { // see if the % is STILL there
                                            string c1 = conditionOne.ToString();
                                            string cnew = String.Empty;
                                            int lastindex1 = 0, krindex = 0, krcindex = 0;
                                            while (true) {
                                                krindex = Math.Min(c1.IndexOf("%karastart[", krcindex) + 10, Math.Min(c1.IndexOf("%karaend[", krcindex) + 8, c1.IndexOf("%karalength[", krcindex) + 11));
                                                if (krindex == -1 || krindex < krcindex) break;
                                                krcindex = c1.IndexOf("]", krindex);
                                                if (krcindex == -1) break;
                                                string r1 = c1.Substring(krindex, krcindex - krindex);
                                                cnew = cnew + c1.Substring(lastindex1, krindex - lastindex1) + Evaluate.ScriptParse(r1);
                                                lastindex1 = krcindex;
                                            }
                                            if (lastindex1 < c1.Length) cnew += c1.Substring(lastindex1, c1.Length - lastindex1);
                                            conditionOne = new StringBuilder(cnew);

                                            for (krindex = 0; krindex != totKaraNum; krindex+=1) {
                                                conditionOne = conditionOne.Replace("%karastart[" + krindex.ToString(Util.cfi) + "]%", times[krindex, 0].ToString(Util.nfi));
                                                conditionOne = conditionOne.Replace("%karalength[" + krindex.ToString(Util.cfi) + "]%", times[krindex, 1].ToString(Util.nfi));
                                                conditionOne = conditionOne.Replace("%karaend[" + krindex.ToString(Util.cfi) + "]%", times[krindex, 2].ToString(Util.nfi));
                                            }
                                        }
                                    }

                                    conditionMet = Evaluate.Eval(Evaluate.ScriptParse(conditionOne.ToString())).Equals(true);
                                    if (conditionMet == false) break;
                                }

                                if (conditionMet == false) continue;

                                thisFiltCode = new StringBuilder(128);
                                thisFiltCode.Append(thisfilter.Template.Code);

                                if (thisFiltCode.Equals(String.Empty)) break;

                                for (optionIndex = 0; optionIndex != thisfilter.NumOptions; optionIndex+=1) {
                                    thisoption = thisfilter.GetOptionByIndex(optionIndex);
                                    thisFiltCode = thisFiltCode.Replace("$" + thisoption.Name + "$", thisoption.Value);
                                }
                                sFiltCode = thisFiltCode.ToString();
                                if (sFiltCode.Contains("%")) {
                                    //Variables
                                    if (sFiltCode.Contains("%pos%")) {
                                        thisFiltCode = thisFiltCode.Replace("%pos%", dl.GetRect(textstart, textlen).X.ToString(Util.nfi) + "," + dl.GetRect(textstart, textlen).Y.ToString(Util.nfi));
                                    }
                                    thisFiltCode = thisFiltCode.Replace("%karalen%", thisKaraLen.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%karastart%", thisKaraStart.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%karamid%", (thisKaraStart + (thisKaraLen >> 1)).ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%karaend%", thisKaraEnd.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%karanum%", karaIndex.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%karanumtot%", totKaraNum.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%linenum%", lineindex.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%linelen%", (endTime - startTime).ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%linestart%", startTime.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%lineend%", endTime.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%layernumtot%", layerColl.Count.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%layernum%", layerIndex.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%layernumlpstot%", layerNumLPSTot.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%layernumlps%", layerIndexInside.ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%style%", dl.style.name);
                                    thisFiltCode = thisFiltCode.Replace("%name%", dl.actor);
                                    thisFiltCode = thisFiltCode.Replace("%lastkarastart%", (times[Math.Max(0, karaIndex - 2), 0]).ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%nextkaraend%", (times[Math.Min(totKaraNum - 1, karaIndex + 1), 0]).ToString(Util.nfi));
                                    thisFiltCode = thisFiltCode.Replace("%text%", String.IsNullOrEmpty(m.Groups[5].Value) ? string.Empty : m.Groups[5].Value);

                                    if (sFiltCode.IndexOf("%") != -1) { // see if the % is STILL there
                                        string tfc1 = thisFiltCode.ToString();
                                        string tfcnew = String.Empty;
                                        int lastindex1 = 0, krindex = 0, krcindex = 0;
                                        while (true) {
                                            krindex = Math.Min(tfc1.IndexOf("%karastart[", krcindex) + 10, Math.Min(tfc1.IndexOf("%karaend[", krcindex) + 8, tfc1.IndexOf("%karalength[", krcindex) + 11));
                                            if (krindex == -1 || krindex < krcindex) break;
                                            krcindex = tfc1.IndexOf("]", krindex);
                                            if (krcindex == -1) break;
                                            string r1 = tfc1.Substring(krindex, krcindex - krindex);
                                            tfcnew = tfcnew + tfc1.Substring(lastindex1, krindex - lastindex1) + Evaluate.ScriptParse(r1);
                                            lastindex1 = krcindex;
                                        }
                                        if (lastindex1 < tfc1.Length) tfcnew += tfc1.Substring(lastindex1, tfc1.Length - lastindex1);
                                        thisFiltCode = new StringBuilder(tfcnew);

                                        for (krindex = 0; krindex != totKaraNum; krindex+=1) {
                                            thisFiltCode = thisFiltCode.Replace("%karastart[" + krindex.ToString(Util.nfi) + "]%", times[krindex, 0].ToString(Util.nfi));
                                            thisFiltCode = thisFiltCode.Replace("%karalength[" + krindex.ToString(Util.nfi) + "]%", times[krindex, 1].ToString(Util.nfi));
                                            thisFiltCode = thisFiltCode.Replace("%karaend[" + krindex.ToString(Util.nfi) + "]%", times[krindex, 2].ToString(Util.nfi));
                                        }
                                    }
                                }

                                sb.Append(Evaluate.ScriptParse(thisFiltCode.ToString()));
                            } // filterIndex

                            if (thislayer.AddK)
                                sb.Append(m.Groups[1].Value + m.Groups[2].Value);
                            if (thislayer.AddASSA)
                                sb.Append(m.Groups[3].Value);
                            if (thislayer.AddBracket)
                                sb.Append(m.Groups[4].Value);
                            if (thislayer.AddText && m.Groups.Count == 6)
                                sb.Append(m.Groups[5].Value);

                            if (thislayer.SyllablePerLine) {
                                //dl.start = dl.start.Add(TimeSpan.FromMilliseconds(thisKaraStart));
                                //dl.end = dl.start.Add(TimeSpan.FromMilliseconds(thisKaraLen));
                                dl.text = sb.ToString();
                                newList.Add(line);
                                line = (Line)mainline.Clone();
                                dl = (DialogueLine)line.line;
                                sb = new StringBuilder(768);
                            }

                            lastindex = m.Index + m.Length;
                        } // karaIndex
                        if (!thislayer.SyllablePerLine) {
                            if (dl.text.Length > lastindex) sb.Append(dl.text.Substring(lastindex, dl.text.Length - lastindex));
                            dl.text = sb.ToString();
                            newList.Add(line);
                        }
                    } // layerIndexInside
                } // layerIndex
            } // lineindex
            SetLineColl(newList);
            ExtractStyles();
        }
コード例 #16
0
ファイル: UnitTest.cs プロジェクト: whesius/allors
        public void AllorsLargeString()
        {
            foreach (var init in this.Inits)
            {
                init();
                foreach (var mark in this.Markers)
                {
                    var aLarge = new StringBuilder().Insert(0, "a", 100000).ToString();
                    var bLarge = new StringBuilder().Insert(0, "b", 100000).ToString();
                    var cLarge = new StringBuilder().Insert(0, "c", 100000).ToString();

                    {
                        var values = C1.Create(this.Session);
                        values.C1StringLarge = aLarge;
                        values.I1StringLarge = bLarge;
                        values.S1StringLarge = cLarge;

                        mark();
                        Assert.IsTrue(values.ExistC1StringLarge);
                        Assert.IsTrue(values.ExistI1StringLarge);
                        Assert.IsTrue(values.ExistS1StringLarge);

                        Assert.IsTrue(aLarge.Equals(values.C1StringLarge));
                        Assert.IsTrue(bLarge.Equals(values.I1StringLarge));
                        Assert.IsTrue(cLarge.Equals(values.S1StringLarge));
                    }

                    {
                        // initial empty
                        var values = C1.Create(this.Session);

                        mark();
                        Assert.IsFalse(values.ExistC1StringLarge);
                        Assert.IsFalse(values.ExistI1StringLarge);
                        Assert.IsFalse(values.ExistS1StringLarge);

                        Assert.IsTrue(values.C1StringLarge == null);
                        Assert.IsTrue(values.I1StringLarge == null);
                        Assert.IsTrue(values.S1StringLarge == null);
                    }

                    {
                        // reset empty
                        var values = C1.Create(this.Session);
                        values.C1StringLarge = aLarge;
                        values.I1StringLarge = bLarge;
                        values.S1StringLarge = cLarge;

                        mark();
                        Assert.IsTrue(values.ExistC1StringLarge);
                        Assert.IsTrue(values.ExistI1StringLarge);
                        Assert.IsTrue(values.ExistS1StringLarge);

                        values.RemoveC1StringLarge();
                        values.RemoveI1StringLarge();
                        values.RemoveS1StringLarge();

                        mark();
                        Assert.IsFalse(values.ExistC1StringLarge);
                        Assert.IsFalse(values.ExistI1StringLarge);
                        Assert.IsFalse(values.ExistS1StringLarge);

                        Assert.IsTrue(values.C1StringLarge == null);
                        Assert.IsTrue(values.I1StringLarge == null);
                        Assert.IsTrue(values.S1StringLarge == null);
                    }

                    {
                        // reset null
                        var values = C1.Create(this.Session);
                        values.C1StringLarge = aLarge;
                        values.I1StringLarge = bLarge;
                        values.S1StringLarge = cLarge;

                        mark();
                        Assert.IsTrue(values.ExistC1StringLarge);
                        Assert.IsTrue(values.ExistI1StringLarge);
                        Assert.IsTrue(values.ExistS1StringLarge);

                        values.C1StringLarge = null;
                        values.I1StringLarge = null;
                        values.S1StringLarge = null;

                        mark();
                        Assert.IsFalse(values.ExistC1StringLarge);
                        Assert.IsFalse(values.ExistI1StringLarge);
                        Assert.IsFalse(values.ExistS1StringLarge);

                        Assert.IsTrue(values.C1StringLarge == null);
                        Assert.IsTrue(values.I1StringLarge == null);
                        Assert.IsTrue(values.S1StringLarge == null);
                    }

                    {
                        // large string in small string
                        var exceptionThrown = false;
                        var values = C1.Create(this.Session);
                        try
                        {
                            mark();
                            values.C1AllorsString = aLarge;
                        }
                        catch (ArgumentException)
                        {
                            exceptionThrown = true;
                        }

                        Assert.IsTrue(exceptionThrown);
                        Assert.IsFalse(values.ExistC1AllorsString);

                        exceptionThrown = false;
                        values = C1.Create(this.Session);
                        try
                        {
                            mark();
                            values.I1AllorsString = aLarge;
                        }
                        catch (ArgumentException)
                        {
                            exceptionThrown = true;
                        }

                        Assert.IsTrue(exceptionThrown);
                        Assert.IsFalse(values.ExistI1AllorsString);

                        exceptionThrown = false;
                        values = C1.Create(this.Session);
                        try
                        {
                            mark();
                            values.S1AllorsString = aLarge;
                        }
                        catch (ArgumentException)
                        {
                            exceptionThrown = true;
                        }

                        Assert.IsTrue(exceptionThrown);
                        Assert.IsFalse(values.ExistS1AllorsString);

                        this.Session.Commit();
                    }
                }
            }
        }
コード例 #17
0
ファイル: Wowhead.cs プロジェクト: LucasPeacecraft/rawr
 private static string getWowheadWeightFilter(Character character)
 {
     StringBuilder wt = new StringBuilder("wt=");
     StringBuilder wtv = new StringBuilder(";wtv=");
     if (character.CurrentModel == "Enhance") // force weapon dps ep value 6 to fix caster weapon display issue
     {
         wt.Append("134:");
         wtv.Append("6:");
     }
     ComparisonCalculationBase[] statValues = CalculationsBase.GetRelativeStatValues(character);
     Array.Sort(statValues, StatValueSorter);
     foreach (ComparisonCalculationBase ccb in statValues)
     {
         string stat = getWowHeadStatID(ccb.Name);
         if (!stat.Equals(string.Empty))
         {
             wt.Append(stat);
             wtv.Append(ccb.OverallPoints.ToString("F2", System.Globalization.CultureInfo.InvariantCulture));
             wt.Append(":");
             wtv.Append(":");
         }
     }
     if (wt.Equals("wt="))
         return string.Empty;
     else
         return wt.ToString().Substring(0, wt.Length - 1) + wtv.ToString().Substring(0, wtv.Length - 1);
 }