Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SensusUI.ShareLocalDataStorePage"/> class.
        /// </summary>
        /// <param name="localDataStore">Local data store to display.</param>
        public ShareLocalDataStorePage(LocalDataStore localDataStore)
        {
            _cancellationTokenSource = new CancellationTokenSource();

            Title = "Sharing Local Data Store";

            StackLayout contentLayout = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            Label statusLabel = new Label
            {
                FontSize = 20,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            contentLayout.Children.Add(statusLabel);

            ProgressBar progressBar = new ProgressBar
            {
                Progress = 0,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            contentLayout.Children.Add(progressBar);

            Button cancelButton = new Button
            {
                Text = "Cancel",
                FontSize = 20,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            cancelButton.Clicked += async (o, e) =>
            {
                await Navigation.PopAsync();
            };

            contentLayout.Children.Add(cancelButton);

            new Thread(() =>
                {
                    string sharePath = null;
                    bool errorWritingShareFile = false;
                    try
                    {
                        sharePath = SensusServiceHelper.Get().GetSharePath(".zip");

                        int numDataWritten = localDataStore.WriteDataToZipFile(sharePath, _cancellationTokenSource.Token, (message, progress) =>
                            {
                                Device.BeginInvokeOnMainThread(async () =>
                                    {
                                        uint duration = 250;

                                        if (message != null)
                                        {
                                            statusLabel.Text = message;
                                            duration = 0;
                                        }

                                        await progressBar.ProgressTo(progress, duration, Easing.Linear);
                                    });
                            });

                        if (numDataWritten == 0)
                            throw new Exception("No data to share.");
                    }
                    catch (Exception ex)
                    {
                        errorWritingShareFile = true;
                        string message = "Error sharing data:  " + ex.Message;
                        SensusServiceHelper.Get().FlashNotificationAsync(message);
                        SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType());
                    }

                    if (_cancellationTokenSource.IsCancellationRequested || errorWritingShareFile)
                    {
                        // always delete the file on cancel / error
                        try
                        {
                            if (File.Exists(sharePath))
                                File.Delete(sharePath);
                        }
                        catch (Exception)
                        {
                        }

                        // if the window has already been popped then the token will have been cancelled. pop the window if needed.
                        if (!_cancellationTokenSource.IsCancellationRequested)
                            Device.BeginInvokeOnMainThread(async () => await Navigation.PopAsync());
                    }
                    else
                    {
                        Device.BeginInvokeOnMainThread(async () =>
                            {
                                await Navigation.PopAsync();
                                SensusServiceHelper.Get().ShareFileAsync(sharePath, "Sensus Data:  " + localDataStore.Protocol.Name, "application/zip");
                            });
                    }

                }).Start();

            Content = new ScrollView
            {
                Content = contentLayout
            };
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SensusUI.ShareLocalDataStorePage"/> class.
        /// </summary>
        /// <param name="localDataStore">Local data store to display.</param>
        public ShareLocalDataStorePage(LocalDataStore localDataStore)
        {
            _cancellationTokenSource = new CancellationTokenSource();

            Title = "Sharing Local Data Store";

            StackLayout contentLayout = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            Label statusLabel = new Label
            {
                FontSize = 20,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            contentLayout.Children.Add(statusLabel);

            ProgressBar progressBar = new ProgressBar
            {
                Progress = 0,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            contentLayout.Children.Add(progressBar);

            Button cancelButton = new Button
            {
                Text = "Cancel",
                FontSize = 20,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            cancelButton.Clicked += async (o, e) =>
            {
                await Navigation.PopAsync();
            };

            contentLayout.Children.Add(cancelButton);

            new Thread(() =>
                {
                    string sharePath = SensusServiceHelper.Get().GetSharePath(".json");
                    bool errorWritingShareFile = false;
                    try
                    {
                        // step 1:  gather data.
                        Device.BeginInvokeOnMainThread(() => statusLabel.Text = "Gathering data...");
                        List<Datum> localData = localDataStore.GetDataForRemoteDataStore(_cancellationTokenSource.Token, progress =>
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                    {
                                        progressBar.ProgressTo(progress, 250, Easing.Linear);
                                    });
                            });

                        // step 2:  write gathered data to file.
                        if (!_cancellationTokenSource.IsCancellationRequested)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                                {
                                    progressBar.ProgressTo(0, 0, Easing.Linear);
                                    statusLabel.Text = "Writing data to file...";
                                });

                            using (StreamWriter shareFile = new StreamWriter(sharePath))
                            {
                                shareFile.WriteLine("[");

                                int dataWritten = 0;
                                foreach (Datum localDatum in localData)
                                {
                                    if (_cancellationTokenSource.IsCancellationRequested)
                                        break;

                                    shareFile.Write((dataWritten++ == 0 ? "" : "," + Environment.NewLine) + localDatum.GetJSON(localDataStore.Protocol.JsonAnonymizer));

                                    if (localData.Count >= 10 && (dataWritten % (localData.Count / 10)) == 0)
                                        Device.BeginInvokeOnMainThread(() => progressBar.ProgressTo(dataWritten / (double)localData.Count, 250, Easing.Linear));
                                }

                                shareFile.WriteLine(Environment.NewLine + "]");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        errorWritingShareFile = true;
                        string message = "Error writing share file:  " + ex.Message;
                        SensusServiceHelper.Get().FlashNotificationAsync(message);
                        SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType());
                    }

                    if (_cancellationTokenSource.IsCancellationRequested || errorWritingShareFile)
                    {
                        // always delete the file on cancel / error
                        try
                        {
                            File.Delete(sharePath);
                        }
                        catch (Exception)
                        {
                        }

                        // the only way to get a cancellation event is to back out of the window, so only pop if there was an error
                        if(errorWritingShareFile)
                            Device.BeginInvokeOnMainThread(async () => await Navigation.PopAsync());
                    }
                    else
                    {
                        Device.BeginInvokeOnMainThread(async () =>
                            {
                                await Navigation.PopAsync();
                                SensusServiceHelper.Get().ShareFileAsync(sharePath, "Sensus Data", "application/json");
                            });
                    }

                }).Start();

            Content = new ScrollView
            {
                Content = contentLayout
            };
        }
Ejemplo n.º 3
0
 void UC_NFotoApartamento_Loaded(object sender, RoutedEventArgs e)
 {
     cbx_infra.ItemsSource = LocalDataStore.GetInfraestructuraDetalleForFoto(_id_apartamento);
 }
Ejemplo n.º 4
0
 public static LocalDataStoreSlot AllocateDataSlot() => LocalDataStore.AllocateSlot();
Ejemplo n.º 5
0
 public static object GetData(LocalDataStoreSlot slot) => LocalDataStore.GetData(slot);
Ejemplo n.º 6
0
 public static void SetData(LocalDataStoreSlot slot, object data) => LocalDataStore.SetData(slot, data);
Ejemplo n.º 7
0
 public static void FreeNamedDataSlot(string name) => LocalDataStore.FreeNamedSlot(name);
Ejemplo n.º 8
0
 public static LocalDataStoreSlot GetNamedDataSlot(string name) => LocalDataStore.GetNamedSlot(name);
Ejemplo n.º 9
0
 public static LocalDataStoreSlot AllocateNamedDataSlot(string name) => LocalDataStore.AllocateNamedSlot(name);
Ejemplo n.º 10
0
 public LocalDataStoreHolder(LocalDataStore store)
 {
     this.m_Store = store;
 }
Ejemplo n.º 11
0
        public DataStorePage(Protocol protocol, DataStore dataStore, bool local)
        {
            Title = (local ? "Local" : "Remote") + " Data Store";

            List <StackLayout> stacks = UiProperty.GetPropertyStacks(dataStore);

            StackLayout buttonStack = new StackLayout
            {
                Orientation     = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            stacks.Add(buttonStack);

            if (dataStore.Clearable)
            {
                Button clearButton = new Button
                {
                    Text = "Clear",
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    FontSize          = 20
                };

                clearButton.Clicked += async(o, e) =>
                {
                    if (await DisplayAlert("Clear data from " + dataStore.Name + "?", "This action cannot be undone.", "Clear", "Cancel"))
                    {
                        dataStore.Clear();
                    }
                };

                buttonStack.Children.Add(clearButton);
            }

            if (local)
            {
                Button shareLocalDataButton = new Button
                {
                    Text = "Share",
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    FontSize          = 20
                };

                shareLocalDataButton.Clicked += async(o, e) =>
                {
                    LocalDataStore localDataStore = dataStore as LocalDataStore;

                    if (localDataStore.DataCount > 0)
                    {
                        await Navigation.PushAsync(new ShareLocalDataStorePage(dataStore as LocalDataStore));
                    }
                    else
                    {
                        UiBoundSensusServiceHelper.Get(true).FlashNotificationAsync("Local data store contains no data to share.");
                    }
                };

                buttonStack.Children.Add(shareLocalDataButton);
            }

            Button okayButton = new Button
            {
                Text = "OK",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                FontSize          = 20
            };

            okayButton.Clicked += async(o, e) =>
            {
                if (local)
                {
                    protocol.LocalDataStore = dataStore as LocalDataStore;
                }
                else
                {
                    protocol.RemoteDataStore = dataStore as RemoteDataStore;
                }

                await Navigation.PopAsync();
            };

            buttonStack.Children.Add(okayButton);

            StackLayout contentLayout = new StackLayout
            {
                Orientation     = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            foreach (StackLayout stack in stacks)
            {
                contentLayout.Children.Add(stack);
            }

            Content = new ScrollView
            {
                Content = contentLayout
            };
        }