コード例 #1
0
 private static void AssertExpectedDecodedArea(TestData testData, CodeArea decoded)
 {
     Assert.AreEqual(testData.Length, decoded.CodeLength, $"Wrong length for code {testData.Code}");
     Assert.AreEqual(testData.LatLo, decoded.SouthLatitude, Precision, $"Wrong low latitude for code {testData.Code}");
     Assert.AreEqual(testData.LatHi, decoded.NorthLatitude, Precision, $"Wrong high latitude for code {testData.Code}");
     Assert.AreEqual(testData.LngLo, decoded.WestLongitude, Precision, $"Wrong low longitude for code {testData.Code}");
     Assert.AreEqual(testData.LngHi, decoded.EastLongitude, Precision, $"Wrong high longitude for code {testData.Code}");
 }
コード例 #2
0
 public static void W(object msg, string add, CodeArea ca = CodeArea.None)
 {
     if (!IsCodeAreaDebugEnabled(ca))
     {
         return;
     }
     Debug.WriteLine(msg, add);
 }
コード例 #3
0
 public static void W(string msg, object arg, CodeArea ca = CodeArea.None)
 {
     if (!IsCodeAreaDebugEnabled(ca))
     {
         return;
     }
     Debug.WriteLine(msg, arg);
 }
コード例 #4
0
 private static bool IsCodeAreaDebugEnabled(CodeArea ca)
 {
     /*if (!schulman.SchulMan.LoggingEnabled) return false;
      * switch (ca)
      * {
      *  case CodeArea.LoadLessons:
      *      if (schulman.SchulMan.LogLessonLoading) return true;
      *      else return false;
      *  case CodeArea.Splash:
      *      return true;
      *  default:
      *      return true;
      * }*/
     return(true);
 }
コード例 #5
0
 public Task <IResult> Create(CodeArea Model)
 {
     this._result.Success = false;
     try
     {
         this._result.Message = "正在執行 insert CodeArea ";
         this._repository.Create(Model);
         this._unitOfWork.SaveChange();
         this._result.Success = true;
     }
     catch (Exception e)
     {
         this._result.Exception = e;
     }
     return(Task.FromResult(this._result));
 }
コード例 #6
0
ファイル: CodeArea.cs プロジェクト: samiudheen/mono-soc-2007
    public override string GetDesignTimeHTML()
    {
        try {
            int CTRLHeight = 10;
            int CTRLWidth  = 10;

            try {
                CodeArea PanelCtrl = (CodeArea)this.Component;
                CTRLHeight = (int)PanelCtrl.Height.Value;
                CTRLWidth  = (int)PanelCtrl.Width.Value;
                return("<textarea style='height:" + CTRLHeight + ";width:" + CTRLWidth + ";border:1px #ccc;'>" + PanelCtrl.Text + "</textarea>");
            }
            catch {
            }
            return("<textarea style='height:" + CTRLHeight + ";width:" + CTRLWidth + ";border:1px #ccc;'> No width and height defined</textarea>");
        }
        catch (Exception ex) {
            return("<div style='height:200px;width:200px;'> Error loading control!! </div>");
        }
    }
コード例 #7
0
        private async Task <IResult> SaveData(string strLocationID, DateTime dtTime)
        {
            this._IResult.Success = false;
            var CheckData = await this._IWeatherMainRepository.GetQuery(dtTime, strLocationID);

            if (CheckData == null)
            {
                string strUrl         = this._Configuration.GetSection("WeatherAPI").Value;
                var    csCodeArea     = this._ICodeAreaRepository.GetAll();
                var    csCodeLocation = this._ICodeLocationRepository.GetAll();
                string strHiours      = DateTime.Now.Hour >= 12 ? "12" : "06";
                var    Result         = await this._IApiManagers.Get <Weather>(string.Format(strUrl, strLocationID, dtTime.ToString("yyyy-MM-dd"), strHiours));

                if (Result != null)
                {
                    WeatherMain csWeatherMain = new WeatherMain();
                    csWeatherMain.ApiId = strLocationID;
                    var Locations = Result.records.locations;

                    #region 資料整理
                    foreach (var item in Locations)
                    {
                        #region 未建立CODELocation表資料
                        if (!(await csCodeLocation).Any(x => x.Id == item.dataid))
                        {
                            CodeLocation CodeLocation = new CodeLocation()
                            {
                                Id   = item.dataid,
                                Name = item.locationsName
                            };
                            var LocationResult = await this._ICodeLocationRepository.Create(CodeLocation);

                            if (!LocationResult.Success)
                            {
                                this._IResult.Success = false;
                                this._IResult.Message = LocationResult.Message + LocationResult.Exception.Message + LocationResult.Exception.StackTrace;
                                break;
                            }
                        }
                        #endregion

                        foreach (var Location in item.location)
                        {
                            #region 未建立CODEArea表資料
                            if (!(await csCodeArea).Any(x => x.Id == Location.geocode))
                            {
                                CodeArea CodeArea = new CodeArea()
                                {
                                    Id           = Location.geocode,
                                    CodeLocation = item.dataid,
                                    Name         = Location.locationName
                                };
                                var AreaResult = await this._ICodeAreaRepository.Create(CodeArea);

                                if (!AreaResult.Success)
                                {
                                    this._IResult.Success = false;
                                    this._IResult.Message = AreaResult.Message + AreaResult.Exception.Message + AreaResult.Exception.StackTrace;
                                    break;
                                }
                            }
                            #endregion

                            csWeatherMain.LocationId = item.dataid;
                            csWeatherMain.Date       = dtTime;
                            csWeatherMain.Ctime      = DateTime.Now;
                            WeatherDetail csWeatherDetail = new WeatherDetail();
                            foreach (var Weather in Location.weatherElement)
                            {
                                csWeatherDetail.AreaId = Location.geocode;
                                var ElementName = (WEATHER)Enum.Parse(typeof(WEATHER), Weather.elementName, true);
                                var ValueModel  = Weather.time.FirstOrDefault();

                                #region 天氣各節點資料
                                switch (ElementName)
                                {
                                case WEATHER.PoP12h:
                                    csWeatherDetail.StartTime = "0600";
                                    csWeatherDetail.EndTime   = "1200";
                                    if (ValueModel != null)
                                    {
                                        DateTime dtStartTime = Convert.ToDateTime(ValueModel.startTime);
                                        csWeatherDetail.RainRatio = Convert.ToDecimal(ValueModel.elementValue.FirstOrDefault().value);
                                    }
                                    else
                                    {
                                        csWeatherDetail.RainRatio = 0;
                                    }
                                    break;

                                case WEATHER.Wx:
                                    if (ValueModel != null)
                                    {
                                        csWeatherDetail.States = ValueModel.elementValue.FirstOrDefault().value;
                                    }
                                    else
                                    {
                                        csWeatherDetail.States = "N/A";
                                    }
                                    break;

                                case WEATHER.AT:
                                    if (ValueModel != null)
                                    {
                                        csWeatherDetail.BodyTemperature = Convert.ToDecimal(ValueModel.elementValue.FirstOrDefault().value);
                                    }
                                    else
                                    {
                                        csWeatherDetail.BodyTemperature = 0;
                                    }
                                    break;

                                case WEATHER.T:
                                    if (ValueModel != null)
                                    {
                                        csWeatherDetail.Temperature = Convert.ToDecimal(ValueModel.elementValue.FirstOrDefault().value);
                                    }
                                    else
                                    {
                                        csWeatherDetail.Temperature = 0;
                                    }
                                    break;

                                case WEATHER.RH:
                                    if (ValueModel != null)
                                    {
                                        csWeatherDetail.Humidity = Convert.ToDecimal(ValueModel.elementValue.FirstOrDefault().value);
                                    }
                                    else
                                    {
                                        csWeatherDetail.Humidity = 0;
                                    }
                                    break;

                                case WEATHER.CI:
                                    if (ValueModel != null)
                                    {
                                        csWeatherDetail.ComfortIndex = Convert.ToDecimal(ValueModel.elementValue[0].value);
                                        csWeatherDetail.Comfort      = ValueModel.elementValue[1].value;
                                    }
                                    else
                                    {
                                        csWeatherDetail.ComfortIndex = 0;
                                        csWeatherDetail.Comfort      = "N/A";
                                    }
                                    break;

                                case WEATHER.WeatherDescription:
                                    if (ValueModel != null)
                                    {
                                        csWeatherDetail.Detail = ValueModel.elementValue.FirstOrDefault().value;
                                    }
                                    else
                                    {
                                        csWeatherDetail.Detail = "N/A";
                                    }
                                    break;

                                case WEATHER.WS:
                                    if (ValueModel != null)
                                    {
                                        csWeatherDetail.WindSpeed = Convert.ToDecimal(ValueModel.elementValue.FirstOrDefault().value);
                                    }
                                    else
                                    {
                                        csWeatherDetail.WindSpeed = 0;
                                    }
                                    break;

                                case WEATHER.WD:
                                    if (ValueModel != null)
                                    {
                                        csWeatherDetail.WindDirection = ValueModel.elementValue.FirstOrDefault().value;
                                    }
                                    else
                                    {
                                        csWeatherDetail.WindDirection = "N/A";
                                    }
                                    break;

                                case WEATHER.Td:
                                    if (ValueModel != null)
                                    {
                                        csWeatherDetail.DewPoint = Convert.ToDecimal(ValueModel.elementValue.FirstOrDefault().value);
                                    }
                                    else
                                    {
                                        csWeatherDetail.DewPoint = 0;
                                    }
                                    break;
                                }
                                #endregion
                            }
                            csWeatherMain.WeatherDetails.Add(csWeatherDetail);
                        }
                    }
                    #endregion

                    var DBResult = await this._IWeatherMainRepository.Create(csWeatherMain);

                    this._IResult.Success   = DBResult.Success;
                    this._IResult.Exception = DBResult.Exception;
                    this._IResult.Message   = DBResult.Message;
                }
            }
            else
            {
                this._IResult.Success = false;
                this._IResult.Message = "已有該天資料";
            }
            return(this._IResult);
        }
コード例 #8
0
ファイル: ccscompiler.cs プロジェクト: lovewitty/cs-script
        bool IsClasslessCode(string rawCode)
        {
            if (ProcessIfMarkedAsClassless(rawCode))
            {
                return(true);
            }

            //ensure "one statement - one line" rule
            string code = new CSharpParser(rawCode).PureCode.Replace("\n", " ").Replace("\r", " ").Replace(";", ";\n");

            string       line;
            StringReader sr = new StringReader(code);

            CodeArea area = CodeArea.unknown;

            while ((line = sr.ReadLine()) != null)
            {
                string clearLine = line.Trim();

                if (clearLine.Length == 0)
                {
                    continue;
                }
                while (true)
                {
                    switch (area)
                    {
                    case CodeArea.unknown:
                    {
                        if (IsUsingDirective(clearLine))
                        {
                            area = CodeArea.header;
                            continue;
                        }
                        else if (!IsDeclaration(clearLine))
                        {
                            area = CodeArea.body;
                            continue;
                        }
                        else
                        {
                            area = CodeArea.footer;
                            continue;
                        }
                    }

                    case CodeArea.header:
                    {
                        if (IsUsingDirective(clearLine))
                        {
                            header.Append(line);
                            header.Append(Environment.NewLine);
                        }
                        else
                        {
                            area = CodeArea.body;
                            continue;
                        }
                        break;
                    }

                    case CodeArea.body:
                    {
                        if (!IsDeclaration(clearLine))
                        {
                            body.Append(line);
                            body.Append(Environment.NewLine);
                        }
                        else
                        {
                            area = CodeArea.footer;
                            continue;
                        }
                        break;
                    }

                    case CodeArea.footer:
                    {
                        footer.Append(line);
                        footer.Append(Environment.NewLine);
                        break;
                    }
                    }
                    break;
                }
            }
            if (body.Length != 0)
            {
                return(true);
            }
            else
            {
                if (footer.Length == 0)
                {
                    return(false);
                }
                else
                {
                    //it is either C# or CC# without body
                    string fotterStr = footer.ToString().TrimStart();
                    if (fotterStr.StartsWith("namespace") && IsToken(fotterStr, 0, "namespace".Length))
                    {
                        return(false);
                    }
                    else
                    {
                        foreach (string classToken in new string[] { "class", "enum", "struct" })
                        {
                            int classStart = -1;
                            while ((classStart = fotterStr.IndexOf(classToken, classStart + 1)) != -1)
                            {
                                if (IsToken(fotterStr, classStart, classToken.Length))
                                {
                                    string decorations = fotterStr.Substring(0, classStart);
                                    if (decorations.IndexOfAny(";{}()".ToCharArray()) != -1)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Auto-generate some places to be used as gameplay elements in otherwise sparse areas. Given an 8 digit PlusCode, creates and warps some standard shapes in the Cell.
        /// </summary>
        /// <param name="plusCode">The area to generate shape(s) in</param>
        /// <param name="autoSave">If true, saves the areas to the database immediately.</param>
        /// <returns>The list of places created for the given area.</returns>
        public static List <DbTables.Place> CreateInterestingPlaces(string plusCode, bool autoSave = true)
        {
            //expected to receive a Cell8
            // populate it with some interesting regions for players.
            Random   r          = new Random();
            CodeArea cell8      = OpenLocationCode.DecodeValid(plusCode); //Reminder: area is .0025 degrees on a Cell8
            int      shapeCount = 1;                                      // 2; //number of shapes to apply to the Cell8
            double   shapeWarp  = .3;                                     //percentage a shape is allowed to have each vertexs drift by.
            List <DbTables.Place> areasToAdd = new List <DbTables.Place>();

            for (int i = 0; i < shapeCount; i++)
            {
                //Pick a shape
                var masterShape     = possibleShapes.OrderBy(s => r.Next()).First();
                var shapeToAdd      = masterShape.Select(s => new Coordinate(s)).ToList();
                var scaleFactor     = r.Next(10, 36) * .01; //Math.Clamp(r.Next, .1, .35); //Ensure that we get a value that isn't terribly useless. 2 shapes can still cover 70%+ of an empty area this way.
                var positionFactorX = r.NextDouble() * resolutionCell8;
                var positionFactorY = r.NextDouble() * resolutionCell8;
                foreach (Coordinate c in shapeToAdd)
                {
                    //scale it to our resolution
                    c.X *= resolutionCell8;
                    c.Y *= resolutionCell8;

                    //multiply this by some factor smaller than 1, so it doesn't take up the entire Cell
                    //If we use NextDouble() here, it scales each coordinate randomly, which would look very unpredictable. Use the results of one call twice to scale proportionally.
                    //but ponder how good/bad it looks for various shapes if each coordinate is scaled differently.
                    c.X *= scaleFactor;
                    c.Y *= scaleFactor;

                    //Rotate the coordinate set some random number of degrees?
                    //TODO: how to rotate these?

                    //Place the shape somewhere randomly by adding the same X/Y value less than the resolution to each point
                    c.X += positionFactorX;
                    c.Y += positionFactorY;

                    //Fuzz each vertex by adding some random distance on each axis less than 30% of the cell's size in either direction.
                    //10% makes the shapes much more recognizable, but not as interesting. Will continue looking into parameters here to help adjust that.
                    c.X += (r.NextDouble() * resolutionCell8 * shapeWarp) * (r.Next() % 2 == 0 ? 1 : -1);
                    c.Y += (r.NextDouble() * resolutionCell8 * shapeWarp) * (r.Next() % 2 == 0 ? 1 : -1);

                    //Let us know if this shape overlaps a neighboring cell. We probably want to make sure we re-draw map tiles if it does.
                    if (c.X > .0025 || c.Y > .0025)
                    {
                        Log.WriteLog("Coordinate for shape " + i + " in Cell8 " + plusCode + " will be out of bounds: " + c.X + " " + c.Y, Log.VerbosityLevels.High);
                    }

                    //And now add the minimum values for the given Cell8 to finish up coordinates.
                    c.X += cell8.Min.Longitude;
                    c.Y += cell8.Min.Latitude;
                }

                //ShapeToAdd now has a randomized layout, convert it to a polygon.
                shapeToAdd.Add(shapeToAdd.First()); //make it a closed shape
                var polygon = factory.CreatePolygon(shapeToAdd.ToArray());
                polygon = CCWCheck(polygon);        //Sometimes squares still aren't CCW? or this gets un-done somewhere later?
                if (!polygon.IsValid || !polygon.Shell.IsCCW)
                {
                    Log.WriteLog("Invalid geometry generated, retrying", Log.VerbosityLevels.High);
                    i--;
                    continue;
                }

                if (!polygon.CoveredBy(Converters.GeoAreaToPolygon(cell8)))
                {
                    //This should only ever require checking the map tile north/east of the current one, even though the vertex fuzzing can potentially move things negative slightly.
                    Log.WriteLog("This polygon is outside of the Cell8 by " + (cell8.Max.Latitude - shapeToAdd.Max(s => s.Y)) + "/" + (cell8.Max.Longitude - shapeToAdd.Max(s => s.X)), Log.VerbosityLevels.High);
                }
                if (polygon != null)
                {
                    DbTables.Place gmd = new DbTables.Place();
                    gmd.ElementGeometry = polygon;
                    gmd.GameElementName = "generated";
                    gmd.Tags.Add(new PlaceTags()
                    {
                        Key = "praxisGenerated", Value = "true"
                    });
                    areasToAdd.Add(gmd); //this is the line that makes some objects occasionally not be CCW that were CCW before. Maybe its the cast to the generic Geometry item?
                }
                else
                {
                    //Inform me that I did something wrong.
                    Log.WriteLog("failed to convert a randomized shape to a polygon.", Log.VerbosityLevels.Errors);
                    continue;
                }
            }

            //Making this function self-contained
            if (autoSave)
            {
                var db = new PraxisContext();
                foreach (var area in areasToAdd)
                {
                    area.ElementGeometry = CCWCheck((Polygon)area.ElementGeometry); //fixes errors that reappeared above
                }
                db.Places.AddRange(areasToAdd);
                db.SaveChanges();
            }

            return(areasToAdd);
        }