Пример #1
0
        private async Task download_multiple(string key, string containerName)
        {
            multiple_storage objs = new multiple_storage();

            objs = await get_files_name(key);

            int count;

            Int32.TryParse(objs.count, out count);
            string rem, counter;
            int    num;

            for (int i = 0; i < count; i++)
            {
                int index = 0;
                counter = (index < 0) ? objs.blobName.ToString() : objs.blobName.ToString().Remove(index, 5);
                index   = 5;
                rem     = (index < 0) ? objs.blobName.ToString() : objs.blobName.ToString().Remove(index, 4);
                Int32.TryParse(counter, out num);
                rem += (num - i).ToString();
                storage obj = await get_file_name(key, true, rem);

                loading_text.Text = "Downloading ...\nFile :" + (i + 1).ToString() + "/" + count.ToString();;
                await download(key, containerName, obj.blobName + obj.extension, obj.blobName);
            }
            result.Text = "File has been downloaded...";
        }
Пример #2
0
        private async Task network_lock(string key, bool mul)
        {
            string ssid = "";
            var    icp  = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();

            if (icp != null)
            {
                if (icp.WlanConnectionProfileDetails != null)
                {
                    ssid = icp.WlanConnectionProfileDetails.GetConnectedSsid();
                }
                else
                {
                    error = "Please connect to the required wifi network...";
                    popup();
                    visible();
                }
            }

            if (mul)
            {
                multiple_storage obj = new multiple_storage();
                obj = await get_files_name(key);

                if (ssid == obj.ssid)
                {
                    await download_multiple(key, obj.containerName);
                }
                else
                {
                    error = "Access Denied...";
                    popup();
                    visible();
                }
            }
            else
            {
                storage obj = new storage();
                obj = await get_file_name(key, mul, "");

                if (ssid == obj.ssid)
                {
                    await download(key, obj.containerName, obj.blobName + obj.extension, "");
                }
                else
                {
                    error = "Access Denied...";
                    popup();
                    visible();
                }
            }
        }
Пример #3
0
        private async Task <string> generate_upload_multiple(IReadOnlyList <StorageFile> files)
        {
            string key           = connection.get_key();
            string containerName = "public";
            string blob          = "HLIN";
            int    count         = 1;

            foreach (StorageFile file in files)
            {
                blob = "HLIN";
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(key);

                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                CloudBlobContainer container = blobClient.GetContainerReference(containerName);

                CloudBlockBlob counterBlob = container.GetBlockBlobReference("counter");

                string content = await counterBlob.DownloadTextAsync();


                int    number = Int32.Parse(content) + 1;
                string rowkey = (number.ToString());
                blob += type;
                blob += rowkey;
                loading_text.Text = "Uploading..." + "\nFile:" + count.ToString() + "/" + files.Count.ToString();


                await create_blob(key, containerName, blob, file);

                storage item = new storage("Public", rowkey, password.Text.ToString(), latitude.Text.ToString(), longitude.Text.ToString(), containerName, file.FileType.ToString(), blob, DateTime.Now, slider.Value, ssid);
                create_table(key, "users", item);
                await update_counter(key, containerName, rowkey);

                count++;
            }
            loading_text.Text = "Finalising...";
            multiple_storage temp = new multiple_storage("Public", "M" + blob, userkey, files.Count.ToString(), password.Text.ToString(), latitude.Text.ToString(), longitude.Text.ToString(), containerName, blob, DateTime.Now, slider.Value, ssid);

            create_table_mutiple(temp);
            loading_text.Text = "Upload done";
            return("M" + blob);
        }
Пример #4
0
        //filename function ends



        //checking function

        //password_lock
        private async Task check_password(string key, string containerName, bool mul)
        {
            string pass, filename;

            if (mul)
            {
                multiple_storage obj = new multiple_storage();
                obj = await get_files_name(key);

                filename = obj.blobName + obj.extension;
                pass     = obj.password;
            }
            else
            {
                storage obj = new storage();
                obj = await get_file_name(key, mul, "");

                filename = obj.blobName + obj.extension;
                pass     = obj.password;
            }


            if (pass == password.Text.ToString())
            {
                if (mul)
                {
                    await download_multiple(key, containerName);
                }
                else
                {
                    await download(key, containerName, filename, "");
                }
            }
            else
            {
                error += "Access Denied ... ";
                popup();
                visible();
            }
        }
Пример #5
0
        private async void create_table_mutiple(multiple_storage item)
        {
            try
            {
                string key       = connection.get_key();
                string tableName = "multiple";
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(key);

                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

                CloudTable table = tableClient.GetTableReference(tableName);
                await table.CreateIfNotExistsAsync();

                TableOperation insertOperation = TableOperation.InsertOrReplace(item);

                await table.ExecuteAsync(insertOperation);
            }
            catch
            {
                error += "Error in Entering table...\nPlease Try again.";
                popup();
            }
        }
Пример #6
0
        //geo_lock
        private async Task check_location(string key, bool mul)
        {
            string     latitude, longitude;
            Geolocator geolocator = new Geolocator();

            geolocator.DesiredAccuracy         = Windows.Devices.Geolocation.PositionAccuracy.High;
            geolocator.DesiredAccuracyInMeters = 50;
            try
            {
                Geoposition geoposition = await geolocator.GetGeopositionAsync(TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(1));

                latitude  = geoposition.Coordinate.Point.Position.Latitude.ToString("0.0000000000");
                longitude = geoposition.Coordinate.Point.Position.Longitude.ToString("0.0000000000");


                string olat, olon, filename, containerName;
                double perimeter = 50;
                if (mul)
                {
                    multiple_storage obj = new multiple_storage();
                    obj = await get_files_name(key);

                    filename      = obj.blobName + obj.extension;
                    olat          = obj.latitude;
                    olon          = obj.longitude;
                    containerName = obj.containerName;
                    perimeter     = obj.perimeter;
                }
                else
                {
                    storage obj = new storage();
                    obj = await get_file_name(key, mul, "");

                    filename      = obj.blobName + obj.extension;
                    olat          = obj.latitude;
                    olon          = obj.longitude;
                    perimeter     = obj.perimeter;
                    containerName = obj.containerName;
                }

                double R = 6371; // km
                double lat1, lat2, lon1, lon2;
                Double.TryParse(latitude, out lat1);
                Double.TryParse(olat, out lat2);
                Double.TryParse(longitude, out lon1);
                Double.TryParse(olon, out lon2);
                double dLat = lat2 - lat1;
                double dLon = lon2 - lon1;


                double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Sin(dLon / 2) * Math.Sin(dLon / 2) * Math.Cos(lat1) * Math.Cos(lat2);
                double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
                double d = R * c;
                if (d < perimeter / 10)
                {
                    if (mul)
                    {
                        await download_multiple(key, containerName);
                    }
                    else
                    {
                        await download(key, containerName, filename, "");
                    }
                }
                else
                {
                    error += "Access Denied ...";
                    popup();
                    visible();
                }
            }
            catch
            {
                error += "Error in fetching latitude...\n Try again...";
                popup();
                visible();
            }
        }