public ItemSet[] GetItems(ItemSpec[] itemSpecs, VersionSpec versionSpec,
                                  DeletedState deletedState, ItemType itemType,
                                  bool includeDownloadInfo)
        {
            if (itemSpecs.Length == 0)
            {
                return(null);
            }

            string workspaceName  = String.Empty;
            string workspaceOwner = String.Empty;

            string item = itemSpecs[0].Item;

            if (!VersionControlPath.IsServerItem(item))
            {
                WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(item);
                if (info != null)
                {
                    workspaceName  = info.Name;
                    workspaceOwner = info.OwnerName;
                }
            }

            return(repository.QueryItems(workspaceName, workspaceOwner,
                                         itemSpecs, versionSpec, deletedState,
                                         itemType, includeDownloadInfo));
        }
Example #2
0
    public override void Run()
    {
        string path = Environment.CurrentDirectory;

        if (Arguments.Length > 0)
        {
            path = Arguments[0];
        }
        if (!VersionControlPath.IsServerItem(path))
        {
            path = Path.GetFullPath(path);
        }

        // process command options
        RecursionType rtype  = OptionRecursive ? RecursionType.Full : RecursionType.OneLevel;
        DeletedState  dstate = OptionDeleted ? DeletedState.Any : DeletedState.NonDeleted;

        ItemSpec itemSpec = new ItemSpec(path, rtype);
        ItemSet  itemSet  = VersionControlServer.GetItems(itemSpec, VersionFromString(OptionVersion), dstate, ItemType.Any, false);

        Item[] items = itemSet.Items;

        foreach (Item item in items)
        {
            Console.Write(item.ServerItem);
            if ((item.ItemType == ItemType.Folder) && (!item.ServerItem.EndsWith(Path.DirectorySeparatorChar.ToString())))
            {
                Console.Write("/");
            }
            Console.WriteLine();
        }

        Console.WriteLine(items.Length + " item(s)");
    }
 public void OnPerforming(PerformingContext filterContext)
 {
     using (var connection = JobStorage.Current.GetConnection())
     {
         var      recurring  = connection.GetRecurringJobs().FirstOrDefault(p => p.Job.ToString() == filterContext.BackgroundJob.Job.ToString());
         TimeSpan difference = DateTime.UtcNow.Subtract(recurring.LastExecution.Value);
         if (recurring != null && difference.Seconds < 15)
         {
             // Execution was due in the past. We don't want to automaticly execute jobs after server crash though.
             var storageConnection = connection as JobStorageConnection;
             if (storageConnection == null)
             {
                 return;
             }
             var jobId        = filterContext.BackgroundJob.Id;
             var deletedState = new DeletedState()
             {
                 Reason = "Task was due in the past. Please Execute manually if required."
             };
             using (var transaction = connection.CreateWriteTransaction())
             {
                 transaction.RemoveFromSet("retries", jobId);      // Remove from retry state
                 transaction.RemoveFromSet("schedule", jobId);     // Remove from schedule state
                 transaction.SetJobState(jobId, deletedState);     // update status with failed state
                 transaction.Commit();
             }
         }
     }
 }
 public ExtendedItem[][] GetExtendedItems(ItemSpec[] itemSpecs,
                                          DeletedState deletedState,
                                          ItemType itemType)
 {
     return(Repository.QueryItemsExtended(null, null,
                                          itemSpecs, deletedState, itemType));
 }
        //    <QueryItems xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/ClientServices/03">
        //      <workspaceName>string</workspaceName>
        //      <workspaceOwner>string</workspaceOwner>
        //      <items>
        //        <ItemSpec item="string" recurse="None or OneLevel or Full" did="int" />
        //        <ItemSpec item="string" recurse="None or OneLevel or Full" did="int" />
        //      </items>
        //      <version />
        //      <deletedState>NonDeleted or Deleted or Any</deletedState>
        //      <itemType>Any or Folder or File</itemType>
        //      <generateDownloadUrls>boolean</generateDownloadUrls>
        //      <options>int</options>
        //    </QueryItems>
        public List <Item> QueryItems(string workspaceName, string workspaceOwner, ItemSpec[] itemSpecs, VersionSpec versionSpec,
                                      DeletedState deletedState, ItemType itemType,
                                      bool includeDownloadInfo)
        {
            var invoker = new SoapInvoker(this);
            var msg     = invoker.CreateEnvelope("QueryItems");

            if (!string.IsNullOrEmpty(workspaceName))
            {
                msg.Add(new XElement(MessageNs + "workspaceName", workspaceName));
            }
            if (!string.IsNullOrEmpty(workspaceOwner))
            {
                msg.Add(new XElement(MessageNs + "workspaceOwner", workspaceOwner));
            }
            msg.Add(new XElement(MessageNs + "items", itemSpecs.Select(itemSpec => itemSpec.ToXml(MessageNs + "ItemSpec"))));
            msg.Add(versionSpec.ToXml(MessageNs + "version"));
            msg.Add(new XElement(MessageNs + "deletedState", deletedState));
            msg.Add(new XElement(MessageNs + "itemType", itemType));
            msg.Add(new XElement(MessageNs + "generateDownloadUrls", includeDownloadInfo.ToLowString()));

            var result = invoker.InvokeResult();

            return(result.Descendants(MessageNs + "Item").Select(Item.FromXml).ToList());
        }
Example #6
0
        public ExtendedItem[][] QueryItemsExtended(string workspaceName, string workspaceOwner,
                                                   ItemSpec[] itemSpecs,
                                                   DeletedState deletedState, ItemType itemType)
        {
            Message msg = new Message(GetWebRequest(new Uri(Url)), "QueryItemsExtended");

            if (!String.IsNullOrEmpty(workspaceName))
            {
                msg.Body.WriteElementString("workspaceName", workspaceName);
            }
            if (!String.IsNullOrEmpty(workspaceOwner))
            {
                msg.Body.WriteElementString("workspaceOwner", workspaceOwner);
            }

            msg.Body.WriteStartElement("items");
            foreach (ItemSpec itemSpec in itemSpecs)
            {
                itemSpec.ToXml(msg.Body, "ItemSpec");
            }
            msg.Body.WriteEndElement();

            msg.Body.WriteElementString("deletedState",
                                        deletedState.ToString());
            msg.Body.WriteElementString("itemType",
                                        itemType.ToString());

            List <ExtendedItem[]> listOfItemArrays = new List <ExtendedItem[]>();

            using (HttpWebResponse response = Invoke(msg))
            {
                XmlReader results = msg.ResponseReader(response);
                while (results.Read())
                {
                    if (results.NodeType == XmlNodeType.Element &&
                        results.Name == "ArrayOfExtendedItem")
                    {
                        List <ExtendedItem> items = new List <ExtendedItem>();
                        while (results.Read())
                        {
                            //Console.WriteLine("	 " + results.Name + ":" + results.NodeType);
                            if (results.NodeType == XmlNodeType.EndElement &&
                                results.Name == "ArrayOfExtendedItem")
                            {
                                break;
                            }
                            if (results.NodeType == XmlNodeType.Element &&
                                results.Name == "ExtendedItem")
                            {
                                items.Add(ExtendedItem.FromXml(this, results));
                            }
                        }
                        listOfItemArrays.Add(items.ToArray());
                    }
                }
            }

            return(listOfItemArrays.ToArray());
        }
Example #7
0
    public void DeletedShouldShiftToDroppingOnUpdate()
    {
        IGridState deletedState = new DeletedState(gridMock);

        deletedState.OnUpdate();
        gridMock.Received().DropBlocks();
        gridMock.Received().SetState(GridStates.Dropping);
    }
Example #8
0
    public void DeletedShouldShiftToDroppingOnUpdate()
    {
        IGridState deletedState = new DeletedState(gridMock);

        deletedState.OnUpdate();
        gridMock.Received().DropBlocks();
        gridMock.Received().SetState(GridStates.Dropping);
    }
    public static void GetCreatedAt_ReturnsCorrectValue_DeletedState()
    {
        var state = new DeletedState();

        var result = state.GetCreatedAt();

        Assert.Equal(state.DeletedAt, result);
    }
Example #10
0
        public void ChangeToDeletedState()
        {
            #region DeletedState
            var client = new BackgroundJobClient();
            var jobId  = client.Enqueue(() => Console.WriteLine("Hello"));

            var state = new DeletedState();
            client.ChangeState(jobId, state, EnqueuedState.StateName);
            #endregion
        }
 public List <Item> QueryItems(Workspace workspace, ItemSpec itemSpec, VersionSpec versionSpec,
                               DeletedState deletedState, ItemType itemType,
                               bool includeDownloadInfo)
 {
     if (workspace == null)
     {
         return(QueryItems(itemSpec, versionSpec, deletedState, itemType, includeDownloadInfo));
     }
     return(QueryItems(workspace.Name, workspace.OwnerName, new [] { itemSpec }, versionSpec, deletedState, itemType, includeDownloadInfo));
 }
        public void JsonSerialize_ReturnsCorrectString_After170()
        {
            var state = new DeletedState();

            var serialized = SerializationHelper.Serialize <IState>(state, SerializationOption.TypedInternal);

            Assert.Equal(
                "{\"$type\":\"Hangfire.States.DeletedState, Hangfire.Core\"}",
                serialized);
        }
        public ItemSet GetItems(ItemSpec itemSpec, VersionSpec versionSpec,
                                DeletedState deletedState, ItemType itemType,
                                bool includeDownloadInfo)
        {
            List <ItemSpec> itemSpecs = new List <ItemSpec>();

            itemSpecs.Add(itemSpec);
            ItemSet[] itemSet = GetItems(itemSpecs.ToArray(), versionSpec, deletedState,
                                         itemType, includeDownloadInfo);
            return(itemSet[0]);
        }
        /// <summary>
        /// Changes state of a job with the specified <paramref name="jobId"/>
        /// to the <see cref="DeletedState"/>. If <paramref name="fromState"/> value
        /// is not null, state change will be performed only if the current state name
        /// of a job equal to the given value.
        /// </summary>
        ///
        /// <remarks>
        /// The job is not actually being deleted, this method changes only
        /// its state.
        ///
        /// This operation does not provides guarantee that the job will not be
        /// performed. If you deleting a job that is performing right now, it
        /// will be performed anyway, despite of this call.
        ///
        /// The method returns result of a state transition. It can be false
        /// if a job was expired, its method does not exist or there was an
        /// exception during the state change process.
        /// </remarks>
        ///
        /// <param name="client">An instance of <see cref="IBackgroundJobClient"/> implementation.</param>
        /// <param name="jobId">Identifier of job, whose state is being changed.</param>
        /// <param name="fromState">Current state assertion, or null if unneeded.</param>
        /// <returns>True, if state change succeeded, otherwise false.</returns>
        public static bool Delete(this IBackgroundJobClient client, string jobId, string fromState)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            var state = new DeletedState();

            return(client.ChangeState(jobId, state, fromState));
        }
 public List <ExtendedItem> QueryItemsExtended(Workspace workspace, ItemSpec itemSpec,
                                               DeletedState deletedState, ItemType itemType)
 {
     if (workspace == null)
     {
         return(QueryItemsExtended(string.Empty, string.Empty, new List <ItemSpec> {
             itemSpec
         }, deletedState, itemType));
     }
     return(QueryItemsExtended(workspace.Name, workspace.OwnerName, new List <ItemSpec> {
         itemSpec
     }, deletedState, itemType));
 }
Example #16
0
        /// <summary>
        /// Changes state of a job with the specified <paramref name="jobId"/>
        /// to the <see cref="DeletedState"/>. If <paramref name="fromState"/> value
        /// is not null, state change will be performed only if the current state name
        /// of a job equal to the given value.
        /// </summary>
        ///
        /// <remarks>
        /// The job is not actually being deleted, this method changes only
        /// its state.
        ///
        /// This operation does not provides guarantee that the job will not be
        /// performed. If you deleting a job that is performing right now, it
        /// will be performed anyway, despite of this call.
        ///
        /// The method returns result of a state transition. It can be false
        /// if a job was expired, its method does not exist or there was an
        /// exception during the state change process.
        /// </remarks>
        ///
        /// <param name="client">An instance of <see cref="IBackgroundJobClient"/> implementation.</param>
        /// <param name="jobId">Identifier of job, whose state is being changed.</param>
        /// <param name="fromState">Current state assertion, or null if unneeded.</param>
        /// <returns>True, if state change succeeded, otherwise false.</returns>
        public static bool Delete(
            [NotNull] this IBackgroundJobClient client,
            [NotNull] string jobId,
            [CanBeNull] string fromState)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var state = new DeletedState();

            return(client.ChangeState(jobId, state, fromState));
        }
Example #17
0
        public ItemSet[] QueryItems(string workspaceName, string workspaceOwner,
                                    ItemSpec[] itemSpecs, VersionSpec versionSpec,
                                    DeletedState deletedState, ItemType itemType,
                                    bool generateDownloadUrls)
        {
            Message msg = new Message(GetWebRequest(new Uri(Url)), "QueryItems");

            if (!String.IsNullOrEmpty(workspaceName))
            {
                msg.Body.WriteElementString("workspaceName", workspaceName);
            }
            if (!String.IsNullOrEmpty(workspaceOwner))
            {
                msg.Body.WriteElementString("workspaceOwner", workspaceOwner);
            }
            msg.Body.WriteStartElement("items");
            foreach (ItemSpec itemSpec in itemSpecs)
            {
                itemSpec.ToXml(msg.Body, "ItemSpec");
            }
            msg.Body.WriteEndElement();

            versionSpec.ToXml(msg.Body, "version");

            msg.Body.WriteElementString("deletedState",
                                        deletedState.ToString());
            msg.Body.WriteElementString("itemType",
                                        itemType.ToString());
            msg.Body.WriteElementString("generateDownloadUrls",
                                        generateDownloadUrls.ToString().ToLower());

            List <ItemSet> itemSet = new List <ItemSet>();

            using (HttpWebResponse response = Invoke(msg))
            {
                XmlReader results = msg.ResponseReader(response);

                while (results.Read())
                {
                    if (results.NodeType == XmlNodeType.Element &&
                        results.Name == "ItemSet")
                    {
                        itemSet.Add(ItemSet.FromXml(this, results));
                    }
                }
            }

            return(itemSet.ToArray());
        }
        public ExtendedItem[] GetExtendedItems(string path,
                                               DeletedState deletedState,
                                               ItemType itemType)
        {
            List <ItemSpec> itemSpecs = new List <ItemSpec>();

            itemSpecs.Add(new ItemSpec(path, RecursionType.OneLevel));
            ExtendedItem[][] items = GetExtendedItems(itemSpecs.ToArray(), deletedState, itemType);

            if (items.Length == 0)
            {
                return(null);
            }
            return(items[0]);
        }
Example #19
0
        internal QueryProvider(IQueryable <TDmn> internalQuery, TPermissions permissions, HttpStatusCode getAllPermissions, bool isGetAll)
        {
            internalQuery.ValidateNotNullParameter(nameof(internalQuery));
            permissions.ValidateNotNullParameter(nameof(permissions));

            this.permissions       = permissions;
            this.getAllPermissions = getAllPermissions;

            this.internalQuery = internalQuery;
            this.isGetAll      = isGetAll;

            this.filters  = new List <IFilter <TDmn, TPermissions> >();
            this.includes = new List <string>();

            this.DeletedState = DeletedState.NonDeleted;
        }
        //    <QueryItemsExtended xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/ClientServices/03">
        //      <workspaceName>string</workspaceName>
        //      <workspaceOwner>string</workspaceOwner>
        //      <items>
        //        <ItemSpec item="string" recurse="None or OneLevel or Full" did="int" />
        //        <ItemSpec item="string" recurse="None or OneLevel or Full" did="int" />
        //      </items>
        //      <deletedState>NonDeleted or Deleted or Any</deletedState>
        //      <itemType>Any or Folder or File</itemType>
        //      <options>int</options>
        //    </QueryItemsExtended>
        public List <ExtendedItem> QueryItemsExtended(string workspaceName, string workspaceOwner, List <ItemSpec> itemSpecs,
                                                      DeletedState deletedState, ItemType itemType)
        {
            var invoker = new SoapInvoker(this);
            var msg     = invoker.CreateEnvelope("QueryItemsExtended");

            msg.Add(new XElement(MessageNs + "workspaceName", workspaceName));
            msg.Add(new XElement(MessageNs + "workspaceOwner", workspaceOwner));
            msg.Add(new XElement(MessageNs + "items", itemSpecs.Select(itemSpec => itemSpec.ToXml(MessageNs + "ItemSpec"))));
            msg.Add(new XElement(MessageNs + "deletedState", deletedState));
            msg.Add(new XElement(MessageNs + "itemType", itemType));

            var result = invoker.InvokeResult();

            return(result.Descendants(MessageNs + "ExtendedItem").Select(ExtendedItem.FromXml).ToList());
        }
        public static bool HasDeletedState(this IIsDeletedFlagEntity entity, DeletedState state)
        {
            switch (state)
            {
            case DeletedState.NotDeleted:
                return(!entity.IsDeleted);

            case DeletedState.Deleted:
                return(entity.IsDeleted);

            case DeletedState.Any:
                return(true);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
    internal static DateTime?GetCreatedAt(this IState state)
    {
        if (state is null)
        {
            throw new ArgumentNullException(nameof(state));
        }

        return(state switch
        {
            ScheduledState scheduled => scheduled.ScheduledAt,
            EnqueuedState enqueued => enqueued.EnqueuedAt,
            ProcessingState processing => processing.StartedAt,
            SucceededState succeeded => succeeded.SucceededAt,
            FailedState failed => failed.FailedAt,
            DeletedState deleted => deleted.DeletedAt,
            _ => default(DateTime?),
        });
        public static IEnumerable <T> OfDeletedState <T>(this IEnumerable <T> query, DeletedState state)
            where T : class, IIsDeletedFlagEntity
        {
            switch (state)
            {
            case DeletedState.NotDeleted:
                return(query.OfNotDeleted());

            case DeletedState.Deleted:
                return(query.OfDeleted());

            case DeletedState.Any:
                return(query);

            default:
                throw new ArgumentOutOfRangeException(nameof(state));
            }
        }
Example #24
0
        private static TDtoProp ExecuteMemberAndConvert <TDmnProp, TDtoProp>(
            TPermissions permissions,
            TDmn domain,
            string[] includes,
            DeletedState deletedState,
            Expression <Func <TDmn, TDmnProp> > dmnExpression,
            Expression <Func <TDto, TDtoProp> > dtoExpression,
            IConverter <TDmnProp, TDtoProp, TPermissions> converter)
            where TDmnProp : class, IDomain
            where TDtoProp : class, IDto, new()
        {
            string dtoMemberName = GetMemberName(dtoExpression).ToLower();

            string[] nextIncludes = GetNextIncludes(includes, dtoMemberName);

            TDmnProp domainProperty = ExecuteMember(dmnExpression, domain);

            return(deletedState == DeletedState.All || domainProperty.UtcDateDeleted.HasValue == (deletedState == DeletedState.Deleted) ?
                   converter.Convert(domainProperty, permissions, nextIncludes, deletedState) : null);
        }
Example #25
0
        protected TDtoProp[] HandlePermissions <TDmnProp, TDtoProp>(
            bool hasPermissions,
            TPermissions permissions,
            List <string> excludedProperties,
            TDmn domain,
            string[] includes,
            DeletedState deletedState,
            Expression <Func <TDmn, IEnumerable <TDmnProp> > > dmnExpression,
            Expression <Func <TDto, TDtoProp[]> > dtoExpression,
            IConverter <TDmnProp, TDtoProp, TPermissions> converter)
            where TDmnProp : class, IDomain
            where TDtoProp : class, IDto, new()
        {
            if (!hasPermissions)
            {
                excludedProperties.Add(GetMemberName(dtoExpression));
            }

            return(hasPermissions && HasInclude(dtoExpression, includes) ?
                   ExecuteMemberAndConvert(permissions, domain, includes, deletedState, dmnExpression, dtoExpression, converter) : null);
        }
Example #26
0
    public override void Run()
    {
        if (Arguments.Length < 1)
        {
            Console.WriteLine("Usage: tf view <itemSpec>");
            Environment.Exit((int)ExitCode.Failure);
        }

        // process command options
        RecursionType rtype  = OptionRecursive ? RecursionType.Full : RecursionType.None;
        DeletedState  dstate = OptionDeleted ? DeletedState.Any : DeletedState.NonDeleted;

        List <ItemSpec> itemSpecs = new List <ItemSpec>();

        foreach (string path in Arguments)
        {
            itemSpecs.Add(new ItemSpec(Path.GetFullPath(path), rtype));
        }

        ItemSet[] itemSets = VersionControlServer.GetItems(itemSpecs.ToArray(), VersionFromString(OptionVersion),
                                                           dstate, ItemType.Any, true);

        foreach (ItemSet itemSet in itemSets)
        {
            foreach (Item item in itemSet.Items)
            {
                string tname = Path.GetTempFileName();
                item.DownloadFile(tname);

                using (StreamReader sr = new StreamReader(tname))
                {
                    Console.WriteLine(sr.ReadToEnd());
                }

                File.Delete(tname);
            }
        }
    }
Example #27
0
        private static TDtoProp[] ExecuteMemberAndConvert <TDmnProp, TDtoProp>(
            TPermissions permissions,
            TDmn domain,
            string[] includes,
            DeletedState deletedState,
            Expression <Func <TDmn, IEnumerable <TDmnProp> > > dmnExpression,
            Expression <Func <TDto, TDtoProp[]> > dtoExpression,
            IConverter <TDmnProp, TDtoProp, TPermissions> converter)
            where TDmnProp : class, IDomain
            where TDtoProp : class, IDto, new()
        {
            string dtoMemberName = GetMemberName(dtoExpression).ToLower();

            string[] nextIncludes = GetNextIncludes(includes, dtoMemberName);

            TDmnProp[] domainProperty = ExecuteMember(dmnExpression, domain)
                                        .Where(dmn => deletedState == DeletedState.All || dmn.UtcDateDeleted.HasValue == (deletedState == DeletedState.Deleted))
                                        .ToArray();

            return(domainProperty
                   .Select(i => converter.Convert(i, permissions, nextIncludes, deletedState))
                   .ToArray());
        }
        //    <QueryItems xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/ClientServices/03">
        //      <workspaceName>string</workspaceName>
        //      <workspaceOwner>string</workspaceOwner>
        //      <items>
        //        <ItemSpec item="string" recurse="None or OneLevel or Full" did="int" />
        //        <ItemSpec item="string" recurse="None or OneLevel or Full" did="int" />
        //      </items>
        //      <version />
        //      <deletedState>NonDeleted or Deleted or Any</deletedState>
        //      <itemType>Any or Folder or File</itemType>
        //      <generateDownloadUrls>boolean</generateDownloadUrls>
        //      <options>int</options>
        //    </QueryItems>
        public List<Item> QueryItems(string workspaceName, string workspaceOwner, ItemSpec[] itemSpecs, VersionSpec versionSpec,
                                     DeletedState deletedState, ItemType itemType, 
                                     bool includeDownloadInfo)
        {
            var invoker = new SoapInvoker(this);
            var msg = invoker.CreateEnvelope("QueryItems");
            if (!string.IsNullOrEmpty(workspaceName))
                msg.Add(new XElement(MessageNs + "workspaceName", workspaceName));
            if (!string.IsNullOrEmpty(workspaceOwner))
                msg.Add(new XElement(MessageNs + "workspaceOwner", workspaceOwner));
            msg.Add(new XElement(MessageNs + "items", itemSpecs.Select(itemSpec => itemSpec.ToXml(MessageNs + "ItemSpec"))));
            msg.Add(versionSpec.ToXml(MessageNs + "version"));
            msg.Add(new XElement(MessageNs + "deletedState", deletedState));
            msg.Add(new XElement(MessageNs + "itemType", itemType));
            msg.Add(new XElement(MessageNs + "generateDownloadUrls", includeDownloadInfo.ToLowString()));

            var result = invoker.InvokeResult();
            return result.Descendants(MessageNs + "Item").Select(Item.FromXml).ToList();
        }
Example #29
0
        public ItemSet[] GetItems(ItemSpec[] itemSpecs, VersionSpec versionSpec,
															DeletedState deletedState, ItemType itemType, 
															bool includeDownloadInfo)
        {
            if (itemSpecs.Length == 0) return null;

            string workspaceName = String.Empty;
            string workspaceOwner = String.Empty;

            string item = itemSpecs[0].Item;
            if (!VersionControlPath.IsServerItem(item))
                {
                    WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(item);
                    if (info != null)
                        {
                            workspaceName = info.Name;
                            workspaceOwner = info.OwnerName;
                        }
                }

            return repository.QueryItems(workspaceName, workspaceOwner,
                                                                     itemSpecs, versionSpec, deletedState,
                                                                     itemType, includeDownloadInfo);
        }
 public List <Item> QueryItems(ItemSpec itemSpec, VersionSpec versionSpec,
                               DeletedState deletedState, ItemType itemType,
                               bool includeDownloadInfo)
 {
     return(QueryItems(string.Empty, string.Empty, new [] { itemSpec }, versionSpec, deletedState, itemType, includeDownloadInfo));
 }
 public static IQueryable <T> FilterToken <T>(this IQueryable <T> query, int tokenId, TokenValidity tokenValidity, DeletedState deletedState) where T : class, IToken
 {
     return(query.Filter(tokenValidity, deletedState, tokenId));
 }
Example #32
0
        private void ExecuteContinuationsIfExist(ElectStateContext context)
        {
            // The following lines are executed inside a distributed job lock,
            // so it is safe to get continuation list here.
            var continuations = GetContinuations(context.Connection, context.BackgroundJob.Id);
            var nextStates    = new Dictionary <string, IState>();

            // Getting continuation data for all continuations – state they are waiting
            // for and their next state.
            foreach (var continuation in continuations)
            {
                if (String.IsNullOrWhiteSpace(continuation.JobId))
                {
                    continue;
                }

                var currentState = GetContinuaionState(context, continuation.JobId, ContinuationStateFetchTimeout);
                if (currentState == null)
                {
                    continue;
                }

                // All continuations should be in the awaiting state. If someone changed
                // the state of a continuation, we should simply skip it.
                if (currentState.Name != AwaitingState.StateName)
                {
                    continue;
                }

                IState nextState;

                if (continuation.Options.HasFlag(JobContinuationOptions.OnlyOnSucceededState) &&
                    context.CandidateState.Name != SucceededState.StateName)
                {
                    nextState = new DeletedState {
                        Reason = "Continuation condition was not met"
                    };
                }
                else
                {
                    try
                    {
                        nextState = JsonConvert.DeserializeObject <IState>(
                            currentState.Data["NextState"],
                            new JsonSerializerSettings {
                            TypeNameHandling = TypeNameHandling.Objects
                        });
                    }
                    catch (Exception ex)
                    {
                        nextState = new FailedState(ex)
                        {
                            Reason = "An error occurred while deserializing the continuation"
                        };
                    }
                }

                if (!nextStates.ContainsKey(continuation.JobId))
                {
                    // Duplicate continuations possible, when they were added before version 1.6.10.
                    // Please see details in comments for the AddContinuation method near the line
                    // with checking for existence (continuations.Exists).
                    nextStates.Add(continuation.JobId, nextState);
                }
            }

            foreach (var tuple in nextStates)
            {
                _stateChanger.ChangeState(new StateChangeContext(
                                              context.Storage,
                                              context.Connection,
                                              tuple.Key,
                                              tuple.Value,
                                              AwaitingState.StateName));
            }
        }
Example #33
0
        public ItemSet[] QueryItems(string workspaceName, string workspaceOwner, 
																ItemSpec[] itemSpecs, VersionSpec versionSpec, 
																DeletedState deletedState, ItemType itemType, 
																bool generateDownloadUrls)
        {
            Message msg = new Message(GetWebRequest (new Uri(Url)), "QueryItems");

            if (!String.IsNullOrEmpty(workspaceName)) msg.Body.WriteElementString("workspaceName", workspaceName);
            if (!String.IsNullOrEmpty(workspaceOwner)) msg.Body.WriteElementString("workspaceOwner", workspaceOwner);
            msg.Body.WriteStartElement("items");
            foreach (ItemSpec itemSpec in itemSpecs)
                itemSpec.ToXml(msg.Body, "ItemSpec");
            msg.Body.WriteEndElement();

            versionSpec.ToXml(msg.Body, "version");

            msg.Body.WriteElementString("deletedState",
                                                                    deletedState.ToString());
            msg.Body.WriteElementString("itemType",
                                                                    itemType.ToString());
            msg.Body.WriteElementString("generateDownloadUrls",
                                                                    generateDownloadUrls.ToString().ToLower());

            List<ItemSet> itemSet = new List<ItemSet>();
            using (HttpWebResponse response = Invoke(msg))
                {
                    XmlReader results = msg.ResponseReader(response);

                    while (results.Read())
                        {
                            if (results.NodeType == XmlNodeType.Element &&
                                    results.Name == "ItemSet")
                                itemSet.Add(ItemSet.FromXml(this, results));
                        }
                }

            return itemSet.ToArray();
        }
        //    <QueryItemsExtended xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/ClientServices/03">
        //      <workspaceName>string</workspaceName>
        //      <workspaceOwner>string</workspaceOwner>
        //      <items>
        //        <ItemSpec item="string" recurse="None or OneLevel or Full" did="int" />
        //        <ItemSpec item="string" recurse="None or OneLevel or Full" did="int" />
        //      </items>
        //      <deletedState>NonDeleted or Deleted or Any</deletedState>
        //      <itemType>Any or Folder or File</itemType>
        //      <options>int</options>
        //    </QueryItemsExtended>
        public List<ExtendedItem> QueryItemsExtended(string workspaceName, string workspaceOwner, List<ItemSpec>  itemSpecs,
                                                     DeletedState deletedState, ItemType itemType)
        {
            var invoker = new SoapInvoker(this);
            var msg = invoker.CreateEnvelope("QueryItemsExtended");
            msg.Add(new XElement(MessageNs + "workspaceName", workspaceName));
            msg.Add(new XElement(MessageNs + "workspaceOwner", workspaceOwner));
            msg.Add(new XElement(MessageNs + "items", itemSpecs.Select(itemSpec => itemSpec.ToXml(MessageNs + "ItemSpec"))));
            msg.Add(new XElement(MessageNs + "deletedState", deletedState));
            msg.Add(new XElement(MessageNs + "itemType", itemType));

            var result = invoker.InvokeResult();
            return result.Descendants(MessageNs + "ExtendedItem").Select(ExtendedItem.FromXml).ToList();
        }
 public List<ExtendedItem> QueryItemsExtended(Workspace workspace, ItemSpec itemSpec,
                                              DeletedState deletedState, ItemType itemType)
 {
     if (workspace == null)
         return QueryItemsExtended(string.Empty, string.Empty, new List<ItemSpec> { itemSpec }, deletedState, itemType);
     return QueryItemsExtended(workspace.Name, workspace.OwnerName, new List<ItemSpec> { itemSpec }, deletedState, itemType);
 }
 public List<Item> QueryItems(ItemSpec itemSpec, VersionSpec versionSpec,
                              DeletedState deletedState, ItemType itemType, 
                              bool includeDownloadInfo)
 {
     return QueryItems(string.Empty, string.Empty, new [] { itemSpec }, versionSpec, deletedState, itemType, includeDownloadInfo);
 }
 public List<Item> QueryItems(Workspace workspace, ItemSpec itemSpec, VersionSpec versionSpec,
                              DeletedState deletedState, ItemType itemType, 
                              bool includeDownloadInfo)
 {
     if (workspace == null)
         return QueryItems(itemSpec, versionSpec, deletedState, itemType, includeDownloadInfo);
     return QueryItems(workspace.Name, workspace.OwnerName, new [] { itemSpec }, versionSpec, deletedState, itemType, includeDownloadInfo);
 }
Example #38
0
        public ItemSet GetItems(ItemSpec itemSpec, VersionSpec versionSpec,
														DeletedState deletedState, ItemType itemType, 
														bool includeDownloadInfo)
        {
            List<ItemSpec> itemSpecs = new List<ItemSpec>();
            itemSpecs.Add(itemSpec);
            ItemSet[] itemSet = GetItems(itemSpecs.ToArray(), versionSpec, deletedState,
                                                                     itemType, includeDownloadInfo);
            return itemSet[0];
        }
Example #39
0
        public ExtendedItem[][] QueryItemsExtended(string workspaceName, string workspaceOwner, 
																							 ItemSpec[] itemSpecs,	
																							 DeletedState deletedState, ItemType itemType)
        {
            Message msg = new Message(GetWebRequest (new Uri(Url)), "QueryItemsExtended");

            if (!String.IsNullOrEmpty(workspaceName)) msg.Body.WriteElementString("workspaceName", workspaceName);
            if (!String.IsNullOrEmpty(workspaceOwner)) msg.Body.WriteElementString("workspaceOwner", workspaceOwner);

            msg.Body.WriteStartElement("items");
            foreach (ItemSpec itemSpec in itemSpecs)
                {
                    itemSpec.ToXml(msg.Body, "ItemSpec");
                }
            msg.Body.WriteEndElement();

            msg.Body.WriteElementString("deletedState",
                                                                    deletedState.ToString());
            msg.Body.WriteElementString("itemType",
                                                                    itemType.ToString());

            List< ExtendedItem[] > listOfItemArrays = new List<ExtendedItem[] >();
            using (HttpWebResponse response = Invoke(msg))
                {
                    XmlReader results = msg.ResponseReader(response);
                    while (results.Read())
                        {
                            if (results.NodeType == XmlNodeType.Element &&
                                    results.Name == "ArrayOfExtendedItem")
                                {
                                    List<ExtendedItem> items = new List<ExtendedItem>();
                                    while (results.Read())
                                        {
                                            //Console.WriteLine("	 " + results.Name + ":" + results.NodeType);
                                            if (results.NodeType == XmlNodeType.EndElement &&
                                                    results.Name == "ArrayOfExtendedItem") break;
                                            if (results.NodeType == XmlNodeType.Element &&
                                                    results.Name == "ExtendedItem")
                                                items.Add(ExtendedItem.FromXml(this, results));
                                        }
                                    listOfItemArrays.Add(items.ToArray());
                                }
                        }
                }

            return listOfItemArrays.ToArray();
        }
Example #40
0
    public override void Run()
    {
        Workspace workspace = GetWorkspaceFromCache();

        // process command options
        DeletedState  dstate = OptionDeleted ? DeletedState.Any : DeletedState.NonDeleted;
        RecursionType rtype  = OptionRecursive ? RecursionType.Full : RecursionType.OneLevel;

        List <ItemSpec> itemSpecs = new List <ItemSpec>();

        for (int i = 0; i < Arguments.Length; i++)
        {
            string path = Arguments[i];
            if (!VersionControlPath.IsServerItem(path))
            {
                path = Path.GetFullPath(path);
            }
            itemSpecs.Add(new ItemSpec(path, rtype));
        }

        ExtendedItem[][] items = workspace.GetExtendedItems(itemSpecs.ToArray(),
                                                            dstate, ItemType.Any);
        if (items.Length == 0)
        {
            Console.WriteLine("No items match " + Arguments[0]);
            Environment.Exit((int)ExitCode.Failure);
        }

        foreach (ExtendedItem[] itemArray in items)
        {
            foreach (ExtendedItem item in itemArray)
            {
                Console.WriteLine("Local information:");
                Console.WriteLine("	 Local path : " + item.LocalItem);
                Console.WriteLine("	 Server path: " + item.TargetServerItem);
                Console.WriteLine("	 Changeset  : " + item.VersionLocal);
                Console.WriteLine("	 Change     : " + item.ChangeType.ToString().ToLower());
                Console.WriteLine("	 Type       : " + item.ItemType.ToString().ToLower());

                Console.WriteLine("Server information:");
                Console.WriteLine("	 Server path  : " + item.SourceServerItem);
                Console.WriteLine("	 Changeset    : " + item.VersionLatest);
                Console.WriteLine("	 Deletion Id  : " + item.DeletionId);
                Console.WriteLine("	 Lock         : " + item.LockStatus.ToString().ToLower());
                Console.WriteLine("	 Lock Owner   : " + item.LockOwner);
                Console.WriteLine("	 Last Modified: Not Implemented");
                Console.WriteLine("	 Type         : " + item.ItemType.ToString().ToLower());

                Encoding encoding = Encoding.GetEncoding(item.Encoding);
                Console.WriteLine("	 File type    : " + encoding.HeaderName);

                long len = 0;
                if (!String.IsNullOrEmpty(item.LocalItem))
                {
                    FileInfo fi = new FileInfo(item.LocalItem);
                    len = fi.Length;
                }

                Console.WriteLine("	 Size         : " + Convert.ToString(len));
            }
        }
    }
Example #41
0
        public ExtendedItem[][] GetExtendedItems(ItemSpec[] itemSpecs,
																							DeletedState deletedState,
																							ItemType itemType)
        {
            return Repository.QueryItemsExtended(Name, OwnerName,
                                                                                     itemSpecs, deletedState, itemType);
        }
Example #42
0
        public ExtendedItem[] GetExtendedItems(string path,
																					 DeletedState deletedState,
																					 ItemType itemType)
        {
            List<ItemSpec> itemSpecs = new List<ItemSpec>();
            itemSpecs.Add(new ItemSpec(path, RecursionType.OneLevel));
            ExtendedItem[][] items = GetExtendedItems(itemSpecs.ToArray(), deletedState, itemType);

            if (items.Length == 0) return null;
            return items[0];
        }