Beispiel #1
0
        public override void Present(GlassService service)
        {
            base.Present(service);

            if (service.GetType() == typeof (StopwatchService))
            {
                if (_card == null)
                {
                    _card = new LiveCard(service, service.GetType().FullName);
                    _renderer = new ChronometerRenderer(service);
                    _card.SetDirectRenderingEnabled(true).SurfaceHolder.AddCallback(_renderer);

                    var mi = new Intent(service, typeof(MenuActivity));
                    var b = new Bundle();
                    b.PutInt("ResourceID", Resource.Menu.stopwatch);
                    mi.PutExtras(b);
                    mi.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);

                    _card.SetAction(PendingIntent.GetActivity(service, 0, mi, 0));
                    _card.Attach(service);

                    _card.Publish(LiveCard.PublishMode.Reveal);
                }
                else
                {
                    _card.Navigate();
                }
            }
        }
Beispiel #2
0
        public override void ServiceDestroyed(GlassService service)
        {
            if (_card != null && _card.IsPublished)
            {
                _card.Unpublish();
                _card = null;
            }

        }
Beispiel #3
0
        public static void SyncDown(string tabela, int versao)
        {
            string url = GlassService.GetUrl("sync_down.php");

            string responseString = "";
            int    pagina         = 0;

            do
            {
                var request = (HttpWebRequest)WebRequest.Create(url);

                string postData = "";

                postData += "&tipo=" + "sync_down";
                postData += "&pagina=" + pagina.ToString();
                postData += "&versao=" + versao.ToString();
                postData += "&tabela=" + tabela;
                postData += "&itens=10";

                byte[] data = Encoding.UTF8.GetBytes(postData);

                request.Method        = "POST";
                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = data.Length;

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }

                try
                {
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    responseString = (new StreamReader(response.GetResponseStream())).ReadToEnd();

                    if (!responseString.StartsWith("eof"))
                    {
                        RestoreData(responseString);
                    }
                    else
                    {
                        responseString = "";
                    }
                }
                catch (Exception ex)
                {
                    Logs.Log(ex.Message);
                    throw;
                }

                pagina++;
            } while (!string.IsNullOrEmpty(responseString.Trim()));
        }
Beispiel #4
0
        public static void SyncUp(string json)
        {
            var request = (HttpWebRequest)WebRequest.Create(GlassService.GetUrl("sync_up.php"));

            request.Method      = "POST";
            request.ContentType = "application/json; charset=utf-8";

            byte[] data = Encoding.UTF8.GetBytes(json);
            request.ContentLength = data.Length;

            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            try
            {
                HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
                string          responseString = (new StreamReader(response.GetResponseStream()).ReadToEnd());

                if (responseString.Length > 0)
                {
                    string      respJson = "{\"result\":" + responseString + "}";
                    XmlDocument xdoc     = JsonConvert.DeserializeXmlNode(respJson, "table");

                    foreach (XmlNode n in xdoc.DocumentElement.ChildNodes)
                    {
                        ConfirmSync(n);
                        Status("Enviando dados para o servidor", "", totalSync, syncCount++, 1);
                    }
                }
            }
            catch (Exception ex)
            {
                Logs.Log(ex.Message);
                throw;
            }
        }
Beispiel #5
0
        public static Dictionary <string, int> SyncCheck(out int total, bool forceAll)
        {
            StringBuilder sb = new StringBuilder();

            SyncManager.forceAll = forceAll;

            sb.Append("{\"tabelas\":[");
            bool first = true;

            foreach (string table in syncTables)
            {
                string tbName = table.Replace("!", "");

                if (!first)
                {
                    sb.Append(",");
                }

                int versaoNum = 0;

                if (!forceAll)
                {
                    versaoNum = GetTableVersion(table);
                }

                sb.Append(string.Format("{{\"nome\":\"{0}\",\"versao\":\"{1}\"}}", tbName, versaoNum));

                first = false;
            }

            sb.Append("]}");

            string json = sb.ToString();

            var request = (HttpWebRequest)WebRequest.Create(GlassService.GetUrl("sync_check.php"));

            request.Method      = "POST";
            request.ContentType = "application/json; charset=utf-8";

            byte[] data = Encoding.UTF8.GetBytes(json);
            request.ContentLength = data.Length;

            Dictionary <string, int> ret = new Dictionary <string, int>();

            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            total = 0;

            try
            {
                HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
                string          responseString = (new StreamReader(response.GetResponseStream()).ReadToEnd());

                if (responseString.Length > 0)
                {
                    XmlDocument xdoc = JsonConvert.DeserializeXmlNode(responseString, "table");

                    foreach (XmlNode n in xdoc.DocumentElement.ChildNodes)
                    {
                        string tb  = "";
                        int    qtd = 0;

                        foreach (XmlNode nt in n.ChildNodes)
                        {
                            if (nt.Name.Equals("NOME", StringComparison.InvariantCultureIgnoreCase))
                            {
                                tb = nt.InnerText;
                            }

                            if (nt.Name.Equals("QTD", StringComparison.InvariantCultureIgnoreCase))
                            {
                                int.TryParse(nt.InnerText, out qtd);
                            }
                        }

                        total += qtd;

                        ret.Add(tb, qtd);
                    }
                }
            }
            catch (Exception ex)
            {
                Logs.Log(ex.Message);
                throw;
            }

            syncCount = 0;
            totalSync = total;
            return(ret);
        }
Beispiel #6
0
 public virtual void Present(GlassService service, Type type, object parms = null)
 {
 }
Beispiel #7
0
 public virtual void Present(GlassService service)
 {
     _activeService = service;
 }
Beispiel #8
0
        public virtual void ServiceDestroyed(GlassService service)
        {

        }
Beispiel #9
0
 public virtual void ServiceCreated(GlassService service)
 {
     _activeItems.Add(service);
     _activeService = service;
 }