Exemplo n.º 1
0
        public bool Compare(LargeStream other)
        {
            if (this.content == other.content && this.length == other.length)
            {
                return(true);
            }

            return(false);
        }
        public Stream GetWriteStream(object entity, string etag, bool? checkETagForEquality, DataServiceOperationContext operationContext)
        {
            this.ThrowIfDisposed();
            CallOrderLog += "-GetWriteStream";
            bool returnEmptyStream;
            if (!operationContext.IsBatchRequest || !operationContext.AbsoluteServiceUri.MakeRelativeUri(operationContext.AbsoluteRequestUri).OriginalString.StartsWith("$"))
            {
                CheckETag(entity, etag, checkETagForEquality, operationContext, out returnEmptyStream);
            }

            string slug = operationContext.RequestHeaders["Slug"];
            if (entity.GetType() == typeof(Photo))
            {
                Photo p = (Photo)entity;

                if (operationContext.RequestMethod.Equals("POST", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(slug))
                {
                    int id;
                    if (int.TryParse(slug, out id))
                    {
                        p.ID = id;
                    }
                    else
                    {
                        p.Description = slug;
                    }
                }
            }
            else if (entity.GetType() == typeof(NorthwindModel.Customers))
            {
                NorthwindModel.Customers c = (NorthwindModel.Customers)entity;

                if (operationContext.RequestMethod.Equals("POST", StringComparison.OrdinalIgnoreCase))
                {
                    Random rand = TestUtil.Random;
                    c.CustomerID = "C" + rand.Next(1000, 9999).ToString();
                    c.CompanyName = "Microsoft";

                    if (!string.IsNullOrEmpty(slug))
                    {
                        c.CustomerID = slug;
                    }
                }
            }
            else if (entity.GetType() == typeof(NorthwindModel.Orders))
            {
                NorthwindModel.Orders o = (NorthwindModel.Orders)entity;
                if (operationContext.RequestMethod.Equals("POST", StringComparison.OrdinalIgnoreCase))
                {
                    Random rand = TestUtil.Random;
                    o.OrderID = rand.Next(1000, 9999);
                }
            }
            else if (entity.GetType() == typeof(RowEntityTypeWithIDAsKey) && (((RowEntityTypeWithIDAsKey)entity).TypeName == CustomRowBasedContext.CustomerFullName || ((RowEntityTypeWithIDAsKey)entity).TypeName == CustomRowBasedContext.CustomerWithBirthdayFullName))
            {
                int id;
                if (int.TryParse(slug, out id))
                {
                    ((RowEntityTypeWithIDAsKey)entity).ID = id;
                }
                else
                {
                    ((RowEntityTypeWithIDAsKey)entity).ID = TestUtil.Random.Next(1000, 9999);
                }
            }
            else if (entity.GetType() == typeof(RowComplexType) && (((RowComplexType)entity).TypeName == "AstoriaUnitTests.Stubs.Customer" || ((RowComplexType)entity).TypeName == "AstoriaUnitTests.Stubs.CustomerWithBirthday"))
            {
                int id;
                if (int.TryParse(slug, out id))
                {
                    ((RowComplexType)entity).Properties["ID"] = id;
                }
                else
                {
                    ((RowComplexType)entity).Properties["ID"] = TestUtil.Random.Next(1000, 9999);
                }
            }

            ValidateArguments(entity, operationContext);
            SetCustomResponseHeaders(operationContext);

            Stream s;
            switch (DataServiceStreamProvider.ProviderStorageMode)
            {
                case StorageMode.Disk:
                    s = File.Open(GetStoragePath(entity), FileMode.Create, FileAccess.Write);
                    break;
                case StorageMode.LargeStream:
                    s = new LargeStream();
                    LargeStreamStorage[GetStoragePath(entity)] = (LargeStream)s;
                    break;
                default:
                    throw new InvalidOperationException("Unknown StorageMode!");
            }

            GetWriteStreamCalled = true;
            return s;
        }
Exemplo n.º 3
0
        public bool Compare(LargeStream other)
        {
            if (this.content == other.content && this.length == other.length)
            {
                return true;
            }

            return false;
        }