Inhalte aufrufen

Profilbild

Error when create a plugin


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
14 Antworten zu diesem Thema

#1 Xuan Can

Xuan Can

    Member

  • Members
  • PunktPunkt
  • 11 Beiträge

Geschrieben: 22 September 2016 - 04:21

i'm writing a plugin to counter user online and total user access my website. but I get an error message on View when i active my plugin.
 

Here error:

 

 

Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'model' does not exist in the current context

Source Error:

 
Line 1:  @model SmartStore.WebCounter.Models.spThongKe_Edit_Result
Line 2:  @using SmartStore.WebCounter.Models
Line 3:  @using System.Web.ApplicationServices;
Source File: e:\Project\ATM\SmartStoreNET-2.5.x\src\Presentation\SmartStore.Web\Plugins\SmartStore.WebCounter\Views\WidgetsWebCounter\PublicInfo.cshtml    Line: 1

Anyone can help me. Thanks a lot!


  • RidgeOi gefällt das

#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 22 September 2016 - 11:37

That's an MVC issue. Several reasons are listed here.

  • Xuan Can gefällt das

Marcus Gesing

Smartstore AG


#3 Xuan Can

Xuan Can

    Member

  • Members
  • PunktPunkt
  • 11 Beiträge

Geschrieben: 23 September 2016 - 09:09

thanks you, I've fixed it.



#4 Xuan Can

Xuan Can

    Member

  • Members
  • PunktPunkt
  • 11 Beiträge

Geschrieben: 28 September 2016 - 05:57

 

That's an MVC issue. Several reasons are listed here.

 

Hi Admin, i have other problem so i need your's help.
My "Web Counter" plugin use global.asax to get user access my shop. I use function Application Start, Session_Start, Session_End:
 

namespace SmartStore.WebCounter
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            Application.Add("Homnay", 0);
            Application.Add("HomQua", 0);
            Application.Add("TuanNay", 0);
            Application.Add("TuanTruoc", 0);
            Application.Add("ThangNay", 0);
            Application.Add("ThangTruoc", 0);
            Application.Add("TatCa", 0);
            Application.Add("visitors_online", 0);

        }

         void Session_Start(object sender, EventArgs e)
        {
            Session.Timeout = 5;
            SmartStoreEntities ctx = new SmartStoreEntities();
            Application.Lock();
            Application["visitors_online"] = (Convert.ToInt32(Application["visitors_online"]) + 1).ToString("#,###");
            Application.UnLock();
            try
            {
                ObjectResult<spThongKe_Edit_Result> Thongkes = ctx.spThongKe_Edit();
                var ThongKe = Thongkes.FirstOrDefault();
                if (ThongKe != null)
                {
                    Application["HomNay"] = ThongKe.HomNay == 0 ? "0" : long.Parse("0" + ThongKe.HomNay).ToString("#,###");
                    Application["HomQua"] = ThongKe.HomQua == 0 ? "0" : long.Parse("0" + ThongKe.HomQua).ToString("#,###");
                    Application["TuanNay"] = ThongKe.TuanNay == 0 ? "0" : long.Parse("0" + ThongKe.TuanNay).ToString("#,###");
                    Application["TuanTruoc"] = ThongKe.TuanTruoc == 0 ? "0" : long.Parse("0" + ThongKe.TuanTruoc).ToString("#,###");
                    Application["ThangNay"] = ThongKe.ThangNay == 0 ? "0" : long.Parse("0" + ThongKe.ThangNay).ToString("#,###");
                    Application["ThangTruoc"] = ThongKe.ThangTruoc == 0 ? "0" : long.Parse("0" + ThongKe.ThangTruoc).ToString("#,###");
                    Application["TatCa"] = ThongKe.TatCa == 0 ? "0" : long.Parse("0" + ThongKe.TatCa).ToString("#,###");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        void Session_End(object sender, EventArgs e)
        {
            Application.Lock();
            Application["visitors_online"] = (Convert.ToInt32(Application["visitors_online"]) - 1).ToString("#,###");
            Application.UnLock();
        }
    }
}

But when i run my shop. Controller don't call to global.asax to get data. Can you help to the way to call global.asax (in other project) when my shop (main project) run or the way to call function Application Start, Session_Start and Session_End. 
here my controller:
 

        // GET: WidgetsWebCounter
        [ChildActionOnly]
        public ActionResult PublicInfo()
        {
            return View();
        }

        [HttpGet]
        [ChildActionOnly]
        public JsonResult Refresh()
        {
            var visitors_online = HttpContext.Application["visitors_online"] as string;
            var HomNay = HttpContext.Application["HomNay"] as string;
            var HomQua = HttpContext.Application["HomQua"] as string;
            var TuanNay = HttpContext.Application["TuanNay"] as string;
            var TuanTruoc = HttpContext.Application["TuanTruoc"] as string;
            var ThangNay = HttpContext.Application["ThangNay"] as string;
            var ThangTruoc = HttpContext.Application["ThangTruoc"] as string;
            var TatCa = HttpContext.Application["TatCa"] as string;
            var obj = new { visitors_online, HomNay, HomQua, TuanNay, TuanTruoc, ThangNay, ThangTruoc, TatCa };
            return Json(obj, JsonRequestBehavior.AllowGet);
        }

Thans you very much!



#5 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 28 September 2016 - 12:17

Do not add a global.asax to your plugin. Instead implement IPreApplicationStart or IStartupTask like here.
 
Instead of the session events you could use a HttpRuntime.Cache object to manage your data.

Marcus Gesing

Smartstore AG


#6 Xuan Can

Xuan Can

    Member

  • Members
  • PunktPunkt
  • 11 Beiträge

Geschrieben: 31 October 2016 - 11:33

 

Do not add a global.asax to your plugin. Instead implement IPreApplicationStart or IStartupTask like here.
 
Instead of the session events you could use a HttpRuntime.Cache object to manage your data.

 

I use a HttpRuntime.Cache to save data but when i refresh page void OnBeginRequest called 4 times. Why such? Is there any way to know new request and call to void OnBeginRequest only new user access my shop. Thnks alot



#7 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 31 October 2016 - 13:21

You can write an event consumer for the customer inserted event. advantage: the customer entity tells you more about the customer (SystemName, IsSystemAccount...).

  • Xuan Can gefällt das

Marcus Gesing

Smartstore AG


#8 Xuan Can

Xuan Can

    Member

  • Members
  • PunktPunkt
  • 11 Beiträge

Geschrieben: 15 November 2016 - 04:44

 

You can write an event consumer for the customer inserted event. advantage: the customer entity tells you more about the customer (SystemName, IsSystemAccount...).

 

Thks alot. Now i am writting in view to display of multi language. I use @T("String"), but has error: "CS0103: The name 'T' does not exist in the current context". There's more, i has many errors as  Predefined type 'System.String' is not defined or imported, Predefined type 'System.Object' is not defined or imported, The name 'Html' does not exist in the current context. Are there something I'm missing?



#9 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 15 November 2016 - 12:58

Check if your plugin references the SmartStore.Web.Framework project.


  • Xuan Can gefällt das

Marcus Gesing

Smartstore AG


#10 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1118 Beiträge

Geschrieben: 15 November 2016 - 21:18

Thks alot. Now i am writting in view to display of multi language. I use @T("String"), but has error: "CS0103: The name 'T' does not exist in the current context". There's more, i has many errors as  Predefined type 'System.String' is not defined or imported, Predefined type 'System.Object' is not defined or imported, The name 'Html' does not exist in the current context. Are there something I'm missing?

 

In your plugin project:

  • Switch to PluginDev build
  • Build your plugin
  • Switch back to Debug build
  • Restart Visual Studio.
  • Intellisense should work now!

  • Xuan Can gefällt das

Murat Cakir
SmartStore AG


#11 Xuan Can

Xuan Can

    Member

  • Members
  • PunktPunkt
  • 11 Beiträge

Geschrieben: 23 November 2016 - 04:21

thanks you very much. I've fixed this error. :)

Now i has a problem. can u help me? I use bootstap color picker to config color of display plugin like config of theme.

<script src="/Plugins/SmartStore.WebCounter/Content/Scripts/bootstrap-colorpicker.js"></script>
<script src="/Plugins/SmartStore.WebCounter/Content/Scripts/bootstrap-colorpicker-globalinit.js"></script>

but when the Configure page load, color picker not set to value of setting. Default color in color picker is red :(

 

https://flic.kr/p/Ngnouo



#12 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 23 November 2016 - 16:15

Scripts are added by plugins this way: 
@{
  Html.AddScriptParts(true, Url.Content("~/Plugins/SmartStore.WebCounter/Content/Scripts/my-script.js"));
}
But the bootstrap color-picker ist already embedded in .NET. See \Views\Shared\EditorTemplates\Color.cshtml.

  • Xuan Nguyen gefällt das

Marcus Gesing

Smartstore AG


#13 Xuan Nguyen

Xuan Nguyen

    Newbie

  • Members
  • Punkt
  • 9 Beiträge

Geschrieben: 13 December 2016 - 03:50

 

Scripts are added by plugins this way: 
@{
  Html.AddScriptParts(true, Url.Content("~/Plugins/SmartStore.WebCounter/Content/Scripts/my-script.js"));
}
But the bootstrap color-picker ist already embedded in .NET. See \Views\Shared\EditorTemplates\Color.cshtml.

 

 
I follow your instructions, but color in color picker when configurtion page loading still is red. I do not understand how color.cshtml was embedded? Can you give more details? Further, the plugin configuration page no has "hint" when hover on the title of each value I want to configure. How i get it?


#14 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 13 December 2016 - 12:39

Color.cshtml is an editor template. If you want to use it, you must decorate your view model property with the "Color" UIHint attribute. Example:
[SmartResourceDisplayName("Plugins.SmartStore.WebCounter.BackgroundColor")]
[UIHint("Color")]
public string BackgroundColor { get; set; }
The hint for a property or setting is displayed if the SmartResourceDisplayName (see above) has a ".Hint" resource string. Example:
<LocaleResource Name="BackgroundColor">
  <Value>Background Color</Value>
</LocaleResource>
<LocaleResource Name="BackgroundColor.Hint">
  <Value>Specifies the background color of whatever....</Value>
</LocaleResource>

  • Xuan Nguyen gefällt das

Marcus Gesing

Smartstore AG


#15 Xuan Nguyen

Xuan Nguyen

    Newbie

  • Members
  • Punkt
  • 9 Beiträge

Geschrieben: 14 December 2016 - 04:29

i've done it. Thanks you very much.  :lol:  :lol: