Ejemplo n.º 1
0
        private async void CheckContent()
        {
            var       db         = Services.XServices.Instance.GetService <Services.XDatabase>();
            IComosWeb m_ComosWeb = Services.XServices.Instance.GetService <IComosWeb>();

            ViewModels.ProjectData ProjectData = Services.XServices.Instance.GetService <ViewModels.ProjectData>();


            foreach (string uid in UIDsToDownload)
            {
                //if (db.GetCachedScreen(uid) == null)
                if (1 == 1)
                {
                    List <CSpecification> specs = null;
                    try
                    {
                        specs = await m_ComosWeb.GetObjectSpecification(
                            ProjectData.SelectedDB.Key, ProjectData.SelectedProject.UID, ProjectData.SelectedLayer.UID, ProjectData.SelectedLanguage.LCID, uid);
                    }
                    catch (TaskCanceledException) { return; } // If there is a Logout Request
                    catch (Exception e)
                    {
                        await App.Current.MainPage.DisplayAlert("Error", "Error al obtener atributos: " + e.Message, Services.TranslateExtension.TranslateText("OK"));

                        return;
                    }

                    if (specs != null)
                    {
                        foreach (var item in specs)
                        {
                            //cache mobile
                            //if (item.Name.Equals("Z10T00002"))
                            if (item.Name.Equals(Pages.comos.Constants.MobileTabName))
                            {
                                string html;
                                try
                                {
                                    html = await m_ComosWeb.GetObjectSpecificationAsHtml(ProjectData.SelectedDB.Key, ProjectData.SelectedProject.UID,
                                                                                         ProjectData.SelectedLayer.UID, ProjectData.SelectedLanguage.LCID, uid, item.Name);
                                }
                                catch (TaskCanceledException) { return; } // If there is a Logout Request
                                catch (Exception ex)
                                {
                                    await App.Current.MainPage.DisplayAlert("Error", "Error al cargar atributos: " + ex.Message, Services.TranslateExtension.TranslateText("OK"));

                                    return;
                                }

                                db.CacheScreen(uid, html);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <PageAttributes> DownloadDeviceContent(string UID, bool push, bool onlymobile = true, bool recursive = true)
        {
            PageAttributes mobilepage = null;
            bool           download   = false;
            IComosWeb      m_ComosWeb = Services.XServices.Instance.GetService <IComosWeb>();

            ViewModels.ProjectData projectdata = Services.XServices.Instance.GetService <ViewModels.ProjectData>();
            Services.XDatabase     db          = Services.XServices.Instance.GetService <Services.XDatabase>();


            List <CSpecification> Specifications;

            try
            {
                Specifications = await m_ComosWeb.GetObjectSpecification(
                    projectdata.SelectedDB.Key,
                    projectdata.SelectedProject.UID,
                    projectdata.SelectedLayer.UID,
                    projectdata.SelectedLanguage.LCID,
                    UID);
            }
            catch (TaskCanceledException) { return(null); } // If there is a Logout Request
            catch (Exception e)
            {
                await App.Current.MainPage.DisplayAlert("Error", "Error al obtener atributos: " + e.Message, Services.TranslateExtension.TranslateText("OK"));

                return(null);
            }

            if (Specifications == null || Specifications.Count == 0)
            {
                return(null);
            }

            foreach (var item in Specifications)
            {
                //TO DO DOWNLOAD EVERYTHING???

                if (item.Name.Equals(Constants.MobileTabName) || !onlymobile)
                {
                    download = true;
                }

                if (download)
                {
                    CSystemObject sysobj;
                    try
                    {
                        sysobj = await m_ComosWeb.GetObject(projectdata.SelectedLayer, UID, projectdata.SelectedLanguage.LCID);
                    }
                    catch (TaskCanceledException) { return(null); } // If there is a Logout Request
                    catch (Exception ex)
                    {
                        await App.Current.MainPage.DisplayAlert("Error", "Error al cargar objetos de Comos Web: " + ex.Message, Services.TranslateExtension.TranslateText("OK"));

                        return(null);
                    }

                    if (sysobj == null)
                    {
                        return(null);
                    }

                    CObject o = new CObject()
                    {
                        ClassType       = sysobj.SystemType,
                        Description     = sysobj.Description,
                        IsClientPicture = sysobj.IsClientPicture,
                        Name            = sysobj.Name,
                        UID             = sysobj.UID,
                        OverlayUID      = projectdata.SelectedLayer.UID,
                        Picture         = sysobj.Picture,
                        ProjectUID      = projectdata.SelectedProject.UID,
                        SystemFullName  = sysobj.Name,
                    };

                    //check if its download only

                    PageAttributes page = null;
                    if (!push)
                    {
                        page = new PageAttributes();
                        await page.Init(projectdata.SelectedDB.Key, projectdata.SelectedLanguage.LCID, item, o);
                    }
                    else
                    {
                        page = new PageAttributes(projectdata.SelectedDB.Key, projectdata.SelectedLanguage.LCID, item, o);
                    }

                    //download all documents if not pushing to page
                    if (!push)
                    {
                        List <string> uids_docs = await page.DownloadDocuments();

                        foreach (var doc in uids_docs)
                        {
                            // string[] filename_mime = await DownloadDocument(doc, false);
                            CDocument filename_mime = await DownloadDocument(doc, false);

                            if (filename_mime != null && filename_mime.FileName != null)
                            {
                                db.CacheDocumentFilePath(filename_mime.FileName, filename_mime.MimeType, doc, projectdata.SelectedProject.UID, projectdata.SelectedLayer.UID, filename_mime.Name, filename_mime.Description, filename_mime.Picture);
                            }
                            else
                            {
                                if (recursive)
                                {
                                    await DownloadDeviceContent(doc, false, true, false);
                                }
                            }
                        }
                    }

                    if (item.Name.Equals(Constants.MobileTabName))
                    {
                        mobilepage = page;
                    }

                    download = false;
                }
            }

            return(mobilepage);
        }
Ejemplo n.º 3
0
        public async Task <CDocument> DownloadDocument(string UID, bool open)
        {
            IComosWeb m_ComosWeb = Services.XServices.Instance.GetService <ComosWebSDK.IComosWeb>();

            ViewModels.ProjectData ProjectData = Services.XServices.Instance.GetService <ViewModels.ProjectData>();

            // Need to Lock to wait big files (on sleep will logout comosweb)
            m_ComosWeb.Lock();
            CSystemObject o;

            try
            {
                o = await m_ComosWeb.GetObject(
                    ProjectData.SelectedDB.Key,
                    ProjectData.SelectedProject.UID,
                    ProjectData.SelectedLayer.UID,
                    UID, ProjectData.SelectedLanguage.LCID);
            }
            catch (TaskCanceledException) { return(await Task.FromResult <CDocument>(null)); } // If there is a Logout Request
            catch (Exception e)
            {
                await App.Current.MainPage.DisplayAlert("Error", "Error al descargar documento: " + e.Message, Services.TranslateExtension.TranslateText("OK"));

                return(await Task.FromResult <CDocument>(null));
            }

            if (o == null)
            {
                return(await Task.FromResult <CDocument>(null));
            }
            if (o.DocumentType != null)
            {
                bool exportpdf = string.Compare(o.DocumentType.Name, "ComosReport", StringComparison.CurrentCultureIgnoreCase) == 0;
                if (!exportpdf)
                {
                    exportpdf = string.Compare(o.DocumentType.Name, "ComosIReport", StringComparison.CurrentCultureIgnoreCase) == 0;
                }
                // Is a comos report.
                CDocument result = await Task.Run <CDocument>(async() =>
                {
                    HttpResponseMessage response;
                    try
                    {
                        response = await m_ComosWeb.ComosWeb.GetDocumentStream(
                            ProjectData.SelectedDB.Key,
                            ProjectData.SelectedProject.UID,
                            ProjectData.SelectedLayer.UID,
                            UID, exportpdf);
                    }
                    catch (TaskCanceledException) { return(null); } // If there is a Logout Request
                    catch (Exception ex)
                    {
                        await App.Current.MainPage.DisplayAlert("Error", "Error al cargar documento: " + ex.Message, Services.TranslateExtension.TranslateText("OK"));
                        return(null);
                    }

                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        string filename = response.Content.Headers.ContentDisposition.FileName;
                        System.Diagnostics.Debug.WriteLine(response.Content.Headers.ContentDisposition.DispositionType);
                        filename              = filename.Trim(new char[] { '"' });
                        filename              = filename.Replace("/", "-");
                        var stream            = await response.Content.ReadAsStreamAsync();
                        var platform          = Services.XServices.Instance.GetService <Services.IPlatformSystem>();
                        string filename_saved = await platform.SaveAndOpenDocument(filename, stream, response.Content.Headers.ContentType.MediaType, open);
                        return(new CDocument()
                        {
                            Description = o.Description,
                            Name = o.Name,
                            UID = o.UID,
                            FileName = filename_saved,
                            Picture = o.Picture,
                            MimeType = response.Content.Headers.ContentType.MediaType
                        });
                    }
                    else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        return(await Task.FromResult <CDocument>(null));
                    }
                    else
                    {
                        var platform = Services.XServices.Instance.GetService <Services.IPlatformSystem>();
                        platform.ShowToast("Error:" + response.ReasonPhrase);
                        return(await Task.FromResult <CDocument>(null));
                        //throw new Exception(response.ReasonPhrase);
                    }
                });

                return(result);
            }

            m_ComosWeb.UnLock();

            return(await Task.FromResult <CDocument>(null));
        }
Ejemplo n.º 4
0
        private async Task <bool> LoadDevices()
        {
            bool result = false;

            try
            {
                ViewModels.ProjectData projectdata = Services.XServices.Instance.GetService <ViewModels.ProjectData>();

                IComosWeb m_ComosWeb = Services.XServices.Instance.GetService <IComosWeb>();
                IDatabase db         = Services.XServices.Instance.GetService <IDatabase>();

                CObject o = db.GetCObjectByFullName(projectdata.SelectedLayer.UID, GetQueryFullName());

                if (o == null)
                {
                    try
                    {
                        o = await m_ComosWeb.GetObjectBySystemFullName(projectdata.SelectedLayer, GetQueryFullName());
                    }
                    catch (Exception ex)
                    {
                        await App.Current.MainPage.DisplayAlert("Error", "Error al cargar query: " + ex.Message, Services.TranslateExtension.TranslateText("OK"));

                        return(false);
                    }
                    db.InsertCObject(o, projectdata.SelectedLayer.UID);
                }

                if (o == null)
                {
                    await App.Current.MainPage.DisplayAlert(Services.TranslateExtension.TranslateText("error"), Services.TranslateExtension.TranslateText("event_container_not_found"), "OK");

                    return(false);
                }

                try
                {
                    m_QueryResult = await m_ComosWeb.GetqueriesResult(
                        projectdata.SelectedDB.Key, o.ProjectUID, o.OverlayUID, projectdata.SelectedLanguage.LCID, o.UID, null);
                }
                catch (Exception ex)
                {
                    await App.Current.MainPage.DisplayAlert("Error", "Error al cargar query: " + ex.Message, Services.TranslateExtension.TranslateText("OK"));

                    return(false);
                }

                if (m_QueryResult != null)
                {
                    Converters.IsQueryCachedValue cachehandler = new Converters.IsQueryCachedValue();
                    cachehandler.GetQueryCachedValues(m_QueryResult);

                    if (m_QueryResult.Rows.Length > 0)
                    {
                        List <ViewModel> unassignedEventsList = new List <ViewModel>();
                        foreach (var row in m_QueryResult.Rows)
                        {
                            unassignedEventsList.Add(new ViewModel(m_QueryResult.Columns, row));
                        }

                        this.DeviceContainerCollection = unassignedEventsList.ToArray();

                        OnPropertyChanged("EventContainerCollection");

                        /*OnPropertyChanged("TasksAttributeNames");
                         *          UpdateSortingAndGrouping();*/
                        result = true;
                    }
                    else
                    {
                        ShowToast("No hay resultados");
                        result = false;
                    }
                }
                else
                {
                    //page not loaded at comosweboffline
                    ShowToast("No hay resultados");
                }

                ((ListView)ListViewDevices_).EndRefresh();
            }
            catch (Exception e)
            {
                await App.Current.MainPage.DisplayAlert(Services.TranslateExtension.TranslateText("error"), e.Message,
                                                        "OK");

                return(false);
            }

            return(result);
        }