Pullasync错误新表

时间:2017-04-12 14:36:29

标签: xamarin.android azure-sql-database azure-mobile-services

我使用Visual Studio在数据库中创建了一个新表。

我为我的新表创建了一个数据对象,添加到我的startup.mobileApp,我的控制器和我的模型中。无论我的pullasync()有什么错误......

"您要查找的资源已被删除,其名称已更改或暂时不可用xamarin"

我的商品手机:

public class AlertMateriel
{
    public string Id { get; set; }

    [JsonProperty(PropertyName = "IdMateriel")]
    public string IdMateriel { get; set; }

    [JsonProperty(PropertyName = "IdDemandeur")]
    public string IdDemandeur { get; set; }

    [JsonProperty(PropertyName = "Demande")]
    public string Demande{ get; set; }

    [JsonProperty(PropertyName = "IdAssignMat")]
    public string IdAssignMat { get; set; }

    [JsonProperty(PropertyName = "IdReceveur")]

    public string IdReceveur { get; set; }

    [JsonProperty(PropertyName = "VU")]
    public bool VU { get; set; }

    [JsonProperty(PropertyName = "Deleted")]
    public string Deleted { get; set; }

    [Microsoft.WindowsAzure.MobileServices.Version]
    public byte[] Version
    {
        get;
        set;
    }
}

服务:

 public class AlertMateriel : EntityData
{
    public string IdMateriel { get; set; }

    public string IdDemandeur { get; set; }
    public string Demande { get; set; }
    public string IdAssignMat { get; set; }
    public bool VU { get; set; }
    public string IdReceveur { get; set; }

}

控制器:

 public class AlertMaterielController : TableController<AlertMateriel>
{
    protected override void Initialize(HttpControllerContext controllerContext)
    {
        base.Initialize(controllerContext);
        ChantierContext context = new ChantierContext();
        DomainManager = new EntityDomainManager<AlertMateriel>(context, Request);
    }

    // GET tables/MaterielDB
    public IQueryable<AlertMateriel> GetAllAlertMateriel()
    {
        return Query();
    }

    public SingleResult<AlertMateriel> GetAllMateriel(string id)
    {
        return Lookup(id);
    }


    public Task<AlertMateriel> PatchAlertMateriel(string id, Delta<AlertMateriel> patch)
    {
        return UpdateAsync(id, patch);
    }


    public async Task<IHttpActionResult> PostAlertMateriel(AlertMateriel item)
    {
        AlertMateriel current = await InsertAsync(item);
        return CreatedAtRoute("Tables", new { id = current.Id }, current);
    }


    public Task DeleteAlertMateirel(string id)
    {
        return DeleteAsync(id);
    }
}

的活动:

public class DefMatTable : Activity
{
    private IMobileServiceSyncTable<AlertMateriel> AlertMat;
    private IMobileServiceSyncTable<AssignMaterielDB> AssignMaterielTable;
    private IMobileServiceSyncTable<Chantiers> ChantiersTable;
    private IMobileServiceSyncTable<MaterielDB> MaterielTable;
    private IMobileServiceSyncTable<Personnel> PersonnelTable;
    private TableLayout _table;
    private MobileServiceClient client;
    private ArrayAdapter _adapter3;
    private string idengin="";
    private string idassign = "";
    private string iddemandeur = "";
    private string idreceveur = "";

    /*
    private TextView Engin;
    private TextView Chantier;
    private TextView Cdt;
    private TextView datedu;
    private TextView dateau;
    private ArrayAdapter _adapter;*/

    const string applicationURL = @"url";
    const string applicationKey = @"key";
    public List<string> assignmatod { get; private set; }
    const string localDbFilename = "localstore.db";
    private ProgressDialog progress;

    protected override async void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.Layout_DemandeMat2);
        this.Window.AddFlags(WindowManagerFlags.Fullscreen);
        this.Window.ClearFlags(WindowManagerFlags.Fullscreen);
        //this.Title += " " + ;
        CurrentPlatform.Init();
        client = new MobileServiceClient(applicationURL);
        await InitLocalStoreAsync();
        ChantiersTable = client.GetSyncTable<Chantiers>();
        AssignMaterielTable = client.GetSyncTable<AssignMaterielDB>();
        MaterielTable = client.GetSyncTable<MaterielDB>();
        PersonnelTable = client.GetSyncTable<Personnel>();
        AlertMat = client.GetSyncTable<AlertMateriel>();
        // Create your application here


        await SyncAsync(pullData: true);
        string idass = Intent.GetStringExtra("IdAssignMat");
        AssignMaterielDB assign = await AssignMaterielTable.LookupAsync(idass);

        _table = FindViewById<TableLayout>(Resource.Id.table_main);
       TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(
            ViewGroup.LayoutParams.WrapContent,
            ViewGroup.LayoutParams.WrapContent
            );

        List<string> assignmatod = new List<string>();
        try
        {
            //string idass = Intent.GetStringExtra("IdAssignMat");
            string IdUser = Intent.GetStringExtra("IdUser");
            string Estcdt = Intent.GetStringExtra("iscdt");

            if (Estcdt == "True")
            {
                var thelist = await AssignMaterielTable.Where(idmat => idmat.Id == idass).Take(1).ToListAsync();

                //var thelist2 = await AssignPersonnelTable.Where(n => n.IdUser == IdUser).ToListAsync();

                foreach (AssignMaterielDB item in thelist)
                {

                    var chantier = await ChantiersTable.Where(idchat => idchat.Id == item.IdChantier).Take(1).ToListAsync();

                    var Matthelist = await MaterielTable.Where(Idmat => Idmat.Id == item.IdEngin).Take(1).ToListAsync();
                    foreach (MaterielDB mat in Matthelist)
                    {
                        foreach (Chantiers ch in chantier)
                        {
                            var listper = await PersonnelTable.Where(Idmat => Idmat.Id == ch.Cdt).ToListAsync();
                            foreach (Personnel pe in listper)
                            {
                                assignmatod.Add(item.Id);
                                TableRow tableR = new TableRow(this);
                                TextView text = new TextView(this);
                                text.SetText(ch.NomChantier.ToCharArray(), 0, ch.NomChantier.Length);
                                text.Gravity = GravityFlags.Center;
                                tableR.AddView(text,0);
                                TextView text2 = new TextView(this);
                                text2.Gravity = GravityFlags.Center;
                                string cdttr = pe.Pers_Prenom + " " + pe.Pers_Nom;
                                text2.SetText(cdttr.ToCharArray(), 0,cdttr.Length);
                                tableR.AddView(text2, 1);
                                TextView text3 = new TextView(this);
                                text3.Gravity = GravityFlags.Center;
                                text3.SetText(item.DateDebut.ToString("d").ToCharArray(), 0, item.DateDebut.ToString("d").Length);
                                tableR.AddView(text3, 2);
                                TextView text4 = new TextView(this);
                                text3.Gravity = GravityFlags.Center;
                                text4.SetText(item.DateFin.ToString("d").ToCharArray(), 0, item.DateFin.ToString("d").Length);
                                tableR.AddView(text4, 3);
                                tableR.Id =View.GenerateViewId();
                                tableR.Clickable = true;
                                idengin = item.IdEngin;
                                idassign = idass;
                                iddemandeur = IdUser;
                                idreceveur = ch.Cdt;
                                tableR.Click += HandleClick;
                                _table.AddView(tableR);
                                //    _listView.ItemClick += _listView_ItemClick;

                            }
                        }
                    }
                }
            }

            _adapter3 = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, assignmatod);

        }
        catch (MobileServiceInvalidOperationException e)
        {
            Console.Error.WriteLine(@"ERROR {0}", e.Message);
            //  return null;
        }


    }



    private   void HandleClick(object sender, EventArgs e)
     {
         var clickedTableRow = sender as TableRow;
         int s = clickedTableRow.Id;
         var tag = clickedTableRow.Tag;
        string ideng = idengin;
        string idass = idassign;
        string idrecev = idreceveur;
        string iddeman = iddemandeur;
         string arg = _adapter3.GetItem(s-1).ToString();
        string message = "Envoyer une demande pour cette engin sur la période concernée?";
       CreateAndShowDialogDemande(message, "DEMANDE ENGIN", ideng, iddeman, idass, idrecev);


       Toast.MakeText(this, tag + " idassign "+ s+ "arg " + arg, ToastLength.Long).Show();

     }


    private async void CreateAndShowDialogDemande(string message, string title, string idmat, string IdDemande, string IdAssignMat, string Idreceveur )
    {
        Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(this);
        string IdDuChantier = Intent.GetStringExtra("IdDuChantier");
        builder.SetMessage(message);
        builder.SetTitle(title);
        builder.Create();
        builder.SetPositiveButton("Faire la demande ?", async (senderAlert, args) =>
        {

            var Demande = new AlertMateriel
            {

                IdMateriel = idmat,
                IdDemandeur = IdDemande,
                IdAssignMat = IdAssignMat,
                IdReceveur = Idreceveur,
                VU = false,
                Deleted = "False",



            };
            try
            {
                progress = new Android.App.ProgressDialog(this);
                progress.Indeterminate = true;
                progress.SetProgressStyle(Android.App.ProgressDialogStyle.Spinner);
                progress.SetMessage("Envoie de la Demande ...");
                progress.SetCancelable(false);
                progress.Show();
                await AlertMat.InsertAsync(Demande);
                await SyncAsync(pullData: true);
                progress.Cancel();
                CreateAndShowDialog("Demande", "Votre demande a été envoyé...");
                // Toast.MakeText(this, "Votre demande a été envoyé", ToastLength.Long).Show();
                //await client.SyncContext.PushAsync();
            }
            catch (Exception e)
            {
                CreateAndShowDialog(e.ToString(), "Error");
            }



        });
        builder.SetNegativeButton("Annuler", (senderAlert, args) =>
        {
            builder.Dispose();
        });



        builder.Show();

    }

    private void CreateAndShowDialog(String title, string message)
    {
        Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(this);

        builder.SetMessage(message);
        builder.SetTitle(title);
        builder.SetNegativeButton("Rester sur la page", (senderAlert, args) =>
        {
            builder.Dispose();
        });
        builder.Create().Show();


    }


    private async Task InitLocalStoreAsync()
    {
        // new code to initialize the SQLite store
        string path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), localDbFilename);

        if (!File.Exists(path))
        {
            File.Create(path).Dispose();
        }

        var store = new MobileServiceSQLiteStore(path);
        store.DefineTable<AlertMateriel>();
        store.DefineTable<Personnel>();
        store.DefineTable<Chantiers>();
        store.DefineTable<AssignMaterielDB>();
        store.DefineTable<MaterielDB>();

        // Uses the default conflict handler, which fails on conflict
        // To use a different conflict handler, pass a parameter to InitializeAsync. For more details, see http://go.microsoft.com/fwlink/?LinkId=521416
        await client.SyncContext.InitializeAsync(store);
    }
    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
        AuthenticationAgentContinuationHelper.SetAuthenticationAgentContinuationEventArgs(requestCode, resultCode, data);
    }


    private async Task SyncAsync(bool pullData = false)
    {
        try
        {
            await client.SyncContext.PushAsync();

            await ChantiersTable.PullAsync("allTodoItems", ChantiersTable.CreateQuery()); // query ID is used for incremental sync
            await AssignMaterielTable.PullAsync("allMat", AssignMaterielTable.CreateQuery());
            await MaterielTable.PullAsync("alltvx", MaterielTable.CreateQuery());
            await PersonnelTable.PullAsync("allUsers", PersonnelTable.CreateQuery());
            await AlertMat.PullAsync("AlertMateirel", AlertMat.CreateQuery());
        }
        catch (Java.Net.MalformedURLException)
        {
            CreateAndShowDialog("", "Error");
        }
        catch (Exception e)
        {
            CreateAndShowDialog( "Error", e.ToString());
        }
    }
}}

例外:

MobileServiceInvalidOperationException Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. 04-13 09:59:47.656 I/mono-stdout( 3806): Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient+<ThrowInvalidResponse>d__18.MoveNext () [0x0022f] in <7e121fd8cdc34770a425d1c0c9715a23>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 at System.Runtime.Comp ilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 04-13 09:59:47.656 I/mono-stdout( 3806): at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient+<ThrowInvalidResponse>d__18.MoveNext () [0x0022f] in <7e121fd8cdc34770a425d1c0c9715a23>:0 04-13 09:59:47.656 I/mono-stdout( 3806): --- End of stack trace from previous location where exception was thrown --- 04-13 09:59:47.656 I/mono-stdout( 3806): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 04-13 09:59:47.656 I/mono-stdout( 3806): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 04-13 09:59:47.656 I/mono-stdout( 3806): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 04-13 09:59:47.656 I/mono-stdout( 3806): at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 04-13 09:59:47.656 I/mono-stdout( 3806): at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 04-13 09:59:47.656 I/mono-stdout( 3806): at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient+<SendRequestAsync>d__1d.MoveNext () [0x0010d] in <7e121fd8cdc34770a425d1c0c9715a23>:0 04-13 09:59:47.656 I/mono-stdout( 3806): --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient+<SendRequestAsync>d__1d.MoveNext () [0x0010d] in <7e121fd8cdc34770a425d1c0c9715a23>:0

如果缺少某些内容或需要更多详细信息,请与我们联系。

先谢谢你。

0 个答案:

没有答案