Exemplo n.º 1
0
        public ChartForm()
        {
            //if (true)//ставим поддержку IE11
            //{
            //  var appName = System.IO.Path.GetFileName(Application.ExecutablePath);

            //  Microsoft.Win32.Registry
            //    .CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true)
            //    .SetValue(appName, 11000, Microsoft.Win32.RegistryValueKind.DWord);
            //}

            var avatar = CreateAvatar();

            System.IO.File.WriteAllBytes(ApplicationHlp.MapPath("avatar.png"), avatar);

            h.Protocol().Register_ResourceProtocol(StarResource.ResourceManager);
            h.Protocol().Register("nres2", (url, context) => (byte[])StarResource.ResourceManager.GetObject(url.Substring(context.ProtocolPrefix.Length + 3).Trim('/', '\\').Replace('.', '_')));
            h.Protocol().Register("avatar", (url, context) => avatar);

            InitializeComponent();

            var values = new List <PinValue <double> >();

            var timer = new Timer {
                Interval = (int)TimeSpan.FromSeconds(0.15).TotalMilliseconds
            };

            timer.Tick += (_s, _e) =>
                          values.Add(new PinValue <double>(DateTime.UtcNow, Math.Sin((DateTime.UtcNow - new DateTime(2000, 1, 1)).TotalSeconds)));
            timer.Start();


            //Action<object, EventArgs> action = (o, e) => Console.WriteLine(e);

            //foreach (var eventInfo in this.GetType().GetEvents())
            //{
            //  EventTest.AddEventHandler(eventInfo, this, action);
            //}
            //this.htmlSync = new HtmlDesktopSynchronizer(webBrowser1, () => HtmlView(), json => Console.WriteLine(json.ToString()), isTrace:false);
            this.htmlSync = new HDesktopSynchronizer(webBrowser1, () => HView(values), json => Console.WriteLine(json.ToString()), isTrace: false, refreshInterval: TimeSpan.FromMilliseconds(100));
            webBrowser1.ScriptErrorsSuppressed = true;
            webBrowser1.DocumentCompleted     += (_s, _e) =>
            {
                webBrowser1.Document.Window.Error += (__s, __e) =>
                                                     Console.WriteLine("{0}: {1}[{2}]", __e.Description, __e.Url, __e.LineNumber);
            };
        }
Exemplo n.º 2
0
        public GamerReflectionUi()
        {
            var files = System.IO.Directory.GetFiles(ApplicationHlp.MapPath("Analyze"))
                        .OrderBy(file => ConvertHlp.ToDouble(System.IO.Path.GetFileNameWithoutExtension(file)))
                        .ToArray();

            string selectedFile   = null;
            Bitmap selectedBitmap = null;

            Mat[] selectedChannels = null;

            h.Protocol().Register("img",
                                  (url, context) =>
            {
                var urlPath     = url.Trim('/', '\\').Substring((context.ProtocolPrefix + "://").Length);
                var ss          = urlPath.Split('.');
                var imgFilename = ss.FirstOrDefault();
                var kind        = ss.ElementAtOrDefault(1);
                var imgPath     = files.FirstOrDefault(file => System.IO.Path.GetFileNameWithoutExtension(file) == imgFilename);
                switch (kind)
                {
                case "source":
                    return(System.IO.File.ReadAllBytes(imgPath));

                case "h":
                    return(selectedChannels.Else_Empty().ElementAtOrDefault(0)._f(_ => _.Resize(0.5).ToBitmap().ToBytes()));

                case "s":
                    return(selectedChannels.Else_Empty().ElementAtOrDefault(1)._f(_ => _.Resize(0.5).ToBitmap().ToBytes()));

                case "v":
                    return(selectedChannels.Else_Empty().ElementAtOrDefault(2)._f(_ => _.Resize(0.5).ToBitmap().ToBytes()));
                }
                return(null);
            }
                                  );

            InitializeComponent();


            //var filename = "unknown.bmp";


            //Console.WriteLine(img);



            var points = new CheckPoint[] { };

            new SoftTech.Wui.HDesktopSynchronizer(webBrowser1, () => HView(files, selectedFile, selectedBitmap), json =>
            {
                try
                {
                    switch (json.JPath("data", "command").ToString_Fair())
                    {
                    case "select-file":
                        {
                            var path     = json.JPath("data", "file").ToString_Fair();
                            selectedFile = path;

                            var img_data     = System.IO.File.ReadAllBytes(path);
                            var bitmap       = (Bitmap)Bitmap.FromStream(new System.IO.MemoryStream(img_data));
                            selectedChannels = new Mat(bitmap.ToIplImage(), true).Split();
                        }
                        break;

                    //case "select":
                    //  {
                    //    switch (json.JPath("event", "type").ToString_Fair())
                    //    {
                    //      case "mousemove":
                    //        x = ConvertHlp.ToInt(json.JPath("event", "clientX"));
                    //        y = ConvertHlp.ToInt(json.JPath("event", "clientY"));
                    //        if (x != null && y != null && x >= 0 && y >= 0 && x < img.Width && y < img.Height)
                    //          color = img.Get<byte>(y.Value, x.Value);
                    //        break;
                    //      case "mousedown":
                    //        {
                    //          var _x = ConvertHlp.ToInt(json.JPath("event", "clientX"));
                    //          var _y = ConvertHlp.ToInt(json.JPath("event", "clientY"));
                    //          if (_x != null && _y != null && _x >= 0 && _y >= 0 && _x < img.Width && _y < img.Height)
                    //          {
                    //            var _color = bitmap.GetPixel(_x.Value, _y.Value);
                    //            points = new[] { new CheckPoint(_x.Value, _y.Value, (uint)_color.ToArgb()) }.Concat(points).Take(10).ToArray();
                    //          }
                    //        }
                    //        break;
                    //    }
                    //  }
                    //  break;
                    default:
                        Console.WriteLine(json);
                        break;
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc);
                }
            });
        }
Exemplo n.º 3
0
        protected void Application_Start(object sender, EventArgs e)
        {
            string appPath   = HttpContext.Current.Server.MapPath("");
            string logFolder = ApplicationHlp.CheckAndCreateFolderPath(appPath, "Logs");

            try
            {
                Logger.EnableLogging(Path.Combine(logFolder, "site.log"), 2);

                GlobalConfiguration.Configure(WebApiConfig.Register);

                string databaseFolder = ApplicationHlp.CheckAndCreateFolderPath(appPath, "Data");

                IDataLayer userConnection = new SQLiteDataLayer(string.Format(
                                                                    connectionStringFormat, Path.Combine(databaseFolder, "user.db3")));

                IDataLayer fabricConnection = new SQLiteDataLayer(string.Format(
                                                                      connectionStringFormat, Path.Combine(databaseFolder, "fabric.db3")));

                IDataLayer messageConnection = new SQLiteDataLayer(string.Format(
                                                                       connectionStringFormat, Path.Combine(databaseFolder, "message.db3")));

                IDataLayer forumConnection = new SQLiteDataLayer(string.Format(
                                                                     connectionStringFormat, Path.Combine(databaseFolder, "forum.db3")));

                Logger.AddMessage("Подключения к базам данных успешно созданы");

                SQLiteDatabaseHlp.CheckAndCreateDataBoxTables(userConnection);
                SQLiteDatabaseHlp.CheckAndCreateDataBoxTables(fabricConnection);
                MessageHlp.CheckAndCreateMessageTables(messageConnection);
                MessageHlp.CheckAndCreateMessageTables(forumConnection);
                DialogueHlp.CheckAndCreateDialogueTables(forumConnection);

                MetaHlp.ReserveDiapasonForMetaProperty(fabricConnection);

                FabricHlp.CheckAndCreateMenu(fabricConnection, "main");

                EditorSelector sectionEditorSelector = new EditorSelector(
                    new SectionTunes("news", "Новости"),
                    new SectionTunes("articles", "Статьи"),
                    new SectionTunes("forum", "Форум"),
                    new SectionTunes("rules", "Правила").Link(),
                    new SectionTunes("forumSection", "Раздел форума")
                    );

                EditorSelector unitEditorSelector = new EditorSelector(
                    new UnitTunes("reclame", "Рекламный блок").Tile().ImageAlt().Link().Annotation()
                    );

                Shop.Engine.Site.Novosti         = "news";
                Shop.Engine.Site.DirectPageLinks = true;
                //Shop.Engine.Site.AddFolderForNews = true;

                try
                {
                    string fabricScriptPath = Path.Combine(appPath, "FabricScript.sql");
                    if (File.Exists(fabricScriptPath))
                    {
                        string script = File.ReadAllText(fabricScriptPath);
                        Logger.AddMessage("Выполняем стартовый скрипт для fabric.db3: {0}", script);
                        fabricConnection.GetScalar("", script);
                    }

                    string userScriptPath = Path.Combine(appPath, "UserScript.sql");
                    if (File.Exists(userScriptPath))
                    {
                        string script = File.ReadAllText(userScriptPath);
                        Logger.AddMessage("Выполняем стартовый скрипт для user.db3: {0}", script);
                        userConnection.GetScalar("", script);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteException(ex, "Ошибка при выполнении стартового скрипта");
                }

                SiteContext.Default = new BasketballContext(
                    appPath, sectionEditorSelector, unitEditorSelector,
                    userConnection, fabricConnection, messageConnection, forumConnection
                    );

                SiteContext.Default.Pull.StartTask(Labels.Service,
                                                   MemoryChecker((BasketballContext)SiteContext.Default)
                                                   );

                SiteContext.Default.Pull.StartTask(Labels.Service,
                                                   SiteTasks.CleaningSessions(SiteContext.Default,
                                                                              TimeSpan.FromHours(1), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(1)
                                                                              )
                                                   );
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex, "Ошибка создания подключения к базе данных:");
            }
        }