Example #1
0
    public TempType GetNiche(List <GameObject> objects)
    {
        int type_count = System.Enum.GetValues(typeof(TempType)).Length;

        int[] counts = new int[type_count];

        //Type毎の数をカウント
        foreach (var target in objects)
        {
            var type = TempType.Akiyama; //Todo:先生オブジェクトからTypeを抽出する
            counts[(int)type]++;
        }

        //ニッチ(一番数が少ないType)を探す
        TempType nicheType  = TempType.Akiyama;
        var      nicheCount = counts[0];

        for (int i = 1; i < type_count; i++)
        {
            if (counts[i] >= nicheCount)
            {
                continue;
            }
            nicheCount = counts[i];
            nicheType  = (TempType)System.Enum.ToObject(typeof(TempType), i);
        }

        return(nicheType);
    }
        public string Get(string id, string temp, string wind)
        {
            new ApplicationAction("Starting Weather Api Calls", "user", "WeatherTest for " + id).Save();

            new ApplicationAction("Using AutoFac", "user", "DI using a Framework").Save();

            //Dependency Injection with framework Autofac
            var builder = new ContainerBuilder();

            builder.RegisterType <ProcessApi>().As <IProcessApi>();
            builder.RegisterType <Config>().As <IConfig>();
            IContainer Container = builder.Build();


            TempType UserSelectTemp = (TempType)Enum.Parse(typeof(TempType), temp.ToUpper());
            WindType UserSelectWind = (WindType)Enum.Parse(typeof(WindType), wind.ToUpper());


            //List of Apis to call all based on the Strategy pattern
            var WeatherApis = new List <IWeatherStrategy>();

            // add new API which would have been created - TODO make this a dynaimc process so this file does not need to be edited
            WeatherApis.Add(new WeatherDataCollectorBbc());
            WeatherApis.Add(new WeatherDataCollectorAccu());

            new ApplicationAction("Added Apis", "user", "Two Apis").Save();

            //List to hold API call data
            var LocationDataSets = new List <string>();

            using (var scope = Container.BeginLifetimeScope())
            {
                foreach (IWeatherStrategy api in WeatherApis)
                {
                    // call each of the APIs and store the result
                    LocationDataSets.Add(api.gatherData(id, scope.Resolve <IProcessApi>(), scope.Resolve <IConfig>()));
                }
            }

            new ApplicationAction("Creating objects", "user", "Using factory pattern").Save();

            ITemperatureFactory tempFactory  = new TemperatureFactory();
            ITemperature        selectedTemp = tempFactory.CreateTemperature(UserSelectTemp);

            IWindFactory windFactory  = new WindFactory();
            IWind        selectedWind = windFactory.CreateWind(UserSelectWind);

            new ApplicationAction("Calcuating results", "user", "Aggregated result data").Save();

            //call the aggregator to work out the results
            var calculatedLocationWeather = new Aggregator(selectedTemp, selectedWind).AggregateData(LocationDataSets);

            calculatedLocationWeather.Location = id;

            new ApplicationAction("Completed prcoessing", "user", "TReturn data to client").Save();
            //return to client final result
            return(JsonConvert.SerializeObject(calculatedLocationWeather));
        }
Example #3
0
        public static double ConvertTemp(double temp, TempType type)
        {
            if (type == TempType.Celsius)
            {
                return(temp = 13 + temp * 0.7);
            }

            return(0.0);
        }
Example #4
0
 public ITemperature CreateTemperature(TempType type)
 {
     if (type == TempType.CEL)
     {
         return(new TemperatureCelsius());
     }
     else
     {
         return(new TemperatureFahrenheit());
     }
 }
Example #5
0
 public string ConvertTemp(double degree, TempType temptype)
 {
     Type = temptype;
     switch (temptype)
     {
         case TempType.Celsius:
             return (degree*9/5 + 32).ToString(CultureInfo.InvariantCulture) + " " + "Fahrenheit";
         case TempType.Fahrenheit:
             return ((degree - 32)/9*5).ToString(CultureInfo.InvariantCulture) + " " + "Celsius";
     }
     return "Unknown Type";
 }
Example #6
0
        public int GetTemp(TempType type)
        {
            if (type == TempType.MIN)
            {
                return(Convert.ToInt32(txtMinTemp.Text));
            }
            else if (type == TempType.MAX)
            {
                return(Convert.ToInt32(txtMaxTemp.Text));
            }

            return(0);
        }
        public string ConvertTemp(double degree, TempType temptype)
        {
            Type = temptype;
            switch (temptype)
            {
            case TempType.Celsius:
                return((degree * 9 / 5 + 32).ToString(CultureInfo.InvariantCulture) + " " + "Fahrenheit");

            case TempType.Fahrenheit:
                return(((degree - 32) / 9 * 5).ToString(CultureInfo.InvariantCulture) + " " + "Celsius");
            }
            return("Unknown Type");
        }
Example #8
0
 public string ConvertTemp(double degree, TempType temptype)
 {
     this.Type = temptype;
     if (temptype == TempType.Celsius)
     {
         return((degree * 9 / 5 + 32).ToString() + " " + "Fahrenheit");
     }
     if (temptype == TempType.Fahrenheit)
     {
         return(((degree - 32) / 9 * 5).ToString() + " " + "Celsius");
     }
     return("Unknown Type");
 }
 /// <summary>
 /// Gets the media type for the body
 /// </summary>
 /// <param name="Header">The header of the message</param>
 /// <returns>An enum value indicating the media type of the boundary</returns>
 private MediaEnum GetMediaType(MIMEHeader Header)
 {
     string ContentType = GetContentType(Header);
     int x = 0;
     foreach (string TempType in MIMEType.TypeTable)
     {
         if (TempType.Equals(ContentType, StringComparison.InvariantCultureIgnoreCase))
         {
             return (MediaEnum)x;
         }
         ++x;
     }
     return (MediaEnum)MIMEType.TypeTable.Length - 1;
 }
Example #10
0
        private Tuple <string, string> GetPath()
        {
            if (TempName.IsNullOrEmpty() || TempType.IsNullOrEmpty())
            {
                return(null);
            }
            var tuple = GetPath(SiteName, TempName, TempType);

            if (tuple.IsNull())
            {
                return(null);
            }
            return(tuple);
        }
Example #11
0
    public static string ReturnTemparatureFormatted(double value, TempType type)
    {
        string returnValue = "";

        switch (type)
        {
        case TempType.Celcius:
            returnValue = String.Format("{0:0.#}", value - 273.15d) + "°C";
            break;

        case TempType.Fahrenheit:
            returnValue = String.Format("{0:0.#}", (value - 273.15d) * 9d / 5d + 32d) + "°F";
            break;

        case TempType.Kelvin:
            returnValue = String.Format("{0:0.#}", value) + "°K";
            break;
        }
        return(returnValue);
    }
Example #12
0
        public ActionResult Edit(int?id)
        {
            try
            {
                ViewBag.TypeId = new SelectList(TempType.GetList(), "Id", "Description");
                TempModel model = Startup.ModelList.FirstOrDefault(m => m.Id == id);
                if (model == null)
                {
                    string id_string = id == null ? "null" : id.ToString();
                    ViewBag.ErrorMessage = $"Cannot find item with Id {id_string}";
                    return(View("Error"));
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                ViewBag.ErrorMessage = ex.Message;
                return(View("Error"));
            }
        }
Example #13
0
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public string GetIndex(TempType type)
        {
            SysSetting setting = BasePage.SystemSetting;
            string Content = "";
            Content = GetTempateString(1, type);

            //替换三层公共模版变量
            Content = ReplacePublicTemplate(Content);
            Content = ReplacePublicTemplate(Content);
            Content = ReplacePublicTemplate(Content);

            Content = ReplaceSystemSetting(Content);
            Content = ReplaceTagContent(Content);

            return Content;
        }
Example #14
0
 /// <summary>
 /// 根据命令名返回命令
 /// </summary>
 /// <param name="OrderName">命令名</param>
 /// <returns>所查询的命令,如果命令名不存在返回null</returns>
 public static POrder GetOrder(string OrderName)
 {
     foreach (Type SubType in typeof(POrder).Assembly.GetTypes().Where((Type TempType) => TempType.IsSubclassOf(typeof(POrder))))
     {
         try {
             POrder OrderInstance = (POrder)Activator.CreateInstance(SubType);
             if (OrderInstance.Name.Equals(OrderName))
             {
                 return(OrderInstance);
             }
         } catch {
             continue;
         }
     }
     return(null);
 }
 public TemperatureScale(TempType type)
 {
     _type = type;
 }
Example #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtCode.Text))
                {
                    MessageBox.Show("请输入代码");
                    return;
                }
                HA_MethodDAL dal = new HA_MethodDAL();
                TempType     tt  = TempType.Query;

                switch (comboTemplate.Text)
                {
                case "查询":
                    tt = TempType.Query;
                    break;

                case "增删改":
                    tt = TempType.CDUA;
                    break;

                case "存储过程":
                    tt = TempType.SP;
                    break;

                default:
                    break;
                }
                if (cobj == null)
                {
                    int ret = dal.AddNew(new HA_Method
                    {
                        intf_code      = intfcode,
                        m_code         = txtCode.Text,
                        m_desc         = txtDesc.Text,
                        m_reqtype      = txtReqType.Text,
                        m_template     = (int)tt,
                        m_rtnvaluecode = "ret" + txtCode.Text,
                        m_arggrpcode   = comboAGGCode.Text,
                        m_isencrypted  = false,
                        m_funcode      = txtFunCode.Text,
                        m_name         = txtName.Text,
                        m_version      = "",
                        m_pagesize     = Convert.ToInt32(txtPageSize.Text)
                    });

                    if (ret < 0)
                    {
                        MessageBox.Show("保存失败 : " + ret);
                    }
                    HA_RetValObjectDAL voDAL   = new HA_RetValObjectDAL();
                    string             exttype = "";
                    switch (tt)
                    {
                    case TempType.Query:
                        exttype = "BaseObj";
                        break;

                    case TempType.CDUA:
                        exttype = "BaseObj";
                        break;

                    case TempType.SP:
                        exttype = "BaseObj";
                        break;

                    default:
                        break;
                    }

                    ret = voDAL.AddNew(new HA_RetValObject
                    {
                        rv_name    = "ret" + txtCode.Text,
                        rv_exttype = exttype,
                        rv_note    = "Orignal",
                        rv_JSON    = ""
                    });

                    if (ret < 0)
                    {
                        MessageBox.Show("保存失败 : " + ret);
                    }
                }
                else
                {
                    //UpdateProject
                    bool ret = dal.Update(new HA_Method
                    {
                        intf_code      = intfcode,
                        m_code         = txtCode.Text,
                        m_desc         = txtDesc.Text,
                        m_reqtype      = txtReqType.Text,
                        m_template     = (int)tt,
                        m_rtnvaluecode = txtRetVO.Text,
                        m_arggrpcode   = comboAGGCode.Text,
                        m_isencrypted  = false,
                        m_funcode      = txtFunCode.Text,
                        m_name         = txtName.Text,
                        m_version      = "",
                        m_pagesize     = Convert.ToInt32(txtPageSize.Text)
                    });

                    if (ret == false)
                    {
                        MessageBox.Show("保存失败 : " + ret);
                    }
                }
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存失败 : " + ex.Message);
            }
        }
Example #17
0
 public Temperature(TempType tt, double value)
 {
     this.tt = tt;
     Value   = value;
 }
Example #18
0
 public static IEnumerable <Type> ListSubTypes <T>()
 {
     return(typeof(T).Assembly.GetTypes().Where((Type TempType) => TempType.IsSubclassOf(typeof(T))));
 }
Example #19
0
 public TemperatureScale(TempType type)
 {
     _type = type;
 }
Example #20
0
 public TemperatureScale(TempType type)
 {
     this.type = type;
 }
Example #21
0
        public ActionResult Create()
        {
            ViewBag.TypeId = new SelectList(TempType.GetList(), "Id", "Description");

            return(View());
        }
Example #22
0
        /// <summary>
        /// 获取模板内容字符串
        /// </summary>
        /// <param name="TempID">模板的ID</param>
        /// <param name="PageType">模板页面的类型</param>
        /// <returns></returns>
        public string GetTempateString(int TempID, TempType PageType)
        {
            using (DataEntities ent = new DataEntities())
            {

                TemplatePublic tp = (from l in ent.TemplatePublic where l.ID == TempID select l).FirstOrDefault();
                if (TempID <= 0)
                {
                    tp = (from l in ent.TemplatePublic where l.GroupID == DefaultGroup.ID select l).FirstOrDefault();
                }

                switch (PageType)
                {
                    case TempType.JS调用登陆:
                        return tp.JSLogin;
                        break;
                    case TempType.登陆状态:
                        return tp.LoginStatus;
                        break;
                    case TempType.封面:
                        TemplateFace tf = (from l in ent.TemplateFace where l.ID == TempID select l).FirstOrDefault();
                        if (TempID <= 0)
                        {
                            tf = (from l in ent.TemplateFace where l.GroupID == DefaultGroup.ID select l).FirstOrDefault();
                        }
                        return tf.Content;
                        break;
                    case TempType.高级搜索:
                        return tp.AdvancedSearch;
                        break;
                    case TempType.横向搜索JS:
                        return tp.HorizontaSearch;
                        break;
                    case TempType.控制面板:
                        return tp.Controlcontent;
                        break;
                    case TempType.列表:
                        TemplateList tl = (from l in ent.TemplateList where l.ID == TempID select l).FirstOrDefault();
                        if (TempID <= 0)
                        {
                            tl = (from l in ent.TemplateList where l.GroupID == DefaultGroup.ID select l).FirstOrDefault();
                        }
                        return tl.Content;
                    case TempType.列表分页:
                        return tp.ListPager;
                        break;
                    case TempType.留言板:
                        return tp.MessageBoard;
                        break;
                    case TempType.内容:
                        TemplateContent tc = (from l in ent.TemplateContent where l.ID == TempID select l).FirstOrDefault();
                        if (TempID <= 0)
                        {
                            tc = (from l in ent.TemplateContent where l.GroupID == DefaultGroup.ID select l).FirstOrDefault();
                        }
                        return tc.Content;
                        break;
                    case TempType.评论js调用:
                        return tp.Reply;
                        break;
                    case TempType.全站搜索:
                        return tp.SiteSearchContent;
                        break;
                    case TempType.首页:
                        return tp.IndexContent;
                        break;
                    case TempType.搜索:
                        TemplateSearch ts = (from l in ent.TemplateSearch where l.ID == TempID select l).FirstOrDefault();
                        if (TempID <= 0)
                        {
                            ts = (from l in ent.TemplateSearch where l.GroupID == DefaultGroup.ID select l).FirstOrDefault();
                        }
                        return ts.Content;
                        break;
                    case TempType.下载地址:
                        return tp.DownAddress;
                        break;
                    case TempType.相关信息:
                        return tp.RelationInfo;
                        break;
                    case TempType.在线播放地址:
                        return tp.OLPlayaddress;
                        break;
                    case TempType.纵向搜索JS:
                        return tp.VerticalSearch;
                        break;
                    case TempType.最终下载页:
                        return tp.FinalDown;
                        break;
                    case TempType.相册图片列表:
                        return tp.ImageList;
                        break;
                    case TempType.问答回答列表:
                        return tp.AnswerList;
                        break;
                    case TempType.小说章节列表:
                        return tp.ChapterList;
                        break;
                    case TempType.小说章节:
                        return tp.BookChapter;
                        break;
                    case TempType.快播页面:
                        return tp.KuaiboPage;
                        break;
                    case TempType.百度影音页面:
                        return tp.BaiduPage;
                        break;
                    case TempType.单集列表页面:
                        return tp.SingleDrama;
                        break;
                    case TempType.小说首页:
                        return tp.BookIndex;
                        break;
                    case TempType.新闻首页:
                        return tp.NewIndex;
                        break;
                    case TempType.图片首页:
                        return tp.ImageIndex;
                        break;
                    case TempType.问答首页:
                        return tp.QuestionIndex;
                        break;
                    case TempType.人才首页:
                        return tp.JobIndex;
                        break;
                    case TempType.影视首页:
                        return tp.MovieIndex;
                        break;
                    case TempType.默认静态页:
                        return tp.DefaultPage;
                        break;
                    default:
                        return "";
                        break;
                }
            }
        }
Example #23
0
 public float this[TempType type]
 {
     get { return(Temp[(int)type]); }
 }