public void Insert(SyncResultEntryInfo[] infos, IJetTransaction jetTransaction)
        {
            OleDbCommand oleDbCommand = jetTransaction.CreateOleCommand();

            string sqlQuery = string.Empty;
            sqlQuery = "INSERT INTO {0} ([HttpMethod], [HttpStatus], [HttpMessage], [HttpLocation], [Diagnoses], [Payload], [Endpoint], [Stamp]) VALUES (@HttpMethod, @HttpStatus, @HttpMessage, @HttpLocation, @Diagnoses, @Payload, @Endpoint, @Stamp);";

            oleDbCommand.CommandText = string.Format(sqlQuery, _syncResultsTable.TableName);

            foreach (SyncResultEntryInfo info in infos)
            {
                // TODO: Use prepared query
                //oleDbCommand.Parameters.Clear();
                oleDbCommand.Parameters.AddWithValue("@HttpMethod", info.HttpMethod);
                oleDbCommand.Parameters.AddWithValue("@HttpStatus", info.HttpStatus);
                if (null != info.HttpMessage) oleDbCommand.Parameters.AddWithValue("@HttpMessage", info.HttpMessage);
                else oleDbCommand.Parameters.AddWithValue("@HttpMessage", DBNull.Value);
                if (null != info.HttpLocation) oleDbCommand.Parameters.AddWithValue("@HttpLocation", info.HttpLocation);
                else oleDbCommand.Parameters.AddWithValue("@HttpLocation", DBNull.Value);
                if (null != info.DiagnosisXml) oleDbCommand.Parameters.AddWithValue("@Diagnoses", info.DiagnosisXml);
                else oleDbCommand.Parameters.AddWithValue("@Diagnoses", DBNull.Value);
                if (null != info.PayloadXml) oleDbCommand.Parameters.AddWithValue("@Payload", info.PayloadXml);
                else oleDbCommand.Parameters.AddWithValue("@Payload", DBNull.Value);
                oleDbCommand.Parameters.AddWithValue("@Endpoint", info.Endpoint);
                oleDbCommand.Parameters.AddWithValue("@Stamp", info.Stamp.ToString());

                oleDbCommand.ExecuteNonQuery();
            }
        }
Exemplo n.º 2
0
 public void Add(string resourceKind, SyncResultEntryInfo[] syncResultEntryInfos)
 {
     lock (lockObj)
     {
         _provider.Add(resourceKind, syncResultEntryInfos);
     }
 }
        public void Add(string resourceKind, SyncResultEntryInfo[] syncResultEntryInfos)
        {
            ISyncResultsTableAdapter syncResultsTableAdapter = this.GetAdapter(resourceKind);
            IResourceKindTableAdapter resourceKindTableAdapter = StoreEnvironment.Resolve<IResourceKindTableAdapter>(_context);

            using (IJetTransaction jetTransaction = _jetConnectionProvider.GetTransaction(false))
            {
                syncResultsTableAdapter.Insert(syncResultEntryInfos, _runName, _runStamp, jetTransaction);

                jetTransaction.Commit();
            }
        }
        public void DoWork(IRequest request)
        {
            if (request.ContentType != Sage.Common.Syndication.MediaType.Atom)
                throw new RequestException("Atom content type expected");

            //read feed
            string resourceKindName = _requestContext.ResourceKind.ToString();
            SyncFeed feed = new SyncFeed();
            XmlReader reader = XmlReader.Create(request.Stream);
            feed.ReadXml(reader, ResourceKindHelpers.GetPayloadType(_requestContext.ResourceKind));

            /* iterate through all entries and store result information */
            ISyncResultInfoStore syncResultInfoStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetSyncResultStore(_requestContext.SdataContext);

            int noOfEntries = feed.Entries.Count;
            string endpoint = string.Empty;
            try
            {
                endpoint = new RequestContext(new Sage.Common.Syndication.SDataUri(feed.Id)).OriginEndPoint;
            }
            catch { }

            SyncResultEntryInfo[] syncResultEntries = new SyncResultEntryInfo[noOfEntries];
            for (int i = 0; i < noOfEntries; i++)
            {
                SyncFeedEntry entry = (SyncFeedEntry)feed.Entries[i];
                string httpMethod = entry.HttpMethod;
                int httpStatus = -1;
                if (Enum.IsDefined(typeof(HttpStatusCode), entry.HttpStatusCode.ToString()))
                    httpStatus = (int)Enum.Parse(typeof(HttpStatusCode), entry.HttpStatusCode.ToString(), true);
                string httpLocation = entry.HttpLocation;
                string httpMessage = entry.HttpMessage;
                string diagnosisXml = XmlSerializationHelpers.SerializeObjectToXml(entry.Diagnoses);
                string payloadXml = XmlSerializationHelpers.SerializeObjectToXml(entry.Payload);

                syncResultEntries[i] = new SyncResultEntryInfo(httpMethod, httpStatus, httpLocation, httpMessage, diagnosisXml, payloadXml, DateTime.Now, endpoint);
            }

            syncResultInfoStore.Add(resourceKindName, syncResultEntries);
        }
Exemplo n.º 5
0
        public void LogResults(Feed<FeedEntry> targetFeed)
        {
            // input stream MUST be of type ATOM
            if (_request.ContentType != Sage.Common.Syndication.MediaType.Atom)
                throw new RequestException("Atom content type expected");

            string resourceKindName;
            ISyncResultInfoStore syncResultInfoStore;
            string EndPoint;
            int noOfEntries;    // the number of entries retrived ffrom input feed and that will be stored
            string runName;
            string runStamp;

            // Retrieve the resourceKindName
            resourceKindName = _requestContext.ResourceKind.ToString();

            // Retrieve a reference to the synchronisation result store
            syncResultInfoStore = NorthwindAdapter.StoreLocator.GetSyncResultStore(_requestContext.SdataContext);

            // Read query parameters
                if (!_requestContext.SdataUri.QueryArgs.TryGetValue("runName", out runName))
                    runName = null;
                if (!_requestContext.SdataUri.QueryArgs.TryGetValue("runStamp", out runStamp))
                    runName = null;

            syncResultInfoStore.SetRunName(runName);
            syncResultInfoStore.SetRunStamp(runStamp);

            // Retrieve the EndPoint that will be stored into the result store
            // The EndPoint is the base url of the requst that returned the sync target feed.
            // Here: the EndPoint is parsed from ID tag of the feed
            EndPoint = string.Empty;
            try
            {
                EndPoint = new RequestContext(new Sage.Common.Syndication.SDataUri(targetFeed.Id)).OriginEndPoint;
            }
            catch { /* MS: Why do we not expect an EndPoint here ??? */ }

            // Create a list of result entries and add them to the result storage
            noOfEntries = targetFeed.Entries.Count;
            SyncResultEntryInfo[] syncResultEntries = new SyncResultEntryInfo[noOfEntries];
            FeedSerializer serializer = (FeedSerializer)_request.Serializer;

            FeedEntry entry;
            string httpMethod = null;
            int httpStatus = 0;
            string httpLocation = null;
            string httpMessage = null;
            string diagnosisXml = null;
            string payloadXml = null;
            DateTime stamp = DateTime.Now;
            for (int i = 0; i < noOfEntries; i++)
            {
                entry = targetFeed.Entries[i];
                if (entry != null)
                {
                    httpMethod = entry.HttpMethod;
                    httpStatus = -1;
                    if (Enum.IsDefined(typeof(HttpStatusCode), entry.HttpStatusCode.ToString()))
                        httpStatus = (int)Enum.Parse(typeof(HttpStatusCode), entry.HttpStatusCode.ToString(), true);
                    httpLocation = entry.HttpLocation;
                    httpMessage = entry.HttpMessage;
                    payloadXml = this.SerializeFeedEntryToXml(entry, serializer);
                    stamp = entry.Updated.ToLocalTime();
                }
                if (entry.Diagnoses != null && entry.Diagnoses.Count > 0)
                {
                    diagnosisXml = this.SerializeObjectToXml(entry.Diagnoses[0]);
                }
                syncResultEntries[i] = new SyncResultEntryInfo(httpMethod, httpStatus, httpLocation, httpMessage, diagnosisXml, payloadXml, stamp, EndPoint);
            }

            // add entries to result storage
            syncResultInfoStore.Add(resourceKindName, syncResultEntries);
            _request.Response.StatusCode = HttpStatusCode.OK;
        }