Beispiel #1
0
        private void Write(AddAsyncMediaMethod method)
        {
            WriteSignature(method);
            using (_builder.IndentBraced)
            {
                _("if (Entity == null)");

                using (_builder.IndentBraced)
                {
                    _("Context.AddObject(Path, item);");
                }

                _("else");

                using (_builder.IndentBraced)
                {
                    _("var lastSlash = Path.LastIndexOf('/');");
                    _("var shortPath = (lastSlash >= 0 && lastSlash < Path.Length - 1) ? Path.Substring(lastSlash + 1) : Path;");
                    _("Context.AddRelatedObject(Entity, shortPath, item);");
                }

                _("Context.SetSaveStream(item, stream, closeStream, new DataServiceRequestArgs()");
                _("{");
                using (_builder.Indent)
                {
                    _("ContentType = contentType");
                }
                _("});");

                _("if (!deferSaveChanges)");

                using (_builder.IndentBraced)
                {
                    _("return Context.SaveChangesAsync();");
                }

                _("else");

                using (_builder.IndentBraced)
                {
                    _("var retVal = new global::System.Threading.Tasks.TaskCompletionSource<object>();");
                    _("retVal.SetResult(null);");
                    _("return retVal.Task;");
                }
            }
        }
Beispiel #2
0
        private void Write(AddAsyncMediaMethod method)
        {
            WriteSignature(method);
            using (_builder.IndentBraced)
            {
                _("if (Entity == null)");

                using (_builder.IndentBraced)
                {
                    _("Context.AddObject(Path, item);");
                }

                _("else");

                using (_builder.IndentBraced)
                {
                    _("var lastSlash = Path.LastIndexOf('/');");
                    _("var shortPath = (lastSlash >= 0 && lastSlash < Path.Length - 1) ? Path.Substring(lastSlash + 1) : Path;");
                    _("Context.AddRelatedObject(Entity, shortPath, item);");
                }

                _("Context.SetSaveStream(item, stream, closeStream, new DataServiceRequestArgs()");
                _("{");
                using (_builder.Indent)
                {
                    _("ContentType = contentType");
                }
                _("});");

                _("if (!deferSaveChanges)");

                using (_builder.IndentBraced)
                {
                    _("return Context.SaveChangesAsync();");
                }

                _("else");

                using (_builder.IndentBraced)
                {
                    _("var retVal = new global::System.Threading.Tasks.TaskCompletionSource<object>();");
                    _("retVal.SetResult(null);");
                    _("return retVal.Task;");
                }
            }
        }