当前位置: 首页>>代码示例>>C#>>正文


C# Transaction.PushCommand方法代码示例

本文整理汇总了C#中Transaction.PushCommand方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.PushCommand方法的具体用法?C# Transaction.PushCommand怎么用?C# Transaction.PushCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transaction的用法示例。


在下文中一共展示了Transaction.PushCommand方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SmartUpload

        private void SmartUpload(SyncEngine client, IPersistenceEngine server)
        {
            if (server == null)
                throw new ArgumentException("The server engine must be not null");

            if (client == null)
                throw new ArgumentException("The client engine must be not null and a SyncProvider");

            IList<Entity> commands = GetPeerMetadataEngine(client, Peer.Client).Load("from " + SyncUtils.COMMAND + " c orderby c.Processed, c.Number select c", 1, 0);

            EntitySet commandsToRemove = ((EntitySet)commands).Clone();

            Command[] optimized = OptimizeCommands(client, commands);

            Transaction t = new Transaction(client.MetadataEngine.Factory.Model);
            foreach (Command c in optimized)
            {
                c.ClientId = client.ClientId;

                CompoundCreateCommand ccc = c as CompoundCreateCommand;
                if (ccc != null)
                    foreach (Command cmd in ccc.InnerCommands)
                        cmd.ClientId = client.ClientId;

                t.PushCommand(c);
            }
            t.Commit(server, false);

            // Deletes the metadata once they are processed
            t = new Transaction(client.MetadataEngine.Factory.Model);
            t.Delete(commandsToRemove);
            t.Commit(client.MetadataEngine, false);
        }
开发者ID:npenin,项目名称:uss,代码行数:33,代码来源:Synchronizer.cs

示例2: SmartUploadDownload


//.........这里部分代码省略.........
                            else
                            {
                                clientCommands.Remove(ce);
                                ct.Delete(ce);
                            }
                        }
                    }
                }
            }
            ct.Commit(GetPeerMetadataEngine(client, Peer.Client), false);
            st.Commit(GetPeerMetadataEngine(server, Peer.Server), false);

            EntitySet clientCommandsToRemove = ((EntitySet)clientCommands).Clone();
            EntitySet serverCommandsToRemove = ((EntitySet)serverCommands).Clone();

            Command[] optimizedClientCommands = OptimizeCommands(client, clientCommands);
            Command[] optimizedServerCommands = OptimizeCommands(server, serverCommands);

            StringCollection dataToProcess = new StringCollection();
            foreach (string filter in filters)
                foreach (Entity e in server.Load(filter))
                    dataToProcess.Add(string.Concat(e.Type, SEPARATOR, e.Id));

            t = new Transaction(client.Factory.Model);
            foreach (Command c in optimizedServerCommands)
            {
                string key = string.Empty;

                CompoundCreateCommand ccc = c as CompoundCreateCommand;
                if (ccc != null)
                    key = string.Concat(ccc.Type, SEPARATOR, ccc.ParentId);

                CompoundUpdateCommand cuc = c as CompoundUpdateCommand;
                if (cuc != null)
                    key = string.Concat(cuc.ParentType, SEPARATOR, cuc.ParentId);

                DeleteEntityCommand dec = c as DeleteEntityCommand;
                if (dec != null)
                    key = string.Concat(dec.Type, SEPARATOR, dec.ParentId);

                DeleteAttributeCommand dac = c as DeleteAttributeCommand;
                if (dac != null)
                    key = string.Concat(dac.ParentType, SEPARATOR, dac.ParentId);

                CreateReferenceCommand crc = c as CreateReferenceCommand;
                if (crc != null)
                    key = string.Concat(crc.ParentType, SEPARATOR, crc.ParentId);

                DeleteReferenceCommand drc = c as DeleteReferenceCommand;
                if (drc != null)
                    key = string.Concat(drc.ParentType, SEPARATOR, drc.ParentId);

                if (key != null && key != string.Empty && filters.Count > 0 && !dataToProcess.Contains(key))
                    continue;

                c.IgnoreMetadata = true;
                t.PushCommand(c);
            }
            t.Commit(client, false);

            #endregion

            #region Upload

            if (optimizedClientCommands.Length > 0)
            {
                t = new Transaction(server.Factory.Model);
                t.PushCommand(optimizedClientCommands);
                t.Commit(server, false);

            }

            // Updates the last transaction id for the client
            Entity info = GetPeerMetadataEngine(server, Peer.Server).Load(SyncUtils.INFO)[0];
            connection[SyncUtils.TRANSACTION].Value = info.GetInt32(SyncUtils.TRANSACTION);

            t = new Transaction(GetPeerMetadataEngine(server, Peer.Server).Factory.Model);

            t.Serialize(connection);
            t.Commit(GetPeerMetadataEngine(server, Peer.Server), false);

            // Deletes the metadata once they are processed
            if (clientCommands.Count > 0)
            {
                t = new Transaction(GetPeerMetadataEngine(server, Peer.Client).Factory.Model);
                t.Delete(clientCommandsToRemove);
                t.Commit(GetPeerMetadataEngine(client, Peer.Client), false);
            }

            // Deletes all tombstoned server commands
            if (tombstone != TimeSpan.MaxValue)
            {
                serverCommands = GetPeerMetadataEngine(server, Peer.Server).Load("from Evaluant.Uss.Sync.Command c where c.Processed > #" + DateTime.Now.Add(-tombstone) + "# select c");
                t = new Transaction(GetPeerMetadataEngine(server, Peer.Server).Factory.Model);
                t.Delete(serverCommandsToRemove);
                t.Commit(GetPeerMetadataEngine(server, Peer.Server), false);
            }

            #endregion
        }
开发者ID:npenin,项目名称:uss,代码行数:101,代码来源:Synchronizer.cs

示例3: SmartDownload

        private void SmartDownload(IPersistenceEngine client, SyncEngine server, string clientId)
        {
            if (client == null)
                throw new ArgumentException("The client engine must be not null");

            if (server == null)
                throw new ArgumentException("The server engine must be not null and a SyncProvider");

            Entity connection = GetConnection(clientId, server);
            int lastSync = connection.GetInt32(SyncUtils.TRANSACTION);

            Command[] commands = OptimizeCommands((SyncEngine)client,
                    GetPeerMetadataEngine(server, Peer.Server).Load("from Evaluant.Uss.Sync.Command c where (c.ClientId!='" + client + "' || c.ClientId==null) and c.Transaction>" + lastSync.ToString() + " orderby c.Processed, c.Number", 1, 0)
                    );

            StringCollection dataToProcess = new StringCollection();
            foreach (string filter in filters)
                foreach (Entity e in server.Load(filter))
                    dataToProcess.Add(string.Concat(e.Type, SEPARATOR, e.Id));

            Transaction t = new Transaction(client.Factory.Model);
            foreach (Command c in commands)
            {
                string key = string.Empty;

                CompoundCreateCommand ccc = c as CompoundCreateCommand;
                if (ccc != null)
                    key = string.Concat(ccc.Type, SEPARATOR, ccc.ParentId);

                CompoundUpdateCommand cuc = c as CompoundUpdateCommand;
                if (cuc != null)
                    key = string.Concat(cuc.ParentType, SEPARATOR, cuc.ParentId);

                if (key != null && key != string.Empty && filters.Count > 0 && !dataToProcess.Contains(key))
                    continue;

                c.IgnoreMetadata = true;
                t.PushCommand(c);
            }
            t.Commit(client, false);

            Entity info = GetPeerMetadataEngine(server, Peer.Server).Load(SyncUtils.INFO)[0];
            connection[SyncUtils.TRANSACTION].Value = info.GetInt32(SyncUtils.TRANSACTION);

            IPersistenceEngine peerMetadataEngine = GetPeerMetadataEngine(server, Peer.Server);

            t = new Transaction(peerMetadataEngine.Factory.Model);

            t.Serialize(connection);
            t.Commit(peerMetadataEngine, false);
        }
开发者ID:npenin,项目名称:uss,代码行数:51,代码来源:Synchronizer.cs


注:本文中的Transaction.PushCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。