Exemplo n.º 1
0
        public WorldObjectBase(int descriptorLength)
        {
            descriptors = new DescriptorData(descriptorLength);

            // Use 'this' for mono compatibility.
            this.ObjectData = new ObjectData();
        }
Exemplo n.º 2
0
 public SelectCursorPathTool(AdventureData adventureData, int t)
     : base(createResources(adventureData, t), createAssetInfoArray(t), Controller.ACTION_CUSTOM, 0)
 {
     this.adventureData = adventureData;
     this.t             = t;
     this.type          = DescriptorData.getCursorTypeString(t);
 }
Exemplo n.º 3
0
        public static void WriteToBuffer(this DescriptorData d, string txt, int length)
        {
            if (d == null)
            {
                throw new ArgumentNullException(nameof(d));
            }

            if (string.IsNullOrEmpty(d.outbuf))
            {
                return;
            }

            var len = length;

            if (len <= 0)
            {
                len = txt.Length;
            }

            if (d.outtop == 0 && !d.fcommand)
            {
                d.outbuf = "\r\n" + d.outbuf;
                d.outtop = 2;
            }

            d.outtop += len;
            d.outbuf  = txt;
        }
Exemplo n.º 4
0
        public static void ShowTitle(this DescriptorData d)
        {
            var ch = d.Character;

            if (ch.PlayerData.Flags.IsSet(PCFlags.NoIntro))
            {
                d.WriteToBuffer("Press enter...", 0);
            }
            else
            {
                if (ch.Act.IsSet((int)PlayerFlags.Rip))
                {
                    ch.SendRIPTitle();
                }
                else if (ch.Act.IsSet((int)PlayerFlags.Ansi))
                {
                    ch.SendANSITitle();
                }
                else
                {
                    ch.SendASCIITitle();
                }
            }

            d.ConnectionStatus = ConnectionTypes.PressEnter;
        }
Exemplo n.º 5
0
        protected static AssetInformation[] createAssetInfoArray(int t)
        {
            string type = DescriptorData.getCursorTypeString(t);

            AssetInformation[] array = new AssetInformation[1];
            array[0] = new AssetInformation("", type, true, AssetsConstants.CATEGORY_CURSOR, AssetsController.FILTER_NONE);
            return(array);
        }
Exemplo n.º 6
0
 private static void CheckStateIsNot(EntityStates state, DescriptorData descriptorData, string errorMessage, string argumentName)
 {
     if (descriptorData.State == state)
     {
         throw new TaupoInvalidOperationException(
                   string.Format(CultureInfo.InvariantCulture, "{0} {1} is in {2} state.", errorMessage, argumentName, state));
     }
 }
Exemplo n.º 7
0
            private void ApplyResponseAndUpdateState(DescriptorData descriptor, KeyValuePair <IHttpRequest, HttpResponseData> pair)
            {
                this.ApplyResponseToDescriptor(descriptor, pair.Value);

                if (!pair.Value.StatusCode.IsError())
                {
                    this.UpdateDescriptorState(descriptor);
                }
            }
Exemplo n.º 8
0
        private static void ConnectUser(ITcpUser user)
        {
            var descrip = new DescriptorData(9999, 9999, 9999)
            {
                User = user
            };

            db.DESCRIPTORS.Add(descrip);
        }
Exemplo n.º 9
0
        public static void SendTo(this DescriptorData d, string txt)
        {
            if (d == null || string.IsNullOrEmpty(txt))
            {
                return;
            }

            d.WriteToBuffer(color.colorize(txt, d), 0);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Converts a string with color tokens into the desired output tokens
        /// using the Character's desired preferences
        /// </summary>
        /// <param name="txt"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        public static string colorize(string txt, DescriptorData d)
        {
            if (string.IsNullOrEmpty(txt) || d == null)
            {
                return(string.Empty);
            }

            // TODO finish this
            return(string.Empty);
        }
Exemplo n.º 11
0
        public static void display_prompt(DescriptorData d)
        {
            var ch     = d.Character;
            var och    = d.Original ?? d.Character;
            var buffer = string.Empty;

            var ansi = !och.IsNpc() && och.Act.IsSet((int)PlayerFlags.Ansi);

            const string helpstart = "<Type HELP START>";

            if (ch == null)
            {
                LogManager.Instance.Bug("Null ch");
                return;
            }

            string prompt;

            if (!ch.IsNpc() && !ch.PlayerData.Flags.IsSet(PCFlags.HelpStart))
            {
                prompt = helpstart;
            }
            else if (!ch.IsNpc() && ch.SubState != CharacterSubStates.None &&
                     !ch.PlayerData.SubPrompt.IsNullOrEmpty())
            {
                prompt = ch.PlayerData.SubPrompt;
            }
            else if (ch.IsNpc() || (ch.CurrentFighting == null && ch.PlayerData.Prompt.IsNullOrEmpty()))
            {
                prompt = default_prompt(ch);
            }
            else if (ch.CurrentFighting != null)
            {
                prompt = ch.PlayerData.FPrompt.IsNullOrEmpty()
                             ? default_fprompt(ch)
                             : ch.PlayerData.FPrompt;
            }
            else
            {
                prompt = ch.PlayerData.Prompt;
            }

            if (ansi)
            {
                prompt      = prompt.Insert(0, AnsiCodes.Reset.GetName());
                d.prevcolor = Convert.ToChar(0x08);
            }

            // Clear out old color stuff
            {
                // TODO
            }

            ch.SendTo(buffer);
        }
Exemplo n.º 12
0
 public CursorsWindow(Rect rect, GUIContent content, GUIStyle style, params GUILayoutOption[] options)
     : base(rect, content, style)
 {
     Options       = options;
     ButtonContent = new GUIContent("Cursors");
     cursors       = new List <CursorInfo>();
     foreach (var cursor in DescriptorData.getCursorTypes())
     {
         cursors.Add(new CursorInfo(cursor));
     }
 }
 public ButtonsWindow(Rect rect, GUIContent content, GUIStyle style, params GUILayoutOption[] options)
     : base(rect, content, style)
 {
     Options       = options;
     ButtonContent = new GUIContent("Buttons");
     buttons       = new List <ButtonInfo>();
     foreach (var button in DescriptorData.getActionTypes())
     {
         buttons.Add(new ButtonInfo(button));
     }
 }
Exemplo n.º 14
0
            private void UpdateResponse(DataServiceResponseData responseData, DescriptorData descriptor, HttpResponseData response)
            {
                var operationResponse = new ChangeOperationResponseData(descriptor);

                operationResponse.StatusCode = (int)response.StatusCode;
                foreach (var header in response.Headers)
                {
                    operationResponse.Headers.Add(header.Key, header.Value);
                }

                responseData.Add(operationResponse);
            }
Exemplo n.º 15
0
    public virtual object Clone()
    {
        //TODO the keepShowing is now no included due to decide the final situation
        DescriptorData dd = (DescriptorData)this.MemberwiseClone();

        if (buttons != null)
        {
            dd.buttons = new List <CustomButton>();
            foreach (CustomButton cb in buttons)
            {
                dd.buttons.Add((CustomButton)cb.Clone());
            }
        }
        dd.commentaries = commentaries;
        if (contents != null)
        {
            dd.contents = new List <ChapterSummary>();
            foreach (ChapterSummary cs in contents)
            {
                dd.contents.Add((ChapterSummary)cs.Clone());
            }
        }
        if (cursors != null)
        {
            dd.cursors = new List <CustomCursor>();
            foreach (CustomCursor cc in cursors)
            {
                dd.cursors.Add((CustomCursor)cc.Clone());
            }
        }
        if (arrows != null)
        {
            dd.arrows = new List <CustomArrow>();
            foreach (CustomArrow ca in arrows)
            {
                dd.arrows.Add((CustomArrow)ca.Clone());
            }
        }
        dd.description       = (description != null ? description : null);
        dd.graphicConfig     = graphicConfig;
        dd.guiCustomized     = guiCustomized;
        dd.guiType           = guiType;
        dd.playerMode        = playerMode;
        dd.playerName        = (playerName != null ? playerName : null);
        dd.title             = (title != null ? title : null);
        dd.inventoryPosition = inventoryPosition;
        return(dd);
    }
Exemplo n.º 16
0
        private void VerifyDescriptor(DescriptorData expected, Descriptor actual, int responseOrder)
        {
            EntityDescriptorData entityDescriptorData = expected as EntityDescriptorData;
            LinkDescriptorData   linkDescriptorData   = expected as LinkDescriptorData;
            StreamDescriptorData streamDescriptorData = expected as StreamDescriptorData;

            if (entityDescriptorData != null)
            {
                EntityDescriptor entityDescriptor = actual as EntityDescriptor;
                this.Assert.IsNotNull(entityDescriptor, GetVerificationFailureMessage(responseOrder, "Unexpected descriptor type:\r\nExpected: {0}\r\nActual:   {1}\r\nExpected descriptor data: {2}.", typeof(EntityDescriptor).Name, actual.GetType().Name, entityDescriptorData));

                this.Assert.AreSame(
                    entityDescriptorData.Entity,
                    entityDescriptor.Entity,
                    GetVerificationFailureMessage(responseOrder, "Entity verification failed for the entity descriptor data: {0}.", expected));
            }
            else if (linkDescriptorData != null)
            {
                LinkDescriptor linkDescriptor = actual as LinkDescriptor;
                this.Assert.IsNotNull(linkDescriptor, GetVerificationFailureMessage(responseOrder, "Unexpected descriptor type:\r\nExpected: {0}\r\nActual:   {1}\r\nExpected descriptor data: {2}.", typeof(LinkDescriptor).Name, actual.GetType().Name, linkDescriptorData));

                bool notMatch = linkDescriptorData.SourceDescriptor.Entity != linkDescriptor.Source ||
                                (linkDescriptorData.TargetDescriptor == null && linkDescriptor.Target != null) ||
                                (linkDescriptorData.TargetDescriptor != null && linkDescriptorData.TargetDescriptor.Entity != linkDescriptor.Target) ||
                                linkDescriptorData.SourcePropertyName != linkDescriptor.SourceProperty;

                this.Assert.IsFalse(notMatch, GetVerificationFailureMessage(responseOrder, "Link verification failed.\r\nExpected: {0}\r\nActual:   {1}", linkDescriptorData, linkDescriptor.ToTraceString()));
            }
            else
            {
#if WINDOWS_PHONE
                throw new TaupoNotSupportedException("StreamDescriptors are not supported on Windows Phone");
#else
                ExceptionUtilities.CheckObjectNotNull(streamDescriptorData, "Expected was not an entity, link, or stream descriptor: {0}", expected);

                StreamDescriptor streamDescriptor = actual as StreamDescriptor;

                this.Assert.IsNotNull(streamDescriptor, GetVerificationFailureMessage(responseOrder, "Unexpected descriptor type:\r\nExpected: {0}\r\nActual:   {1}\r\nExpected descriptor data: {2}.", typeof(StreamDescriptor).Name, actual.GetType().Name, streamDescriptorData));

                this.Assert.AreEqual(streamDescriptorData.State.ToProductEnum(), streamDescriptor.State, GetVerificationFailureMessage(responseOrder, "Stream descriptor state verification failed."));
                this.Assert.AreEqual(streamDescriptorData.Name, streamDescriptor.StreamLink.Name, GetVerificationFailureMessage(responseOrder, "Stream descriptor name verification failed."));
                this.Assert.AreEqual(streamDescriptorData.ETag, streamDescriptor.StreamLink.ETag, GetVerificationFailureMessage(responseOrder, "Stream descriptor etag verification failed."));
                this.Assert.AreEqual(streamDescriptorData.ContentType, streamDescriptor.StreamLink.ContentType, GetVerificationFailureMessage(responseOrder, "Stream descriptor content type verification failed."));
                this.Assert.AreEqual(streamDescriptorData.EditLink, streamDescriptor.StreamLink.EditLink, GetVerificationFailureMessage(responseOrder, "Stream descriptor edit link verification failed."));
                this.Assert.AreEqual(streamDescriptorData.SelfLink, streamDescriptor.StreamLink.SelfLink, GetVerificationFailureMessage(responseOrder, "Stream descriptor self link verification failed."));
#endif
            }
        }
Exemplo n.º 17
0
    /**
     * Loads the descriptor of the current ZIP adventure loaded
     *
     * @return The descriptor data of the game
     */
    public static DescriptorData loadDescriptorData(InputStreamCreator isCreator, List <Incidence> incidences)
    {
        DescriptorData descriptorData = null;

        if (Loader.adventureData != null)
        {
            descriptorData = Loader.adventureData;
        }
        else
        {
            try
            {
                // Set the adventure handler
                DescriptorHandler descriptorParser = new DescriptorHandler(isCreator);

                //factory.setValidating(false);
                //SAXParser saxParser = factory.newSAXParser();

                // Read and close the inputstrea
                string descriptorIS = isCreator.buildInputStream("descriptor.xml");
                //saxParser.parse(descriptorIS, descriptorParser);
                //descriptorIS.close();
                descriptorParser.Parse(descriptorIS);

                // Store the adventure data
                descriptorData = descriptorParser.getGameDescriptor();
            }
            catch (Exception e) { Debug.LogError(e); }

            //catch (ParserConfigurationException e)
            //{
            //    incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e));
            //}
            //catch (SAXException e)
            //{
            //    incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e));
            //}
            //catch (IOException e)
            //{
            //    incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.IO"), e));
            //}
            //catch (IllegalArgumentException e)
            //{
            //    incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.NoDescriptor"), e));
            //}
        }
        return(descriptorData);
    }
Exemplo n.º 18
0
        public static void WriteToPager(this DescriptorData d, string txt, int length)
        {
            var len = length <= 0 ? txt.Length : length;

            if (len == 0)
            {
                return;
            }

            if (string.IsNullOrEmpty(d.PageBuffer))
            {
                d.PageSize   = Program.MAX_STRING_LENGTH;
                d.PageBuffer = new string('\0', d.PageSize);
            }
            if (string.IsNullOrEmpty(d.PagePoint))
            {
                d.PagePoint   = d.PageBuffer;
                d.PageTop     = 0;
                d.PageCommand = "";
            }
            if (d.PageTop == 0 && !d.fcommand)
            {
                var bufferArray = d.PageBuffer.ToCharArray();
                bufferArray[0] = '\r';
                bufferArray[1] = '\n';
                d.PageTop      = 2;
                d.PageBuffer   = bufferArray.ToString();
            }

            //int pagerOffset = d.PagePoint - d.PageBuffer;
            while (d.PageTop + len >= d.PageSize)
            {
                if (d.PageSize > Program.MAX_STRING_LENGTH * 16)
                {
                    LogManager.Instance.Bug("Pager overflow. Ignoring.\r\n");
                    d.PageTop    = 0;
                    d.PagePoint  = string.Empty;
                    d.PageBuffer = string.Empty;
                    d.PageSize   = Program.MAX_STRING_LENGTH;
                    return;
                }

                d.PageSize *= 2;
                // recreate?
            }

            // TODO finish this
        }
        private ChangeData CreateChangeData(DescriptorData descriptorData, IDictionary <object, IEnumerable <NamedValue> > propertyValuesBeforeSave)
        {
            var entityDescriptorData = descriptorData as EntityDescriptorData;

            if (entityDescriptorData != null)
            {
                IEnumerable <NamedValue> propertyValues;
                ExceptionUtilities.Assert(propertyValuesBeforeSave.TryGetValue(entityDescriptorData.Entity, out propertyValues), "Could not find property values for descriptor: {0}", entityDescriptorData);

                return(EntityChangeData.Create(entityDescriptorData, propertyValues));
            }

            var linkDescriptorData = descriptorData as LinkDescriptorData;

            ExceptionUtilities.CheckObjectNotNull(linkDescriptorData, "Descriptor was neither an entity nor a link");

            return(LinkChangeData.Create(linkDescriptorData));
        }
Exemplo n.º 20
0
            private static void SetContentIDHeader(DescriptorData descriptor, ExpectedClientRequest expectedRequest, bool isBatch)
            {
                if (isBatch)
                {
                    expectedRequest.Headers[HttpHeaders.ContentId] = descriptor.ChangeOrder.ToString(CultureInfo.InvariantCulture);
                    var entityDescriptorData = descriptor as EntityDescriptorData;

                    if (entityDescriptorData != null && entityDescriptorData.Identity == null)
                    {
                        entityDescriptorData.Identity = new Uri("$" + descriptor.ChangeOrder, UriKind.Relative);
                        entityDescriptorData.EditLink = entityDescriptorData.Identity;
                    }
                }
                else
                {
                    expectedRequest.Headers[HttpHeaders.ContentId] = null;
                }
            }
        public void deleteCursor(int type)
        {
            string typeS    = DescriptorData.getCursorTypeString(type);
            int    position = -1;

            for (int i = 0; i < adventureData.getCursors().Count; i++)
            {
                if (adventureData.getCursors()[i].getType().Equals(typeS))
                {
                    position = i;
                    break;
                }
            }
            if (position >= 0)
            {
                Controller.getInstance().addTool(new DeleteCursorTool(adventureData, position));
            }
        }
Exemplo n.º 22
0
            private void ApplyResponseToDescriptor(DescriptorData descriptor, HttpResponseData response)
            {
                var entityDescriptor = descriptor as EntityDescriptorData;
                var streamDescriptor = descriptor as StreamDescriptorData;

                if (entityDescriptor != null)
                {
                    if (entityDescriptor.IsMediaLinkEntry && entityDescriptor.DefaultStreamState == EntityStates.Modified)
                    {
                        // in this case (and only this case), the response headers apply to the stream itself
                        entityDescriptor.DefaultStreamDescriptor.UpdateFromHeaders(response.Headers);
                    }
                    else
                    {
                        entityDescriptor.UpdateFromHeaders(response.Headers);
                    }

                    if (response.StatusCode != HttpStatusCode.NoContent)
                    {
                        var entityInstance = response.DeserializeAndCast <EntityInstance>(this.parent.FormatSelector);
                        entityDescriptor.UpdateFromPayload(entityInstance, this.contextData.BaseUri);
                    }

                    if (entityDescriptor.IsMediaLinkEntry && entityDescriptor.DefaultStreamState != EntityStates.Unchanged)
                    {
                        this.VerifyStreamClosed(entityDescriptor.DefaultStreamDescriptor);
                    }
                }
                else
                {
                    if (streamDescriptor != null)
                    {
                        streamDescriptor.UpdateFromHeaders(response.Headers);
                        this.VerifyStreamClosed(streamDescriptor);
                    }
                    else
                    {
                        ExceptionUtilities.Assert(descriptor is LinkDescriptorData, "Descriptor is of unexpected type '{0}'", descriptor.GetType());
                    }
                }
            }
Exemplo n.º 23
0
        protected static ResourcesUni createResources(AdventureData adventureData, int t)
        {
            string       type       = DescriptorData.getCursorTypeString(t);
            ResourcesUni resources  = new ResourcesUni();
            bool         introduced = false;

            for (int i = 0; i < adventureData.getCursors().Count; i++)
            {
                if (adventureData.getCursors()[i].getType().Equals(type) && adventureData.getCursors()[i].getPath() != null)
                {
                    resources.addAsset(type, adventureData.getCursors()[i].getPath());
                    introduced = true;
                    break;
                }
            }

            if (!introduced)
            {
                resources.addAsset(type, null);
            }

            return(resources);
        }
 public string getCursorPath(int type)
 {
     return(getCursorPath(DescriptorData.getCursorTypeString(type)));
 }
 public bool isCursorTypeAllowed(string type)
 {
     return(isCursorTypeAllowed(DescriptorData.getCursorTypeIndex(type)));
 }
Exemplo n.º 26
0
		/// <summary>
		/// Test an archive for integrity/validity
		/// </summary>
		/// <param name="testData">Perform low level data Crc check</param>
		/// <param name="strategy">The <see cref="TestStrategy"></see> to apply.</param>
		/// <param name="resultHandler">The <see cref="ZipTestResultHandler"></see> handler to call during testing.</param>
		/// <returns>true if all tests pass, false otherwise</returns>
		/// <exception cref="ObjectDisposedException">The object has already been closed.</exception>
		public bool TestArchive(bool testData, TestStrategy strategy, ZipTestResultHandler resultHandler)
		{
			if (isDisposed_) {
				throw new ObjectDisposedException("ZipFile");
			}
			
			TestStatus status = new TestStatus(this);

			if ( resultHandler != null ) {
				resultHandler(status, null);
			}

			HeaderTest test = testData ? (HeaderTest.Header | HeaderTest.Extract) : HeaderTest.Header;

			bool testing = true;

			try {
				int entryIndex = 0;

				while ( testing && (entryIndex < Count) ) {
					if ( resultHandler != null ) {
						status.SetEntry(this[entryIndex]);
						status.SetOperation(TestOperation.EntryHeader);
						resultHandler(status, null);
					}

					try	{
						TestLocalHeader(this[entryIndex], test);
					}
					catch(ZipException ex) {
						status.AddError();

						if ( resultHandler != null ) {
							resultHandler(status,
								string.Format("Exception during test - '{0}'", ex.Message));
						}

						if ( strategy == TestStrategy.FindFirstError ) {
							testing = false; 
						}
					}

					if ( testing && testData && this[entryIndex].IsFile ) {
						if ( resultHandler != null ) {
							status.SetOperation(TestOperation.EntryData);
							resultHandler(status, null);
						}

                        Crc32 crc = new Crc32();

                        using (Stream entryStream = this.GetInputStream(this[entryIndex]))
                        {

                            byte[] buffer = new byte[4096];
                            long totalBytes = 0;
                            int bytesRead;
                            while ((bytesRead = entryStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                crc.Update(buffer, 0, bytesRead);

                                if (resultHandler != null)
                                {
                                    totalBytes += bytesRead;
                                    status.SetBytesTested(totalBytes);
                                    resultHandler(status, null);
                                }
                            }
                        }

						if (this[entryIndex].Crc != crc.Value) {
							status.AddError();
							
							if ( resultHandler != null ) {
								resultHandler(status, "CRC mismatch");
							}

							if ( strategy == TestStrategy.FindFirstError ) {
								testing = false;
							}
						}

						if (( this[entryIndex].Flags & (int)GeneralBitFlags.Descriptor) != 0 ) {
							ZipHelperStream helper = new ZipHelperStream(baseStream_);
							DescriptorData data = new DescriptorData();
							helper.ReadDataDescriptor(this[entryIndex].LocalHeaderRequiresZip64, data);
							if (this[entryIndex].Crc != data.Crc) {
								status.AddError();
							}

							if (this[entryIndex].CompressedSize != data.CompressedSize) {
								status.AddError();
							}

							if (this[entryIndex].Size != data.Size) {
								status.AddError();
							}
						}
					}

					if ( resultHandler != null ) {
						status.SetOperation(TestOperation.EntryComplete);
						resultHandler(status, null);
					}

					entryIndex += 1;
				}

				if ( resultHandler != null ) {
					status.SetOperation(TestOperation.MiscellaneousTests);
					resultHandler(status, null);
				}

				// TODO: the 'Corrina Johns' test where local headers are missing from
				// the central directory.  They are therefore invisible to many archivers.
			}
			catch (Exception ex) {
				status.AddError();

				if ( resultHandler != null ) {
					resultHandler(status, string.Format("Exception during test - '{0}'", ex.Message));
				}
			}

			if ( resultHandler != null ) {
				status.SetOperation(TestOperation.Complete);
				status.SetEntry(null);
				resultHandler(status, null);
			}

			return (status.ErrorCount == 0);
		}
Exemplo n.º 27
0
 /**
  * Constructor
  */
 public DescriptorHandler(InputStreamCreator isCreator)
 {
     currentstring = string.Empty;
     gameDescriptor = new DescriptorData();
     this.isCreator = isCreator;
 }
Exemplo n.º 28
0
 public static int colorcode(string src, string dst, DescriptorData d, int dstlen, int vislen)
 {
     // TODO
     return(0);
 }
        /// <summary>
        /// Calculates expected data for a request during DataServiceContext.SaveChanges for a particular descriptor.
        /// </summary>
        /// <param name="contextData">The context data</param>
        /// <param name="propertyValuesBeforeSave">The property values of the tracked client objects before the call to SaveChanges</param>
        /// <param name="descriptorData">The descriptor data</param>
        /// <param name="options">The save changes options</param>
        /// <returns>The expected client request</returns>
        public ExpectedClientRequest CalculateRequest(DataServiceContextData contextData, IDictionary <object, IEnumerable <NamedValue> > propertyValuesBeforeSave, DescriptorData descriptorData, SaveChangesOptions options)
        {
            ExceptionUtilities.CheckArgumentNotNull(contextData, "contextData");
            ExceptionUtilities.CheckArgumentNotNull(descriptorData, "descriptorData");
            ExceptionUtilities.CheckArgumentNotNull(propertyValuesBeforeSave, "propertyValuesBeforeSave");

            var linkDescriptorData   = descriptorData as LinkDescriptorData;
            var entityDescriptorData = descriptorData as EntityDescriptorData;
            var streamDescriptorData = descriptorData as StreamDescriptorData;

            ExpectedClientRequest request = null;

            if (linkDescriptorData != null)
            {
                if (linkDescriptorData.WillTriggerSeparateRequest())
                {
                    request = this.CreateLinkRequest(linkDescriptorData, options);
                }
            }
            else if (entityDescriptorData != null)
            {
                if (entityDescriptorData.State == EntityStates.Added)
                {
                    request = this.CreateEntityInsertRequest(contextData, propertyValuesBeforeSave, entityDescriptorData, options);
                }
                else if (entityDescriptorData.State == EntityStates.Modified)
                {
                    request = this.CreateEntityUpdateRequest(contextData, propertyValuesBeforeSave, entityDescriptorData, options);
                }
                else if (entityDescriptorData.State == EntityStates.Deleted)
                {
                    request = this.CreateEntityDeleteRequest(entityDescriptorData, options);
                }
            }
            else if (streamDescriptorData != null)
            {
                if (streamDescriptorData.State == EntityStates.Added)
                {
                    request = this.CreateStreamInsertRequest(contextData, streamDescriptorData, options);
                }
                else if (streamDescriptorData.State == EntityStates.Modified)
                {
                    request = this.CreateStreamUpdateRequest(streamDescriptorData, options);
                }
            }

            if (request != null)
            {
                request.Headers[HttpHeaders.MaxDataServiceVersion] = ToClientHeaderFormat(contextData.MaxProtocolVersion);

                // perform sanity checks
                var missingHeaders = headersThatWillBeGenerated.Where(h => !request.Headers.ContainsKey(h)).ToArray();
                ExceptionUtilities.Assert(missingHeaders.Length == 0, "Generated request was missing headers: {0}", string.Join(", ", missingHeaders));
                ExceptionUtilities.CheckObjectNotNull(request.Uri, "Generated request was missing a Uri");

                // sanity check: Client sends content-type header for delete request
                if (request.GetEffectiveVerb() == HttpVerb.Delete)
                {
                    ExceptionUtilities.Assert(
                        request.Headers[HttpHeaders.ContentType] == null,
                        "Incorrect expectation: client should never send ContentType header for DELETE requests.");
                }
            }

            return(request);
        }
Exemplo n.º 30
0
 /**
  * Constructor
  */
 public DescriptorHandler(InputStreamCreator isCreator)
 {
     currentstring  = string.Empty;
     gameDescriptor = new DescriptorData();
     this.isCreator = isCreator;
 }
Exemplo n.º 31
0
 public static bool pager_output(DescriptorData d)
 {
     // TODO
     return(false);
 }
Exemplo n.º 32
0
 public static void set_pager_input(DescriptorData d, string argument)
 {
     d.PageCommand = argument.Trim();
 }